validation: Move block into BlockConnected signal
What changed, and why it matters
This commit is a small internal cleanup in how Bitcoin Core hands off newly connected blocks to background notification threads. It moves a block's shared ownership explicitly onto the scheduler thread so the heavy validation thread is not delayed by memory cleanup. There is no user-facing bug fix or security vulnerability being patched; it is a performance and clarity improvement.
No security action required. Treat as routine code-quality/performance improvement during normal review.
Security signals we found
No memory-safety bug is fixed; the change is defensive and deterministic
No input validation, cryptography, or network parsing changes
No privilege boundary or authorization change
No CVE, advisory, or vendor security disclosure referenced in commit
Evidence from the diff
The change transfers ownership of std::shared_ptr
Changed components
src/validation.cppsrc/validationinterface.cppsrc/validationinterface.hInspect captured patch +5 / −5
diff --git a/src/validation.cpp b/src/validation.cpp
index 1efe109b..f9cc7d78 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3391,9 +3391,9 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
}
pindexNewTip = m_chain.Tip();
- for (const auto& [index, block] : connected_blocks) {
+ for (auto& [index, block] : std::move(connected_blocks)) {
if (m_chainman.m_options.signals) {
- m_chainman.m_options.signals->BlockConnected(chainstate_role, Assert(block), Assert(index));
+ m_chainman.m_options.signals->BlockConnected(chainstate_role, std::move(Assert(block)), Assert(index));
}
}
diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp
index 3c142f8d..3e939de9 100644
--- a/src/validationinterface.cpp
+++ b/src/validationinterface.cpp
@@ -219,12 +219,12 @@ void ValidationSignals::TransactionRemovedFromMempool(const CTransactionRef& tx,
ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
}
-void ValidationSignals::BlockConnected(const ChainstateRole& role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
+void ValidationSignals::BlockConnected(const ChainstateRole& role, 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 = [role, pblock, pindex, this] {
+ auto event = [role, pblock = std::move(pblock), pindex, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); });
};
ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
diff --git a/src/validationinterface.h b/src/validationinterface.h
index 4777e8dc..641afd55 100644
--- a/src/validationinterface.h
+++ b/src/validationinterface.h
@@ -223,7 +223,7 @@ public:
void TransactionAddedToMempool(const NewMempoolTransactionInfo&, uint64_t mempool_sequence);
void TransactionRemovedFromMempool(const CTransactionRef&, MemPoolRemovalReason, uint64_t mempool_sequence);
void MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>&, unsigned int nBlockHeight);
- void BlockConnected(const kernel::ChainstateRole&, const std::shared_ptr<const CBlock>&, const CBlockIndex* pindex);
+ 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 ChainStateFlushed(const kernel::ChainstateRole&, const CBlockLocator&);
void BlockChecked(const std::shared_ptr<const CBlock>&, const BlockValidationState&);
Why this scored 17/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.