Skip to content

Commit 17c864b

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 49607f0 commit 17c864b

3 files changed

Lines changed: 217 additions & 208 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use crate::ln::channelmanager::{
5656
MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
5757
};
5858
use crate::ln::funding::{
59-
FeeRateAdjustmentError, FundingContribution, FundingTemplate, FundingTxInput, PriorContribution,
59+
FeeRateAdjustmentError, FundingContribution, FundingTemplate, FundingTxInput,
6060
};
6161
use crate::ln::interactivetxs::{
6262
AbortReason, HandleTxCompleteValue, InteractiveTxConstructor, InteractiveTxConstructorArgs,
@@ -12383,6 +12383,16 @@ where
1238312383
});
1238412384
}
1238512385

12386+
let spliceable_balance = self.get_next_splice_out_maximum(&self.funding).map_err(|e| {
12387+
APIError::ChannelUnavailable {
12388+
err: format!(
12389+
"Channel {} cannot be spliced at this time: {}",
12390+
self.context.channel_id(),
12391+
e
12392+
),
12393+
}
12394+
})?;
12395+
1238612396
let (min_rbf_feerate, prior_contribution) = if self.is_rbf_compatible().is_err() {
1238712397
// Channel can never RBF (e.g., zero-conf).
1238812398
(None, None)
@@ -12415,16 +12425,7 @@ where
1241512425
.as_ref()
1241612426
.and_then(|pending_splice| pending_splice.contributions.last())
1241712427
{
12418-
let spliceable_balance = self
12419-
.get_next_splice_out_maximum(&self.funding)
12420-
.map_err(|e| APIError::ChannelUnavailable {
12421-
err: format!(
12422-
"Channel {} cannot be spliced at this time: {}",
12423-
self.context.channel_id(),
12424-
e
12425-
),
12426-
})?;
12427-
Some(PriorContribution::new(prior.clone(), spliceable_balance))
12428+
Some(prior.clone())
1242812429
} else {
1242912430
None
1243012431
}
@@ -12446,7 +12447,12 @@ where
1244612447
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT,
1244712448
};
1244812449

12449-
Ok(FundingTemplate::new(Some(shared_input), min_rbf_feerate, prior_contribution))
12450+
Ok(FundingTemplate::new(
12451+
Some(shared_input),
12452+
min_rbf_feerate,
12453+
prior_contribution,
12454+
spliceable_balance,
12455+
))
1245012456
}
1245112457

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

0 commit comments

Comments
 (0)