What changed, and why it matters
This Monero update fixes a bug in how nodes ask each other for blockchain history. Previously, a node could get stuck or drop a peer when it already knew about some blocks from another connection, because it would not ask for the next batch of hashes. The patch lets a node recognize when it already has enough of a peer's promised chain and request the following chunk instead. It is a network-synchronization robustness improvement rather than a direct theft or remote-code-execution vulnerability.
Treat as a routine bugfix / reliability improvement. Nodes should upgrade in due course to avoid sync stalls, but there is no urgent security patch requirement based on this diff alone. Monitor Monero release notes for any later security framing.
Security signals we found
P2P protocol synchronization logic change
Potential denial-of-service via peer dropping or sync stall
No authentication or cryptographic boundary crossed
No memory-unsafe operations or input parsing changes visible
Evidence from the diff
The commit modifies the P2P cryptonote protocol handler to track whether a chain entry was requested from a known hash and whether the whole entry is already known via other peers or the local main chain. It adds a m_chain_entry_from_requested_hash flag in connection_context.h and uses it in cryptonote_protocol_handler.inl to decide when to call request_chain(false) for the next chain entry instead of erroring out or dropping the peer. It also resets m_last_known_hash to the null hash in two request_chain paths and adds a standby transition when the rest of the current chain entry is already requested from other peers.
Changed components
src/cryptonote_basic/connection_context.hsrc/cryptonote_protocol/cryptonote_protocol_handler.inlInspect captured patch +55 / −0
### src/cryptonote_basic/connection_context.h
@@ -108,6 +108,7 @@ namespace cryptonote
copyable_atomic m_callback_request_count; //in debug purpose: problem with double callback rise
crypto::hash m_last_known_hash;
bool m_refresh_for_next_span = false;
+ bool m_chain_entry_from_requested_hash = false;
uint32_t m_pruning_seed;
uint16_t m_rpc_port;
uint32_t m_rpc_credits_per_hash;
### src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -208,6 +208,7 @@ namespace cryptonote
{
NOTIFY_REQUEST_CHAIN::request r = {};
context.m_needed_objects.clear();
+ context.m_last_known_hash = crypto::null_hash;
m_core.get_short_chain_history(r.block_ids, context.m_expect_height);
handler_request_blocks_history( r.block_ids ); // change the limit(?), sleep(?)
r.prune = m_sync_pruned_blocks;
@@ -721,6 +722,7 @@ namespace cryptonote
else if( bvc.m_marked_as_orphaned )
{
context.m_needed_objects.clear();
+ context.m_last_known_hash = crypto::null_hash;
context.m_state = cryptonote_connection_context::state_synchronizing;
NOTIFY_REQUEST_CHAIN::request r = {};
m_core.get_short_chain_history(r.block_ids, context.m_expect_height);
@@ -2061,6 +2063,10 @@ skip:
CHECK_AND_ASSERT_MES(!r.block_ids.empty(), false, "Short chain history is empty");
// Continue from this peer's last known block, which may still be queued.
+ // One in our main chain is already covered by the chain history.
+ int where;
+ if (context.m_last_known_hash != crypto::null_hash && m_core.have_block_unlocked(context.m_last_known_hash, &where) && where == HAVE_BLOCK_MAIN_CHAIN)
+ context.m_last_known_hash = crypto::null_hash;
if (context.m_last_known_hash != crypto::null_hash && r.block_ids.front() != context.m_last_known_hash)
{
context.m_expect_height = std::numeric_limits<uint64_t>::max();
@@ -2078,6 +2084,31 @@ skip:
return true;
};
+ // a span this peer reserved but did not deliver, as after an idle kick
+ const auto holds_span = [this, &context]() {
+ bool holds = false;
+ m_block_queue.foreach([&context, &holds](const block_queue::span &s) {
+ holds = s.connection_id == context.m_connection_id && s.blocks.empty();
+ return !holds;
+ });
+ return holds;
+ };
+
+ // other connections may have queued or added this peer's whole chain entry
+ const auto chain_entry_known = [this, &context, &holds_span]() {
+ const uint64_t first_height = context.m_expected_heights_start;
+ const uint64_t last_height = context.m_last_response_height;
+ const auto known_at_height = [this](const crypto::hash &hash, uint64_t height) {
+ return m_block_queue.have_height(hash) == height || m_core.get_block_id_by_height(height) == hash;
+ };
+ // a full entry from where we asked, with both ends at the given heights
+ return context.m_chain_entry_from_requested_hash
+ && context.m_expected_heights.size() + HASH_OF_HASHES_STEP > BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT
+ && known_at_height(context.m_expected_heights.front(), first_height)
+ && known_at_height(context.m_last_known_hash, last_height)
+ && !holds_span();
+ };
+
// if we don't need to get next span, and the block queue is full enough, wait a bit
if (!force_next_span)
{
@@ -2108,6 +2139,12 @@ skip:
{
if (context.m_remote_blockchain_height > m_block_queue.get_next_needed_height(bc_height))
{
+ if (chain_entry_known())
+ {
+ MDEBUG(context << "All hashes up to " << context.m_last_response_height << " are known, asking for the next chain entry");
+ check_span_lock.unlock();
+ return request_chain(false);
+ }
MERROR(context << "Nothing we can request from this peer, and we did not request anything previously");
return false;
}
@@ -2292,6 +2329,11 @@ skip:
{
if (context.m_remote_blockchain_height > m_block_queue.get_next_needed_height(m_core.get_current_blockchain_height()))
{
+ if (chain_entry_known())
+ {
+ MDEBUG(context << "All hashes up to " << context.m_last_response_height << " are known, asking for the next chain entry");
+ return request_chain(false);
+ }
MERROR(context << "Nothing we can request from this peer, and we did not request anything previously");
return false;
}
@@ -2434,6 +2476,14 @@ skip:
MLOG_PEER_STATE("Nothing to do for now, switching to normal state");
return true;
}
+ // other connections are still downloading the rest of this peer's chain entry, wait for them
+ if (!context.m_needed_objects.empty() && !holds_span() && std::all_of(context.m_needed_objects.begin(), context.m_needed_objects.end(),
+ [this](const std::pair<crypto::hash, uint64_t> &o) { return m_block_queue.requested(o.first); }))
+ {
+ context.m_state = cryptonote_connection_context::state_standby;
+ MLOG_PEER_STATE("Rest of the chain entry is requested from other peers, waiting");
+ return true;
+ }
MLOG_PEER_STATE("We can download nothing from this peer, dropping");
return false;
}
@@ -2644,6 +2694,10 @@ skip:
}
context.m_expected_heights_start = arg.start_height;
+ // we asked from the last known hash, or from our top block when there is none
+ context.m_chain_entry_from_requested_hash = context.m_last_known_hash == crypto::null_hash
+ ? arg.start_height + 1 == context.m_expect_height
+ : arg.m_block_ids.front() == context.m_last_known_hash;
context.m_expected_heights.clear();
context.m_expected_heights.reserve(arg.m_block_ids.size());Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.