Merge bitcoin/bitcoin#35210: [31.x] validation: correct lifetime of precomputed tx data

0cedd6abf2 validation: correct lifetime of precomputed tx data (Antoine Poinsot)

Pull request description:

  This backports #35209 to the version 31 branch.

ACKs for top commit:
  fanquake:
    ACK 0cedd6abf2

Tree-SHA512: 12e3b73c5e2e5b49d9abd9d3dcf9aee98f98fcaa1d9f05ae8fe4e7d19bef5a22dad0eafd51acf9720b215c4d166dae2931a45528ac362e5cdb953c690febea96
This commit is contained in:
merge-script
2026-05-07 11:41:38 +02:00

View File

@@ -2508,11 +2508,10 @@ 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`.
std::vector<PrecomputedTransactionData> txsdata(block.vtx.size());
std::optional<CCheckQueueControl<CScriptCheck>> control;
if (auto& queue = m_chainman.GetCheckQueue(); queue.HasThreads() && fScriptChecks) control.emplace(queue);
std::vector<PrecomputedTransactionData> txsdata(block.vtx.size());
std::vector<int> prevheights;
CAmount nFees = 0;
int nInputs = 0;