Skip to content

rpc: add testsubmitpackage for 1p1c test submissions - #35286

Draft
instagibbs wants to merge 2 commits into
bitcoin:masterfrom
instagibbs:2026-05-testsubmitpackage_2
Draft

instagibbs wants to merge 2 commits into
bitcoin:masterfrom
instagibbs:2026-05-testsubmitpackage_2

Conversation

@instagibbs

@instagibbs instagibbs commented May 13, 2026 •

Copy link
Copy Markdown
Member

A test-only companion to submitpackage that validates a strict 1p1c [parent, child] bundle without mutating the mempool. Intended as a wallet pre-flight check for CPFP fee-bumping packages.

Enables rbf and sibling eviction evaluation, just like submitpackage.

Diverging behaviors from submitpackage:

Hard rejects packages that aren't exactly 2 txs in a child-with-parents topology, and parents that pass individual acceptance (caller should use testsubmitpackage on parent alone for that).


To do this "properly" without rejecting the self-sufficient parents (and not giving surprising results that don't match reality), we would need fairly extensive changes to mempool acceptance logic, more book-keeping to unroll test-accepted subpackage state (while risking mutating the mempool in brittle ways), and possibly other changes.

This is a partial addressing of #32160, hopefully addressing most of the missing functionality people are requesting.

@DrahtBot

DrahtBot commented May 13, 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.

Type Reviewers
Concept ACK ismaelsadeeq, w0xlt

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

Conflicts

No conflicts as of last run.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • src/validation.cpp: Used f.e. with testsubmitpackage → Used e.g. with testsubmitpackage [f.e. is not the intended English abbreviation for “for example”]

Possible places where comparison-specific test macros should replace generic comparisons:

  • test/functional/rpc_testsubmitpackage.py: assert parent_A.txid_hex == parent_B.txid_hex → Prefer assert_equal(parent_A.txid_hex, parent_B.txid_hex).
  • test/functional/rpc_testsubmitpackage.py: assert parent_A.wtxid_hex != parent_B.wtxid_hex → Prefer assert_not_equal(parent_A.wtxid_hex, parent_B.wtxid_hex).

2026-10-21 21:06:07

@instagibbs

instagibbs commented May 13, 2026 •

Copy link
Copy Markdown
Member Author

cc @ajtowns @ismaelsadeeq as discussed, let's focus on concept / approach ACKs first, name is clearly up for debate, etc etc

@instagibbs
instagibbs force-pushed the 2026-05-testsubmitpackage_2 branch from 7032df7 to a723ef3 Compare May 13, 2026 18:47
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/25817910490/job/75851154109
LLM reason (✨ experimental): Fuzz RPC tests failed because the RPC command testsubmitpackage was not registered in RPC_COMMANDS_SAFE_FOR_FUZZING/RPC_COMMANDS_NOT_SAFE_FOR_FUZZING (per src/test/fuzz/rpc.cpp).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@ismaelsadeeq

Copy link
Copy Markdown
Member

Concept ACK, users normally test run submissions to see whether they will get through; so having testsubmitpackage rpc to test run 1p1c package is very useful.

I will review the approach and correctness.

@ismaelsadeeq ismaelsadeeq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is simple to reason about. I suggest some improvements that will make the code easier to reason about.
Also, I think there are still opportunities to dedup things in rpc/mempool.cpp shared code of testsubmitpackage and submitpackage, in the code args collection, help text and the logic.

Comment thread src/validation.cpp
/*test_accept=*/ false,
/*test_accept=*/ test_accept,
/*allow_replacement=*/ true,
/*allow_sibling_eviction=*/ false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a723ef3
This is weird to read? why is allow_sibling_eviction tied to test_accept?

Comment thread src/validation.h
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
* @param[in] client_maxfeerate If exceeded by an individual transaction, rest of (sub)package evaluation is aborted.
* Only for sanity checks against local submission of transactions.
* @param[in] test_package_feerates If true (only honored when test_accept is true), use child-with-parents

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a723ef3

test_package_feerates is a bit hard to read?

Can you use a clearer name for this, maybe test_accept_as_package?

Comment thread src/validation.cpp
if (args.m_test_accept) {
// Populate the would-be-replaced txs from the changeset for surfacing through the result.
// In real submission FinalizeSubpackage() does this; we exit before it runs.
if (Assume(m_subpackage.m_changeset)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a723ef3

  • The loop that copies staged removals into replaced transactions is duplicated at both test_accept sites. A helper like CollectStagedRemovals() would dedup things
  • The two sites guard the changeset access inconsistently one uses if (test_accept && Assume(changeset)), the other nests if (test_accept) { if
    (Assume(changeset)). Would be nice to make them consistent ( a helper would solve this too since the two code paths are identical).

Comment thread src/validation.cpp
auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
AssertLockHeld(cs_main);
if (test_accept) {
if (test_package_feerates) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a723ef3

I think this is a good time to split the individual-evaluation dry-run path out of ProcessNewPackage into its own function. This removes the test_package_feerates parameter, and the branching ProcessNewPackage now always goes through AcceptPackage.

self.test_topology_rejected()
self.test_parent_passes_individually_rejected()
self.test_basic_1p1c_cpfp()
self.test_no_mempool_mutation_on_success()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a723ef3

Seems redundant to have this independent.
Can we fold test_no_mempool_mutation_on_success into test_basic_1p1c_cpfp they build the same 1p1c bundle; the mempool-unchanged check belongs alongside the
basic success assertions rather than in a separate test?

result_ok = node.testsubmitpackage([parent["hex"], child["hex"]], maxfeerate=0)
assert_equal(result_ok["package_msg"], "success")

self.generate(self.wallet, 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a723ef3

Side note? It seems like a hack to always generate a block when we want to remove a transaction or restart the node, which is much heavier. I think it's part of the reason why the tests are slow.
It is worth having evict from mempool rpc for this case and others, which could eliminate this.

Another way to do this is to also use unit tests, and remove them directly.

@instagibbs

Copy link
Copy Markdown
Member Author

@ismaelsadeeq Interestingly I haven't had a lot of positive feedback yet on this PR. In the LN world, for example, the parent may end up having fees >=minfee, due to trimmed htlcs. Many of these projects don't even use test RPCs.

I think it might make sense to look for more buy-in from prospective users before iterating further.

@ismaelsadeeq

Copy link
Copy Markdown
Member

Many of these projects don't even use test RPCs.

It seems LND uses testflight as a prerequisite for broadcasting.

@GeorgeTsagk mentioned

testMempoolAccept: pre-flight bumped txs before broadcasting. btcwallet.go

See 2140-dev#24

@ajtowns

ajtowns commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

I think it might make sense to look for more buy-in from prospective users before iterating further.

Would it be possible to somehow test txs with nSequence relative locktimes spending currently out-of-mempool txs? I guess "Assume utxo txid vout sPK amt height exists, and validate this tx against it" might be feasible? Would let you check "does this claim tx actually work with this commitment tx, or is there some subtle policy breakage that's been introduced that I didn't check?" I realise this is probably horrible scope creep :)

@instagibbs

Copy link
Copy Markdown
Member Author

@ajtowns #32142 I think?

@w0xlt

w0xlt commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

@dergoegge

Copy link
Copy Markdown
Member

The code looks fine to me, but it'd be helpful for users that want this to say so explicitly here, to help us decide if we should maintain this.

I think it might make sense to look for more buy-in from prospective users before iterating further.

It's been a month since this, any update?

@instagibbs
instagibbs marked this pull request as draft July 1, 2026 15:36
@andrewtoth

Copy link
Copy Markdown
Contributor

I think this is relevant if we want to support private broadcast via submitpackage. Right now we have no way to test the validity before queuing the package for private broadcast. I'm not sure about consumers of the test RPC though, which is the bulk of the code here. If there is not yet indication of buy-in for the RPC, could we instead split out just the internal dry-run of ProcessNewPackage into its own change?

A test-only companion to submitpackage that validates a strict 1p1c
[parent, child] bundle without mutating the mempool. Intended as a
wallet pre-flight check for CPFP fee-bumping packages.

Enables rbf and sibling eviction evaluation, just like
submitblock.

Diverging behaviors from submitpackage:

Hard rejects packages that aren't exactly 2 txs in a child-with-parents
topology, and parents that pass individual acceptance (caller should
use testsubmitpackage on parent alone for that).
Two divergences from submitpackage: sibling eviction was enabled in the
multi-transaction path, which never succeeds there (PackageTRUCChecks
rejects a parent with a mempool descendant) and so only changed which
check rejected the package; and a transaction that passed before a later
one failed its scripts was reported accepted. Leave sibling eviction off
and report successes only once the whole package passes.
@instagibbs
instagibbs force-pushed the 2026-05-testsubmitpackage_2 branch from a723ef3 to 98cdef3 Compare October 21, 2026 21:05
instagibbs added a commit to instagibbs/bitcoin that referenced this pull request Oct 22, 2026
ProcessNewPackage's test mode checks each transaction without package
feerates or replacements, as testmempoolaccept does. With
test_as_submission it runs submission's evaluation instead and stops
short of the mempool, so a caller can learn whether a child pays for its
parent before relaying them. A transaction that passed before another
failed is reported by its own result, as submission reports it. Results
do not list replaced transactions, and a parent that passes alone gives
no answer for its child, which it does not stage.

From bitcoin#35286, without its RPC.
instagibbs added a commit to instagibbs/bitcoin that referenced this pull request Oct 22, 2026
ProcessNewPackage's test mode checks each transaction without package
feerates or replacements, as testmempoolaccept does. With
test_as_submission it runs submission's evaluation instead and stops
short of the mempool, so a caller can learn whether a child pays for its
parent before relaying them. A transaction that passed before another
failed is reported by its own result, as submission reports it. Results
do not list replaced transactions, and a parent that passes alone gives
no answer for its child, which it does not stage.

From bitcoin#35286, without its RPC.
instagibbs added a commit to instagibbs/bitcoin that referenced this pull request Oct 22, 2026
ProcessNewPackage's test mode checks each transaction without package
feerates or replacements, as testmempoolaccept does. With
test_as_submission it runs submission's evaluation instead and stops
short of the mempool, so a caller can learn whether a child pays for its
parent before relaying them. A transaction that passed before another
failed is reported by its own result, as submission reports it. Results
do not list replaced transactions, and a parent that passes alone gives
no answer for its child, which it does not stage.

From bitcoin#35286, without its RPC.
@GeorgeTsagk

Copy link
Copy Markdown

Many of these projects don't even use test RPCs.

It seems LND uses testflight as a prerequisite for broadcasting.

@GeorgeTsagk mentioned

testMempoolAccept: pre-flight bumped txs before broadcasting. btcwallet.go

See 2140-dev#24

A bit of a late comment here but wanted to double down on the fact that we rely on the test endpoints to prepare/shape our batch transactions before we actually submit them in LND.

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.

8 participants