-
Notifications
You must be signed in to change notification settings - Fork 102
Don't fail send_all
retaining reserves for 0 channels
#540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Don't fail send_all
retaining reserves for 0 channels
#540
Conversation
Previouly, `OnchainPayment::send_all_to_address` would fail in the `retain_reserves` mode if the maintained reserves were below the dust limit. Most notably this would happen if we had no channels open at all. Here, we fix this by simply falling back to the draining case (not considering reserves) if the anchor reserves are below dust. We also add a unit test that would have caught this regression in the first place.
.. as this is useful information.
👋 Thanks for assigning @jkczyz as a reviewer! |
We create temporary transactions for fee estimation purposes. Doing this might advance the descriptor state though. So here we call `cancel_tx` to tell the wallet we no longer intend to broadcast the temporary transactions.
🔔 1st Reminder Hey @jkczyz! This PR has been waiting for your review. |
OnchainSendAmount::AllRetainingReserve { cur_anchor_reserve_sats } => { | ||
let change_address_info = locked_wallet.peek_address(KeychainKind::Internal, 0); | ||
let balance = locked_wallet.balance(); | ||
let spendable_amount_sats = self | ||
.get_balances_inner(balance, cur_anchor_reserve_sats) | ||
.map(|(_, s)| s) | ||
.unwrap_or(0); | ||
let tmp_tx = { | ||
let mut tmp_tx_builder = locked_wallet.build_tx(); | ||
tmp_tx_builder | ||
.drain_wallet() | ||
.drain_to(address.script_pubkey()) | ||
.add_recipient( | ||
change_address_info.address.script_pubkey(), | ||
Amount::from_sat(cur_anchor_reserve_sats), | ||
) | ||
.fee_rate(fee_rate); | ||
match tmp_tx_builder.finish() { | ||
Ok(psbt) => psbt.unsigned_tx, | ||
Err(err) => { | ||
const DUST_LIMIT_SATS: u64 = 546; | ||
if cur_anchor_reserve_sats > DUST_LIMIT_SATS { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid the large diff by moving the conditional check into the match
arm and having the else
fall through to OnchainSendAmount::AllRetainingReserve { .. } | OnchainSendAmount::AllDrainingReserve
.
node_a.sync_wallets().unwrap(); | ||
node_b.sync_wallets().unwrap(); | ||
assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, 0); | ||
assert!(((premine_amount_sat * 2 - onchain_fee_buffer_sat)..(premine_amount_sat * 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the ranges use ..=
here and below?
Fixes #539.
Previouly,
OnchainPayment::send_all_to_address
would fail in theretain_reserves
mode if the maintained reserves were below the dustlimit. Most notably this would happen if we had no channels open at all.
Here, we fix this by simply falling back to the draining case (not
considering reserves) if the anchor reserves are below dust. We also add
a unit test that would have caught this regression in the first place.
Note: Github diff really messes up the first commit which is mostly adding an
if
and re-indenting the previous codeblock. It's best reviewed withgit show --color-moved --ignore-all-space