@@ -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
@@ -17397,19 +17402,19 @@ mod tests {
1739717402 // 2 inputs, initiator, 2000 sat/kw feerate
1739817403 assert_eq!(
1739917404 estimate_v2_funding_transaction_fee(&two_inputs, &[], true, false, 2000),
17400- 1516,
17405+ if cfg!(feature = "grind_signatures") { 1512 } else { 1516 } ,
1740117406 );
1740217407
1740317408 // higher feerate
1740417409 assert_eq!(
1740517410 estimate_v2_funding_transaction_fee(&two_inputs, &[], true, false, 3000),
17406- 2274,
17411+ if cfg!(feature = "grind_signatures") { 2268 } else { 2274 } ,
1740717412 );
1740817413
1740917414 // only 1 input
1741017415 assert_eq!(
1741117416 estimate_v2_funding_transaction_fee(&one_input, &[], true, false, 2000),
17412- 972,
17417+ if cfg!(feature = "grind_signatures") { 970 } else { 972 } ,
1741317418 );
1741417419
1741517420 // 0 inputs
@@ -17427,13 +17432,13 @@ mod tests {
1742717432 // splice initiator
1742817433 assert_eq!(
1742917434 estimate_v2_funding_transaction_fee(&one_input, &[], true, true, 2000),
17430- 1740,
17435+ if cfg!(feature = "grind_signatures") { 1736 } else { 1740 } ,
1743117436 );
1743217437
1743317438 // splice acceptor
1743417439 assert_eq!(
1743517440 estimate_v2_funding_transaction_fee(&one_input, &[], false, true, 2000),
17436- 544,
17441+ if cfg!(feature = "grind_signatures") { 542 } else { 544 } ,
1743717442 );
1743817443 }
1743917444
@@ -17457,40 +17462,46 @@ mod tests {
1745717462 use crate::ln::channel::check_v2_funding_inputs_sufficient;
1745817463
1745917464 // positive case, inputs well over intended contribution
17460- assert_eq!(
17461- check_v2_funding_inputs_sufficient(
17462- 220_000,
17463- &[
17464- funding_input_sats(200_000),
17465- funding_input_sats(100_000),
17466- ],
17467- true,
17468- true,
17469- 2000,
17470- ).unwrap(),
17471- 2284,
17472- );
17465+ {
17466+ let expected_fee = if cfg!(feature = "grind_signatures") { 2278 } else { 2284 };
17467+ assert_eq!(
17468+ check_v2_funding_inputs_sufficient(
17469+ 220_000,
17470+ &[
17471+ funding_input_sats(200_000),
17472+ funding_input_sats(100_000),
17473+ ],
17474+ true,
17475+ true,
17476+ 2000,
17477+ ).unwrap(),
17478+ expected_fee,
17479+ );
17480+ }
1747317481
1747417482 // negative case, inputs clearly insufficient
1747517483 {
17476- let res = check_v2_funding_inputs_sufficient(
17477- 220_000,
17478- &[
17479- funding_input_sats(100_000),
17480- ],
17481- true,
17482- true,
17483- 2000,
17484- );
17484+ let expected_fee = if cfg!(feature = "grind_signatures") { 1736 } else { 1740 };
1748517485 assert_eq!(
17486- res.err().unwrap(),
17487- "Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1740. Need more inputs.",
17486+ check_v2_funding_inputs_sufficient(
17487+ 220_000,
17488+ &[
17489+ funding_input_sats(100_000),
17490+ ],
17491+ true,
17492+ true,
17493+ 2000,
17494+ ),
17495+ Err(format!(
17496+ "Total input amount 100000 is lower than needed for contribution 220000, considering fees of {}. Need more inputs.",
17497+ expected_fee,
17498+ )),
1748817499 );
1748917500 }
1749017501
1749117502 // barely covers
1749217503 {
17493- let expected_fee: u64 = 2284;
17504+ let expected_fee = if cfg!(feature = "grind_signatures") { 2278 } else { 2284 } ;
1749417505 assert_eq!(
1749517506 check_v2_funding_inputs_sufficient(
1749617507 (300_000 - expected_fee - 20) as i64,
@@ -17508,25 +17519,28 @@ mod tests {
1750817519
1750917520 // higher fee rate, does not cover
1751017521 {
17511- let res = check_v2_funding_inputs_sufficient(
17512- 298032,
17513- &[
17514- funding_input_sats(200_000),
17515- funding_input_sats(100_000),
17516- ],
17517- true,
17518- true,
17519- 2200,
17520- );
17522+ let expected_fee = if cfg!(feature = "grind_signatures") { 2506 } else { 2513 };
1752117523 assert_eq!(
17522- res.err().unwrap(),
17523- "Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2513. Need more inputs.",
17524+ check_v2_funding_inputs_sufficient(
17525+ 298032,
17526+ &[
17527+ funding_input_sats(200_000),
17528+ funding_input_sats(100_000),
17529+ ],
17530+ true,
17531+ true,
17532+ 2200,
17533+ ),
17534+ Err(format!(
17535+ "Total input amount 300000 is lower than needed for contribution 298032, considering fees of {}. Need more inputs.",
17536+ expected_fee
17537+ )),
1752417538 );
1752517539 }
1752617540
17527- // barely covers, less fees (no extra weight, no init )
17541+ // barely covers, less fees (no extra weight, not initiator )
1752817542 {
17529- let expected_fee: u64 = 1088;
17543+ let expected_fee = if cfg!(feature = "grind_signatures") { 1084 } else { 1088 } ;
1753017544 assert_eq!(
1753117545 check_v2_funding_inputs_sufficient(
1753217546 (300_000 - expected_fee - 20) as i64,
0 commit comments