Skip to content

Fix reachable unwrap of outbound_htlc_minimum_msat - #211

Merged
tnull merged 1 commit into
lightningdevkit:mainfrom
tnull:2023-11-fix-reachable-chandetails-unwrap
Nov 27, 2023
Merged

tnull merged 1 commit into
lightningdevkit:mainfrom
tnull:2023-11-fix-reachable-chandetails-unwrap

Conversation

@tnull

@tnull tnull commented Nov 27, 2023

Copy link
Copy Markdown
Collaborator

Fixes #208.

As the unwrap previously was reachable we now expose the field as an Option. Additionally, we document the unwrap safety of the other ChannelDetails fields where applicable.

As the `unwrap` previously was reachable we now expose the field as an
`Option`. Additionally, we document the unwrap safety of the other
`ChannelDetails` fields where applicable.
@tnull
tnull force-pushed the 2023-11-fix-reachable-chandetails-unwrap branch from 492762e to d09c572 Compare November 27, 2023 13:01
@tnull
tnull merged commit f42d604 into lightningdevkit:main Nov 27, 2023
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Nov 28, 2026
…nfirmed_unlocked_amount_sats

Follow-up to the previous commit, the same patch. The wallet's sum becomes upstream's
Wallet::get_confirmed_unlocked_amount_sats (ldk-node lightningdevkit#1223, 6fb3d52) word for word, taken alone
with its unit test, so that the Blocknil part is the public wrapper
(Node::confirmed_spendable_onchain_balance_sats, less the anchor reserve) and moving to upstream
drops the copy. Upstream's sum leaves out what ours also skipped (immature coinbase outputs, a
coin whose transaction is too large for tx_add_input); neither is on a provider's wallet, and
either would only make the figure higher than coin selection can use, as before lightningdevkit#211's fix.
The rest of lightningdevkit#1223 (the splice anchor-reserve checks) isn't taken: it conflicts with our
change-keeping splice_in in splice_channel.

Tests: confirmed_unlocked_amount_does_not_depend_on_seeing_a_splice (upstream's; the splice is
signed here for bdk_wallet 3.2.1, ldk3-bdk-3.2.1). The integration test drops its "in a block
but not synced" assertion: the node's background sync can run first, so it raced (failed once).
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Nov 28, 2026
…nd a reserve refusal in splice_in_with_change as InsufficientFunds

From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

- Node::confirmed_spendable_utxo_values: the value of each coin confirmed_spendable_onchain_balance_sats
  counts (Wallet::get_confirmed_unlocked_utxo_values, the filter of upstream's
  get_confirmed_unlocked_amount_sats). The provider sized a splice's fee for a flat 300 vB, so a
  wallet of many small coins was quoted, then refused after the customer's yes; with the values it
  can size the fee for the coins selection would use, largest first.
- In splice_in_inner's Exact arm, when keep_change (splice_in_with_change), the anchor-reserve check
  after coin selection (upstream lightningdevkit#1223) fails with InsufficientFunds, as that method does when no
  coins leave change. It returned ChannelSplicingFailed, which a caller can't tell from a splice that
  can't start. Upstream's splice_in keeps ChannelSplicingFailed.

Tests: splice_in_with_change_reports_a_fee_into_the_anchor_reserve_as_insufficient_funds (fails with
ChannelSplicingFailed without the mapping, checked) and confirmed_spendable_balance_leaves_out_unconfirmed_change,
which now also checks the values at each step.
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Nov 28, 2026
…nnounce in tx_add_input

Coin selection for a splice marks unspendable a coin whose previous
transaction is too large to carry in a tx_add_input (fits_tx_add_input).
get_confirmed_unlocked_utxo_values listed it anyway, and so did the balance
the provider checks, so a provider funded by a large batch payment could
quote a splice on that coin and have it refused after the customer's yes.
The values now use the same filter, and confirmed_spendable_onchain_balance_sats
is their sum (less the anchor reserve), so the provider's two figures agree.
Upstream's get_confirmed_unlocked_amount_sats, which its own splice checks use,
is unchanged. The docs say smallest first, as the provider sizes it.

Test: confirmed_unlocked_utxo_values_leave_out_coins_too_large_to_announce
fails without the filter (both coins listed).

Review of r11 (bitcoin-wallet lightningdevkit#211).
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
From "Blocknil patch (ldk3-confirmed-balance): the on-chain balance a splice's coin selection can spend":

Node::confirmed_spendable_onchain_balance_sats: the coins confirmed as of the wallet's last sync,
unlocked, mature and small enough for tx_add_input, less the anchor reserve. These are the coins
splice_in and splice_in_with_change select from (exclude_unconfirmed);
BalanceDetails::spendable_onchain_balance_sats is BDK's trusted spendable balance, which also
counts our own unconfirmed change, so after an open or splice spends the wallet's coins the two
differ until the change confirms and the wallet syncs.

Why: Blocknil's provider quoted a splice on arrival on that change, took the wallet's yes, found
no coin to splice with, and refused and refunded (bitcoin-wallet lightningdevkit#211; staging smoke, release set
c4d54a95). No public API gave the confirmed figure: Wallet::list_confirmed_funding_inputs, which
walks the same coins, is crate-private. list_balances is unchanged.

Test: confirmed_spendable_balance_leaves_out_unconfirmed_change. A single coin, an open spends
it; the trusted figure counts the change and the new one doesn't, also once the open is in a
block the wallet hasn't synced; after the sync they agree and a splice spends it.

From "Blocknil patch (ldk3-confirmed-balance): the sum is upstream's get_confirmed_unlocked_amount_sats":

Follow-up to the previous commit, the same patch. The wallet's sum becomes upstream's
Wallet::get_confirmed_unlocked_amount_sats (ldk-node lightningdevkit#1223, 6fb3d52) word for word, taken alone
with its unit test, so that the Blocknil part is the public wrapper
(Node::confirmed_spendable_onchain_balance_sats, less the anchor reserve) and moving to upstream
drops the copy. Upstream's sum leaves out what ours also skipped (immature coinbase outputs, a
coin whose transaction is too large for tx_add_input); neither is on a provider's wallet, and
either would only make the figure higher than coin selection can use, as before lightningdevkit#211's fix.
The rest of lightningdevkit#1223 (the splice anchor-reserve checks) was taken later, hand-merged into our
change-keeping splice_in: the three upstream commits that follow this one.

Tests: confirmed_unlocked_amount_does_not_depend_on_seeing_a_splice (upstream's, as upstream
has it: its insert_unconfirmed_tx signs the splice for bdk_wallet 3.2.1, since lightningdevkit#1255). The integration test drops its "in a block
but not synced" assertion: the node's background sync can run first, so it raced (failed once).

From "Blocknil test (ldk3-confirmed-balance): run on Esplora, and check the mined-but-unsynced case again":

confirmed_spendable_balance_leaves_out_unconfirmed_change picked its chain source at random. On
bitcoind (RPC or REST) the node polls the chain every 2 s (src/chain/bitcoind.rs), so the
"confirmed on chain, not yet synced: still 0" assertion raced that poll and failed once; the
previous commit dropped it, putting the cause down to background sync in general, which was
wrong: the test helper turns background sync off for Esplora and Electrum. The test now runs on
Esplora, where what the wallet has seen moves only with sync_wallets, and the assertion is
back. 5 runs of 5 passed.

Regrouped from: b070c76 0060dff a73d527
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

Node::confirmed_spendable_utxo_values: the value of each coin confirmed_spendable_onchain_balance_sats
counts (Wallet::get_confirmed_unlocked_utxo_values, the filter of upstream's
get_confirmed_unlocked_amount_sats). The provider sized a splice's fee for a flat 300 vB, so a
wallet of many small coins was quoted, then refused after the customer's yes; with the values it
can size the fee for the coins selection would use.

Coin selection for a splice marks unspendable a coin whose previous transaction is too large to
carry in a tx_add_input (fits_tx_add_input). The values use the same filter, and
confirmed_spendable_onchain_balance_sats is their sum (less the anchor reserve), so the provider's
two figures agree; a provider funded by a large batch payment no longer quotes a splice on a coin
selection would refuse. Upstream's get_confirmed_unlocked_amount_sats, which its own splice checks
use, is unchanged. The docs say smallest first, as the provider sizes it.

Tests: confirmed_unlocked_utxo_values_leave_out_coins_too_large_to_announce fails without the filter
(both coins listed); confirmed_spendable_balance_leaves_out_unconfirmed_change now also checks the
values at each step.

Regrouped from: f4391cb (its first half) and cc98657. The second half of f4391cb is the next commit.
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
…nsufficientFunds

From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

In splice_in_inner's Exact arm, when keep_change (splice_in_with_change), the anchor-reserve check
after coin selection (upstream lightningdevkit#1223) fails with InsufficientFunds, as that method does when no
coins leave change. It returned ChannelSplicingFailed, which a caller can't tell from a splice that
can't start. Upstream's splice_in keeps ChannelSplicingFailed.

Test: splice_in_with_change_reports_a_fee_into_the_anchor_reserve_as_insufficient_funds (fails with
ChannelSplicingFailed without the mapping, checked at r11).

Regrouped from: f4391cb (its second half).
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
From "Blocknil patch (ldk3-confirmed-balance): the on-chain balance a splice's coin selection can spend":

Node::confirmed_spendable_onchain_balance_sats: the coins confirmed as of the wallet's last sync,
unlocked, mature and small enough for tx_add_input, less the anchor reserve. These are the coins
splice_in and splice_in_with_change select from (exclude_unconfirmed);
BalanceDetails::spendable_onchain_balance_sats is BDK's trusted spendable balance, which also
counts our own unconfirmed change, so after an open or splice spends the wallet's coins the two
differ until the change confirms and the wallet syncs.

Why: Blocknil's provider quoted a splice on arrival on that change, took the wallet's yes, found
no coin to splice with, and refused and refunded (bitcoin-wallet lightningdevkit#211; staging smoke, release set
c4d54a95). No public API gave the confirmed figure: Wallet::list_confirmed_funding_inputs, which
walks the same coins, is crate-private. list_balances is unchanged.

Test: confirmed_spendable_balance_leaves_out_unconfirmed_change. A single coin, an open spends
it; the trusted figure counts the change and the new one doesn't, also once the open is in a
block the wallet hasn't synced; after the sync they agree and a splice spends it.

From "Blocknil patch (ldk3-confirmed-balance): the sum is upstream's get_confirmed_unlocked_amount_sats":

Follow-up to the previous commit, the same patch. The wallet's sum becomes upstream's
Wallet::get_confirmed_unlocked_amount_sats (ldk-node lightningdevkit#1223, 6fb3d52) word for word, taken alone
with its unit test, so that the Blocknil part is the public wrapper
(Node::confirmed_spendable_onchain_balance_sats, less the anchor reserve) and moving to upstream
drops the copy. Upstream's sum leaves out what ours also skipped (immature coinbase outputs, a
coin whose transaction is too large for tx_add_input); neither is on a provider's wallet, and
either would only make the figure higher than coin selection can use, as before lightningdevkit#211's fix.
The rest of lightningdevkit#1223 (the splice anchor-reserve checks) was taken later, hand-merged into our
change-keeping splice_in: the three upstream commits that follow this one.

Tests: confirmed_unlocked_amount_does_not_depend_on_seeing_a_splice (upstream's, as upstream
has it: its insert_unconfirmed_tx signs the splice for bdk_wallet 3.2.1, since lightningdevkit#1255). The integration test drops its "in a block
but not synced" assertion: the node's background sync can run first, so it raced (failed once).

From "Blocknil test (ldk3-confirmed-balance): run on Esplora, and check the mined-but-unsynced case again":

confirmed_spendable_balance_leaves_out_unconfirmed_change picked its chain source at random. On
bitcoind (RPC or REST) the node polls the chain every 2 s (src/chain/bitcoind.rs), so the
"confirmed on chain, not yet synced: still 0" assertion raced that poll and failed once; the
previous commit dropped it, putting the cause down to background sync in general, which was
wrong: the test helper turns background sync off for Esplora and Electrum. The test now runs on
Esplora, where what the wallet has seen moves only with sync_wallets, and the assertion is
back. 5 runs of 5 passed.

Regrouped from: b070c76 0060dff a73d527
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

Node::confirmed_spendable_utxo_values: the value of each coin confirmed_spendable_onchain_balance_sats
counts (Wallet::get_confirmed_unlocked_utxo_values, the filter of upstream's
get_confirmed_unlocked_amount_sats). The provider sized a splice's fee for a flat 300 vB, so a
wallet of many small coins was quoted, then refused after the customer's yes; with the values it
can size the fee for the coins selection would use.

Coin selection for a splice marks unspendable a coin whose previous transaction is too large to
carry in a tx_add_input (fits_tx_add_input). The values use the same filter, and
confirmed_spendable_onchain_balance_sats is their sum (less the anchor reserve), so the provider's
two figures agree; a provider funded by a large batch payment no longer quotes a splice on a coin
selection would refuse. Upstream's get_confirmed_unlocked_amount_sats, which its own splice checks
use, is unchanged. The docs say smallest first, as the provider sizes it.

Tests: confirmed_unlocked_utxo_values_leave_out_coins_too_large_to_announce fails without the filter
(both coins listed); confirmed_spendable_balance_leaves_out_unconfirmed_change now also checks the
values at each step.

Regrouped from: f4391cb (its first half) and cc98657. The second half of f4391cb is the next commit.
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
…nsufficientFunds

From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

In splice_in_inner's Exact arm, when keep_change (splice_in_with_change), the anchor-reserve check
after coin selection (upstream lightningdevkit#1223) fails with InsufficientFunds, as that method does when no
coins leave change. It returned ChannelSplicingFailed, which a caller can't tell from a splice that
can't start. Upstream's splice_in keeps ChannelSplicingFailed.

Test: splice_in_with_change_reports_a_fee_into_the_anchor_reserve_as_insufficient_funds (fails with
ChannelSplicingFailed without the mapping, checked at r11).

Regrouped from: f4391cb (its second half).
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
From "Blocknil patch (ldk3-confirmed-balance): the on-chain balance a splice's coin selection can spend":

Node::confirmed_spendable_onchain_balance_sats: the coins confirmed as of the wallet's last sync,
unlocked, mature and small enough for tx_add_input, less the anchor reserve. These are the coins
splice_in and splice_in_with_change select from (exclude_unconfirmed);
BalanceDetails::spendable_onchain_balance_sats is BDK's trusted spendable balance, which also
counts our own unconfirmed change, so after an open or splice spends the wallet's coins the two
differ until the change confirms and the wallet syncs.

Why: Blocknil's provider quoted a splice on arrival on that change, took the wallet's yes, found
no coin to splice with, and refused and refunded (bitcoin-wallet lightningdevkit#211; staging smoke, release set
c4d54a95). No public API gave the confirmed figure: Wallet::list_confirmed_funding_inputs, which
walks the same coins, is crate-private. list_balances is unchanged.

Test: confirmed_spendable_balance_leaves_out_unconfirmed_change. A single coin, an open spends
it; the trusted figure counts the change and the new one doesn't, also once the open is in a
block the wallet hasn't synced; after the sync they agree and a splice spends it.

From "Blocknil patch (ldk3-confirmed-balance): the sum is upstream's get_confirmed_unlocked_amount_sats":

Follow-up to the previous commit, the same patch. The wallet's sum becomes upstream's
Wallet::get_confirmed_unlocked_amount_sats (ldk-node lightningdevkit#1223, 6fb3d52) word for word, taken alone
with its unit test, so that the Blocknil part is the public wrapper
(Node::confirmed_spendable_onchain_balance_sats, less the anchor reserve) and moving to upstream
drops the copy. Upstream's sum leaves out what ours also skipped (immature coinbase outputs, a
coin whose transaction is too large for tx_add_input); neither is on a provider's wallet, and
either would only make the figure higher than coin selection can use, as before lightningdevkit#211's fix.
The rest of lightningdevkit#1223 (the splice anchor-reserve checks) was taken later, hand-merged into our
change-keeping splice_in: the three upstream commits that follow this one.

Tests: confirmed_unlocked_amount_does_not_depend_on_seeing_a_splice (upstream's, as upstream
has it: its insert_unconfirmed_tx signs the splice for bdk_wallet 3.2.1, since lightningdevkit#1255). The integration test drops its "in a block
but not synced" assertion: the node's background sync can run first, so it raced (failed once).

From "Blocknil test (ldk3-confirmed-balance): run on Esplora, and check the mined-but-unsynced case again":

confirmed_spendable_balance_leaves_out_unconfirmed_change picked its chain source at random. On
bitcoind (RPC or REST) the node polls the chain every 2 s (src/chain/bitcoind.rs), so the
"confirmed on chain, not yet synced: still 0" assertion raced that poll and failed once; the
previous commit dropped it, putting the cause down to background sync in general, which was
wrong: the test helper turns background sync off for Esplora and Electrum. The test now runs on
Esplora, where what the wallet has seen moves only with sync_wallets, and the assertion is
back. 5 runs of 5 passed.

Regrouped from: b070c76 0060dff a73d527
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

Node::confirmed_spendable_utxo_values: the value of each coin confirmed_spendable_onchain_balance_sats
counts (Wallet::get_confirmed_unlocked_utxo_values, the filter of upstream's
get_confirmed_unlocked_amount_sats). The provider sized a splice's fee for a flat 300 vB, so a
wallet of many small coins was quoted, then refused after the customer's yes; with the values it
can size the fee for the coins selection would use.

Coin selection for a splice marks unspendable a coin whose previous transaction is too large to
carry in a tx_add_input (fits_tx_add_input). The values use the same filter, and
confirmed_spendable_onchain_balance_sats is their sum (less the anchor reserve), so the provider's
two figures agree; a provider funded by a large batch payment no longer quotes a splice on a coin
selection would refuse. Upstream's get_confirmed_unlocked_amount_sats, which its own splice checks
use, is unchanged. The docs say smallest first, as the provider sizes it.

Tests: confirmed_unlocked_utxo_values_leave_out_coins_too_large_to_announce fails without the filter
(both coins listed); confirmed_spendable_balance_leaves_out_unconfirmed_change now also checks the
values at each step.

Regrouped from: f4391cb (its first half) and cc98657. The second half of f4391cb is the next commit.
jbesraa added a commit to blocknil/ldk-node that referenced this pull request Dec 2, 2026
…nsufficientFunds

From the review of r11, for the provider's splice on arrival (bitcoin-wallet lightningdevkit#211).

In splice_in_inner's Exact arm, when keep_change (splice_in_with_change), the anchor-reserve check
after coin selection (upstream lightningdevkit#1223) fails with InsufficientFunds, as that method does when no
coins leave change. It returned ChannelSplicingFailed, which a caller can't tell from a splice that
can't start. Upstream's splice_in keeps ChannelSplicingFailed.

Test: splice_in_with_change_reports_a_fee_into_the_anchor_reserve_as_insufficient_funds (fails with
ChannelSplicingFailed without the mapping, checked at r11).

Regrouped from: f4391cb (its second half).
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.

Fix reachable unwrap when creating ChannelDetails

1 participant