mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
log: separate script verification reasons
Replace `fScriptChecks` with `script_check_reason` and log the precise reason when checks are enabled; log a plain "Disabling" when they are skipped. Adjust the functional test to assert the new reason strings. Co-authored-by: w0xlt <woltx@protonmail.com> Co-authored-by: Eunovo <eunovo9@gmail.com> Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com> Co-authored-by: TheCharlatan <seb.kung@gmail.com> Co-authored-by: Andrew Toth <andrewstoth@gmail.com>
This commit is contained in:
@@ -2423,9 +2423,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fScriptChecks = true;
|
||||
const char* script_check_reason;
|
||||
if (m_chainman.AssumedValidBlock().IsNull()) {
|
||||
// TODO
|
||||
script_check_reason = "assumevalid=0 (always verify)";
|
||||
} 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.
|
||||
@@ -2435,15 +2435,15 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
// effectively caching the result of part of the verification.
|
||||
BlockMap::const_iterator it{m_blockman.m_block_index.find(m_chainman.AssumedValidBlock())};
|
||||
if (it == m_blockman.m_block_index.end()) {
|
||||
// TODO
|
||||
script_check_reason = "assumevalid hash not in headers";
|
||||
} else if (it->second.GetAncestor(pindex->nHeight) != pindex) {
|
||||
// TODO
|
||||
script_check_reason = "block not in assumevalid chain";
|
||||
} else if (m_chainman.m_best_header->GetAncestor(pindex->nHeight) != pindex) {
|
||||
// TODO
|
||||
script_check_reason = "block not in best header chain";
|
||||
} else if (m_chainman.m_best_header->nChainWork < m_chainman.MinimumChainWork()) {
|
||||
// TODO
|
||||
script_check_reason = "best header chainwork below minimumchainwork";
|
||||
} else if (GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, params.GetConsensus()) <= TWO_WEEKS_IN_SECONDS) {
|
||||
// TODO
|
||||
script_check_reason = "block too recent relative to best header";
|
||||
} else {
|
||||
// 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
|
||||
@@ -2459,7 +2459,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
// 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
|
||||
// least as good as the expected chain.
|
||||
fScriptChecks = false;
|
||||
script_check_reason = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2572,15 +2572,16 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
Ticks<SecondsDouble>(m_chainman.time_forks),
|
||||
Ticks<MillisecondsDouble>(m_chainman.time_forks) / m_chainman.num_blocks_total);
|
||||
|
||||
if (fScriptChecks != m_prev_script_checks_logged && GetRole() == ChainstateRole::NORMAL) {
|
||||
const bool fScriptChecks{!!script_check_reason};
|
||||
if (script_check_reason != m_last_script_check_reason_logged && GetRole() == ChainstateRole::NORMAL) {
|
||||
if (fScriptChecks) {
|
||||
LogInfo("Enabling script verification at block #%d (%s).",
|
||||
pindex->nHeight, block_hash.ToString());
|
||||
LogInfo("Enabling script verification at block #%d (%s): %s.",
|
||||
pindex->nHeight, block_hash.ToString(), script_check_reason);
|
||||
} else {
|
||||
LogInfo("Disabling script verification at block #%d (%s).",
|
||||
pindex->nHeight, block_hash.ToString());
|
||||
}
|
||||
m_prev_script_checks_logged = fScriptChecks;
|
||||
m_last_script_check_reason_logged = script_check_reason;
|
||||
}
|
||||
|
||||
CBlockUndo blockundo;
|
||||
|
||||
Reference in New Issue
Block a user