Skip to content

Commit

Permalink
WIP Simplify reserve check fn
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Mar 4, 2025
1 parent 8b84cea commit e34d33c
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4137,28 +4137,24 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<(), u64> {
if post_balance == 0 {
// 0 balance is fine
Ok(())
} else {
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
if post_balance >= post_channel_reserve {
Ok(())
} else {
// post is not OK, check pre
if pre_balance == 0 {
// pre OK, post not -> not
Err(post_channel_reserve)
} else {
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
if pre_balance >= pre_channel_reserve {
// pre OK, post not -> not
Err(post_channel_reserve)
} else {
// post not OK, but so was pre -> OK
Ok(())
}
}
}
return Ok(());
}
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
if post_balance >= post_channel_reserve {
return Ok(());
}
// post is not OK, check pre
if pre_balance == 0 {
// pre OK, post not -> not
return Err(post_channel_reserve);
}
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
if pre_balance >= pre_channel_reserve {
// pre OK, post not -> not
return Err(post_channel_reserve);
}
// post not OK, but so was pre -> OK
Ok(())
}

/// Check that balances meet the channel reserve requirements or violates them (below reserve).
Expand Down

0 comments on commit e34d33c

Please sign in to comment.