Skip to content

Commit 018c35d

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

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 14 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,9 +12528,7 @@ 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;
12535-
use bitcoin::Weight;
1253612532

1253712533
// positive case, inputs well over intended contribution
1253812534
assert_eq!(
@@ -12543,7 +12539,7 @@ mod tests {
1254312539
funding_input_sats(100_000),
1254412540
],
1254512541
true,
12546-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12542+
true,
1254712543
2000,
1254812544
).unwrap(),
1254912545
1948,
@@ -12557,7 +12553,7 @@ mod tests {
1255712553
funding_input_sats(100_000),
1255812554
],
1255912555
true,
12560-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12556+
true,
1256112557
2000,
1256212558
);
1256312559
assert_eq!(
@@ -12577,7 +12573,7 @@ mod tests {
1257712573
funding_input_sats(100_000),
1257812574
],
1257912575
true,
12580-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12576+
true,
1258112577
2000,
1258212578
).unwrap(),
1258312579
expected_fee,
@@ -12593,7 +12589,7 @@ mod tests {
1259312589
funding_input_sats(100_000),
1259412590
],
1259512591
true,
12596-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12592+
true,
1259712593
2200,
1259812594
);
1259912595
assert_eq!(
@@ -12613,7 +12609,7 @@ mod tests {
1261312609
funding_input_sats(100_000),
1261412610
],
1261512611
false,
12616-
None,
12612+
false,
1261712613
2000,
1261812614
).unwrap(),
1261912615
expected_fee,

0 commit comments

Comments
 (0)