mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-12 09:29:51 +00:00
BlockCache: fixed collisions of same height blocks
This commit is contained in:
parent
cdc3206ee8
commit
8b27faad6d
3 changed files with 14 additions and 10 deletions
|
@ -154,6 +154,7 @@ struct BlockCache::Impl : public nocopy_nomove
|
|||
BlockCache::BlockCache()
|
||||
: m_impl(new Impl())
|
||||
, m_flushRunning(0)
|
||||
, m_storeIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -171,7 +172,7 @@ void BlockCache::store(const PoolBlock& block)
|
|||
return;
|
||||
}
|
||||
|
||||
uint8_t* data = m_impl->m_data + (static_cast<size_t>(block.m_sidechainHeight % NUM_BLOCKS) * BLOCK_SIZE);
|
||||
uint8_t* data = m_impl->m_data + (static_cast<size_t>((m_storeIndex++) % NUM_BLOCKS) * BLOCK_SIZE);
|
||||
|
||||
*reinterpret_cast<uint32_t*>(data) = static_cast<uint32_t>(n1 + n2);
|
||||
memcpy(data + sizeof(uint32_t), block.m_mainChainData.data(), n1);
|
||||
|
|
|
@ -37,6 +37,7 @@ private:
|
|||
struct Impl;
|
||||
Impl* m_impl;
|
||||
std::atomic<uint32_t> m_flushRunning;
|
||||
std::atomic<uint32_t> m_storeIndex;
|
||||
};
|
||||
|
||||
} // namespace p2pool
|
||||
|
|
|
@ -514,11 +514,6 @@ void SideChain::add_block(const PoolBlock& block)
|
|||
", verified = " << (block.m_verified ? 1 : 0)
|
||||
);
|
||||
|
||||
// Save it for faster syncing on the next p2pool start
|
||||
if (p2pServer()) {
|
||||
p2pServer()->store_in_cache(block);
|
||||
}
|
||||
|
||||
PoolBlock* new_block = new PoolBlock(block);
|
||||
|
||||
MutexLock lock(m_sidechainLock);
|
||||
|
@ -541,6 +536,11 @@ void SideChain::add_block(const PoolBlock& block)
|
|||
if (new_block->m_verified) {
|
||||
if (!new_block->m_invalid) {
|
||||
update_chain_tip(new_block);
|
||||
|
||||
// Save it for faster syncing on the next p2pool start
|
||||
if (P2PServer* server = p2pServer()) {
|
||||
server->store_in_cache(*new_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1013,17 +1013,19 @@ void SideChain::verify_loop(PoolBlock* block)
|
|||
", height " << block->m_sidechainHeight);
|
||||
}
|
||||
|
||||
P2PServer* server = p2pServer();
|
||||
|
||||
// If it came through a broadcast, send it to our peers
|
||||
if (block->m_wantBroadcast && !block->m_broadcasted) {
|
||||
block->m_broadcasted = true;
|
||||
if (p2pServer() && (block->m_depth < UNCLE_BLOCK_DEPTH)) {
|
||||
p2pServer()->broadcast(*block);
|
||||
if (server && (block->m_depth < UNCLE_BLOCK_DEPTH)) {
|
||||
server->broadcast(*block);
|
||||
}
|
||||
}
|
||||
|
||||
// Save it for faster syncing on the next p2pool start
|
||||
if (p2pServer()) {
|
||||
p2pServer()->store_in_cache(*block);
|
||||
if (server) {
|
||||
server->store_in_cache(*block);
|
||||
}
|
||||
|
||||
// Try to verify blocks on top of this one
|
||||
|
|
Loading…
Reference in a new issue