AssumeUTXO index restart leaves stale readiness and races readers #37080

issue l0rinc opened this issue on December 2, 2026
  1. l0rinc commented at 9:15 PM on December 2, 2026: contributor

    When background validation finishes, AssumeUTXO stops and reinitializes the indexes while RPC and REST readers remain available. Stop() leaves a synced index reporting ready, and Init() replaces m_chainstate while readers such as TxIndex::FindTx() use it without synchronization.

    <details> <summary>Reproducer</summary>

    The stale-readiness check shows the stopped index still reporting ready, and the restart loop makes ThreadSanitizer report the concurrent m_chainstate access.

    diff --git a/src/test/baseindex_tests.cpp b/src/test/baseindex_tests.cpp
    index 28ed5f8614..0a50396b23 100644
    --- a/src/test/baseindex_tests.cpp
    +++ b/src/test/baseindex_tests.cpp
    @@ -33,9 +33,11 @@
     
     #include <boost/test/unit_test.hpp>
     
    +#include <atomic>
     #include <chrono>
     #include <functional>
     #include <future>
    +#include <latch>
     #include <memory>
     #include <string>
     #include <thread>
    @@ -235,4 +237,39 @@ BOOST_FIXTURE_TEST_CASE(index_reorg_crash, TestChain100Setup)
         StopIndex(index, m_node);
     }
     
    +BOOST_FIXTURE_TEST_CASE(baseindex_restart_concurrent_reads, TestChain100Setup)
    +{
    +    TxIndex index{interfaces::MakeChain(m_node), /*n_cache_size=*/1_MiB, /*f_memory=*/true};
    +    BOOST_REQUIRE(index.Init());
    +    index.Sync();
    +
    +    index.Stop();
    +    BOOST_CHECK(index.BlockUntilSyncedToCurrentChain()); // TODO: Report a stopped index as unavailable
    +    BOOST_REQUIRE(index.Init());
    +
    +    const Txid txid{m_coinbase_txns[1]->GetHash()};
    +    std::latch reader_started{1};
    +    std::atomic_bool run{true};
    +    std::thread reader{[&] {
    +        reader_started.count_down();
    +        while (run.load(std::memory_order_relaxed)) {
    +            index.BlockUntilSyncedToCurrentChain();
    +            (void)index.FindTx(txid);
    +        }
    +    }};
    +    reader_started.wait();
    +
    +    bool init_ok{true};
    +    for (int i{0}; init_ok && i < 1000; ++i) {
    +        index.Stop();
    +        init_ok = index.Init();
    +        std::this_thread::yield();
    +    }
    +
    +    run.store(false, std::memory_order_relaxed);
    +    reader.join();
    +    index.Stop();
    +    BOOST_REQUIRE(init_ok);
    +}
    +
     BOOST_AUTO_TEST_SUITE_END()
    

    </details>

    The direct fix would be to mark the index unavailable while it restarts and synchronize m_chainstate with its readers, but given that AssumeUTXO fixes haven't attracted much review, I'm proposing to remove AssumeUTXO entirely in #36598 instead.


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-12-03 02:51 UTC

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