Skip to content

Commit 2435ca2

Browse files
committed
Use next_splice_out_maximum_sat to validate funding_contributed
This is equivalent to the previous commit, see the debug assertions added in the previous commit. We now also get to communicate the exact maximum back to the user, instead of some "balance is lower than our reserve" message, which is hard to react to.
1 parent 77668a8 commit 2435ca2

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12579,13 +12579,14 @@ where
1257912579
}
1258012580

1258112581
let our_funding_contribution = contribution.net_value();
12582-
12583-
if let Err(e) = self.validate_splice_contributions(
12584-
our_funding_contribution,
12585-
SignedAmount::ZERO,
12586-
self.funding.get_counterparty_pubkeys().funding_pubkey,
12587-
self.funding.get_holder_pubkeys().clone(),
12588-
) {
12582+
let unsigned_contribution = our_funding_contribution.unsigned_abs();
12583+
if let Err(e) = self.get_next_splice_out_maximum(&self.funding)
12584+
.and_then(|splice_max| splice_max
12585+
.to_sat()
12586+
.checked_add_signed(our_funding_contribution.to_sat())
12587+
.ok_or(format!("Our splice-out value of {unsigned_contribution} is greater than the maximum {splice_max}"))
12588+
)
12589+
{
1258912590
log_error!(logger, "Channel {} cannot be funded: {}", self.context.channel_id(), e);
1259012591
return Err(QuiescentError::FailSplice(self.splice_funding_failed_for(contribution)));
1259112592
}
@@ -14207,12 +14208,14 @@ where
1420714208
// balance. If invalid, disconnect and return the contribution so
1420814209
// the user can reclaim their inputs.
1420914210
let our_funding_contribution = contribution.net_value();
14210-
if let Err(e) = self.validate_splice_contributions(
14211-
our_funding_contribution,
14212-
SignedAmount::ZERO,
14213-
self.funding.get_counterparty_pubkeys().funding_pubkey,
14214-
self.funding.get_holder_pubkeys().clone(),
14215-
) {
14211+
let unsigned_contribution = our_funding_contribution.unsigned_abs();
14212+
if let Err(e) = self.get_next_splice_out_maximum(&self.funding)
14213+
.and_then(|splice_max| splice_max
14214+
.to_sat()
14215+
.checked_add_signed(our_funding_contribution.to_sat())
14216+
.ok_or(format!("Our splice-out value of {unsigned_contribution} is greater than the maximum {splice_max}"))
14217+
)
14218+
{
1421614219
let failed = self.splice_funding_failed_for(contribution);
1421714220
return Err((
1421814221
ChannelError::WarnAndDisconnect(format!(

lightning/src/ln/splicing_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,8 +4045,8 @@ fn do_test_splice_pending_htlcs(config: UserConfig) {
40454045
format!("Channel {} cannot accept funding contribution", channel_id);
40464046
assert_eq!(error, APIError::APIMisuseError { err: cannot_accept_contribution });
40474047
let cannot_be_funded = format!(
4048-
"Channel {} cannot be funded: Channel {} cannot be spliced out; our post-splice channel balance {} is smaller than their selected v2 reserve {}",
4049-
channel_id, channel_id, post_splice_reserve - Amount::ONE_SAT, post_splice_reserve
4048+
"Channel {} cannot be funded: Our splice-out value of {} is greater than the maximum {}",
4049+
channel_id, splice_out_incl_fees + Amount::ONE_SAT, splice_out_incl_fees,
40504050
);
40514051
initiator.logger.assert_log("lightning::ln::channel", cannot_be_funded, 1);
40524052

0 commit comments

Comments
 (0)