@@ -4132,39 +4132,32 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4132
4132
}
4133
4133
}
4134
4134
4135
- /// Check a balance against a channel reserve requirement
4135
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4136
4136
#[cfg(splicing)]
4137
- pub fn check_balance_meets_reserve_requirement(balance : u64, channel_value : u64, dust_limit: u64) -> Result<(), u64> {
4138
- if balance == 0 {
4137
+ 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> {
4138
+ if post_balance == 0 {
4139
4139
// 0 balance is fine
4140
4140
Ok(())
4141
4141
} else {
4142
- let channel_reserve = get_v2_channel_reserve_satoshis(channel_value , dust_limit);
4143
- if balance >= channel_reserve {
4142
+ let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value , dust_limit);
4143
+ if post_balance >= post_channel_reserve {
4144
4144
Ok(())
4145
4145
} else {
4146
- Err(channel_reserve)
4147
- }
4148
- }
4149
- }
4150
-
4151
- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4152
- #[cfg(splicing)]
4153
- 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> {
4154
- match Self::check_balance_meets_reserve_requirement(
4155
- post_balance, post_channel_value, dust_limit
4156
- ) {
4157
- Ok(_) => Ok(()),
4158
- Err(post_channel_reserve) =>
4159
4146
// post is not OK, check pre
4160
- match Self::check_balance_meets_reserve_requirement(
4161
- pre_balance, pre_channel_value, dust_limit
4162
- ) {
4147
+ if pre_balance == 0 {
4163
4148
// pre OK, post not -> not
4164
- Ok(_) => Err(post_channel_reserve),
4165
- // post not OK, but so was pre -> OK
4166
- Err(_) => Ok(()),
4149
+ Err(post_channel_reserve)
4150
+ } else {
4151
+ let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
4152
+ if pre_balance >= pre_channel_reserve {
4153
+ // pre OK, post not -> not
4154
+ Err(post_channel_reserve)
4155
+ } else {
4156
+ // post not OK, but so was pre -> OK
4157
+ Ok(())
4158
+ }
4167
4159
}
4160
+ }
4168
4161
}
4169
4162
}
4170
4163
0 commit comments