Skip to content

txconfirm: keep the signed fee split after a lost broadcast reply - #1652

Merged
bhandras merged 1 commit into
mainfrom
issue-1651-wallet-exit-queue
Nov 27, 2026
Merged

bhandras merged 1 commit into
mainfrom
issue-1651-wallet-exit-queue

Conversation

@bhandras

Copy link
Copy Markdown
Member

When several exit transactions need fee inputs, the wallet can split one confirmed coin into smaller outputs. The node can accept that split and lose its reply. Previously the daemon discarded the signed transaction on the first timeout and could pay for another split from a different coin.

Keep the signed bytes, watch their transaction ID, and exclude their inputs from other fee children while the split is pending. A later funding request resubmits those same bytes. A malformed receipt also leaves the candidate pending. An explicit relay rejection still follows the existing rejection path.

The regression test loses the first reply, supplies a second eligible coin and checks the second broadcast byte for byte. It also checks that the original input stays reserved until confirmation. Package tests and focused race tests passed. A Bitcoin Core regtest run with three independent exits and one wallet coin reached all three sweeps.

The retained candidate lives in the broadcaster process. Restart persistence and approval of a batch of exits are further parts of #1651.

@bhandras

Copy link
Copy Markdown
Member Author

/gateway review

Review the current head for initial broadcast ambiguity and fee input ownership. Check that a lost or malformed receipt keeps the identical signed split, that the blocked parents cannot reuse its inputs, and that definite rejection and confirmation still release the right state. The regression supplies a second confirmed coin after the first timeout. This change covers a live actor. Process restart and batch approval belong to the next slices. Please classify findings by concrete reachability, consequence, existing guards and smallest fix.

@lightninglabs-gateway

lightninglabs-gateway Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

❌ gateway review failed: code-review skill failed across all auth modes: You've hit your org's monthly spend limit · ask your admin to raise it at https://claude.ai/admin-settings/usage · your weekly limit resets Nov 29, 6am (UTC)

See workflow logs for details.

@bhandras
bhandras force-pushed the issue-1651-wallet-exit-queue branch from 152834a to 963277c Compare November 26, 2026 16:54
@bhandras

Copy link
Copy Markdown
Member Author

Claude: Approve, no blockers. On both the first submit and later retries, the split's ownership now follows one rule: only an explicit fee or structural rejection, as classified by ClassifyBroadcastFailure, gives it up. Everything else keeps it. That covers transport errors, an expired transition context, a malformed or mismatched receipt, a "spent or missing inputs" reply, and an "already known" reply. The txid the actor keeps is the local fundedTx.TxHash(), worked out before the submit. The confirmation watch, the predicted output assignments and the pending state are all keyed to it, so a lost or wrong receipt can no longer swap in a backend-reported txid or drop the candidate. TestFanoutAmbiguousPublishRetainsCandidate checks the path that matters. After a lost first receipt, new wallet supply only causes the same signed bytes to be resent. No second input is funded and no new script is derived.

Retained inputs and predicted outputs are released only at the points that end ownership. b.fanoutInputs is set only after the submit stops being a rejection, and it is cleared in processConfirmed and releasePendingFanout. releasePendingFanout is used by both clearPendingFanout (last assigned parent evicted) and clearAndRebuild (explicit rejection on retry). So every way out of feeBumpStateFanoutPending drops the exclusion together with the predicted outputs and leases. Only one split is ever pending, so a single slice is enough. Adding those inputs to excludedOutpointsForOtherParents is safe for every parent, including the ones the split serves, because the split already spends them. An explicit rejection on the first submit still releases the predicted outputs and stays idle without setting the exclusion, which is correct. Dropping the two actorblock_baseline entries in favour of one annotated, bounded await in broadcastFanout is fine.

Follow-up, not a blocker: a lost first receipt now takes the same retain-forever path that retries already had. If the split never reached the network and another wallet user later spends one of its inputs, each rebroadcast gets an ambiguous spend reply. The split then stays pending until its parents are evicted. The input leases make this unlikely, and it only stalls parents that have no other confirmed supply. It does not lose funds. Rebuilding state after a restart is out of scope here, as stated. There is no new test for an explicit rejection on the first submit; TestFeeInputFanoutClearsRejectedPendingFanout covers only the retry case. I reviewed the code but did not run the test suite locally.

A wallet split can reach the network before its sender receives the
reply. Retain the signed transaction and watch its local txid. Keep the
funding inputs unavailable to other children until the split resolves.

Retry the same bytes when another confirmed wallet coin becomes
available. Only an explicit rejection permits building a fresh split.
This covers the active actor lifetime. Process recovery needs durable
storage for the signed candidate.
@bhandras
bhandras force-pushed the issue-1651-wallet-exit-queue branch from 963277c to f7ecd19 Compare November 27, 2026 10:18
@bhandras
bhandras added this pull request to stack #1660 November 27, 2026 10:18
@bhandras

Copy link
Copy Markdown
Member Author

/gateway review

Please review the current commit f7ecd19 against its PR base. Focus on reachable ownership, confirmation gating, and wallet quote correctness within this layer.

@lightninglabs-gateway

lightninglabs-gateway Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

❌ gateway review failed: code-review skill failed across all auth modes: You've hit your org's monthly spend limit · ask your admin to raise it at https://claude.ai/admin-settings/usage · your weekly limit resets Nov 29, 6am (UTC)

See workflow logs for details.

@bhandras

Copy link
Copy Markdown
Member Author

Claude: Approve.

I traced the two paths this commit changes:

  • Ownership guard. b.fanoutInputs is set once, at txconfirm/fee_bump_fsm_logic.go:264, after the split is kept. Every way out of feeBumpStateFanoutPending clears it:

    • confirmation clears it at :436
    • clearPendingFanout, clearAndRebuild and eviction of the last parent all go through releasePendingFanout, which clears it at :537
    • there is only one FSM per broadcaster (newFeeBumpStateMachine), so one owner at a time

    excludedOutpointsForOtherParents (txconfirm/broadcaster.go:682) hides those inputs from every parent's fee child. A wallet that still lists the spent coins can no longer fund a conflicting child.

  • Broadcast ambiguity. The first send and every resend now share broadcastFanout. A split is only rebuilt when the backend explicitly rejects it, meaning ClassifyBroadcastFailure returns Permanent or Fee. In every other case the split is kept and its txid stays watched under the hash computed locally (fundedTx.TxHash()):

    • timeouts and cancelled calls
    • malformed or wrong-txid receipts
    • "already known" and ambiguous-spend errors

    Before this change, a lost first reply released the split, and the next block could fund a second split from another wallet coin. That is the double charge this commit fixes. A wrong-txid resend receipt used to drop the split; now it keeps it, which is the safer choice.

  • Test. TestFanoutAmbiguousPublishRetainsCandidate covers the regression:

    • only the identical signed split is resent, even when new wallet coins appear
    • fundedTemplates and scriptCalls stay at 1
    • the original inputs are excluded, and the exclusion clears on confirmation

Behaviour shared with the existing resend path is unchanged. A first send that hits a conflict string the classifier doesn't know is now kept rather than released. It clears once the split confirms or its parents are evicted, so it is not a blocker. As the commit message says, a split kept this way is lost if the process restarts, until it gets durable storage. That is out of scope here.

I couldn't run go test ./txconfirm/ (permission was denied), so this review is from reading the code only.

@bhandras
bhandras merged commit 1447509 into main Nov 27, 2026
21 of 22 checks passed
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.

1 participant