Added block verification test
This commit is contained in:
@@ -57,6 +57,7 @@ static constexpr uint8_t default_consensus_id[HASH_SIZE] = {
|
||||
|
||||
SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
|
||||
: m_pool(pool)
|
||||
, m_p2pServer(pool ? pool->p2p_server() : nullptr)
|
||||
, m_networkType(type)
|
||||
, m_chainTip(nullptr)
|
||||
, m_poolName(pool_name ? pool_name : "default")
|
||||
@@ -492,8 +493,8 @@ void SideChain::add_block(const PoolBlock& block)
|
||||
);
|
||||
|
||||
// Save it for faster syncing on the next p2pool start
|
||||
if (m_pool->p2p_server()) {
|
||||
m_pool->p2p_server()->store_in_cache(block);
|
||||
if (m_p2pServer) {
|
||||
m_p2pServer->store_in_cache(block);
|
||||
}
|
||||
|
||||
PoolBlock* new_block = new PoolBlock(block);
|
||||
@@ -973,14 +974,14 @@ void SideChain::verify_loop(PoolBlock* block)
|
||||
// If it came through a broadcast, send it to our peers
|
||||
if (block->m_wantBroadcast && !block->m_broadcasted) {
|
||||
block->m_broadcasted = true;
|
||||
if (m_pool->p2p_server() && (block->m_depth < UNCLE_BLOCK_DEPTH)) {
|
||||
m_pool->p2p_server()->broadcast(*block);
|
||||
if (m_p2pServer && (block->m_depth < UNCLE_BLOCK_DEPTH)) {
|
||||
m_p2pServer->broadcast(*block);
|
||||
}
|
||||
}
|
||||
|
||||
// Save it for faster syncing on the next p2pool start
|
||||
if (m_pool->p2p_server()) {
|
||||
m_pool->p2p_server()->store_in_cache(*block);
|
||||
if (m_p2pServer) {
|
||||
m_p2pServer->store_in_cache(*block);
|
||||
}
|
||||
|
||||
// Try to verify blocks on top of this one
|
||||
@@ -1316,7 +1317,9 @@ void SideChain::update_chain_tip(PoolBlock* block)
|
||||
", main chain height = " << log::Gray() << m_chainTip->m_txinGenHeight);
|
||||
|
||||
block->m_wantBroadcast = true;
|
||||
m_pool->update_block_template_async();
|
||||
if (m_pool) {
|
||||
m_pool->update_block_template_async();
|
||||
}
|
||||
prune_old_blocks();
|
||||
}
|
||||
}
|
||||
@@ -1332,7 +1335,7 @@ void SideChain::update_chain_tip(PoolBlock* block)
|
||||
m_pool->update_block_template_async();
|
||||
}
|
||||
|
||||
if (m_pool->p2p_server() && block->m_wantBroadcast && !block->m_broadcasted) {
|
||||
if (m_p2pServer && block->m_wantBroadcast && !block->m_broadcasted) {
|
||||
block->m_broadcasted = true;
|
||||
#ifdef DEBUG_BROADCAST_DELAY_MS
|
||||
struct Work
|
||||
@@ -1343,7 +1346,7 @@ void SideChain::update_chain_tip(PoolBlock* block)
|
||||
};
|
||||
Work* work = new Work{};
|
||||
work->req.data = work;
|
||||
work->server = m_pool->p2p_server();
|
||||
work->server = m_p2pServer;
|
||||
work->block = block;
|
||||
const int err = uv_queue_work(uv_default_loop(), &work->req,
|
||||
[](uv_work_t*)
|
||||
@@ -1362,7 +1365,7 @@ void SideChain::update_chain_tip(PoolBlock* block)
|
||||
LOGERR(1, "update_chain_tip: uv_queue_work failed, error " << uv_err_name(err));
|
||||
}
|
||||
#else
|
||||
m_pool->p2p_server()->broadcast(*block);
|
||||
m_p2pServer->broadcast(*block);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1583,7 +1586,9 @@ void SideChain::prune_old_blocks()
|
||||
|
||||
// If side-chain started pruning blocks it means the initial sync is complete
|
||||
// It's now safe to delete cached blocks
|
||||
m_pool->p2p_server()->clear_cached_blocks();
|
||||
if (m_p2pServer) {
|
||||
m_p2pServer->clear_cached_blocks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace p2pool {
|
||||
|
||||
class p2pool;
|
||||
class P2PServer;
|
||||
struct DifficultyData;
|
||||
struct PoolBlock;
|
||||
class Wallet;
|
||||
@@ -71,10 +72,13 @@ public:
|
||||
time_t last_updated() const;
|
||||
bool is_default() const;
|
||||
|
||||
const PoolBlock* chainTip() const { return m_chainTip; }
|
||||
|
||||
static bool split_reward(uint64_t reward, const std::vector<MinerShare>& shares, std::vector<uint64_t>& rewards);
|
||||
|
||||
private:
|
||||
p2pool* m_pool;
|
||||
P2PServer* m_p2pServer;
|
||||
NetworkType m_networkType;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user