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 committed 2025-05-19 22:06:48 +00:00
1 parent 11fed833b3
commit 4c8c90b556
1 file changed
+9 -6
+9 -6
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 // in multiple threads). Preallocate the vector size so a new allocation
// doesn't invalidate pointers into the vector, and keep txsdata in scope // doesn't invalidate pointers into the vector, and keep txsdata in scope
// for as long as `control`. // 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<PrecomputedTransactionData> txsdata(block.vtx.size());
std::vector<int> prevheights; std::vector<int> prevheights;
@@ -2680,7 +2682,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
tx_state.GetRejectReason(), tx_state.GetDebugMessage()); tx_state.GetRejectReason(), tx_state.GetDebugMessage());
break; break;
} }
control.Add(std::move(vChecks)); if (control) control->Add(std::move(vChecks));
} }
CTxUndo undoDummy; CTxUndo undoDummy;
@@ -2702,10 +2704,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount", state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward)); strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
} }
if (control) {
auto parallel_result = control.Complete(); auto parallel_result = control->Complete();
if (parallel_result.has_value() && state.IsValid()) { 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); state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
}
} }
if (!state.IsValid()) { if (!state.IsValid()) {
LogInfo("Block validation error: %s", state.ToString()); LogInfo("Block validation error: %s", state.ToString());