mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 06:04:42 +02:00
validation: Move block into BlockConnected signal
This makes existing behaviour of the block's destructor triggering on the scheduler thread more explicit by moving it to the thread. The scheduler thread doing so is useful, since it does not block the thread doing validation while releasing a block's memory. Previously, both the caller and the queued event lambda held copies of the shared_ptr. The block would typically be freed on the scheduler thread - but only because it went out of scope before the queued event on the scheduler thread ran. If the scheduler ran first, the block would instead be freed on the validation thread. Now, ownership is transferred at each step when invoking the BlockConnected signal: connected_blocks yields via std::move, BlockConnected takes by value, and the event lambda move-captures the shared_ptr. Though it is possible that this only decrements the block's reference count, blocks are also read from disk in `ConnectTip`, which now explicitly results in their memory being released on the scheduler thread.
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user