m_target_blockhash is paired with a mutable m_cached_target_block that must be kept in sync whenever the hash changes.
Refactor, no behaviour change.
Addresses #36137 (review)
m_target_blockhash is paired with a mutable m_cached_target_block that must be kept in sync whenever the hash changes.
Refactor, no behaviour change.
Addresses #36137 (review)
m_target_blockhash is paired with a mutable m_cached_target_block that
must be kept in sync whenever the hash changes.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36166.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline and AI policy for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | kevkevinpal, purpleKarrot, l0rinc, alexanderwiederin, sedited |
If your review is incorrectly listed, please copy-paste <code><!--meta-tag:bot-skip--></code> into the comment that the bot should ignore.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
ACK 852f201
This looks good to me it moves m_target_blockhash from public to protected and adds setters to interface with it while keeping the cache in sync
ACK 852f201e09cb98e98ad7418ae11933203cd57896
It is a good approach to no longer let clients break that invariant. But why still allow it to derived classes? Data members should better be private, not protected.
PS: I read elsewhere that encapsulation "simply buys code churn and inefficiency", so I am triggered whenever I come across encapsulation in this project. If you believe encapsulation to be a good thing, then I would also appreciate your voice in that PR.
code review ACK 852f201e09cb98e98ad7418ae11933203cd57896
m_target_blockhash and m_cached_target_block must stay in sync, closing off direct writes makes sense - either protected or private works, both beat the previous public member.
5992 | @@ -5993,8 +5993,8 @@ SnapshotCompletionResult ChainstateManager::MaybeValidateSnapshot(Chainstate& va 5993 | validated_cs.m_assumeutxo != Assumeutxo::VALIDATED || 5994 | !validated_cs.m_chain.Tip() || 5995 | // Or the validated chainstate is not targeting the snapshot block... 5996 | - !validated_cs.m_target_blockhash || 5997 | - *validated_cs.m_target_blockhash != *unvalidated_cs.m_from_snapshot_blockhash || 5998 | + !validated_cs.TargetBlockHash() || 5999 | + *validated_cs.TargetBlockHash() != *unvalidated_cs.m_from_snapshot_blockhash ||
nit: a local const auto target{validated_cs.TargetBlockHash()} would be tidier
🙏
ACK 852f201e09cb98e98ad7418ae11933203cd57896
ACK 852f201e09cb98e98ad7418ae11933203cd57896