Repository navigation
Conversation
During IBD and reindex, `ConnectBlock()` skips script verification for blocks in the `assumevalid` period, but still performs one heap allocation for a fresh `txsdata` vector and default-constructs one `PrecomputedTransactionData` entry for every transaction in each connected block. Because `CheckInputScripts()` is not called in that path, that work is unused and only adds allocator churn and avoidable heap fragmentation on large blocks. Leave `txsdata` empty unless `fScriptChecks` is true, then resize it before queued checks can take pointers into the vector. Keep `txsdata` declared before `control` so queued script checks finish before the storage is destroyed.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35663. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
darosior
left a comment
There was a problem hiding this comment.
What is the big picture benefit of this change? On its face it seems unnecessarily risky especially as we just had a high-severity vulnerability related to this very data structure that none of all our eyeballs noticed for a decade.
|
We're in agreement: while this is a tiny change with a modest effect, we have to be absolutely sure the risk is low.
If you think there are specific failure modes or missing coverage around this data structure, pointers would be appreciated. I would rather add coverage now, while we are looking at this area carefully, than leave it alone because it has historically been hard to reason about. It could help us encode our current understanding to make sure we're not afraid of it in the future. |
|
Closing in favor of #35662 |
Problem: During IBD/reindex,
ConnectBlock()skips script verification for blocks in theassumevalidperiod.However, it still performs one heap allocation for a fresh
txsdatavector and default-constructs onePrecomputedTransactionDataentry for every transaction in each connected block.Because
CheckInputScripts()is not called in that path, that work is unused and only adds allocator churn and avoidable heap fragmentation on large blocks.Fix: Leave
txsdataempty unlessfScriptChecksis true, then resize it before queued checks can take pointers into the vector.Update the lifetime comment and add an indexed-use assert that matches the real precondition.
Reproducer: On a synthetic ~7000-transaction block, the skipped-check path avoids the unused heap allocation and saves ~2MB memory per block.
ConnectBlockAllSchnorr mem usage: 7000 txs, num_schnorr=1, num_ecdsa=0, fScriptChecks=false