Skip to content

fix: only fee-bump transactions the wallet broadcast - #129

Merged
ovitrif merged 3 commits into
mainfrom
fix/bump-own-txs-only
Oct 27, 2026
Merged

ovitrif merged 3 commits into
mainfrom
fix/bump-own-txs-only

Conversation

@ovitrif

@ovitrif ovitrif commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Restricts bump_fee_by_rbf to transactions this wallet built and broadcast itself. Any txid without a broadcast record, including one found in the wallet graph that the wallet did not broadcast, now returns the new TransactionNotBroadcastByWallet error ("The wallet has no broadcast record for this transaction") before a replacement is built. Because this check runs first, TransactionNotFound and TransactionAlreadyConfirmed now only apply to recorded transactions; the bump_fee_by_rbf docs list this order.
  • Records the txid of each transaction the wallet broadcasts, before dispatch: PreparedOnchainSend::broadcast (used by the prepared sends and send_to_address_with_broadcast_result / send_all_to_address_with_broadcast_result), Wallet::send_to_address (used by OnchainPayment::send_to_address and send_all_to_address), RBF replacements and CPFP children. Replacements are recorded, so a bumped transaction can be bumped again. Each txid is persisted as its own key under a new wallet_broadcast_txids KV namespace, so the record survives a restart. If the record cannot be written, the send fails with PersistenceFailed and nothing is dispatched.
  • Leaves accelerate_by_cpfp unrestricted. CPFP only spends the wallet's own unspent outputs of the parent and never rebuilds it, so a child can only confirm along with a valid parent and pays the wallet's own funds back to the wallet (or to the given address). Bitkit uses it to boost received transactions, which the wallet never broadcast.
  • Adds TransactionNotBroadcastByWallet to NodeError in ldk_node.udl.

Out of Scope

  • src/payment/onchain.rs, src/wallet/mod.rs: transactions broadcast before this version are not in the record, so an unconfirmed send made before the upgrade cannot be RBF-bumped after it. CPFP still works for them.
  • src/wallet/mod.rs: broadcast transactions are not inserted into the wallet graph at broadcast time; they still reach it through the next sync, as before.
  • Bitkit: needs a new ldk-node release and version bumps in both apps to pick this up, and can map TransactionNotBroadcastByWallet to a Boost error message.

QA Notes

Automated Checks

  • added rbf_bumps_transactions_the_wallet_broadcast, rbf_refuses_transactions_the_wallet_did_not_broadcast and broadcast_record_survives_restart in src/payment/onchain.rs: a wallet send and its replacement can be bumped; an unknown txid and a wallet-graph transaction the wallet did not broadcast are refused and nothing is queued on the broadcaster; the record is read back after the node is rebuilt on the same store.
  • added rbf_bumps_transactions_sent_through_prepared_broadcast: a transaction sent with PreparedOnchainSend::broadcast against the mock Esplora listener can be bumped.
  • added failed_broadcast_record_write_dispatches_nothing: with record writes failing, a wallet send, an RBF bump, a CPFP child and a prepared send each return PersistenceFailed, queue or send nothing, and the wallet send releases its change address; the RBF bump succeeds once writes work again.
  • both new tests fail when the record write in PreparedOnchainSend::broadcast is removed, and the failing-store test fails when the wallet send's cancel_tx is removed.
  • ran cargo test --lib, cargo check --features uniffi and the 20 RBF and CPFP tests in tests/multi_address_types_tests.rs on macOS arm64; all pass.

@ovitrif ovitrif self-assigned this Oct 25, 2026
@ovitrif
ovitrif requested review from a team, ben-kaufman and pwltr and removed request for a team October 25, 2026 10:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T10:51:11.503085Z 4b35821 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@talosmachina talosmachina left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No findings. Limits bump_fee_by_rbf to txids this node recorded at broadcast (sends, prepared sends, RBF replacements, CPFP children), persisted one key per txid in a new KV namespace, and leaves CPFP open. Reviewed 4b35821, full tier.

What I checked, and 6 candidates I ruled out

Read in full: the diff, PreparedOnchainSend::broadcast and its Drop, Wallet::send_to_address, bump_fee_by_rbf, accelerate_by_cpfp, cancel_tx, build_rbf in bdk-wallet-aggregate, the VSS store's read/write error mapping
Call sites traced: every broadcast_transactions and broadcast_user_transaction caller in src/; all user send entry points (send_to_address, send_all_to_address, the *_with_broadcast_result pair, prepare_send_* then broadcast) reach a record_broadcast_txid before dispatch
Run here (Linux, Rust 1.89): cargo test --lib 124 passed, including the three new tests; cargo test --test multi_address_types_tests -- rbf cpfp 20 passed against electrsd/bitcoind; cargo check --features uniffi clean apart from existing warnings; cargo fmt --check clean
CI: no checks ran on this PR (rust.yml is workflow_dispatch only)

Ruled out

  • Record written but nothing dispatched (broadcast records, then try_block_on fails before submission_started): the stale key only lets a later RBF reach build_rbf, which returns TransactionNotFound for a txid not in the graph.
  • Record write fails after persist_all on the RBF/CPFP paths: cancel_tx releases the replacement or child and nothing is broadcast, same shape as the existing send path.
  • Err contract of PreparedOnchainSend::broadcast: the new PersistenceFailed returns before the backend call and is not cached, so "Err proves no dispatch" still holds.
  • Key validity: a 64-char hex txid under a non-empty primary and empty secondary namespace is within the KV alphabet and length limits; NotFound is mapped from both SQLite and VSS (NoSuchKeyError), so absence reads as false rather than PersistenceFailed.
  • Nested block_in_place on VSS (broadcast already runs inside one and the VSS sync write enters another): the inner call runs on the thread the outer one already released, and broadcast already does a block_on at the same depth.
  • Unconfirmed sends from before the upgrade can no longer be RBF-bumped, and an unknown txid now reports TransactionNotBroadcastByWallet instead of TransactionNotFound: both stated in the PR body as intended.

Merge confidence: 4/5, no CI ran on the PR and the new tests exercise the record on SQLite only, not on the VSS store the apps build with.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two independent reviews, nothing blocking a merge.

worth doing, does not block

  • No test covers the broadcast record on the PreparedOnchainSend path (src/payment/onchain.rs:224). Deleting self.wallet.record_broadcast_txid(&self.txid())?; at src/payment/onchain.rs:224 leaves every test green. If that line regressed, transactions sent through send_to_address_with_broadcast_result, send_all_to_address_with_broadcast_result and the prepared sends could no longer be RBF-bumped, and nothing would catch it. How I confirmed it: I removed the line in a scratch copy under $TMPDIR. All 10 prepared_send_tests still passed, including the three new ones. No integration test in tests/ bumps a transaction sent through those APIs. The PR description says OnchainPayment::send_to_address uses this path. It does not: it calls Wallet::send_to_address (onchain.rs:770). So rbf_bumps_transactions_the_wallet_broadcast only exercises the Wallet path. The write-failure branches are also untested. None of the four sites has a test that fails the KV write and checks for PersistenceFailed, no queued broadcast, and a released change reservation. Suggested tests: bump a transaction sent with PreparedOnchainSend::broadcast against the fixture's mock Esplora listener, and add one failing-store case.

nits

  • assert_no_dispatch in the RBF refusal test cannot detect an RBF dispatch (src/payment/onchain.rs:1569). In rbf_refuses_transactions_the_wallet_did_not_broadcast, f.assert_no_dispatch() only checks that the mock TCP listener got no connection. Wallet::bump_fee_by_rbf does not contact the listener. It enqueues on tx_broadcaster, which is drained only by continuously_process_broadcast_queue. That task is spawned in Node::start (src/lib.rs:641), and the fixture never calls start. How I confirmed it: in a scratch copy I added f.assert_no_dispatch() right after a successful bump_fee_by_rbf in rbf_bumps_transactions_the_wallet_broadcast. It passed even though a replacement had been queued. The Err(TransactionNotBroadcastByWallet) assertions do cover the refusal. The "refused without dispatch" claim needs a check that the broadcaster queue is empty, for example get_broadcast_queue().await.try_recv().is_err(), as take_broadcast_and_sync already does.
  • bump_fee_by_rbf error docs are out of date after the new check (src/payment/onchain.rs:932). The record check runs before build_rbf, so any txid without a record now returns TransactionNotBroadcastByWallet. Before, an unknown txid returned TransactionNotFound, and a confirmed received transaction returned TransactionAlreadyConfirmed. The doc at src/payment/onchain.rs:932 still says TransactionNotFound is returned "if the transaction can't be found in the wallet". Now it is only returned for a recorded transaction that has not been synced yet. The new error's message, "was not broadcast by this wallet", is also wrong for sends this wallet made before the upgrade, which the PR lists as out of scope. Bitkit will show that text as a Boost error. Either reword the variant's doc and message to say the transaction has no broadcast record, or document the precedence.

Comment thread src/payment/onchain.rs Resolved
Comment thread src/payment/onchain.rs Resolved
Comment thread src/payment/onchain.rs Resolved
@ovitrif

ovitrif commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Two independent reviews, nothing blocking a merge.

@coreyphillips pushed 1053a38 with all three points addressed:

  • Added a test that bumps a transaction sent with PreparedOnchainSend::broadcast, and a failing-store test covering the wallet send, RBF, CPFP and prepared-send write failures. Both fail without the record write in PreparedOnchainSend::broadcast.
  • The refusal test now checks that the broadcaster queue is empty instead of the listener.
  • The error now reads "The wallet has no broadcast record for this transaction, so it cannot be fee-bumped.", and the bump_fee_by_rbf docs state that the record check runs first.

cargo test --lib and cargo check --features uniffi pass. The description is updated to match, including which send paths use Wallet::send_to_address.

@ovitrif
ovitrif requested a review from coreyphillips October 27, 2026 16:35
coreyphillips
coreyphillips previously approved these changes Oct 27, 2026

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked after 1 new commit (1053a38). Nothing blocking remains.

addressed

  • No test covers the broadcast record on the PreparedOnchainSend path (src/payment/onchain.rs:224). Fixed: rbf_bumps_transactions_sent_through_prepared_broadcast (src/payment/onchain.rs:1684) bumps a transaction sent through PreparedOnchainSend::broadcast. failed_broadcast_record_write_dispatches_nothing (:1714) makes the record write fail at all four sites. In a scratch copy I replaced :224 with a comment, and both tests failed: the first at :1709, the second with Ok(Unknown) vs Err(PersistenceFailed) at :1768. Its change-release assertion does not test anything; that is filed below as a new finding.
  • assert_no_dispatch in the RBF refusal test cannot detect an RBF dispatch (src/payment/onchain.rs:1569). Fixed: The refusal test now calls assert_nothing_queued (src/payment/onchain.rs:1680, helper at :1124), which try_recvs the broadcaster queue. To check it can detect a dispatch, I added it after the successful bump in rbf_bumps_transactions_the_wallet_broadcast in a scratch copy, and it failed at :1126 as it should.
  • bump_fee_by_rbf error docs are out of date after the new check (src/payment/onchain.rs:932). Fixed: The variant doc and Display text now say the wallet has no broadcast record (src/error.rs:136, :244-249). The bump_fee_by_rbf error list at src/payment/onchain.rs:931-942 states that the record check runs first, and that TransactionNotFound and TransactionAlreadyConfirmed only apply to recorded transactions. That matches the order in src/wallet/mod.rs:888-940.

new since the last review

worth doing, does not block

  • Failing-store test's change-address check passes without cancel_tx (src/payment/onchain.rs:1731-1746). The assertion meant to show that a failed wallet send releases its change address compares two values that are always equal. get_drain_script (src/wallet/mod.rs:446-450) returns peek_address(Internal, 0), which is a fixed derivation that does not depend on which addresses are marked used. So change at src/payment/onchain.rs:1731 and the value compared at :1746 are always the same script. Also, the failed send would not have used index 0 anyway: the earlier recorded send already consumed it. How I confirmed it: in a scratch copy I replaced let _ = self.cancel_tx(&tx); in Wallet::send_to_address (src/wallet/mod.rs:1955) with a comment. failed_broadcast_record_write_dispatches_nothing still passed, as did all 12 prepared_send_tests. The PR description and the reply to point 1 both list the change release as tested. It is not. One way to make the check real is the pattern in dropped_unsigned_preparations_release_only_the_last_handles_change. Before enabling failures, prepare and drop a candidate to learn the next change script. Then run the failing send, prepare again, and assert the change output reuses that script.

Comment thread src/payment/onchain.rs Resolved
@ovitrif

ovitrif commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Failing-store test's change-address check passes without cancel_tx

@coreyphillips pushed 5c100a5: the failing-store test now learns the next change script from a dropped candidate and asserts that the failed wallet send leaves it unused. It fails with cancel_tx removed from Wallet::send_to_address. cargo test --lib passes. The push dismissed your approval, so this needs another look.

@ovitrif
ovitrif requested a review from coreyphillips October 27, 2026 16:51

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked after 1 new commit (5c100a5). Nothing blocking remains.

addressed

  • Failing-store test's change-address check passes without cancel_tx (src/payment/onchain.rs:1731-1746). Fixed: src/payment/onchain.rs:1732-1759 now learns the next change script by preparing a candidate and dropping it, which runs cancel_tx in Drop. It then runs the failing wallet send and asserts that a fresh probe returns the same script. In a scratch copy of HEAD the test passed, along with all 126 cargo test --lib tests. With let _ = self.cancel_tx(&tx); replaced by a comment at src/wallet/mod.rs:1955, it failed at onchain.rs:1759 with two different P2WPKH scripts.

@ovitrif
ovitrif merged commit e794b35 into main Oct 27, 2026
@ovitrif
ovitrif deleted the fix/bump-own-txs-only branch October 27, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants