Skip to content

Conversation

@stringintech
Copy link
Contributor

@stringintech stringintech commented Oct 28, 2025

This PR adds functional test coverage for the bitcoin-chainstate tool loading a datadir initialized with an assumeutxo snapshot.

The PR also includes:

  • Fix for assertion crash in ChainstateManager::AddChainstate() when prev_chainstate has no initialized mempool (required for the test to pass)
  • -regtest flag support for bitcoin-chainstate to enable the testing

This work started while experimenting with the bitcoin-chainstate tool and how the kernel API (#30595) behaved when loading a datadir containing assumeutxo data, during the time that PR was still under review. @sedited suggested opening a PR to add this test coverage.

@DrahtBot DrahtBot added the Tests label Oct 28, 2025
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 28, 2025

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

Code Coverage & Benchmarks

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK theStack, sedited
Concept ACK yuvicc
Stale ACK frankomosh

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #33847 (kernel: Improve logging API 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.

Copy link
Contributor

@frankomosh frankomosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK
I think its a nice addition as it adds valuable functional coverage for bitcoin-chainstate.
Few nits and inquiries inline;

@@ -6321,7 +6321,7 @@ Chainstate& ChainstateManager::ActivateExistingSnapshot(uint256 base_blockhash)
LogInfo("[snapshot] switching active chainstate to %s", m_snapshot_chainstate->ToString());

// Mempool is empty at this point because we're still in IBD.
Assert(m_active_chainstate->m_mempool->size() == 0);
Assert(!m_active_chainstate->m_mempool || m_active_chainstate->m_mempool->size() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this now weaker that the original assertion, because I think it will now silently accepts a null mempool pointer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is weaker, yes, but we similarly guard in other situations. We also still have the assertion in ActivateSnapshot to guard this condition at a more critical point in time.

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Consolidating the tests into the regtest case seems fine to me, especially since this is just a utility to showcase and doogfood some of the kernel work.

@@ -6321,7 +6321,7 @@ Chainstate& ChainstateManager::ActivateExistingSnapshot(uint256 base_blockhash)
LogInfo("[snapshot] switching active chainstate to %s", m_snapshot_chainstate->ToString());

// Mempool is empty at this point because we're still in IBD.
Assert(m_active_chainstate->m_mempool->size() == 0);
Assert(!m_active_chainstate->m_mempool || m_active_chainstate->m_mempool->size() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is weaker, yes, but we similarly guard in other situations. We also still have the assertion in ActivateSnapshot to guard this condition at a more critical point in time.

@stringintech stringintech force-pushed the 2025/10/test-bitcoin-chainstate-assumeutxo branch from 986eb77 to 3e7d272 Compare October 30, 2025 11:06
@stringintech
Copy link
Contributor Author

stringintech commented Oct 30, 2025

986eb77 to 3e7d272 - reversed the order of -regtest flag and input DATADIR as suggested by @TheCharlatan and added simple validation for the flag as suggested by @frankomosh.

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 3e7d272b2747f1937010b8fc1fefafcfa0ce3213

@DrahtBot DrahtBot requested a review from frankomosh October 30, 2025 14:01
@yuvicc
Copy link
Contributor

yuvicc commented Oct 30, 2025

Concept ACK

@frankomosh
Copy link
Contributor

ACK 3e7d272

@stringintech stringintech force-pushed the 2025/10/test-bitcoin-chainstate-assumeutxo branch from 3e7d272 to 67740df Compare November 4, 2025 16:18
@stringintech
Copy link
Contributor Author

3e7d272 to 67740df - rebased and resolved conflict with #30595.

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 67740dfe6cfe3f3f91aaad41018a7da9004dcd8c

@frankomosh
Copy link
Contributor

re-ACK 67740df

@stringintech stringintech force-pushed the 2025/10/test-bitcoin-chainstate-assumeutxo branch from 67740df to 6cb63db Compare December 9, 2025 10:33
@stringintech
Copy link
Contributor Author

stringintech commented Dec 9, 2025

67740df to 6cb63db - Rebased and removed unused variable block_tx in tool_bitcoin_chainstate.py.
Also updated PR description.

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ACK 6cb63db

@DrahtBot DrahtBot requested a review from frankomosh December 9, 2025 12:14
// SETUP: Argument parsing and handling
if (argc != 2) {
const bool has_regtest_flag{argc == 3 && std::string(argv[1]) == "-regtest"};
if (argc < 2 || argc > 3 || (argc == 3 && !has_regtest_flag)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking lately whether we can reuse some of our own common utilities for these small, kernel-based applications. These small, single use applications should be able to use our usual utilities, while still benefiting from a clearer kernel interface. I think we are at a point now, where we can confidently mix between the two without risking introducing an entanglement regression between what the kernel requires and what new code might introduce in it. For this reason, I added some basic argument handling on my branch over here: https://github.com/sedited/bitcoin/tree/bitcoin_chainstate_args , that might be interesting for this change here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks! It seems I can cherry-pick your commit as is to replace bfceb4c?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks! It seems I can cherry-pick your commit as is to replace bfceb4c?

Sure, if you think it is a good idea too :)

Copy link
Contributor Author

@stringintech stringintech Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers:

As discussed offline, adding ArgsManager and the G_TRANSLATION_FUN definition that should be added because of it, is causing different compile/link issues since the symbol is also defined in the kernel library and @sedited is suggesting to have the symbol removed from there.

So it seems adapting bitcoin-chainstate.cpp to use the ArgsManager could be done in a follow-up.

Adds -regtest flag to enable testing with regtest chain parameters.
Check mempool exists before accessing size when prev_chainstate doesn't have initialized mempool.
Adds functional test coverage for bitcoin-chainstate tool loading a datadir initialized with an assumeutxo snapshot
@stringintech stringintech force-pushed the 2025/10/test-bitcoin-chainstate-assumeutxo branch from 6cb63db to 7b5d256 Compare December 18, 2025 17:12
@stringintech
Copy link
Contributor Author

6cb63db to 7b5d256 - Rebased and resolved conflict with #30214.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept and code-review ACK 7b5d256

As a follow-up idea, it might make sense to deduplicate the deterministic generation of the snapshot chain between this test and feature_assumeutxo.py, by moving the logic into a test framework module.

@DrahtBot DrahtBot requested a review from sedited January 5, 2026 08:27
Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ACK 7b5d256

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

Labels

Projects

Status: Client Flexibility

Development

Successfully merging this pull request may close these issues.

6 participants