Add CAP exchange protocol, Deadlock fix, Sync stuck fix with retry mechanism

This commit is contained in:
Matt Hess
2025-12-17 00:29:41 +00:00
parent 940f1cabe8
commit 11b545e91b
10 changed files with 1101 additions and 117 deletions
+20 -16
View File
@@ -191,7 +191,7 @@ void BlockCache::store(const PoolBlock& block)
memcpy(data + sizeof(uint32_t) + n1, sidechain_data.data(), n2);
}
void BlockCache::load_all(const SideChain& side_chain, P2PServer& server)
void BlockCache::load_all(SideChain& side_chain, P2PServer& server)
{
// Check cache version - invalidates on recompile
const std::string version_path = DATA_DIR + "p2pool.cache.version";
@@ -221,26 +221,30 @@ void BlockCache::load_all(const SideChain& side_chain, P2PServer& server)
return;
}
LOGINFO(1, "loading cached blocks");
LOGINFO(1, "Loading cached blocks...");
PoolBlock block;
uint32_t blocks_loaded = 0;
PoolBlock block;
uint32_t blocks_loaded = 0;
for (uint64_t i = 0; i < NUM_BLOCKS; ++i) {
const uint8_t* data = m_impl->m_data + i * BLOCK_SIZE;
const uint32_t n = *reinterpret_cast<const uint32_t*>(data);
for (uint64_t i = 0; i < NUM_BLOCKS; ++i) {
const uint8_t* data = m_impl->m_data + i * BLOCK_SIZE;
const uint32_t n = *reinterpret_cast<const uint32_t*>(data);
if (!n || (n + sizeof(uint32_t) > BLOCK_SIZE)) {
continue;
}
if (!n || (n + sizeof(uint32_t) > BLOCK_SIZE)) {
continue;
}
if (block.deserialize(data + sizeof(uint32_t), n, side_chain, uv_default_loop_checked(), false) == 0) {
server.add_cached_block(block);
++blocks_loaded;
}
}
if (block.deserialize(data + sizeof(uint32_t), n, side_chain, uv_default_loop_checked(), false) == 0) {
server.add_cached_block(block);
++blocks_loaded;
}
}
LOGINFO(1, "loaded " << blocks_loaded << " cached blocks");
if (blocks_loaded > 0) {
LOGINFO(1, "Loaded " << blocks_loaded << " blocks from cache");
} else {
LOGINFO(1, "Cache empty, will sync from peers");
}
}
void BlockCache::flush()