BlockCache: fixed collisions of same height blocks
This commit is contained in:
+2
-1
@@ -154,6 +154,7 @@ struct BlockCache::Impl : public nocopy_nomove
|
|||||||
BlockCache::BlockCache()
|
BlockCache::BlockCache()
|
||||||
: m_impl(new Impl())
|
: m_impl(new Impl())
|
||||||
, m_flushRunning(0)
|
, m_flushRunning(0)
|
||||||
|
, m_storeIndex(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +172,7 @@ void BlockCache::store(const PoolBlock& block)
|
|||||||
return;
|
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);
|
*reinterpret_cast<uint32_t*>(data) = static_cast<uint32_t>(n1 + n2);
|
||||||
memcpy(data + sizeof(uint32_t), block.m_mainChainData.data(), n1);
|
memcpy(data + sizeof(uint32_t), block.m_mainChainData.data(), n1);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ private:
|
|||||||
struct Impl;
|
struct Impl;
|
||||||
Impl* m_impl;
|
Impl* m_impl;
|
||||||
std::atomic<uint32_t> m_flushRunning;
|
std::atomic<uint32_t> m_flushRunning;
|
||||||
|
std::atomic<uint32_t> m_storeIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace p2pool
|
} // namespace p2pool
|
||||||
|
|||||||
+11
-9
@@ -514,11 +514,6 @@ void SideChain::add_block(const PoolBlock& block)
|
|||||||
", verified = " << (block.m_verified ? 1 : 0)
|
", 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);
|
PoolBlock* new_block = new PoolBlock(block);
|
||||||
|
|
||||||
MutexLock lock(m_sidechainLock);
|
MutexLock lock(m_sidechainLock);
|
||||||
@@ -541,6 +536,11 @@ void SideChain::add_block(const PoolBlock& block)
|
|||||||
if (new_block->m_verified) {
|
if (new_block->m_verified) {
|
||||||
if (!new_block->m_invalid) {
|
if (!new_block->m_invalid) {
|
||||||
update_chain_tip(new_block);
|
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 {
|
else {
|
||||||
@@ -1013,17 +1013,19 @@ void SideChain::verify_loop(PoolBlock* block)
|
|||||||
", height " << block->m_sidechainHeight);
|
", height " << block->m_sidechainHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
P2PServer* server = p2pServer();
|
||||||
|
|
||||||
// If it came through a broadcast, send it to our peers
|
// If it came through a broadcast, send it to our peers
|
||||||
if (block->m_wantBroadcast && !block->m_broadcasted) {
|
if (block->m_wantBroadcast && !block->m_broadcasted) {
|
||||||
block->m_broadcasted = true;
|
block->m_broadcasted = true;
|
||||||
if (p2pServer() && (block->m_depth < UNCLE_BLOCK_DEPTH)) {
|
if (server && (block->m_depth < UNCLE_BLOCK_DEPTH)) {
|
||||||
p2pServer()->broadcast(*block);
|
server->broadcast(*block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save it for faster syncing on the next p2pool start
|
// Save it for faster syncing on the next p2pool start
|
||||||
if (p2pServer()) {
|
if (server) {
|
||||||
p2pServer()->store_in_cache(*block);
|
server->store_in_cache(*block);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to verify blocks on top of this one
|
// Try to verify blocks on top of this one
|
||||||
|
|||||||
Reference in New Issue
Block a user