From 69533fd20994ccb6b6bbd2fa3e55648bc1869771 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 24 Aug 2021 13:46:38 +0200 Subject: [PATCH] Store only fully verified blocks in the cache --- src/p2p_server.cpp | 4 +--- src/side_chain.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index b73500f..557563a 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -120,7 +120,7 @@ void P2PServer::add_cached_block(const PoolBlock& block) void P2PServer::store_in_cache(const PoolBlock& block) { - if (m_cache) { + if (m_cache && block.m_verified && !block.m_invalid) { m_cache->store(block); } } @@ -1323,8 +1323,6 @@ bool P2PServer::P2PClient::handle_incoming_block_async(PoolBlock* block) return true; } - server->store_in_cache(*block); - struct Work { uv_work_t req; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 79e87c6..06ef897 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -441,6 +441,9 @@ void SideChain::add_block(const PoolBlock& block) ", verified = " << (block.m_verified ? 1 : 0) ); + // Save it for faster syncing on the next p2pool start + m_pool->p2p_server()->store_in_cache(block); + PoolBlock* new_block = new PoolBlock(block); MutexLock lock(m_sidechainLock); @@ -816,6 +819,9 @@ void SideChain::verify_loop(PoolBlock* block) } } + // Save it for faster syncing on the next p2pool start + m_pool->p2p_server()->store_in_cache(*block); + // Try to verify blocks on top of this one for (size_t i = 1; i <= UNCLE_BLOCK_DEPTH; ++i) { auto it = m_blocksByHeight.find(block->m_sidechainHeight + i);