mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
validation: only create a CCheckQueueControl if it's actually going to be used
This will allow CCheckQueueControl to require a CCheckQueue.
This commit is contained in:
@@ -2611,7 +2611,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
// in multiple threads). Preallocate the vector size so a new allocation
|
||||
// doesn't invalidate pointers into the vector, and keep txsdata in scope
|
||||
// for as long as `control`.
|
||||
CCheckQueueControl<CScriptCheck> control(fScriptChecks && parallel_script_checks ? &m_chainman.GetCheckQueue() : nullptr);
|
||||
std::optional<CCheckQueueControl<CScriptCheck>> control;
|
||||
if (fScriptChecks && parallel_script_checks) control.emplace(&m_chainman.GetCheckQueue());
|
||||
|
||||
std::vector<PrecomputedTransactionData> txsdata(block.vtx.size());
|
||||
|
||||
std::vector<int> prevheights;
|
||||
@@ -2680,7 +2682,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
||||
break;
|
||||
}
|
||||
control.Add(std::move(vChecks));
|
||||
if (control) control->Add(std::move(vChecks));
|
||||
}
|
||||
|
||||
CTxUndo undoDummy;
|
||||
@@ -2702,10 +2704,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
|
||||
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
|
||||
}
|
||||
|
||||
auto parallel_result = control.Complete();
|
||||
if (parallel_result.has_value() && state.IsValid()) {
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
|
||||
if (control) {
|
||||
auto parallel_result = control->Complete();
|
||||
if (parallel_result.has_value() && state.IsValid()) {
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
|
||||
}
|
||||
}
|
||||
if (!state.IsValid()) {
|
||||
LogInfo("Block validation error: %s", state.ToString());
|
||||
|
||||
Reference in New Issue
Block a user