cryptonote_core: try-catch in prepare same as cleanup
What changed, and why it matters
This change wraps a blockchain preparation step in a safety net so that if something unexpectedly throws an error, the node still runs cleanup code instead of leaving locks or state in an inconsistent condition. It is a defensive hardening patch rather than a clear fix for a known exploitable bug.
Treat as a low-to-moderate hardening improvement. Review whether any other callers of prepare_handle_incoming_blocks or similar lock-and-cleanup patterns lack exception handling. No immediate emergency response is indicated by the diff alone.
Security signals we found
Exception bypassing cleanup could leave m_incoming_tx_lock locked, causing deadlock or denial of service
Missing exception handling in blockchain block preparation path
Defensive hardening to ensure cleanup runs on all failure paths
Evidence from the diff
The commit modifies core::prepare_handle_incoming_blocks to catch exceptions thrown by m_blockchain_storage.prepare_handle_incoming_blocks. Previously, an exception would bypass the function, leaving m_incoming_tx_lock held and skipping cleanup_handle_incoming_blocks. The patch catches std::exception and unknown exceptions, logs an error, and then proceeds to cleanup and return false. This aligns exception handling with the existing cleanup path used on failure.
Changed components
src/cryptonote_core/cryptonote_core.cppcore::prepare_handle_incoming_blocksm_blockchain_storage.prepare_handle_incoming_blocksInspect captured patch +5 / −1
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 473afa4..999442c 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1407,7 +1407,11 @@ namespace cryptonote
bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks)
{
m_incoming_tx_lock.lock();
- if (!m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks))
+ bool success = false;
+ try { success = m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks); }
+ catch (const std::exception &e) { MERROR("Failed prepare handle incoming blocks: " << e.what()); }
+ catch (...) { MERROR("Failed prepare handling incoming blocks"); }
+ if (!success)
{
cleanup_handle_incoming_blocks(false);
return false;
Why this scored 32/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.