mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-22 15:19:05 +00:00
Force update block template after 30 seconds
To get new transactions in
This commit is contained in:
parent
83cda110aa
commit
74b5ab1798
4 changed files with 21 additions and 0 deletions
|
@ -39,6 +39,7 @@ namespace p2pool {
|
||||||
BlockTemplate::BlockTemplate(p2pool* pool)
|
BlockTemplate::BlockTemplate(p2pool* pool)
|
||||||
: m_pool(pool)
|
: m_pool(pool)
|
||||||
, m_templateId(0)
|
, m_templateId(0)
|
||||||
|
, m_lastUpdated(seconds_since_epoch())
|
||||||
, m_blockHeaderSize(0)
|
, m_blockHeaderSize(0)
|
||||||
, m_minerTxOffsetInTemplate(0)
|
, m_minerTxOffsetInTemplate(0)
|
||||||
, m_minerTxSize(0)
|
, m_minerTxSize(0)
|
||||||
|
@ -110,6 +111,7 @@ BlockTemplate& BlockTemplate::operator=(const BlockTemplate& b)
|
||||||
|
|
||||||
m_pool = b.m_pool;
|
m_pool = b.m_pool;
|
||||||
m_templateId = b.m_templateId;
|
m_templateId = b.m_templateId;
|
||||||
|
m_lastUpdated = b.m_lastUpdated.load();
|
||||||
m_blockTemplateBlob = b.m_blockTemplateBlob;
|
m_blockTemplateBlob = b.m_blockTemplateBlob;
|
||||||
m_merkleTreeMainBranch = b.m_merkleTreeMainBranch;
|
m_merkleTreeMainBranch = b.m_merkleTreeMainBranch;
|
||||||
m_blockHeaderSize = b.m_blockHeaderSize;
|
m_blockHeaderSize = b.m_blockHeaderSize;
|
||||||
|
@ -203,6 +205,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet
|
||||||
}
|
}
|
||||||
|
|
||||||
++m_templateId;
|
++m_templateId;
|
||||||
|
m_lastUpdated = seconds_since_epoch();
|
||||||
|
|
||||||
// When block template generation fails for any reason
|
// When block template generation fails for any reason
|
||||||
auto use_old_template = [this]() {
|
auto use_old_template = [this]() {
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
BlockTemplate& operator=(const BlockTemplate& b);
|
BlockTemplate& operator=(const BlockTemplate& b);
|
||||||
|
|
||||||
void update(const MinerData& data, const Mempool& mempool, Wallet* miner_wallet);
|
void update(const MinerData& data, const Mempool& mempool, Wallet* miner_wallet);
|
||||||
|
uint64_t last_updated() const { return m_lastUpdated.load(); }
|
||||||
|
|
||||||
bool get_difficulties(const uint32_t template_id, uint64_t& height, difficulty_type& mainchain_difficulty, difficulty_type& sidechain_difficulty) const;
|
bool get_difficulties(const uint32_t template_id, uint64_t& height, difficulty_type& mainchain_difficulty, difficulty_type& sidechain_difficulty) const;
|
||||||
uint32_t get_hashing_blob(const uint32_t template_id, uint32_t extra_nonce, uint8_t (&blob)[128], uint64_t& height, difficulty_type& difficulty, difficulty_type& sidechain_difficulty, hash& seed_hash, size_t& nonce_offset) const;
|
uint32_t get_hashing_blob(const uint32_t template_id, uint32_t extra_nonce, uint8_t (&blob)[128], uint64_t& height, difficulty_type& difficulty, difficulty_type& sidechain_difficulty, hash& seed_hash, size_t& nonce_offset) const;
|
||||||
|
@ -69,6 +70,7 @@ private:
|
||||||
mutable uv_rwlock_t m_lock;
|
mutable uv_rwlock_t m_lock;
|
||||||
|
|
||||||
uint32_t m_templateId;
|
uint32_t m_templateId;
|
||||||
|
std::atomic<uint64_t> m_lastUpdated;
|
||||||
|
|
||||||
std::vector<uint8_t> m_blockTemplateBlob;
|
std::vector<uint8_t> m_blockTemplateBlob;
|
||||||
std::vector<uint8_t> m_merkleTreeMainBranch;
|
std::vector<uint8_t> m_merkleTreeMainBranch;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "block_cache.h"
|
#include "block_cache.h"
|
||||||
#include "json_rpc_request.h"
|
#include "json_rpc_request.h"
|
||||||
#include "json_parsers.h"
|
#include "json_parsers.h"
|
||||||
|
#include "block_template.h"
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
@ -972,6 +973,7 @@ void P2PServer::on_timer()
|
||||||
save_peer_list_async();
|
save_peer_list_async();
|
||||||
update_peer_connections();
|
update_peer_connections();
|
||||||
check_zmq();
|
check_zmq();
|
||||||
|
check_block_template();
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PServer::flush_cache()
|
void P2PServer::flush_cache()
|
||||||
|
@ -1106,6 +1108,19 @@ void P2PServer::check_zmq()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void P2PServer::check_block_template()
|
||||||
|
{
|
||||||
|
if (!m_pool->side_chain().precalcFinished()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force update block template every 30 seconds after the initial sync is done
|
||||||
|
if (seconds_since_epoch() >= m_pool->block_template().last_updated() + 30) {
|
||||||
|
LOGINFO(4, "block template is 30 seconds old, updating it");
|
||||||
|
m_pool->update_block_template_async();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
P2PServer::P2PClient::P2PClient()
|
P2PServer::P2PClient::P2PClient()
|
||||||
: m_peerId(0)
|
: m_peerId(0)
|
||||||
, m_expectedMessage(MessageId::HANDSHAKE_CHALLENGE)
|
, m_expectedMessage(MessageId::HANDSHAKE_CHALLENGE)
|
||||||
|
|
|
@ -167,6 +167,7 @@ private:
|
||||||
void flush_cache();
|
void flush_cache();
|
||||||
void download_missing_blocks();
|
void download_missing_blocks();
|
||||||
void check_zmq();
|
void check_zmq();
|
||||||
|
void check_block_template();
|
||||||
void update_peer_connections();
|
void update_peer_connections();
|
||||||
void update_peer_list();
|
void update_peer_list();
|
||||||
void send_peer_list_request(P2PClient* client, uint64_t cur_time);
|
void send_peer_list_request(P2PClient* client, uint64_t cur_time);
|
||||||
|
|
Loading…
Reference in a new issue