validation: Move block into BlockDisconnected signal
What changed, and why it matters
This commit is a small internal cleanup in how Bitcoin Core notifies other parts of the program when a block is disconnected from the chain. It changes the notification so that ownership of the block data is transferred into the background scheduler thread, making the existing behavior more explicit. There is no indication this fixes a security vulnerability or introduces a new attack.
No security action required. Treat as routine code maintenance. Reviewers may optionally verify that no consumers of BlockDisconnected rely on the shared_ptr outliving the signal dispatch, though the move semantics preserve shared ownership semantics.
Security signals we found
No security-relevant keywords in commit title or message
Change is a refactor/cleanup of object lifetime and thread ownership
No bounds checks, input validation, or cryptographic changes
No incident or vulnerability disclosure references supplied
Evidence from the diff
The patch modifies the BlockDisconnected validation signal to take a std::shared_ptr
Changed components
src/validation.cppsrc/validationinterface.cppsrc/validationinterface.hInspect captured patch +4 / −4
diff --git a/src/validation.cpp b/src/validation.cpp
index f9cc7d78..00c1bab5 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2982,7 +2982,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
// Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted:
if (m_chainman.m_options.signals) {
- m_chainman.m_options.signals->BlockDisconnected(pblock, pindexDelete);
+ m_chainman.m_options.signals->BlockDisconnected(std::move(pblock), pindexDelete);
}
return true;
}
diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp
index 3e939de9..45f38b37 100644
--- a/src/validationinterface.cpp
+++ b/src/validationinterface.cpp
@@ -241,12 +241,12 @@ void ValidationSignals::MempoolTransactionsRemovedForBlock(const std::vector<Rem
ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
}
-void ValidationSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
+void ValidationSignals::BlockDisconnected(std::shared_ptr<const CBlock> pblock, const CBlockIndex* pindex)
{
auto log_msg = LOG_MSG("%s: block hash=%s block height=%d", __func__,
pblock->GetHash().ToString(),
pindex->nHeight);
- auto event = [pblock, pindex, this] {
+ auto event = [pblock = std::move(pblock), pindex, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockDisconnected(pblock, pindex); });
};
ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
diff --git a/src/validationinterface.h b/src/validationinterface.h
index 641afd55..8cfe4138 100644
--- a/src/validationinterface.h
+++ b/src/validationinterface.h
@@ -224,7 +224,7 @@ public:
void TransactionRemovedFromMempool(const CTransactionRef&, MemPoolRemovalReason, uint64_t mempool_sequence);
void MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>&, unsigned int nBlockHeight);
void BlockConnected(const kernel::ChainstateRole&, std::shared_ptr<const CBlock>, const CBlockIndex* pindex);
- void BlockDisconnected(const std::shared_ptr<const CBlock> &, const CBlockIndex* pindex);
+ void BlockDisconnected(std::shared_ptr<const CBlock>, const CBlockIndex* pindex);
void ChainStateFlushed(const kernel::ChainstateRole&, const CBlockLocator&);
void BlockChecked(const std::shared_ptr<const CBlock>&, const BlockValidationState&);
void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr<const CBlock>&);
Why this scored 16/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.