Skip to content

Commit edd3851

Browse files
committed
Account for grind_signatures in splice funding tx
When estimating the splice funding transaction fees, adjust for grind_signatures. Since LDK supplies one of the signatures, only adjust by 1 WU even though spending the shared input requires two signatures.
1 parent 81447c9 commit edd3851

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6547,6 +6547,11 @@ fn estimate_v2_funding_transaction_fee(
65476547
.saturating_add(BASE_INPUT_WEIGHT)
65486548
.saturating_add(EMPTY_SCRIPT_SIG_WEIGHT)
65496549
.saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT);
6550+
#[cfg(feature = "grind_signatures")]
6551+
{
6552+
// Guarantees a low R signature
6553+
weight -= 1;
6554+
}
65506555
}
65516556
}
65526557

@@ -17427,7 +17432,7 @@ mod tests {
1742717432
// splice initiator
1742817433
assert_eq!(
1742917434
estimate_v2_funding_transaction_fee(&one_input, &[], true, true, 2000),
17430-
1740,
17435+
1738,
1743117436
);
1743217437

1743317438
// splice acceptor
@@ -17468,7 +17473,7 @@ mod tests {
1746817473
true,
1746917474
2000,
1747017475
).unwrap(),
17471-
2284,
17476+
2282,
1747217477
);
1747317478

1747417479
// negative case, inputs clearly insufficient
@@ -17484,13 +17489,13 @@ mod tests {
1748417489
);
1748517490
assert_eq!(
1748617491
res.err().unwrap(),
17487-
"Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1740. Need more inputs.",
17492+
"Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1738. Need more inputs.",
1748817493
);
1748917494
}
1749017495

1749117496
// barely covers
1749217497
{
17493-
let expected_fee: u64 = 2284;
17498+
let expected_fee: u64 = 2282;
1749417499
assert_eq!(
1749517500
check_v2_funding_inputs_sufficient(
1749617501
(300_000 - expected_fee - 20) as i64,
@@ -17520,7 +17525,7 @@ mod tests {
1752017525
);
1752117526
assert_eq!(
1752217527
res.err().unwrap(),
17523-
"Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2513. Need more inputs.",
17528+
"Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2511. Need more inputs.",
1752417529
);
1752517530
}
1752617531

lightning/src/ln/interactivetxs.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,15 @@ impl InputOwned {
17061706
InputOwned::Single(single) => single.satisfaction_weight,
17071707
// TODO(taproot): Needs to consider different weights based on channel type
17081708
InputOwned::Shared(_) => {
1709-
Weight::from_wu(EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT)
1709+
let mut weight = 0;
1710+
weight += EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT;
1711+
#[cfg(feature = "grind_signatures")]
1712+
{
1713+
// Guarantees a low R signature
1714+
weight -= 1;
1715+
}
1716+
1717+
Weight::from_wu(weight)
17101718
},
17111719
}
17121720
}
@@ -2314,6 +2322,11 @@ pub(super) fn calculate_change_output_value(
23142322
weight = weight.saturating_add(BASE_INPUT_WEIGHT);
23152323
weight = weight.saturating_add(EMPTY_SCRIPT_SIG_WEIGHT);
23162324
weight = weight.saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT);
2325+
#[cfg(feature = "grind_signatures")]
2326+
{
2327+
// Guarantees a low R signature
2328+
weight -= 1;
2329+
}
23172330
}
23182331
}
23192332

0 commit comments

Comments
 (0)