Skip to content

Commit c1656b1

Browse files
committed
fix check_v2_funding_inputs_sufficient: take bool instead of weight
1 parent bc741a5 commit c1656b1

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,13 +4544,12 @@ fn estimate_v2_funding_transaction_fee(
45444544
#[cfg(splicing)]
45454545
pub(super) fn check_v2_funding_inputs_sufficient(
45464546
contribution_amount: i64, funding_inputs: &[(TxIn, Transaction, Weight)], is_initiator: bool,
4547-
extra_common_input_weight: Option<Weight>, funding_feerate_sat_per_1000_weight: u32,
4547+
is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
45484548
) -> Result<u64, ChannelError> {
45494549
let mut total_input_witness_weight = Weight::from_wu(funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
4550-
if is_initiator {
4551-
if let Some(extra) = extra_common_input_weight {
4552-
total_input_witness_weight += extra;
4553-
}
4550+
if is_initiator && is_splice {
4551+
// consider the weight of the witness needed for spending the old funding transaction
4552+
total_input_witness_weight += Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
45544553
}
45554554
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs.len(), total_input_witness_weight, funding_feerate_sat_per_1000_weight);
45564555

@@ -8232,8 +8231,7 @@ impl<SP: Deref> FundedChannel<SP> where
82328231

82338232
// Check that inputs are sufficient to cover our contribution.
82348233
// Extra common weight is the weight for spending the old funding
8235-
let extra_input_weight = Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
8236-
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)
8234+
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
82378235
.map_err(|err| APIError::APIMisuseError { err: format!(
82388236
"Insufficient inputs for splicing; channel ID {}, err {}",
82398237
self.context.channel_id(), err,
@@ -12530,7 +12528,6 @@ mod tests {
1253012528
#[cfg(splicing)]
1253112529
#[test]
1253212530
fn test_check_v2_funding_inputs_sufficient() {
12533-
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
1253412531
use crate::ln::channel::check_v2_funding_inputs_sufficient;
1253512532
use bitcoin::Weight;
1253612533

@@ -12543,7 +12540,7 @@ mod tests {
1254312540
funding_input_sats(100_000),
1254412541
],
1254512542
true,
12546-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12543+
true,
1254712544
2000,
1254812545
).unwrap(),
1254912546
1948,
@@ -12557,7 +12554,7 @@ mod tests {
1255712554
funding_input_sats(100_000),
1255812555
],
1255912556
true,
12560-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12557+
true,
1256112558
2000,
1256212559
);
1256312560
assert_eq!(
@@ -12577,7 +12574,7 @@ mod tests {
1257712574
funding_input_sats(100_000),
1257812575
],
1257912576
true,
12580-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12577+
true,
1258112578
2000,
1258212579
).unwrap(),
1258312580
expected_fee,
@@ -12593,7 +12590,7 @@ mod tests {
1259312590
funding_input_sats(100_000),
1259412591
],
1259512592
true,
12596-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12593+
true,
1259712594
2200,
1259812595
);
1259912596
assert_eq!(
@@ -12613,7 +12610,7 @@ mod tests {
1261312610
funding_input_sats(100_000),
1261412611
],
1261512612
false,
12616-
None,
12613+
false,
1261712614
2000,
1261812615
).unwrap(),
1261912616
expected_fee,

0 commit comments

Comments
 (0)