@@ -10960,18 +10960,9 @@ where
10960
10960
// Note: post-splice channel value is not yet known at this point, counterparty contribution is not known
10961
10961
// (Cannot test for miminum required post-splice channel value)
10962
10962
let their_funding_contribution = SignedAmount::ZERO;
10963
- let counterparty_public_key = self
10964
- .funding
10965
- .channel_transaction_parameters
10966
- .counterparty_parameters
10967
- .as_ref()
10968
- .expect("counterparty_parameters should be set")
10969
- .pubkeys
10970
- .funding_pubkey;
10971
10963
self.validate_splice_contributions(
10972
10964
adjusted_funding_contribution,
10973
10965
their_funding_contribution,
10974
- counterparty_public_key,
10975
10966
)
10976
10967
.map_err(|err| APIError::APIMisuseError { err })?;
10977
10968
@@ -11068,19 +11059,22 @@ where
11068
11059
)));
11069
11060
}
11070
11061
11071
- self.validate_splice_contributions(
11062
+ self.validate_splice_contributions(our_funding_contribution, their_funding_contribution)
11063
+ .map_err(|e| ChannelError::WarnAndDisconnect(e))?;
11064
+
11065
+ Ok(FundingScope::for_splice(
11066
+ &self.funding,
11067
+ &self.context,
11072
11068
our_funding_contribution,
11073
11069
their_funding_contribution,
11074
11070
msg.funding_pubkey,
11075
- )
11076
- .map_err(|e| ChannelError::WarnAndDisconnect(e))
11071
+ ))
11077
11072
}
11078
11073
11079
11074
#[cfg(splicing)]
11080
11075
fn validate_splice_contributions(
11081
11076
&self, our_funding_contribution: SignedAmount, their_funding_contribution: SignedAmount,
11082
- counterparty_funding_pubkey: PublicKey,
11083
- ) -> Result<FundingScope, String> {
11077
+ ) -> Result<(), String> {
11084
11078
if our_funding_contribution.abs() > SignedAmount::MAX_MONEY {
11085
11079
return Err(format!(
11086
11080
"Channel {} cannot be spliced; our {} contribution exceeds the total bitcoin supply",
@@ -11097,77 +11091,76 @@ where
11097
11091
));
11098
11092
}
11099
11093
11100
- // Sanity check all funding contributions here; we need to do this before building a `FundingScope`
11094
+ let (holder_balance_remaining, counterparty_balance_remaining) =
11095
+ self.get_holder_counterparty_balances_floor_incl_fee(&self.funding).map_err(|e| {
11096
+ format!("Channel {} cannot be spliced; {}", self.context.channel_id(), e)
11097
+ })?;
11101
11098
11102
- let our_channel_balance = Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
11103
- AddSigned::checked_add_signed(
11104
- our_channel_balance.to_sat(),
11099
+ let post_channel_value = self.funding.compute_post_splice_value(
11105
11100
our_funding_contribution.to_sat(),
11106
- )
11107
- .ok_or(format!(
11108
- "Channel {} cannot be spliced out; our {} contribution exhausts our channel balance: {}",
11109
- self.context.channel_id(),
11110
- our_funding_contribution,
11111
- our_channel_balance,
11112
- ))?;
11113
-
11114
- let their_channel_balance = Amount::from_sat(
11115
- self.funding.get_value_satoshis() - self.funding.get_value_to_self_msat() / 1000,
11116
- );
11117
- AddSigned::checked_add_signed(
11118
- their_channel_balance.to_sat(),
11119
11101
their_funding_contribution.to_sat(),
11120
- )
11121
- .ok_or(format!(
11122
- "Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
11123
- self.context.channel_id(),
11124
- their_funding_contribution,
11125
- their_channel_balance,
11126
- ))?;
11127
-
11128
- let splice_funding = FundingScope::for_splice(
11129
- &self.funding,
11130
- &self.context,
11131
- our_funding_contribution,
11132
- their_funding_contribution,
11133
- counterparty_funding_pubkey,
11134
11102
);
11135
-
11136
- let (holder_balance_remaining, counterparty_balance_remaining) =
11137
- self.get_holder_counterparty_balances_floor_incl_fee(&splice_funding).map_err(|e| {
11138
- format!("Channel {} cannot be spliced; {}", self.context.channel_id(), e)
11139
- })?;
11103
+ let counterparty_selected_channel_reserve = Amount::from_sat(
11104
+ get_v2_channel_reserve_satoshis(post_channel_value, MIN_CHAN_DUST_LIMIT_SATOSHIS),
11105
+ );
11106
+ let holder_selected_channel_reserve = Amount::from_sat(get_v2_channel_reserve_satoshis(
11107
+ post_channel_value,
11108
+ self.context.counterparty_dust_limit_satoshis,
11109
+ ));
11140
11110
11141
11111
// We allow parties to draw from their previous reserve, as long as they satisfy their v2 reserve
11142
11112
11143
11113
if our_funding_contribution != SignedAmount::ZERO {
11144
- let counterparty_selected_channel_reserve_satoshis = splice_funding
11145
- .counterparty_selected_channel_reserve_satoshis
11146
- .expect("counterparty_selected_channel_reserve_satoshis should be set");
11147
- holder_balance_remaining
11148
- .checked_sub(Amount::from_sat(counterparty_selected_channel_reserve_satoshis))
11114
+ let post_splice_holder_balance = Amount::from_sat(
11115
+ AddSigned::checked_add_signed(
11116
+ holder_balance_remaining.to_sat(),
11117
+ our_funding_contribution.to_sat(),
11118
+ )
11119
+ .ok_or(format!(
11120
+ "Channel {} cannot be {}; our remaining balance {} does not cover our negative funding contribution {}",
11121
+ self.context.channel_id(),
11122
+ if our_funding_contribution.is_positive() { "spliced in" } else { "spliced out" },
11123
+ holder_balance_remaining,
11124
+ our_funding_contribution,
11125
+ ))?,
11126
+ );
11127
+
11128
+ post_splice_holder_balance.checked_sub(counterparty_selected_channel_reserve)
11149
11129
.ok_or(format!(
11150
- "Channel {} cannot be {}; We cannot afford the new counterparty mandated reserve {} vs {}",
11130
+ "Channel {} cannot be {}; Our post-splice channel balance {} is smaller than their selected v2 reserve {}",
11151
11131
self.context.channel_id(),
11152
11132
if our_funding_contribution.is_positive() { "spliced in" } else { "spliced out" },
11153
- holder_balance_remaining, counterparty_selected_channel_reserve_satoshis,
11133
+ post_splice_holder_balance,
11134
+ counterparty_selected_channel_reserve,
11154
11135
))?;
11155
11136
}
11156
11137
11157
11138
if their_funding_contribution != SignedAmount::ZERO {
11158
- let holder_selected_channel_reserve_satoshis =
11159
- splice_funding.holder_selected_channel_reserve_satoshis;
11160
- counterparty_balance_remaining
11161
- .checked_sub(Amount::from_sat(holder_selected_channel_reserve_satoshis))
11139
+ let post_splice_counterparty_balance = Amount::from_sat(
11140
+ AddSigned::checked_add_signed(
11141
+ counterparty_balance_remaining.to_sat(),
11142
+ their_funding_contribution.to_sat(),
11143
+ )
11144
+ .ok_or(format!(
11145
+ "Channel {} cannot be {}; their remaining balance {} does not cover their negative funding contribution {}",
11146
+ self.context.channel_id(),
11147
+ if their_funding_contribution.is_positive() { "spliced in" } else { "spliced out" },
11148
+ counterparty_balance_remaining,
11149
+ their_funding_contribution,
11150
+ ))?,
11151
+ );
11152
+
11153
+ post_splice_counterparty_balance.checked_sub(holder_selected_channel_reserve)
11162
11154
.ok_or(format!(
11163
- "Channel {} cannot be {}; They cannot afford the new holder mandated reserve {} vs {}",
11155
+ "Channel {} cannot be {}; Their post-splice channel balance {} is smaller than our selected v2 reserve {}",
11164
11156
self.context.channel_id(),
11165
11157
if their_funding_contribution.is_positive() { "spliced in" } else { "spliced out" },
11166
- counterparty_balance_remaining, holder_selected_channel_reserve_satoshis,
11158
+ post_splice_counterparty_balance,
11159
+ holder_selected_channel_reserve,
11167
11160
))?;
11168
11161
}
11169
11162
11170
- Ok(splice_funding )
11163
+ Ok(() )
11171
11164
}
11172
11165
11173
11166
#[cfg(splicing)]
@@ -11320,12 +11313,16 @@ where
11320
11313
11321
11314
let our_funding_contribution = funding_negotiation_context.our_funding_contribution;
11322
11315
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
11323
- self.validate_splice_contributions(
11316
+ self.validate_splice_contributions(our_funding_contribution, their_funding_contribution)
11317
+ .map_err(|e| ChannelError::WarnAndDisconnect(e))?;
11318
+
11319
+ Ok(FundingScope::for_splice(
11320
+ &self.funding,
11321
+ &self.context,
11324
11322
our_funding_contribution,
11325
11323
their_funding_contribution,
11326
11324
msg.funding_pubkey,
11327
- )
11328
- .map_err(|e| ChannelError::WarnAndDisconnect(e))
11325
+ ))
11329
11326
}
11330
11327
11331
11328
#[cfg(splicing)]
0 commit comments