coins: replace remaining HaveCoin calls with GetCoin #34320

pull l0rinc wants to merge 5 commits into bitcoin:master from l0rinc:l0rinc/remove-HaveCoin changing 13 files +149 −144
  1. l0rinc commented at 4:17 pm on January 16, 2026: contributor

    Split out of #34132 (review).

    Problem

    We have two ways to check a coin exists in the db. One tries to deserialize, the other just returns whether any value is associated with the key. But we usually need the full value we probed for, and HaveCoin cannot cache the returned value, so it can trigger an extra lookup if HaveCoin uses Exists and the caller later needs the actual value. We’re already delegating most HaveCoin calls to GetCoin anyway for the above reasons, so the current implementation of HaveCoin is redundant.

    Fix

    Replace HaveCoin calls with GetCoin, reuse ReadRaw in dbwrapper, stop ignoring deserialization failures, and readjust tests to this simpler state.

    See https://github.com/bitcoin/bitcoin/blob/cd0959ce9b7c5b80ebd45b652d557630b4dc604b/src/dbwrapper.cpp#L304-L331 and https://github.com/bitcoin/bitcoin/blob/ a9b7f5614c24fe6f386448604c325ec4fa6c98a5/src/dbwrapper.h#L206-L241.

    Notes

    • It seems #26331 did not fix #26112.
    • After this PR deserialization failures will crash the app, see #33866 for similar cleanups. This is deliberate to fail early instead of trying to recover.
  2. test: add `HaveInputs` call-path unit tests
    Add unit tests covering `CCoinsViewCache::HaveInputs()`.
    
    The tests document that `HaveInputs()` consults the cache first and that a cache miss pulls from the backing view via `GetCoin()`.
    0fbda2005f
  3. dbwrapper: let `Read` throw on deserialization failure
    When `CDBWrapper::Read()` fails deserialization we silently return `false`, which makes decode failures indistinguishable from missing keys.
    
    Drop the catch so deserialization errors fail fast.
    This is in line with other recent changes where we're not trying to recover from database failures - and to make this explicit, see: https://github.com/bitcoin/bitcoin/pull/33866
    b795d4853b
  4. dbwrapper: have `Read` and `Exists` reuse `ReadRaw`
    `CDBWrapper::Exists()` and `::ReadRaw()` both issue a LevelDB `::Get`.
    Introduce a small helper returning the raw value bytes (as `std::string`) for a given key.
    Move `Exists` closer to the read methods.
    7d8280aaee
  5. test: use `GetCoin` in coins cache tests
    Simplify existence checks in coins-related tests.
    Separated this from the production code changes since the usages here are just for convenience, not correctness.
    fe8df84796
  6. coins: replace remaining `HaveCoin` calls with `GetCoin()` and remove the former
    `HaveCoin` duplicated `GetCoin()` semantics and added another confusing UTXO API surface.
    9b4e0448b2
  7. DrahtBot added the label UTXO Db and Indexes on Jan 16, 2026
  8. DrahtBot commented at 4:17 pm on January 16, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34320.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34165 (coins: don’t mutate main cache when connecting block by andrewtoth)
    • #34132 (refactor: inline CCoinsViewErrorCatcher into CCoinsViewDB by l0rinc)
    • #34124 (refactor: make CCoinsView a purely virtual abstract base class by l0rinc)
    • #32427 ((RFC) kernel: Replace leveldb-based BlockTreeDB with flat-file based store by sedited)
    • #32317 (kernel: Separate UTXO set access from validation functions by sedited)
    • #31132 (validation: fetch block inputs on parallel threads 3x faster IBD by andrewtoth)

    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.

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • AddCoin(outp, std::move(coin), false) in src/test/coins_tests.cpp
    • AddCoin(outp, std::move(coin), false) in src/test/coins_tests.cpp

    2026-01-16


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-18 03:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me