validation: don't accept txs to the mempool while loading a snapshot #36346

pull 0xShadowX wants to merge 1 commits into bitcoin:master from 0xShadowX:fix-loadtxoutset-mempool-recheck changing 3 files +82 −0
  1. 0xShadowX commented at 5:16 PM on September 26, 2026: none

    ActivateSnapshot checks that the mempool is empty before it starts, but PopulateAndValidateSnapshot then runs without cs_main, which takes minutes on mainnet. A transaction entering the mempool in that window (e.g. through sendrawtransaction) hits the assert in AddChainstate:

    Assertion failed: (!prev_chainstate.m_mempool || prev_chainstate.m_mempool->size() == 0), function AddChainstate, file validation.cpp, line 6201.
    

    By then the base blockhash file has been written, so the node needs -reindex to start again.

    This sets a flag on ChainstateManager while ActivateSnapshot runs, and AcceptToMemoryPool and ProcessNewPackage reject with snapshot-loading while it's set. testmempoolaccept still works. A second loadtxoutset started while one is running is also rejected.

    test_mempool_blocked_during_load in feature_assumeutxo.py pauses the load through a FIFO, checks that sendrawtransaction and submitpackage are rejected and the mempool stays empty, then lets the load finish. On master the transaction is accepted and the node aborts. The test is skipped where os.mkfifo isn't available.

  2. DrahtBot added the label Validation on Sep 26, 2026
  3. DrahtBot commented at 5:16 PM on September 26, 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/36346.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. fjahr commented at 10:07 PM on September 26, 2026: contributor

    I haven't looked at the code or verified the issue but it seems to me the correct fix would be to prevent the user from putting a tx into the mempool when we don't want one to get there instead of letting them do it and then fail, even if it's a graceful failure with this change.

  5. validation: don't accept txs to the mempool while loading a snapshot
    ActivateSnapshot checks that the mempool is empty, then releases cs_main
    while PopulateAndValidateSnapshot runs, which can take minutes. A
    transaction added to the mempool in that window (e.g. through
    sendrawtransaction) made AddChainstate hit its empty-mempool assert after
    the base blockhash file was already written, and the node then needed
    -reindex to start again.
    
    Set a flag on ChainstateManager for the duration of ActivateSnapshot and
    reject transactions and packages in AcceptToMemoryPool and
    ProcessNewPackage while it is set. test_accept calls still work since
    they don't add anything to the mempool. A second concurrent loadtxoutset
    is rejected while the flag is set.
    ca21d8f5fb
  6. 0xShadowX force-pushed on Sep 27, 2026
  7. 0xShadowX renamed this:
    validation: recheck mempool before activating a snapshot
    validation: don't accept txs to the mempool while loading a snapshot
    on Sep 27, 2026
  8. 0xShadowX commented at 7:55 AM on September 27, 2026: none

    Makes sense, changed it to that. While a snapshot is loading, AcceptToMemoryPool and ProcessNewPackage now reject with "snapshot-loading" (test_accept still works), so the load no longer fails because of the mempool. Updated the description and the test.


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-09-28 10:51 UTC

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