Repository navigation
Build splice_in_with_all from manually selected inputs - #1176
Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
173105a to
fbaa8d4
Compare
tnull
left a comment
There was a problem hiding this comment.
Seems Leo's suggestion here might make sense to add in this PR?: #1103 (comment)
| // retained as an explicit output to one of our own addresses, which stays | ||
| // fixed across fee bumps. The address is reserved so that other change-address | ||
| // consumers skip it until the splice transaction reaches the wallet. | ||
| let reserve_output = if cur_anchor_reserve_sats > DUST_LIMIT_SATS { |
There was a problem hiding this comment.
Codex:
- [P2] Preserve small configured anchor reserves — src/lib.rs:1891 (/home/tnull/workspace/ldk-node-review-pr-1176-0T4Hm0/src/lib.rs:1891). With
per_channel_reserve_sats = 546, this condition omits the reserve output. Because the previous balance check was removed, splice_in_with_all now succeeds
and drains the wallet to zero sats. Preserve positive reserves using the destination’s dust threshold, or reject the splice when preservation is
impossible.
There was a problem hiding this comment.
Thoughts on doing it for open_channel_with_all in this PR? See below.
Claude:
Fixed. A positive reserve is always kept as an output now, rounded up to the dust limit when it is below it, and the insufficient-funds check uses that amount. Added
splice_in_with_all_bump_fee_retains_dust_limit_anchor_reserve.open_channel_with_allhas the same>comparison; I left it alone here.
| .and_then(|builder| builder.add_outputs(reserve_output.into_iter().collect()).build()) | ||
| .map_err(|e| { | ||
| log_error!(self.logger, "Failed to splice channel: {}", e); | ||
| Error::ChannelSplicingFailed |
There was a problem hiding this comment.
Codex:
- [P2] Report fee shortfalls as InsufficientFunds — src/lib.rs:1970 (/home/tnull/workspace/ldk-node-review-pr-1176-0T4Hm0/src/lib.rs:1970). With 26,000 sats
confirmed, a 25,000-sat reserve, no local channel balance, and a 2,500 sat/kwu feerate, LDK rejects the contribution before the subsequent insufficient-
funds check. This mapping returns ChannelSplicingFailed, preventing callers from identifying the funding shortage. Map ManuallySelectedInputsInsufficient
to InsufficientFunds.
There was a problem hiding this comment.
Claude:
Fixed.
ManuallySelectedInputsInsufficientmaps toInsufficientFunds; the other build errors still map toChannelSplicingFailed.
tnull
left a comment
There was a problem hiding this comment.
CI is failing, not sure if flake:
thread 'splice_rounds_discarded_while_the_channel_is_listed_fail_at_close' (307885) panicked at tests/integration_tests_rust.rs:4488:5:
assertion `left == right` failed: the bump reused an input of the first round
left: [OutPoint { txid: ec9c78fceb249288b98f6b1772c1b2b648178638e4799baeae8a6b086af0c555, vout: 1 }, OutPoint { txid: ec9c78fceb249288b98f6b1772c1b2b648178638e4799baeae8a6b086af0c555, vout: 0 }]
right: [OutPoint { txid: ec9c78fceb249288b98f6b1772c1b2b648178638e4799baeae8a6b086af0c555, vout: 1 }]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
splice_rounds_discarded_while_the_channel_is_listed_fail_at_close
|
|
||
| let contribution = funding_template | ||
| .with_prior_contribution(feerate, max_feerate) | ||
| .add_inputs(inputs) |
There was a problem hiding this comment.
Since a bump now keeps these manually selected inputs, LDK no longer falls back to coin selection (it returns ManuallySelectedInputsInsufficient instead of MissingCoinSelectionSource). So bumping above the prior contribution's max feerate (1.5x) now fails, even if the wallet has received new confirmed coins since the splice. Before, the bump could use those new coins. Is that OK?
There was a problem hiding this comment.
Hmm... good point.
Claude:
The check is LDK's: the builder adjusts the prior contribution against its old
max_feeratebefore storing the new one, so adding inputs to the prior-seeded builder fails the same way (filed as https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/issues/5282). Added a commit sobump_channel_funding_feehandles it: whenrbf_prior_contributionreturnsManuallySelectedInputsInsufficient, the bump is rebuilt viawithout_prior_contributionfrom all confirmed funds, the pending round's inputs plus any coins confirmed since, with the reserve paid to a fresh reserved address.splice_in_with_all_bump_fee_above_max_feerate_adds_new_coinscovers it. Once LDK applies the caller's maximum, a bump past the ceiling without new coins is adjusted in place again; the rebuild stays for pulling in new coins.
| } | ||
|
|
||
| // Manually selected inputs are consumed in full with no change output: the | ||
| // amount added to the channel is what remains after fees, and a later fee bump |
There was a problem hiding this comment.
With this, the splice_in_with_all docs line "The amount spliced in is determined at min_fee_rate, or at the estimate if unset." (from #1159) is no longer accurate: the amount is what remains after fees at feerate, which can be a pending splice's RBF minimum, and a fee bump lowers it. Maybe update it to say that?
|
@tnull On the CI failure: I don't think it's a flake. |
Yup, updating the test. |
Claude ended up writing this, but maybe best to leave for a separate PR given we want to add |
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
fbaa8d4 to
c875410
Compare
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
c875410 to
7e32a0b
Compare
Dropped in favor of including it in #1181. |
7e32a0b to
c3a9bc1
Compare
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
Have we considered that while the anchor reserves sits on the output of the unconfirmed splice transaction, it cannot be used to help confirm force-closes on other channels ? This is particularly relevant for zero-fee commitment channels; for those channels a failure to select any confirmed output directly leads to a failure to propagate the force-close.
I am thinking the fundamental issue is that none of the reserve sits in independent, locked utxos. A separate set of utxos 100% dedicated to the anchor reserve, and that doesn't get touched when a user calls splice_in_with_all would be useful. Issue #1198 proposes an approach for how to build this set of utxos.
tnull
left a comment
There was a problem hiding this comment.
Mostly looks good, claude:
- An existing test now covers less, and its doc comment is stale (tests/integration_tests_rust.rs:4953-4966, splice_rounds_discarded_while_the_channel_is_listed_fail_at_close).
- The test used to bump from a fresh coin so that "the two rounds are contributions of their own". It asserted that the bump shared only the channel funding output with the first round,
and that RECLAIMED_ADDRESSES == 2, i.e. each DiscardFunding returned its own round's contribution.- The PR changes it so the bump reuses the first round's inputs and asserts == 1. The case where each discard event returns a separate contribution is no longer tested, yet the doc
comment still says the test "bumps the round's fee from another coin, so the two rounds are contributions of their own".- Suggested fix: keep the original scenario by bumping above the first round's maximum feerate after a new coin confirms. That now goes through the rebuild path and gives the bump its
own inputs. Alternatively, make the first round a fixed-amount splice_in. At minimum, update the doc comment.- The commit message promises more than the code delivers (main commit). It says the reserve mark is dropped "if the contribution cannot be built or LDK rejects it". But if
funding_contributed fails with ContributionPending via QuiescentError::DoNothing, LDK sends no DiscardFunding. The address then stays marked used until restart. The only cost is a
skipped address (a small address-gap/privacy issue), so either soften the wording or release the address explicitly on that error.- A fee bump can now pull in newly confirmed coins. When a bump goes past the earlier maximum feerate, the rebuild sweeps in any coins confirmed since the splice. A user who asked for a
higher fee ends up putting more money into the channel. It's documented in the rustdoc and CHANGELOG, so this is a design point for discussion rather than a bug. Failing with an error,
or only adding new coins when the original inputs can't cover the fee, would be the more conservative choice.- A tiny value_added isn't caught on the in-place bump path. The below-dust check in build_splice_in_with_all_contribution only runs when the contribution is built or rebuilt. If
rbf_prior_contribution succeeds by adjusting the existing contribution, value_added could drop below dust without a check. This is a very unlikely edge case and LDK may reject it
anyway.
|
Fixed 1 and 4. The other two are either unreachable or intended / will need to be fixed once we bump the LDK dependency. Claude responses inline.
Fixed, the first way: a new coin confirms, then the bump asks for 1000 sat/kwu, past the first round's maximum of 375, so it is rebuilt from the round's inputs and the coin. The test checks the bump spends exactly those, and both discards return a contribution again (
I don't think that case is reachable.
This is mostly https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/issues/5282. LDK checks the in-place adjustment against the first round's (Follow-up for the pin bump: both tests reach the rebuild only through the stale-maximum check; after https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/pulls/5297 they adjust in place and the discard test's reclaim count drops back to one. Give them a bump the pending inputs can't cover, or return the discard test to a fixed-amount first round.)
Fixed. LDK's adjustment of manually selected inputs only checks that the fee is covered, and |
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
c3a9bc1 to
120a068
Compare
tnull
left a comment
There was a problem hiding this comment.
This needs a rebase, also feel free to squash.
The RBF splice test builds its own bitcoind with a lower incrementalrelayfee so that LDK's minimum RBF bump of 25 sat/kwu satisfies BIP125's absolute fee increase requirement. Upcoming tests that fee-bump a splice_in_with_all splice need the same setup, so make it a helper next to setup_bitcoind_and_electrsd. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. A bump that LDK would pay by leaving less than dust to add to the channel is rebuilt the same way, so the dust check of the initial splice applies: without new coins to cover the fee, the bump fails with InsufficientFunds and the pending splice stands. LDK currently bounds the adjustment by the first round's maximum rather than the bump's, so today most bumps more than 1.5x above the first round's estimate take this path. Once https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/pulls/5297 is in the pin, only bumps the pending inputs cannot cover do, and the two tests that bump past the first round's maximum say how to keep the rebuild under test. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
120a068 to
96d615b
Compare
Done. |
tankyleo
left a comment
There was a problem hiding this comment.
Discussed offline, utxo splits are out of scope for this PR
tnull
left a comment
There was a problem hiding this comment.
Looks good I think, just one comment on code hygiene
| } | ||
|
|
||
| pub(crate) async fn cancel_tx(&self, tx: Transaction) -> Result<(), Error> { | ||
| self.release_outputs(tx.output).await |
There was a problem hiding this comment.
Hmm, if we now refactor to have release_outputs, can we inline these calls rather than having both the old and new APIs available. Same with reserve_internal_address above.
While LLMs don't get confused, I personally dislike the growing number of tiny helper methods that all do something slightly different. IMO, it almost always makes sense to inline helper methods less than 5-7 LoC as it's easier to spot at the callsite what actually happens rather than having to jump around/remembering a bazillion tiny methods with slightly different semantics.
There was a problem hiding this comment.
Had Claude rename get_new_internal_address to next_unused_internal_address to avoid a single pub(crate) method taking a bool.
🤖 Fixed for release_outputs: cancel_tx and release_outputs_inner are gone, the loop is inlined, and the DiscardFunding handler passes its outputs straight to it. cancel_tx did the same thing with a different argument type, so dropping it lost nothing. get_new_internal_address and reserve_internal_address do different things, one marks the address used and the other doesn't, so collapsing them means one method with a bool switch, and get_new_internal_address(true) at the call site says less than reserve_internal_address() does. I kept the two names over the private method that takes the flag, and renamed get_new_internal_address to next_unused_internal_address, since repeated calls return the same address until it is used or reserved.
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. A bump that LDK would pay by leaving less than dust to add to the channel is rebuilt the same way, so the dust check of the initial splice applies: without new coins to cover the fee, the bump fails with InsufficientFunds and the pending splice stands. LDK currently bounds the adjustment by the first round's maximum rather than the bump's, so today most bumps more than 1.5x above the first round's estimate take this path. Once https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/pulls/5297 is in the pin, only bumps the pending inputs cannot cover do, and the two tests that bump past the first round's maximum say how to keep the rebuild under test. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
96d615b to
869930c
Compare
splice_in_with_all estimated the maximum amount with a wallet drain and then ran coin selection for that exact amount. The resulting contribution had at most the anchor reserve as a change output, so bump_channel_funding_fee had nothing else to pay a higher fee from. With anchor channels enabled, the bump shrank the change output and so spent the reserve on the splice fee. Without a reserve there was no change output at all; LDK keeps the value added fixed for coin-selected contributions, so the bump fell back to coin selection, which failed for want of further inputs. The drain estimate also ran at the funding feerate estimate while the contribution could be built at a pending splice's higher RBF minimum, so coin selection for that amount could eat into the reserve or fail. Instead, hand LDK the wallet's confirmed UTXOs as manually selected inputs. They are consumed in full with no change output, the amount added to the channel is whatever remains after fees at the template's feerate, and a later fee bump is paid by adding a little less to the channel. When an anchor reserve is required, it is kept as an explicit output back to one of the wallet's own addresses, which stays fixed across bumps; a reserve below the dust limit is rounded up to it rather than dropped. That address is marked used as soon as it is handed out, since the splice transaction only reaches the wallet once negotiation completes and until then BDK would offer the same address as change elsewhere. The mark is dropped again if the contribution cannot be built, or by the DiscardFunding event LDK sends when it rejects a contribution that reserved anything. Insufficient-funds checks stay in front of LDK, which would otherwise build a near-empty contribution, and inputs that cannot cover the reserve and the fee report InsufficientFunds too. The drain-based splice estimate is removed along with the shared-input handling in the drain helpers that only it used. Fixes lightningdevkit#1168. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`splice_in_with_all` now hands LDK manually selected inputs, which LDK adjusts for a fee bump only up to the contribution's maximum feerate and never supplements by coin selection. A bump past that maximum, as when fees rise by more than half since the splice, failed even though the wallet may have received coins since. Instead, `bump_channel_funding_fee` now replaces such a contribution with one built the same way from all confirmed funds: the pending round's inputs plus any coins confirmed in the meantime. The replacement keeps the anchor reserve as its own output, paid to a fresh reserved address. A bump that LDK would pay by leaving less than dust to add to the channel is rebuilt the same way, so the dust check of the initial splice applies: without new coins to cover the fee, the bump fails with InsufficientFunds and the pending splice stands. LDK currently bounds the adjustment by the first round's maximum rather than the bump's, so today most bumps more than 1.5x above the first round's estimate take this path. Once https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/pulls/5297 is in the pin, only bumps the pending inputs cannot cover do, and the two tests that bump past the first round's maximum say how to keep the rebuild under test. Suggested by shubhamkmr04 in lightningdevkit#1176. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
869930c to
de25e1b
Compare
Fixes #1168.
Node::splice_in_with_allestimated the maximum amount with a wallet drain and then ran coin selection for that exact amount. The resulting contribution had at most the anchor reserve as a change output, sobump_channel_funding_feehad nothing else to pay a higher fee from. With anchor channels enabled, the bump shrank the change output and spent the reserve on the splice fee. Without a reserve there was no change output at all, so the bump failed withChannelSplicingFailed. The drain estimate also ran at the funding feerate estimate while the contribution could be built at a pending splice's higher RBF minimum.This PR instead hands LDK the wallet's confirmed UTXOs as manually selected inputs (
FundingBuilder::add_inputs). They are consumed in full with no change output, the amount added to the channel is whatever remains after fees at the template's feerate, and a later fee bump is paid by adding a little less to the channel. When an anchor reserve is required, it is kept as an explicit output back to one of the wallet's own addresses, which stays fixed across bumps.The reserve address is marked used in BDK as soon as it is handed out, since the splice transaction only reaches the wallet once negotiation completes and until then BDK would offer the same address as change elsewhere. The mark is dropped again if the contribution cannot be built, or via
DiscardFundingif LDK rejects it.Insufficient-funds checks stay in front of LDK, which would otherwise build a near-empty contribution. The drain-based splice estimate is removed along with the shared-input handling in the drain helpers that only it used.
LDK adjusts a contribution of manually selected inputs only up to its maximum feerate and never supplements it by coin selection, so a bump past that maximum failed even when the wallet had received coins since. The last commit has
bump_channel_funding_feerebuild such a contribution from all confirmed funds instead: the pending round's inputs plus any coins confirmed in the meantime. Today most bumps more than 1.5x above the first round's estimate take this path because LDK checks the first round's maximum rather than the bump's (https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/issues/5282); once https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/pulls/5297 is in the pin, only bumps the pending inputs cannot cover do.The first commit extracts the low
-incrementalrelayfeebitcoind setup used by the splice RBF tests into a shared helper, since the new tests need it too.The reserve and no-reserve bump tests fail on
main: with a reserve the bump leaves the spliced-in amount unchanged while the fee rises, i.e. it is paid from the reserve; without a reservebump_channel_funding_feereturnsChannelSplicingFailed.🤖 Generated with Claude Code