#35271 Update CoinsView::NeedsUpgrade to add additional checks
https://github.com/bitcoin/bitcoin/pull/35271 · · +2/-1 in 1 files, 1 commits · labels: CI failed · draft
Goal
- Prevent false positives where nonstandard or downstream chainstates trigger legacy database upgrades
Tightens CCoinsViewDB::NeedsUpgrade() to verify that the key found by cursor->Seek() matches the DB_COINS prefix. Because LevelDB's Seek finds the first key greater than or equal to the target, a database containing keys sorting after DB_COINS but lacking any DB_COINS entries would previously return true from cursor->Valid().
Problem: Downstream forks or nonstandard chainstate databases with key prefixes sorting after DB_COINS could falsely signal that a legacy UTXO database upgrade is required.
Category: Validation (#48 of 48)
P4 · bug fix
- P4 because legacy UTXO format was deprecated long ago and Core does not trigger this false positive
- The benefit applies strictly to downstream projects rather than standard node operations
The change is marginal in Core because the legacy DB_COINS format was deprecated long ago and Core's UTXO database schema does not appear to trigger this false positive. The author acknowledged the motivation originated downstream in Elements rather than in Bitcoin Core.
Membership: Modifies CCoinsViewDB::NeedsUpgrade() in src/txdb.cpp, which inspects the UTXO LevelDB database structure.
Factors: security/stability 0, bug 1, performance 0, user value 0, leverage 0
Reviewability: Stale: Author silent
- Author is inactive with failing CI linter and an unanswered question whether to close
The author has been inactive for over 120 days, the PR remains in draft with a failing CI linter check, and a maintainer question about whether to close has gone unanswered.
Author status: silent since opening day 2026-05-12
Open concerns:
- No demonstration that Bitcoin Core databases ever write keys sorting after DB_COINS to trigger this condition.
- Linter failure due to trailing whitespace.
- maflcko asked whether the author is still working on the PR or if it should be closed.
Resolved concerns:
- sedited initially closed the PR as unnecessary for Core, but reopened after the author noted its utility in downstream Elements.
Agreement: Neutral
- No reviewers have endorsed merging this into Core
- Reopened out of courtesy for downstream projects after initially closing it (sedited)
- Questioned whether Bitcoin Core databases ever write keys that trigger this condition (l0rinc)
- Asked whether the author is still working on this or if it should be closed (maflcko)
Reopened for downstream utility but no Core ACK; author asked if still working on it
sedited initially closed the PR because legacy upgrade logic rarely changes, but reopened it out of courtesy for downstream use. l0rinc offered test suggestions and asked whether Core ever produced such keys, and maflcko asked if the PR should be closed. No reviewer explicitly endorsed merging it into Core.
- sedited: 'I don't think this needs fixing... If there is a motivation for this in the form of an actual bug report or down stream issue, I'll be happy to re-open this.'
- tomt1664: 'Motivation is that it is needed downstream in Elements... thought it may be relevant in other contexts.'
- sedited: 'I'll re-open this then, given that it is a rather small change.'
- l0rinc: 'Can you please explain why there happens to be another key whose byte value is greater than DB_COINS can happen for a Bitcoin Core-produced chainstate?'
- maflcko: 'are you still working on this, or can it be closed?'
Review verdicts (DrahtBot): 0
Files
0 lines under test/bench/ci.
- src/txdb.cpp +2/-1
Card
This PR adds a key-prefix verification check to CCoinsViewDB::NeedsUpgrade() so that LevelDB cursor->Seek() does not mistake a subsequent key for a legacy DB_COINS key. The issue was observed downstream in Elements rather than in Bitcoin Core chainstate databases. Reviewers questioned whether Core is affected, and while sedited reopened it as a small cleanup, the author has been silent for four months with maflcko inquiring whether to close it.