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:
Cory Fields
2025-05-06 14:43:38 +00:00
parent 11fed833b3
commit 4c8c90b556

View File

@@ -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());