@@ -4273,40 +4273,29 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
42734273 }
42744274 }
42754275
4276- /// Check a balance against a channel reserve requirement
4277- #[cfg(splicing)]
4278- pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<(), u64> {
4279- if balance == 0 {
4280- // 0 balance is fine
4281- Ok(())
4282- } else {
4283- let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4284- if balance >= channel_reserve {
4285- Ok(())
4286- } else {
4287- Err(channel_reserve)
4288- }
4289- }
4290- }
4291-
42924276 /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
42934277 #[cfg(splicing)]
42944278 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> {
4295- match Self::check_balance_meets_reserve_requirement(
4296- post_balance, post_channel_value, dust_limit
4297- ) {
4298- Ok(_) => Ok(()),
4299- Err(post_channel_reserve) =>
4300- // post is not OK, check pre
4301- match Self::check_balance_meets_reserve_requirement(
4302- pre_balance, pre_channel_value, dust_limit
4303- ) {
4304- // pre OK, post not -> not
4305- Ok(_) => Err(post_channel_reserve),
4306- // post not OK, but so was pre -> OK
4307- Err(_) => Ok(()),
4308- }
4279+ if post_balance == 0 {
4280+ // 0 balance is fine
4281+ return Ok(());
43094282 }
4283+ let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
4284+ if post_balance >= post_channel_reserve {
4285+ return Ok(());
4286+ }
4287+ // post is not OK, check pre
4288+ if pre_balance == 0 {
4289+ // pre OK, post not -> not
4290+ return Err(post_channel_reserve);
4291+ }
4292+ let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
4293+ if pre_balance >= pre_channel_reserve {
4294+ // pre OK, post not -> not
4295+ return Err(post_channel_reserve);
4296+ }
4297+ // post not OK, but so was pre -> OK
4298+ Ok(())
43104299 }
43114300
43124301 /// Check that balances meet the channel reserve requirements or violates them (below reserve).
0 commit comments