From 681d3a00e0625863ba3108f2145cbb2a0fb5353b Mon Sep 17 00:00:00 2001 From: aiwe Date: Sun, 5 May 2024 16:10:38 -0500 Subject: [PATCH] Enhance new top block message --- .../CryptoNoteProtocolHandler.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp b/src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp index a849f7b90..3c6ad4c20 100755 --- a/src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp +++ b/src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp @@ -303,19 +303,23 @@ bool CryptoNoteProtocolHandler::process_payload_sync_data(const CORE_SYNC_DATA& } } else { int64_t diff = static_cast(hshd.current_height) - static_cast(get_current_blockchain_height()); + uint64_t blocks = std::abs(diff); + uint64_t days = blocks / (24 * 60 * 60 / m_currency.difficultyTarget()); - // drop and eventually ban if peer is on fork too deep behind us + // drop connection and eventually ban if peer is on fork too deep behind us if (diff < 0 && std::abs(diff) > (int64_t)CryptoNote::parameters::CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW && m_core.isInCheckpointZone(hshd.current_height)) { - logger(Logging::DEBUGGING) << context << "Sync data returned a new top block candidate: " << get_current_blockchain_height() << " -> " << hshd.current_height - << ". Your node is " << std::abs(diff) << " blocks (" << std::abs(diff) / (24 * 60 * 60 / m_currency.difficultyTarget()) << " days) " - << "ahead. The block candidate is too deep behind and in checkpoint zone, dropping connection"; + logger(Logging::DEBUGGING) << context << "There's a new top block candidate: " << get_current_blockchain_height() << " -> " << hshd.current_height + << ". Your node is " << std::to_string(blocks) << " " << ((blocks == 1) ? "block" : "blocks") + << (days > 0 ? " (" + std::to_string(days) + " " + ((days == 1) ? "day" : "days") + ") " : " ") + << "ahead. The block candidate is too deep behind and in checkpoint zone, dropping connection."; m_p2p->drop_connection(context, true); } logger(diff >= 0 ? (is_initial ? Logging::INFO : Logging::DEBUGGING) : Logging::TRACE, Logging::BRIGHT_YELLOW) << context << - "Sync data returned a new top block candidate: " << get_current_blockchain_height() << " -> " << hshd.current_height - << ". Your node is " << std::abs(diff) << " blocks (" << std::abs(diff) / (24 * 60 * 60 / m_currency.difficultyTarget()) << " days) " - << (diff >= 0 ? std::string("behind") : std::string("ahead")) << ". " << std::endl << "Synchronization started"; + "There's a new top block candidate: " << get_current_blockchain_height() << " -> " << hshd.current_height + << ". Your node is " << std::to_string(blocks) << " " << ((blocks == 1) ? "block" : "blocks") + << (days > 0 ? " (" + std::to_string(days) + " " + ((days == 1) ? "day" : "days") + ") " : " ") + << (diff >= 0 ? std::string("behind") : std::string("ahead")) << ". Synchronization started." << std::endl; logger(Logging::DEBUGGING) << "Remote top block height: " << hshd.current_height << ", id: " << hshd.top_id; //let the socket to send response to handshake, but request callback, to let send request data after response