Skip to content

Commit 4c8c90b

Browse files
committed
validation: only create a CCheckQueueControl if it's actually going to be used
This will allow CCheckQueueControl to require a CCheckQueue.
1 parent 11fed83 commit 4c8c90b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/validation.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26112611
// in multiple threads). Preallocate the vector size so a new allocation
26122612
// doesn't invalidate pointers into the vector, and keep txsdata in scope
26132613
// for as long as `control`.
2614-
CCheckQueueControl<CScriptCheck> control(fScriptChecks && parallel_script_checks ? &m_chainman.GetCheckQueue() : nullptr);
2614+
std::optional<CCheckQueueControl<CScriptCheck>> control;
2615+
if (fScriptChecks && parallel_script_checks) control.emplace(&m_chainman.GetCheckQueue());
2616+
26152617
std::vector<PrecomputedTransactionData> txsdata(block.vtx.size());
26162618

26172619
std::vector<int> prevheights;
@@ -2680,7 +2682,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26802682
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
26812683
break;
26822684
}
2683-
control.Add(std::move(vChecks));
2685+
if (control) control->Add(std::move(vChecks));
26842686
}
26852687

26862688
CTxUndo undoDummy;
@@ -2702,10 +2704,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27022704
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
27032705
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
27042706
}
2705-
2706-
auto parallel_result = control.Complete();
2707-
if (parallel_result.has_value() && state.IsValid()) {
2708-
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
2707+
if (control) {
2708+
auto parallel_result = control->Complete();
2709+
if (parallel_result.has_value() && state.IsValid()) {
2710+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
2711+
}
27092712
}
27102713
if (!state.IsValid()) {
27112714
LogInfo("Block validation error: %s", state.ToString());

0 commit comments

Comments
 (0)