cryptonote_core: fully parse incoming block batches
What changed, and why it matters
This change alters how Monero processes batches of incoming blocks. Previously, if any block in a batch was already known, the code would skip fully parsing the remaining blocks. Now it parses all blocks regardless. This could have hidden a bug where incomplete parsing led to inconsistent state, but the patch itself is small and the exact security impact is not stated by the vendor.
Treat as a routine correctness fix; review related block-handling paths for similar early-exit patterns and monitor for follow-up security advisories from the Monero project.
Security signals we found
Logic change in block ingestion path
Early-exit removal in batch parsing
Potential state-consistency issue mitigated by full parsing
Evidence from the diff
In Blockchain::prepare_handle_incoming_blocks, the loop that parses extra incoming blocks used to terminate early when blocks_exist became true (i < extra && !blocks_exist). The patch removes that early-exit condition and adds !blocks_exist guards around the have_block(block_hash) checks so that parsing continues for the entire batch. This ensures every block in the batch is parsed and validated even when some are already present locally.
Changed components
src/cryptonote_core/blockchain.cppBlockchain::prepare_handle_incoming_blocksInspect captured patch +3 / −3
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 6a90211..e222756 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -4972,14 +4972,14 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
return true;
}
}
- if (have_block(block_hash))
+ if (!blocks_exist && have_block(block_hash))
blocks_exist = true;
std::advance(it, 1);
}
}
- for (unsigned i = 0; i < extra && !blocks_exist; i++, blockidx++)
+ for (unsigned i = 0; i < extra; i++, blockidx++)
{
block &block = blocks[blockidx];
crypto::hash block_hash;
@@ -4987,7 +4987,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
if (!parse_and_validate_block_from_blob(it->block, block, block_hash))
return false;
- if (have_block(block_hash))
+ if (!blocks_exist && have_block(block_hash))
blocks_exist = true;
std::advance(it, 1);
Why this scored 44/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.