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

Closed
0xShadowX wants to merge 1 commit from fix-loadtxoutset-mempool-recheck into master AGit
0xShadowX commented 2026-09-26 17:16:20 +00:00 (Migrated from github.com)

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.

`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 commented 2026-09-26 17:16:29 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36346 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36346.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36346#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36778](https://github.com/bitcoin/bitcoin/pull/36778) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36778.svg"></sub> (AssumeUTXO: replace `loadtxoutset` RPC with a startup arg by l0rinc) * [#36603](https://github.com/bitcoin/bitcoin/pull/36603) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36603.svg"></sub> (Improve loadtxoutset performance by ajtowns) * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
fjahr commented 2026-09-26 22:07:39 +00:00 (Migrated from github.com)

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.

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.
0xShadowX commented 2026-09-27 07:55:46 +00:00 (Migrated from github.com)

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.

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.
First-time contributor

🔵 Suggestion · Concurrent-load rejection lacks a paused-window test

The paused-load test never exercises the new concurrent-activation guard or verifies that a rejected second request leaves mempool admission blocked.

Location: test/functional/feature_assumeutxo.py:246 (head).

🔵 Suggestion · snapshot-loading rejections skip the documented rejection tracepoint

During snapshot loading, transactions rejected with snapshot-loading bypass mempool:rejected, leaving attached USDT mempool monitors unaware of those rejections.

Location: src/validation.cpp:1778 (head).

🔵 Suggestion · Package test acceptance lacks snapshot-loading coverage

The loading-window test checks only singleton testmempoolaccept, leaving the separate package test-accept exemption untested.

Location: test/functional/feature_assumeutxo.py:247 (head).

Review coverage was incomplete.


Reviewed: ca21d8f5fbc9 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:0816391e25c43735252d9c1658ad19e43fd0322616624be8bdd148902e77ed2c:7627b447f6bdd600e130c23633793b27fe455af0d0967bc63cadfcccbedb55d2 --> <!-- ralph-base:6c01bd0b2dc201c21e80ac3635828abf854ee5a0 --> <!-- ralph-head:ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82 --> <!-- ralph-case:5be56b5d4774bbb13f9cfebbad97e8dbb7e214b5033ac71fb4c436b056cc3e14 --> **🔵 Suggestion · Concurrent-load rejection lacks a paused-window test** The paused-load test never exercises the new concurrent-activation guard or verifies that a rejected second request leaves mempool admission blocked. Location: [`test/functional/feature_assumeutxo.py:246`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82/test/functional/feature_assumeutxo.py#L246>) (head). **🔵 Suggestion · `snapshot-loading` rejections skip the documented rejection tracepoint** During snapshot loading, transactions rejected with `snapshot-loading` bypass `mempool:rejected`, leaving attached USDT mempool monitors unaware of those rejections. Location: [`src/validation.cpp:1778`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82/src/validation.cpp#L1778>) (head). **🔵 Suggestion · Package test acceptance lacks snapshot-loading coverage** The loading-window test checks only singleton `testmempoolaccept`, leaving the separate package test-accept exemption untested. Location: [`test/functional/feature_assumeutxo.py:247`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82/test/functional/feature_assumeutxo.py#L247>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`ca21d8f5fbc9`](<https://git.fish.foo/bitcoin/bitcoin/commit/ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82>) · [Full review report](<https://review.fish.foo/traces/36346-ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82-1934-3.html>) · [Previous reports](<https://review.fish.foo/traces/36346/>) [permalink](<https://review.fish.foo/traces/36346-ca21d8f5fbc9961f2a9d0622c0cf4e23f2a82b82-1934-3.html>)
fjahr commented 2026-11-17 15:03:19 +00:00 (Migrated from github.com)

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.

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 in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36346
No description provided.