Skip to content

Commit 562c438

Browse files
committed
fix check_v2_funding_inputs_sufficient: take bool instead of weight
1 parent fd6c3aa commit 562c438

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
@@ -4688,13 +4688,12 @@ fn estimate_v2_funding_transaction_fee(
46884688
#[cfg(splicing)]
46894689
pub(super) fn check_v2_funding_inputs_sufficient(
46904690
contribution_amount: i64, funding_inputs: &[(TxIn, Transaction, Weight)], is_initiator: bool,
4691-
extra_common_input_weight: Option<Weight>, funding_feerate_sat_per_1000_weight: u32,
4691+
is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
46924692
) -> Result<u64, ChannelError> {
46934693
let mut total_input_witness_weight = Weight::from_wu(funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
4694-
if is_initiator {
4695-
if let Some(extra) = extra_common_input_weight {
4696-
total_input_witness_weight += extra;
4697-
}
4694+
if is_initiator && is_splice {
4695+
// consider the weight of the witness needed for spending the old funding transaction
4696+
total_input_witness_weight += Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
46984697
}
46994698
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs.len(), total_input_witness_weight, funding_feerate_sat_per_1000_weight);
47004699

@@ -8425,8 +8424,7 @@ impl<SP: Deref> FundedChannel<SP> where
84258424

84268425
// Check that inputs are sufficient to cover our contribution.
84278426
// Extra common weight is the weight for spending the old funding
8428-
let extra_input_weight = Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
8429-
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)
8427+
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
84308428
.map_err(|err| APIError::APIMisuseError { err: format!(
84318429
"Insufficient inputs for splicing; channel ID {}, err {}",
84328430
self.context.channel_id(), err,
@@ -12959,9 +12957,7 @@ mod tests {
1295912957
#[cfg(splicing)]
1296012958
#[test]
1296112959
fn test_check_v2_funding_inputs_sufficient() {
12962-
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
1296312960
use crate::ln::channel::check_v2_funding_inputs_sufficient;
12964-
use bitcoin::Weight;
1296512961

1296612962
// positive case, inputs well over intended contribution
1296712963
assert_eq!(
@@ -12972,7 +12968,7 @@ mod tests {
1297212968
funding_input_sats(100_000),
1297312969
],
1297412970
true,
12975-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12971+
true,
1297612972
2000,
1297712973
).unwrap(),
1297812974
1948,
@@ -12986,7 +12982,7 @@ mod tests {
1298612982
funding_input_sats(100_000),
1298712983
],
1298812984
true,
12989-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12985+
true,
1299012986
2000,
1299112987
);
1299212988
assert_eq!(
@@ -13006,7 +13002,7 @@ mod tests {
1300613002
funding_input_sats(100_000),
1300713003
],
1300813004
true,
13009-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
13005+
true,
1301013006
2000,
1301113007
).unwrap(),
1301213008
expected_fee,
@@ -13022,7 +13018,7 @@ mod tests {
1302213018
funding_input_sats(100_000),
1302313019
],
1302413020
true,
13025-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
13021+
true,
1302613022
2200,
1302713023
);
1302813024
assert_eq!(
@@ -13042,7 +13038,7 @@ mod tests {
1304213038
funding_input_sats(100_000),
1304313039
],
1304413040
false,
13045-
None,
13041+
false,
1304613042
2000,
1304713043
).unwrap(),
1304813044
expected_fee,

0 commit comments

Comments
 (0)