Skip to content

Commit 7ff5eb7

Browse files
committed
Include spliceable balance in every FundingTemplate
There's no reason not to do so, and it allows us to fail earlier when the user's net contribution exceeds their spliceable balance.
1 parent bbcb671 commit 7ff5eb7

3 files changed

Lines changed: 293 additions & 240 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use crate::ln::channelmanager::{
5757
MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
5858
};
5959
use crate::ln::funding::{
60-
FeeRateAdjustmentError, FundingContribution, FundingTemplate, FundingTxInput, PriorContribution,
60+
FeeRateAdjustmentError, FundingContribution, FundingTemplate, FundingTxInput,
6161
};
6262
use crate::ln::interactivetxs::{
6363
AbortReason, HandleTxCompleteValue, InteractiveTxConstructor, InteractiveTxConstructorArgs,
@@ -12482,6 +12482,16 @@ where
1248212482
});
1248312483
}
1248412484

12485+
let spliceable_balance = self.get_next_splice_out_maximum(&self.funding).map_err(|e| {
12486+
APIError::ChannelUnavailable {
12487+
err: format!(
12488+
"Channel {} cannot be spliced at this time: {}",
12489+
self.context.channel_id(),
12490+
e
12491+
),
12492+
}
12493+
})?;
12494+
1248512495
let (min_rbf_feerate, prior_contribution) = if self.is_rbf_compatible().is_err() {
1248612496
// Channel can never RBF (e.g., zero-conf).
1248712497
(None, None)
@@ -12514,16 +12524,7 @@ where
1251412524
.as_ref()
1251512525
.and_then(|pending_splice| pending_splice.contributions.last())
1251612526
{
12517-
let spliceable_balance = self
12518-
.get_next_splice_out_maximum(&self.funding)
12519-
.map_err(|e| APIError::ChannelUnavailable {
12520-
err: format!(
12521-
"Channel {} cannot be spliced at this time: {}",
12522-
self.context.channel_id(),
12523-
e
12524-
),
12525-
})?;
12526-
Some(PriorContribution::new(prior.clone(), spliceable_balance))
12527+
Some(prior.clone())
1252712528
} else {
1252812529
None
1252912530
}
@@ -12545,7 +12546,12 @@ where
1254512546
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT,
1254612547
};
1254712548

12548-
Ok(FundingTemplate::new(Some(shared_input), min_rbf_feerate, prior_contribution))
12549+
Ok(FundingTemplate::new(
12550+
Some(shared_input),
12551+
min_rbf_feerate,
12552+
prior_contribution,
12553+
spliceable_balance,
12554+
))
1254912555
}
1255012556

1255112557
/// Returns whether this channel can ever RBF, independent of splice state.

0 commit comments

Comments
 (0)