Repository navigation
fix: only fee-bump transactions the wallet broadcast - #129
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
talosmachina
left a comment
There was a problem hiding this comment.
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 (
broadcastrecords, thentry_block_onfails beforesubmission_started): the stale key only lets a later RBF reachbuild_rbf, which returnsTransactionNotFoundfor a txid not in the graph. - Record write fails after
persist_allon the RBF/CPFP paths:cancel_txreleases the replacement or child and nothing is broadcast, same shape as the existing send path. Errcontract ofPreparedOnchainSend::broadcast: the newPersistenceFailedreturns before the backend call and is not cached, so "Errproves 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 asfalserather thanPersistenceFailed. - Nested
block_in_placeon VSS (broadcastalready runs inside one and the VSS sync write enters another): the inner call runs on the thread the outer one already released, andbroadcastalready does ablock_onat the same depth. - Unconfirmed sends from before the upgrade can no longer be RBF-bumped, and an unknown txid now reports
TransactionNotBroadcastByWalletinstead ofTransactionNotFound: 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
left a comment
There was a problem hiding this comment.
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 throughsend_to_address_with_broadcast_result,send_all_to_address_with_broadcast_resultand 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 10prepared_send_testsstill passed, including the three new ones. No integration test intests/bumps a transaction sent through those APIs. The PR description saysOnchainPayment::send_to_addressuses this path. It does not: it callsWallet::send_to_address(onchain.rs:770). Sorbf_bumps_transactions_the_wallet_broadcastonly 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 forPersistenceFailed, no queued broadcast, and a released change reservation. Suggested tests: bump a transaction sent withPreparedOnchainSend::broadcastagainst the fixture's mock Esplora listener, and add one failing-store case.
nits
assert_no_dispatchin the RBF refusal test cannot detect an RBF dispatch (src/payment/onchain.rs:1569). Inrbf_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_rbfdoes not contact the listener. It enqueues ontx_broadcaster, which is drained only bycontinuously_process_broadcast_queue. That task is spawned inNode::start(src/lib.rs:641), and the fixture never callsstart. How I confirmed it: in a scratch copy I addedf.assert_no_dispatch()right after a successfulbump_fee_by_rbfinrbf_bumps_transactions_the_wallet_broadcast. It passed even though a replacement had been queued. TheErr(TransactionNotBroadcastByWallet)assertions do cover the refusal. The "refused without dispatch" claim needs a check that the broadcaster queue is empty, for exampleget_broadcast_queue().await.try_recv().is_err(), astake_broadcast_and_syncalready does.bump_fee_by_rbferror docs are out of date after the new check (src/payment/onchain.rs:932). The record check runs beforebuild_rbf, so any txid without a record now returnsTransactionNotBroadcastByWallet. Before, an unknown txid returnedTransactionNotFound, and a confirmed received transaction returnedTransactionAlreadyConfirmed. The doc at src/payment/onchain.rs:932 still saysTransactionNotFoundis 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.
@coreyphillips pushed 1053a38 with all three points addressed:
|
coreyphillips
left a comment
There was a problem hiding this comment.
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 throughPreparedOnchainSend::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 withOk(Unknown)vsErr(PersistenceFailed)at :1768. Its change-release assertion does not test anything; that is filed below as a new finding. assert_no_dispatchin the RBF refusal test cannot detect an RBF dispatch (src/payment/onchain.rs:1569). Fixed: The refusal test now callsassert_nothing_queued(src/payment/onchain.rs:1680, helper at :1124), whichtry_recvs the broadcaster queue. To check it can detect a dispatch, I added it after the successful bump inrbf_bumps_transactions_the_wallet_broadcastin a scratch copy, and it failed at :1126 as it should.bump_fee_by_rbferror 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). Thebump_fee_by_rbferror list at src/payment/onchain.rs:931-942 states that the record check runs first, and thatTransactionNotFoundandTransactionAlreadyConfirmedonly 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) returnspeek_address(Internal, 0), which is a fixed derivation that does not depend on which addresses are marked used. Sochangeat 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 earlierrecordedsend already consumed it. How I confirmed it: in a scratch copy I replacedlet _ = self.cancel_tx(&tx);inWallet::send_to_address(src/wallet/mod.rs:1955) with a comment.failed_broadcast_record_write_dispatches_nothingstill passed, as did all 12prepared_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 indropped_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.
@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 |
coreyphillips
left a comment
There was a problem hiding this comment.
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 runscancel_txin 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 126cargo test --libtests. Withlet _ = 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.
Description
bump_fee_by_rbfto 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 newTransactionNotBroadcastByWalleterror ("The wallet has no broadcast record for this transaction") before a replacement is built. Because this check runs first,TransactionNotFoundandTransactionAlreadyConfirmednow only apply to recorded transactions; thebump_fee_by_rbfdocs list this order.PreparedOnchainSend::broadcast(used by the prepared sends andsend_to_address_with_broadcast_result/send_all_to_address_with_broadcast_result),Wallet::send_to_address(used byOnchainPayment::send_to_addressandsend_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 newwallet_broadcast_txidsKV namespace, so the record survives a restart. If the record cannot be written, the send fails withPersistenceFailedand nothing is dispatched.accelerate_by_cpfpunrestricted. 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.TransactionNotBroadcastByWallettoNodeErrorinldk_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.TransactionNotBroadcastByWalletto a Boost error message.QA Notes
Automated Checks
rbf_bumps_transactions_the_wallet_broadcast,rbf_refuses_transactions_the_wallet_did_not_broadcastandbroadcast_record_survives_restartinsrc/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.rbf_bumps_transactions_sent_through_prepared_broadcast: a transaction sent withPreparedOnchainSend::broadcastagainst the mock Esplora listener can be bumped.failed_broadcast_record_write_dispatches_nothing: with record writes failing, a wallet send, an RBF bump, a CPFP child and a prepared send each returnPersistenceFailed, queue or send nothing, and the wallet send releases its change address; the RBF bump succeeds once writes work again.PreparedOnchainSend::broadcastis removed, and the failing-store test fails when the wallet send'scancel_txis removed.cargo test --lib,cargo check --features uniffiand the 20 RBF and CPFP tests intests/multi_address_types_tests.rson macOS arm64; all pass.