From 1a8361029909be8b81d67544b0975f9225a3a889 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 31 Aug 2021 23:11:58 +0200 Subject: [PATCH] P2PServer: simplified the code a bit --- src/p2p_server.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index e88bc36..493624a 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -1296,15 +1296,17 @@ bool P2PServer::P2PClient::on_block_broadcast(const uint8_t* buf, uint32_t size) m_broadcastedHashes.insert(server->m_block->m_sidechainId); } - if (server->m_block->m_prevId != server->m_pool->miner_data().prev_id) { + const MinerData& miner_data = server->m_pool->miner_data(); + + if (server->m_block->m_prevId != miner_data.prev_id) { // This peer is mining on top of a different Monero block, investigate it const uint64_t peer_height = server->m_block->m_txinGenHeight; - const uint64_t our_height = server->m_pool->miner_data().height; + const uint64_t our_height = miner_data.height; if (peer_height < our_height) { if (our_height - peer_height < 5) { using namespace std::chrono; - const int64_t elapsed_ms = duration_cast(system_clock::now() - server->m_pool->miner_data().time_received).count(); + const int64_t elapsed_ms = duration_cast(system_clock::now() - miner_data.time_received).count(); if ((our_height - peer_height > 1) || (elapsed_ms >= 1000)) { LOGWARN(5, "peer " << static_cast(m_addrString) << " broadcasted a stale block (" << elapsed_ms << " ms late, mainchain height " << peer_height << ", expected >= " << our_height << "), ignoring it"); return true;