refactor: untangle assumevalid decision branches

Flatten nested conditionals into a linear gating sequence for readability and precise logging. No functional change, TODOs are addressed in next commit
This commit is contained in:
Lőrinc committed 2025-10-01 23:34:23 -04:00
1 parent 9bc298556c
commit f2ea6f04e7
1 file changed
+16 -7
+16 -7
View File
@@ -2424,17 +2424,27 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
} }
bool fScriptChecks = true; bool fScriptChecks = true;
if (!m_chainman.AssumedValidBlock().IsNull()) { if (m_chainman.AssumedValidBlock().IsNull()) {
// TODO
} else {
constexpr int64_t TWO_WEEKS_IN_SECONDS{60 * 60 * 24 * 7 * 2};
// We've been configured with the hash of a block which has been externally verified to have a valid history. // We've been configured with the hash of a block which has been externally verified to have a valid history.
// A suitable default value is included with the software and updated from time to time. Because validity // A suitable default value is included with the software and updated from time to time. Because validity
// relative to a piece of software is an objective fact these defaults can be easily reviewed. // relative to a piece of software is an objective fact these defaults can be easily reviewed.
// This setting doesn't force the selection of any particular chain but makes validating some faster by // This setting doesn't force the selection of any particular chain but makes validating some faster by
// effectively caching the result of part of the verification. // effectively caching the result of part of the verification.
BlockMap::const_iterator it{m_blockman.m_block_index.find(m_chainman.AssumedValidBlock())}; BlockMap::const_iterator it{m_blockman.m_block_index.find(m_chainman.AssumedValidBlock())};
if (it != m_blockman.m_block_index.end()) { if (it == m_blockman.m_block_index.end()) {
if (it->second.GetAncestor(pindex->nHeight) == pindex && // TODO
m_chainman.m_best_header->GetAncestor(pindex->nHeight) == pindex && } else if (it->second.GetAncestor(pindex->nHeight) != pindex) {
m_chainman.m_best_header->nChainWork >= m_chainman.MinimumChainWork()) { // TODO
} else if (m_chainman.m_best_header->GetAncestor(pindex->nHeight) != pindex) {
// TODO
} else if (m_chainman.m_best_header->nChainWork < m_chainman.MinimumChainWork()) {
// TODO
} else if (GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, params.GetConsensus()) <= TWO_WEEKS_IN_SECONDS) {
// TODO
} else {
// This block is a member of the assumed verified chain and an ancestor of the best header. // This block is a member of the assumed verified chain and an ancestor of the best header.
// Script verification is skipped when connecting blocks under the // Script verification is skipped when connecting blocks under the
// assumevalid block. Assuming the assumevalid block is valid this // assumevalid block. Assuming the assumevalid block is valid this
@@ -2449,8 +2459,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
// artificially set the default assumed verified block further back. // artificially set the default assumed verified block further back.
// The test against the minimum chain work prevents the skipping when denied access to any chain at // The test against the minimum chain work prevents the skipping when denied access to any chain at
// least as good as the expected chain. // least as good as the expected chain.
fScriptChecks = (GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, params.GetConsensus()) <= 60 * 60 * 24 * 7 * 2); fScriptChecks = false;
}
} }
} }