@@ -6561,6 +6561,11 @@ fn estimate_v2_funding_transaction_fee(
65616561 .saturating_add(BASE_INPUT_WEIGHT)
65626562 .saturating_add(EMPTY_SCRIPT_SIG_WEIGHT)
65636563 .saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT);
6564+ #[cfg(feature = "grind_signatures")]
6565+ {
6566+ // Guarantees a low R signature
6567+ weight -= 1;
6568+ }
65646569 }
65656570 }
65666571
@@ -17413,19 +17418,19 @@ mod tests {
1741317418 // 2 inputs, initiator, 2000 sat/kw feerate
1741417419 assert_eq!(
1741517420 estimate_v2_funding_transaction_fee(&two_inputs, &[], true, false, 2000),
17416- 1516,
17421+ if cfg!(feature = "grind_signatures") { 1512 } else { 1516 } ,
1741717422 );
1741817423
1741917424 // higher feerate
1742017425 assert_eq!(
1742117426 estimate_v2_funding_transaction_fee(&two_inputs, &[], true, false, 3000),
17422- 2274,
17427+ if cfg!(feature = "grind_signatures") { 2268 } else { 2274 } ,
1742317428 );
1742417429
1742517430 // only 1 input
1742617431 assert_eq!(
1742717432 estimate_v2_funding_transaction_fee(&one_input, &[], true, false, 2000),
17428- 972,
17433+ if cfg!(feature = "grind_signatures") { 970 } else { 972 } ,
1742917434 );
1743017435
1743117436 // 0 inputs
@@ -17443,13 +17448,13 @@ mod tests {
1744317448 // splice initiator
1744417449 assert_eq!(
1744517450 estimate_v2_funding_transaction_fee(&one_input, &[], true, true, 2000),
17446- 1740,
17451+ if cfg!(feature = "grind_signatures") { 1736 } else { 1740 } ,
1744717452 );
1744817453
1744917454 // splice acceptor
1745017455 assert_eq!(
1745117456 estimate_v2_funding_transaction_fee(&one_input, &[], false, true, 2000),
17452- 544,
17457+ if cfg!(feature = "grind_signatures") { 542 } else { 544 } ,
1745317458 );
1745417459 }
1745517460
@@ -17473,40 +17478,46 @@ mod tests {
1747317478 use crate::ln::channel::check_v2_funding_inputs_sufficient;
1747417479
1747517480 // positive case, inputs well over intended contribution
17476- assert_eq!(
17477- check_v2_funding_inputs_sufficient(
17478- 220_000,
17479- &[
17480- funding_input_sats(200_000),
17481- funding_input_sats(100_000),
17482- ],
17483- true,
17484- true,
17485- 2000,
17486- ).unwrap(),
17487- 2284,
17488- );
17481+ {
17482+ let expected_fee = if cfg!(feature = "grind_signatures") { 2278 } else { 2284 };
17483+ assert_eq!(
17484+ check_v2_funding_inputs_sufficient(
17485+ 220_000,
17486+ &[
17487+ funding_input_sats(200_000),
17488+ funding_input_sats(100_000),
17489+ ],
17490+ true,
17491+ true,
17492+ 2000,
17493+ ).unwrap(),
17494+ expected_fee,
17495+ );
17496+ }
1748917497
1749017498 // negative case, inputs clearly insufficient
1749117499 {
17492- let res = check_v2_funding_inputs_sufficient(
17493- 220_000,
17494- &[
17495- funding_input_sats(100_000),
17496- ],
17497- true,
17498- true,
17499- 2000,
17500- );
17500+ let expected_fee = if cfg!(feature = "grind_signatures") { 1736 } else { 1740 };
1750117501 assert_eq!(
17502- res.err().unwrap(),
17503- "Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1740. Need more inputs.",
17502+ check_v2_funding_inputs_sufficient(
17503+ 220_000,
17504+ &[
17505+ funding_input_sats(100_000),
17506+ ],
17507+ true,
17508+ true,
17509+ 2000,
17510+ ),
17511+ Err(format!(
17512+ "Total input amount 100000 is lower than needed for contribution 220000, considering fees of {}. Need more inputs.",
17513+ expected_fee,
17514+ )),
1750417515 );
1750517516 }
1750617517
1750717518 // barely covers
1750817519 {
17509- let expected_fee: u64 = 2284;
17520+ let expected_fee = if cfg!(feature = "grind_signatures") { 2278 } else { 2284 } ;
1751017521 assert_eq!(
1751117522 check_v2_funding_inputs_sufficient(
1751217523 (300_000 - expected_fee - 20) as i64,
@@ -17524,25 +17535,28 @@ mod tests {
1752417535
1752517536 // higher fee rate, does not cover
1752617537 {
17527- let res = check_v2_funding_inputs_sufficient(
17528- 298032,
17529- &[
17530- funding_input_sats(200_000),
17531- funding_input_sats(100_000),
17532- ],
17533- true,
17534- true,
17535- 2200,
17536- );
17538+ let expected_fee = if cfg!(feature = "grind_signatures") { 2506 } else { 2513 };
1753717539 assert_eq!(
17538- res.err().unwrap(),
17539- "Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2513. Need more inputs.",
17540+ check_v2_funding_inputs_sufficient(
17541+ 298032,
17542+ &[
17543+ funding_input_sats(200_000),
17544+ funding_input_sats(100_000),
17545+ ],
17546+ true,
17547+ true,
17548+ 2200,
17549+ ),
17550+ Err(format!(
17551+ "Total input amount 300000 is lower than needed for contribution 298032, considering fees of {}. Need more inputs.",
17552+ expected_fee
17553+ )),
1754017554 );
1754117555 }
1754217556
17543- // barely covers, less fees (no extra weight, no init )
17557+ // barely covers, less fees (no extra weight, not initiator )
1754417558 {
17545- let expected_fee: u64 = 1088;
17559+ let expected_fee = if cfg!(feature = "grind_signatures") { 1084 } else { 1088 } ;
1754617560 assert_eq!(
1754717561 check_v2_funding_inputs_sufficient(
1754817562 (300_000 - expected_fee - 20) as i64,
0 commit comments