I considered this but decided not to, because we can't use a similar pattern for pblock and it doesn't simplify things - just moves the asserts to different places. I don't really have a preference either way, if you feel like the reference is better here I'm happy to update it.
<details>
<summary>git diff on 2f8f2e9001</summary>
diff --git a/src/validation.cpp b/src/validation.cpp
index 83c16867fe..873c269335 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2988,7 +2988,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
}
struct ConnectedBlock {
- const CBlockIndex* pindex;
+ CBlockIndex& pindex;
std::shared_ptr<const CBlock> pblock;
};
@@ -3099,7 +3099,7 @@ bool Chainstate::ConnectTip(
Chainstate& current_cs{m_chainman.CurrentChainstate()};
m_chainman.MaybeValidateSnapshot(*this, current_cs);
- connected_blocks.emplace_back(pindexNew, std::move(block_to_connect));
+ connected_blocks.emplace_back(*Assert(pindexNew), std::move(block_to_connect));
return true;
}
@@ -3393,7 +3393,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
for (const auto& [index, block] : 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, Assert(block), &index);
}
}
</details>