@@ -4095,39 +4095,32 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40954095 }
40964096 }
40974097
4098- /// Check a balance against a channel reserve requirement
4098+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
40994099 #[cfg(splicing)]
4100- pub fn check_balance_meets_reserve_requirement(balance : u64, channel_value : u64, dust_limit: u64) -> Result<(), u64> {
4101- if balance == 0 {
4100+ 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> {
4101+ if post_balance == 0 {
41024102 // 0 balance is fine
41034103 Ok(())
41044104 } else {
4105- let channel_reserve = get_v2_channel_reserve_satoshis(channel_value , dust_limit);
4106- if balance >= channel_reserve {
4105+ let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value , dust_limit);
4106+ if post_balance >= post_channel_reserve {
41074107 Ok(())
41084108 } else {
4109- Err(channel_reserve)
4110- }
4111- }
4112- }
4113-
4114- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4115- #[cfg(splicing)]
4116- 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> {
4117- match Self::check_balance_meets_reserve_requirement(
4118- post_balance, post_channel_value, dust_limit
4119- ) {
4120- Ok(_) => Ok(()),
4121- Err(post_channel_reserve) =>
41224109 // post is not OK, check pre
4123- match Self::check_balance_meets_reserve_requirement(
4124- pre_balance, pre_channel_value, dust_limit
4125- ) {
4110+ if pre_balance == 0 {
41264111 // pre OK, post not -> not
4127- Ok(_) => Err(post_channel_reserve),
4128- // post not OK, but so was pre -> OK
4129- Err(_) => Ok(()),
4112+ Err(post_channel_reserve)
4113+ } else {
4114+ let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
4115+ if pre_balance >= pre_channel_reserve {
4116+ // pre OK, post not -> not
4117+ Err(post_channel_reserve)
4118+ } else {
4119+ // post not OK, but so was pre -> OK
4120+ Ok(())
4121+ }
41304122 }
4123+ }
41314124 }
41324125 }
41334126
0 commit comments