kernel: improve BlockChecked ownership semantics

Subscribers to the BlockChecked validation interface event may need
access to the block outside of the callback scope. Currently, this
is only possible by copying the block, which makes exposing this
validation interface event publicly either cumbersome or with significant
copy overhead.

By using shared_ptr, we make the shared ownership explicit and allow
users to safely use the block outside of the callback scope.
This commit is contained in:
stickies-v
2025-07-28 13:57:52 +01:00
parent 9ba1fff29e
commit 1d9f1cb4bd
8 changed files with 24 additions and 22 deletions

View File

@@ -3178,7 +3178,7 @@ bool Chainstate::ConnectTip(
CCoinsViewCache view(&CoinsTip());
bool rv = ConnectBlock(*block_to_connect, state, pindexNew, view);
if (m_chainman.m_options.signals) {
m_chainman.m_options.signals->BlockChecked(*block_to_connect, state);
m_chainman.m_options.signals->BlockChecked(block_to_connect, state);
}
if (!rv) {
if (state.IsInvalid())
@@ -4554,7 +4554,7 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& blo
}
if (!ret) {
if (m_options.signals) {
m_options.signals->BlockChecked(*block, state);
m_options.signals->BlockChecked(block, state);
}
LogError("%s: AcceptBlock FAILED (%s)\n", __func__, state.ToString());
return false;