@@ -8,6 +8,7 @@ use bitcoin::hash_types::Txid;
8
8
9
9
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
10
10
11
+ use ln:: channel:: ANCHOR_OUTPUT_VALUE ;
11
12
use ln:: channelmanager:: PaymentPreimage ;
12
13
use ln:: chan_utils:: { TxCreationKeys , HTLCOutputInCommitment } ;
13
14
use ln:: chan_utils;
@@ -409,11 +410,18 @@ impl PackageTemplate {
409
410
}
410
411
amounts
411
412
} ,
412
- _ => 0 ,
413
+ PackageTemplate :: HolderCommitmentTx { ref utxo_input, .. } => {
414
+ if let Some ( utxo_input) = utxo_input {
415
+ return utxo_input. 1 . amount + ANCHOR_OUTPUT_VALUE ;
416
+ } else { return 0 }
417
+ } ,
418
+ PackageTemplate :: HolderHTLCTx { ref input } => {
419
+ input. 1 . amount
420
+ } ,
413
421
} ;
414
422
amounts
415
423
}
416
- pub ( crate ) fn package_weight ( & self , destination_script : & Script ) -> usize {
424
+ pub ( crate ) fn package_weight ( & self , destination_script : & Script , local_commitment : & Transaction ) -> usize {
417
425
let mut input = Vec :: new ( ) ;
418
426
let witnesses_weight = match self {
419
427
PackageTemplate :: MalleableJusticeTx { ref inputs } => {
@@ -443,7 +451,33 @@ impl PackageTemplate {
443
451
}
444
452
weight
445
453
} ,
446
- _ => { return 0 }
454
+ PackageTemplate :: HolderCommitmentTx { ref utxo_input, .. } => {
455
+ // Post-Anchor Commitment Package weight accoutning:
456
+ let commitment_weight =
457
+ 900 // base commitment tx (900 WU)
458
+ + local_commitment. output . len ( ) * 172 // num-htlc-outputs * htlc-output (172 WU)
459
+ + 224 ; // funding spending witness (224 WU)
460
+ // If a feerate-bump is required:
461
+ let cpfp_weight: usize = if let Some ( utxo_input) = utxo_input {
462
+ 40 // CPFP transaction basic fields (40 WU)
463
+ + 2 // witness marker (2 WU)
464
+ + 164 // anchor input (164 WU)
465
+ + 115 // anchor witness (115 WU)
466
+ + 164 // bumping input (164 WU)
467
+ + utxo_input. 1 . witness_weight as usize // bumping witness (`utxo_input.1.witness_weight`)
468
+ + 32 // output amount (32 WU)
469
+ + 4 // output scriptpubkey-length (4 WU)
470
+ + destination_script. len ( ) * 4 // output scriptpubkey (`destination_script.len() * 4`)
471
+ } else { 0 } ;
472
+ return commitment_weight + cpfp_weight;
473
+ } ,
474
+ PackageTemplate :: HolderHTLCTx { ref input } => {
475
+ if input. 1 . preimage . is_some ( ) {
476
+ return 706 ; // HTLC-Success with option_anchor_outputs
477
+ } else {
478
+ return 666 ; // HTLC-Timeout with option_anchor_outputs
479
+ }
480
+ } ,
447
481
} ;
448
482
let bumped_tx = Transaction {
449
483
version : 2 ,
@@ -927,6 +961,12 @@ pub(crate) fn compute_output_value<F: Deref, L: Deref>(predicted_weight: usize,
927
961
where F :: Target : FeeEstimator ,
928
962
L :: Target : Logger ,
929
963
{
964
+ // If transaction is still relying ont its pre-committed feerate to get confirmed return
965
+ // a 0-value output-value as it won't be consumed further
966
+ if input_amounts == 0 {
967
+ return Some ( ( 0 , previous_feerate) ) ;
968
+ }
969
+
930
970
// If old feerate is 0, first iteration of this claim, use normal fee calculation
931
971
if previous_feerate != 0 {
932
972
if let Some ( ( new_fee, feerate) ) = feerate_bump ( predicted_weight, input_amounts, previous_feerate, fee_estimator, logger) {
0 commit comments