Skip to content

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

Closed
0xShadowX wants to merge 1 commit into
bitcoin:masterfrom
0xShadowX:fix-loadtxoutset-mempool-recheck
Closed

0xShadowX wants to merge 1 commit into
bitcoin:masterfrom
0xShadowX:fix-loadtxoutset-mempool-recheck

Conversation

@0xShadowX

@0xShadowX 0xShadowX commented Sep 26, 2026 •

Copy link
Copy Markdown

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.

@DrahtBot

DrahtBot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36778 (AssumeUTXO: replace loadtxoutset RPC with a startup arg by l0rinc)
  • #36603 (Improve loadtxoutset performance by ajtowns)
  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)

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.

@fjahr

fjahr commented Sep 26, 2026

Copy link
Copy Markdown
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.

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.
@0xShadowX
0xShadowX force-pushed the fix-loadtxoutset-mempool-recheck branch from ceeee32 to ca21d8f Compare September 27, 2026 07:55
@0xShadowX 0xShadowX changed the title validation: recheck mempool before activating a snapshot validation: don't accept txs to the mempool while loading a snapshot Sep 27, 2026
@0xShadowX

Copy link
Copy Markdown
Author

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.

@fjahr

fjahr commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

I think this one more issue that is so fringe that we may not really want to address it. But if we would I prefer #36778 for a more structural solution. And there are further changes to this code upcoming with #36603 so I would rather close this or maybe it could be turned into an issue to make sure this doesn't get lost but even that is probably not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants