From 255d312ae0d03171dd31a2fab5fbb87e508c4024 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 2 Nov 2022 12:49:12 +0100 Subject: [PATCH] SideChain: log blocks with the same id --- src/p2p_server.cpp | 2 +- src/pool_block.h | 12 ++++++++++++ src/side_chain.cpp | 22 ++++++++++++++++------ src/side_chain.h | 6 ++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 2002fd9..e98e95f 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -2063,7 +2063,7 @@ bool P2PServer::P2PClient::handle_incoming_block_async(const PoolBlock* block) P2PServer* server = static_cast(m_owner); if (server->m_pool->side_chain().block_seen(*block)) { - LOGINFO(6, "block " << block->m_sidechainId << " was received before, skipping it"); + LOGINFO(6, "block " << block->m_sidechainId << " (nonce " << block->m_nonce << ", extra_nonce " << block->m_extraNonce << ") was received before, skipping it"); return true; } diff --git a/src/pool_block.h b/src/pool_block.h index ba06155..f17c24e 100644 --- a/src/pool_block.h +++ b/src/pool_block.h @@ -145,6 +145,18 @@ struct PoolBlock // Both tx types are allowed by Monero consensus during v15 because it needs to process pre-fork mempool transactions, // but P2Pool can switch to using only TXOUT_TO_TAGGED_KEY for miner payouts starting from v15 FORCEINLINE uint8_t get_tx_type() const { return (m_majorVersion < HARDFORK_VIEW_TAGS_VERSION) ? TXOUT_TO_KEY : TXOUT_TO_TAGGED_KEY; } + + typedef std::array full_id; + + FORCEINLINE full_id get_full_id() const + { + full_id key; + uint8_t* p = key.data(); + memcpy(p, m_sidechainId.h, HASH_SIZE); + memcpy(p + HASH_SIZE, &m_nonce, NONCE_SIZE); + memcpy(p + HASH_SIZE + NONCE_SIZE, &m_extraNonce, EXTRA_NONCE_SIZE); + return key; + } }; } // namespace p2pool diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 97dba75..8f4bc6e 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -453,13 +453,13 @@ bool SideChain::block_seen(const PoolBlock& block) // Check if it was received before MutexLock lock(m_seenBlocksLock); - return !m_seenBlocks.insert(block.m_sidechainId).second; + return !m_seenBlocks.insert(block.get_full_id()).second; } void SideChain::unsee_block(const PoolBlock& block) { MutexLock lock(m_seenBlocksLock); - m_seenBlocks.erase(block.m_sidechainId); + m_seenBlocks.erase(block.get_full_id()); } bool SideChain::add_external_block(PoolBlock& block, std::vector& missing_blocks) @@ -604,10 +604,20 @@ void SideChain::add_block(const PoolBlock& block) auto result = m_blocksById.insert({ new_block->m_sidechainId, new_block }); if (!result.second) { - LOGWARN(3, "add_block: trying to add the same block twice, id = " - << new_block->m_sidechainId << ", sidechain height = " - << new_block->m_sidechainHeight << ", height = " - << new_block->m_txinGenHeight); + const PoolBlock* old_block = result.first->second; + + LOGWARN(3, "add_block: trying to add the same block twice:" + << "\nnew block id = " << new_block->m_sidechainId + << ", sidechain height = " << new_block->m_sidechainHeight + << ", height = " << new_block->m_txinGenHeight + << ", nonce = " << new_block->m_nonce + << ", extra_nonce = " << new_block->m_extraNonce + << "\nold block id = " << old_block->m_sidechainId + << ", sidechain height = " << old_block->m_sidechainHeight + << ", height = " << old_block->m_txinGenHeight + << ", nonce = " << old_block->m_nonce + << ", extra_nonce = " << old_block->m_extraNonce + ); delete new_block; return; diff --git a/src/side_chain.h b/src/side_chain.h index 1b14de6..13f357f 100644 --- a/src/side_chain.h +++ b/src/side_chain.h @@ -18,6 +18,7 @@ #pragma once #include "uv_util.h" +#include "pool_block.h" #include #include @@ -25,9 +26,6 @@ namespace p2pool { class p2pool; class P2PServer; -struct DifficultyData; -struct PoolBlock; -class Wallet; struct MinerShare { @@ -112,7 +110,7 @@ private: uint64_t m_seenWalletsLastPruneTime; uv_mutex_t m_seenBlocksLock; - unordered_set m_seenBlocks; + unordered_set m_seenBlocks; std::vector m_difficultyData;