-
Notifications
You must be signed in to change notification settings - Fork 103
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
Open
tnull
wants to merge
3
commits into
lightningdevkit:main
Choose a base branch
from
tnull:2025-05-fix-sendall-retaining-reserve-for-dust
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -496,6 +496,86 @@ fn onchain_send_receive() { | |
assert_eq!(node_b_payments.len(), 5); | ||
} | ||
|
||
#[test] | ||
fn onchain_send_all_retains_reserve() { | ||
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); | ||
let chain_source = TestChainSource::Esplora(&electrsd); | ||
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false); | ||
|
||
// Setup nodes | ||
let addr_a = node_a.onchain_payment().new_address().unwrap(); | ||
let addr_b = node_b.onchain_payment().new_address().unwrap(); | ||
|
||
let premine_amount_sat = 1_000_000; | ||
let reserve_amount_sat = 25_000; | ||
let onchain_fee_buffer_sat = 1000; | ||
premine_and_distribute_funds( | ||
&bitcoind.client, | ||
&electrsd.client, | ||
vec![addr_a.clone(), addr_b.clone()], | ||
Amount::from_sat(premine_amount_sat), | ||
); | ||
|
||
node_a.sync_wallets().unwrap(); | ||
node_b.sync_wallets().unwrap(); | ||
assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, premine_amount_sat); | ||
assert_eq!(node_b.list_balances().spendable_onchain_balance_sats, premine_amount_sat); | ||
|
||
// Send all over, with 0 reserve as we don't have any channels open. | ||
let txid = node_a.onchain_payment().send_all_to_address(&addr_b, true, None).unwrap(); | ||
|
||
wait_for_tx(&electrsd.client, txid); | ||
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Should the ranges use |
||
.contains(&node_b.list_balances().spendable_onchain_balance_sats)); | ||
|
||
// Refill to make sure we have enough reserve for the channel open. | ||
let txid = bitcoind | ||
.client | ||
.send_to_address(&addr_a, Amount::from_sat(reserve_amount_sat)) | ||
.unwrap() | ||
.0 | ||
.parse() | ||
.unwrap(); | ||
wait_for_tx(&electrsd.client, txid); | ||
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6); | ||
node_a.sync_wallets().unwrap(); | ||
node_b.sync_wallets().unwrap(); | ||
assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, reserve_amount_sat); | ||
|
||
// Open a channel. | ||
open_channel(&node_b, &node_a, premine_amount_sat, false, &electrsd); | ||
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6); | ||
node_a.sync_wallets().unwrap(); | ||
node_b.sync_wallets().unwrap(); | ||
expect_channel_ready_event!(node_a, node_b.node_id()); | ||
expect_channel_ready_event!(node_b, node_a.node_id()); | ||
|
||
assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, 0); | ||
assert!(((premine_amount_sat - reserve_amount_sat - onchain_fee_buffer_sat) | ||
..premine_amount_sat) | ||
.contains(&node_b.list_balances().spendable_onchain_balance_sats)); | ||
|
||
// Send all over again, this time ensuring the reserve is accounted for | ||
let txid = node_b.onchain_payment().send_all_to_address(&addr_a, true, None).unwrap(); | ||
|
||
wait_for_tx(&electrsd.client, txid); | ||
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6); | ||
|
||
node_a.sync_wallets().unwrap(); | ||
node_b.sync_wallets().unwrap(); | ||
|
||
assert_eq!(node_b.list_balances().total_onchain_balance_sats, reserve_amount_sat); | ||
assert_eq!(node_b.list_balances().spendable_onchain_balance_sats, 0); | ||
assert!(((premine_amount_sat - reserve_amount_sat - onchain_fee_buffer_sat) | ||
..premine_amount_sat) | ||
.contains(&node_a.list_balances().spendable_onchain_balance_sats)); | ||
} | ||
|
||
#[test] | ||
fn onchain_wallet_recovery() { | ||
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theelse
fall through toOnchainSendAmount::AllRetainingReserve { .. } | OnchainSendAmount::AllDrainingReserve
.