Skip to content

Commit 2c97aa3

Browse files
committed
fix check_v2_funding_inputs_sufficient: take bool instead of weight
1 parent 4abec03 commit 2c97aa3

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
@@ -4731,13 +4731,12 @@ fn estimate_v2_funding_transaction_fee(
47314731
#[cfg(splicing)]
47324732
pub(super) fn check_v2_funding_inputs_sufficient(
47334733
contribution_amount: i64, funding_inputs: &[(TxIn, Transaction, Weight)], is_initiator: bool,
4734-
extra_common_input_weight: Option<Weight>, funding_feerate_sat_per_1000_weight: u32,
4734+
is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
47354735
) -> Result<u64, ChannelError> {
47364736
let mut total_input_witness_weight = Weight::from_wu(funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
4737-
if is_initiator {
4738-
if let Some(extra) = extra_common_input_weight {
4739-
total_input_witness_weight += extra;
4740-
}
4737+
if is_initiator && is_splice {
4738+
// consider the weight of the witness needed for spending the old funding transaction
4739+
total_input_witness_weight += Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
47414740
}
47424741
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs.len(), total_input_witness_weight, funding_feerate_sat_per_1000_weight);
47434742

@@ -8471,8 +8470,7 @@ impl<SP: Deref> FundedChannel<SP> where
84718470

84728471
// Check that inputs are sufficient to cover our contribution.
84738472
// Extra common weight is the weight for spending the old funding
8474-
let extra_input_weight = Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
8475-
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)
8473+
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
84768474
.map_err(|err| APIError::APIMisuseError { err: format!(
84778475
"Insufficient inputs for splicing; channel ID {}, err {}",
84788476
self.context.channel_id(), err,
@@ -12976,9 +12974,7 @@ mod tests {
1297612974
#[cfg(splicing)]
1297712975
#[test]
1297812976
fn test_check_v2_funding_inputs_sufficient() {
12979-
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
1298012977
use crate::ln::channel::check_v2_funding_inputs_sufficient;
12981-
use bitcoin::Weight;
1298212978

1298312979
// positive case, inputs well over intended contribution
1298412980
assert_eq!(
@@ -12989,7 +12985,7 @@ mod tests {
1298912985
funding_input_sats(100_000),
1299012986
],
1299112987
true,
12992-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
12988+
true,
1299312989
2000,
1299412990
).unwrap(),
1299512991
1948,
@@ -13003,7 +12999,7 @@ mod tests {
1300312999
funding_input_sats(100_000),
1300413000
],
1300513001
true,
13006-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
13002+
true,
1300713003
2000,
1300813004
);
1300913005
assert_eq!(
@@ -13023,7 +13019,7 @@ mod tests {
1302313019
funding_input_sats(100_000),
1302413020
],
1302513021
true,
13026-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
13022+
true,
1302713023
2000,
1302813024
).unwrap(),
1302913025
expected_fee,
@@ -13039,7 +13035,7 @@ mod tests {
1303913035
funding_input_sats(100_000),
1304013036
],
1304113037
true,
13042-
Some(Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT)),
13038+
true,
1304313039
2200,
1304413040
);
1304513041
assert_eq!(
@@ -13059,7 +13055,7 @@ mod tests {
1305913055
funding_input_sats(100_000),
1306013056
],
1306113057
false,
13062-
None,
13058+
false,
1306313059
2000,
1306413060
).unwrap(),
1306513061
expected_fee,

0 commit comments

Comments
 (0)