coins: make cursor iteration DB-only #35572

pull l0rinc wants to merge 4 commits into bitcoin:master from l0rinc:l0rinc/coins-view-db-cursor changing 9 files +25 −47
  1. l0rinc commented at 6:41 AM on June 21, 2026: contributor

    Problem: CCoinsView::Cursor() makes cursor iteration look like a generic coins view operation, but cursor iteration is only supported by the DB-backed coins view. The cache override only threw, and the coins_view fuzz target only asserted that deterministic unsupported throw path.

    Fix: Make cursor iteration a CCoinsViewDB operation. Cursor users now take the DB-backed view directly, CCoinsView no longer exposes Cursor(), and the fuzz target keeps DB-backed cursor coverage while dropping the unsupported cache throw probe. The UTXO stats path is also tightened to pass the non-null DB view by reference, and stale null handling for DB cursors is removed.

    This was extracted from review discussion in #35295 (review) and extended based on #35562 (comment).

  2. DrahtBot added the label UTXO Db and Indexes on Jun 21, 2026
  3. DrahtBot commented at 6:41 AM on June 21, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Stale ACK sedited

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35474 (node: move index ownership to NodeContext by w0xlt)
    • #29700 (kernel, refactor: return error status on all fatal errors by ryanofsky)
    • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in src/validation.cpp:5896 in 5df2bbf543
    5892 | @@ -5893,7 +5893,7 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
    5893 |  
    5894 |      try {
    5895 |          maybe_stats = ComputeUTXOStats(
    5896 | -            CoinStatsHashType::HASH_SERIALIZED, snapshot_coinsdb, m_blockman, [&interrupt = m_interrupt] { SnapshotUTXOHashBreakpoint(interrupt); });
    5897 | +            CoinStatsHashType::HASH_SERIALIZED, *snapshot_coinsdb, m_blockman, [&interrupt = m_interrupt] { SnapshotUTXOHashBreakpoint(interrupt); });
    


    sedited commented at 12:50 PM on June 21, 2026:

    Nit: Maybe rather change the snapshot_coinsdb to a reference?


    l0rinc commented at 2:27 PM on June 21, 2026:

    Indeed, pushed (+ found one additional case), thanks!

  5. sedited approved
  6. sedited commented at 1:08 PM on June 21, 2026: contributor

    ACK 34620b0490a1a6be681afbbdc89ba037d6143739

    This might be a nice use case for the NotNull<>.

  7. l0rinc force-pushed on Jun 21, 2026
  8. in src/rpc/blockchain.cpp:1087 in 66a1420343 outdated
    1089 | -        LOCK(::cs_main);
    1090 | -        coins_view = &active_chainstate.CoinsDB();
    1091 | -        blockman = &active_chainstate.m_blockman;
    1092 | -    }
    1093 | +    const CCoinsViewDB& coins_view{WITH_LOCK(::cs_main, return active_chainstate.CoinsDB())};
    1094 | +    BlockManager& blockman{active_chainstate.m_blockman};
    


    sedited commented at 3:52 PM on June 21, 2026:

    Nit: I think the correctness of the lock scope change would be even clearer if the blockman is retrieved from the chainman.


    l0rinc commented at 4:02 PM on June 21, 2026:

    If you don't mind I'd like to do that in a follow-up - current changes are all trivial, that needs a bit more thought

  9. sedited approved
  10. sedited commented at 4:00 PM on June 21, 2026: contributor

    Re-ACK 66a14203439e85136de703f2f2ab282aae102549

  11. DrahtBot added the label Needs rebase on Jun 24, 2026
  12. l0rinc force-pushed on Jun 24, 2026
  13. coins: pass DB view to cursor users
    Cursor iteration is only supported by the coins database view.
    
    Pass `CCoinsViewDB` pointers to UTXO stats code and use the concrete DB pointer in the coins_view fuzz target before removing the abstract hook.
    
    Co-authored-by: sedited <seb.kung@gmail.com>
    c6fbe2f66c
  14. coins: drop cursor from base view
    `CCoinsView` does not need to expose cursor iteration now that the few cursor users take `CCoinsViewDB` directly.
    Keep `Cursor()` on `CCoinsViewDB`, where iteration is supported, and remove the empty, forwarding, and throwing base-view overrides.
    
    This also removes the coins_view fuzz target probe that only asserted the unsupported `CCoinsViewCache::Cursor()` throw path.
    
    Co-authored-by: sedited <seb.kung@gmail.com>
    35aedb2823
  15. coins: pass UTXO stats view by reference
    The UTXO stats helpers require a non-null coins DB view after cursor users were narrowed to `CCoinsViewDB`.
    
    Use references for the DB view in the UTXO stats helpers and for local DB-view/block-manager variables at call sites, so the path no longer spells a nullable contract.
    
    Co-authored-by: sedited <seb.kung@gmail.com>
    3d2f2d8de0
  16. coins: drop stale cursor null checks
    `CCoinsViewDB::Cursor()` now owns cursor iteration and constructs the cursor directly.
    
    Drop the leftover handling for the old generic nullable cursor contract from DB cursor call sites.
    
    Co-authored-by: sedited <seb.kung@gmail.com>
    72db4accbf
  17. l0rinc force-pushed on Jun 24, 2026
  18. DrahtBot added the label CI failed on Jun 24, 2026
  19. DrahtBot commented at 9:31 PM on June 24, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/28130662519/job/83305756869</sub> <sub>LLM reason (✨ experimental): CI failed during compilation of the fuzz target (test_fuzz): coins_view.cpp references an undeclared backend_coins_db (and calls Cursor() on CCoinsView), causing clang errors.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  20. DrahtBot removed the label CI failed on Jun 24, 2026
  21. DrahtBot removed the label Needs rebase on Jun 24, 2026

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-06-27 17:51 UTC

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