Blockchain: cancel pop_blocks() operation on interupt
What changed, and why it matters
This change makes Monero's blockchain rewind operation stop early if the user sends an interrupt signal (Ctrl-C). Previously, the code would keep popping blocks even after being told to cancel, which could leave the blockchain database in an inconsistent or poorly defined state. The fix is a one-line check of a cancellation flag inside the loop that removes blocks.
Treat as a low-severity robustness improvement. Review whether `pop_blocks()` callers handle an early-exit count correctly and consider adding higher-level rollback or idempotency guarantees for interrupted rewinds. No urgent security patch cycle is indicated by the diff alone.
Security signals we found
SIGINT handling now propagates into a state-mutating blockchain loop
Potential for partially-rewound blockchain state if interrupted mid-operation
No explicit synchronization or rollback beyond the cancellation flag check
Evidence from the diff
In Blockchain::pop_blocks(), the while loop now checks !m_cancel.load() in addition to i < nblocks. m_cancel is set to true by Blockchain::cancel(), which is invoked on SIGINT. Without this guard, a long-running pop_blocks() could continue modifying the database after a shutdown was requested, potentially producing a partially-rewound chain. The patch is minimal and does not add rollback, atomicity, or recovery logic; it only makes the loop responsive to the existing cancellation signal.
Changed components
src/cryptonote_core/blockchain.cppBlockchain::pop_blocks()Blockchain::cancel()Inspect captured patch +1 / −1
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 171087d..ce330f3 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -562,7 +562,7 @@ void Blockchain::pop_blocks(uint64_t nblocks)
const uint64_t blockchain_height = m_db->height();
if (blockchain_height > 0)
nblocks = std::min(nblocks, blockchain_height - 1);
- while (i < nblocks)
+ while (i < nblocks && !m_cancel.load())
{
pop_block_from_blockchain();
++i;
Why this scored 21/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.