@@ -288,25 +288,53 @@ impl PackageSolvingData {
288
288
PackageSolvingData :: RevokedHTLCOutput ( ref outp) => { outp. amount } ,
289
289
PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ref outp) => { outp. htlc . amount_msat / 1000 } ,
290
290
PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ref outp) => { outp. htlc . amount_msat / 1000 } ,
291
+ PackageSolvingData :: HolderFundingOutput ( ref outp) => {
292
+ if let Some ( ref utxo_input) = outp. utxo_input {
293
+ return utxo_input. 1 . amount + 330 ; //TODO: move ANCHOR_OUTPUT_VALUE in chan_utils
294
+ } else {
295
+ return 0 ;
296
+ }
297
+ } ,
291
298
// Note: Currently, amounts of holder outputs spending witnesses aren't used
292
299
// as we can't malleate spending package to increase their feerate. This
293
300
// should change with the remaining anchor output patchset.
294
301
PackageSolvingData :: HolderHTLCOutput ( ..) => { unreachable ! ( ) } ,
295
- PackageSolvingData :: HolderFundingOutput ( ..) => { unreachable ! ( ) } ,
296
302
} ;
297
303
amt
298
304
}
299
- fn weight ( & self ) -> usize {
305
+ fn weight ( & self , destination_script : & Script , num_commitment_outputs : usize ) -> usize {
300
306
let weight = match self {
301
307
PackageSolvingData :: RevokedOutput ( ref outp) => { outp. weight as usize } ,
302
308
PackageSolvingData :: RevokedHTLCOutput ( ref outp) => { outp. weight as usize } ,
303
309
PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => { WEIGHT_OFFERED_HTLC as usize } ,
304
310
PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => { WEIGHT_RECEIVED_HTLC as usize } ,
305
- // Note: Currently, weights of holder outputs spending witnesses aren't used
306
- // as we can't malleate spending package to increase their feerate. This
307
- // should change with the remaining anchor output patchset.
308
- PackageSolvingData :: HolderHTLCOutput ( ..) => { unreachable ! ( ) } ,
309
- PackageSolvingData :: HolderFundingOutput ( ..) => { unreachable ! ( ) } ,
311
+ PackageSolvingData :: HolderFundingOutput ( ref outp) => {
312
+ // Post-Anchor Commitment Package weight accoutning:
313
+ let commitment_weight =
314
+ 900 // base commitment tx (900 WU)
315
+ + num_commitment_outputs * 172 // num-outputs * P2WSH-output (172 WU)
316
+ + 224 ; // funding spending witness (224 WU)
317
+ // If a feerate-bump is required:
318
+ let cpfp_weight: usize = if let Some ( ref utxo_input) = outp. utxo_input {
319
+ 40 // CPFP transaction basic fields (40 WU)
320
+ + 2 // witness marker (2 WU)
321
+ + 164 // anchor input (164 WU)
322
+ + 115 // anchor witness (115 WU)
323
+ + 164 // bumping input (164 WU)
324
+ + utxo_input. 1 . witness_weight as usize // bumping witness (`utxo_input.1.witness_weight`)
325
+ + 32 // output amount (32 WU)
326
+ + 4 // output scriptpubkey-length (4 WU)
327
+ + destination_script. len ( ) * 4 // output scriptpubkey (`destination_script.len() * 4`)
328
+ } else { 0 } ;
329
+ return commitment_weight + cpfp_weight;
330
+ } ,
331
+ PackageSolvingData :: HolderHTLCOutput ( ref outp) => {
332
+ if outp. preimage . is_some ( ) {
333
+ return 706 ; // HTLC-Success with option_anchor_outputs
334
+ } else {
335
+ return 666 ; // HTLC-Timeout with option_anchor_outputs
336
+ }
337
+ } ,
310
338
} ;
311
339
weight
312
340
}
@@ -589,13 +617,13 @@ impl PackageTemplate {
589
617
self . inputs . iter ( ) . map ( |( _, outp) | outp. absolute_tx_timelock ( self . height_original ) )
590
618
. max ( ) . expect ( "There must always be at least one output to spend in a PackageTemplate" )
591
619
}
592
- pub ( crate ) fn package_weight ( & self , destination_script : & Script ) -> usize {
620
+ pub ( crate ) fn package_weight ( & self , destination_script : & Script , num_commitment_outputs : usize ) -> usize {
593
621
let mut inputs_weight = 0 ;
594
622
let mut witnesses_weight = 2 ; // count segwit flags
595
623
for ( _, outp) in self . inputs . iter ( ) {
596
624
// previous_out_point: 36 bytes ; var_int: 1 byte ; sequence: 4 bytes
597
625
inputs_weight += 41 * WITNESS_SCALE_FACTOR ;
598
- witnesses_weight += outp. weight ( ) ;
626
+ witnesses_weight += outp. weight ( destination_script , num_commitment_outputs ) ;
599
627
}
600
628
// version: 4 bytes ; count_tx_in: 1 byte ; count_tx_out: 1 byte ; lock_time: 4 bytes
601
629
let transaction_weight = 10 * WITNESS_SCALE_FACTOR ;
@@ -1081,6 +1109,6 @@ mod tests {
1081
1109
let package = PackageTemplate :: build_package ( txid, 0 , revk_outp, 0 , true , 100 ) ;
1082
1110
// (nVersion (4) + nLocktime (4) + count_tx_in (1) + prevout (36) + sequence (4) + script_length (1) + count_tx_out (1) + value (8) + var_int (1)) * WITNESS_SCALE_FACTOR
1083
1111
// + witness marker (2) + WEIGHT_REVOKED_OUTPUT
1084
- assert_eq ! ( package. package_weight( & Script :: new( ) ) , ( 4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1 ) * WITNESS_SCALE_FACTOR + 2 + WEIGHT_REVOKED_OUTPUT as usize ) ;
1112
+ assert_eq ! ( package. package_weight( & Script :: new( ) , 0 ) , ( 4 + 4 + 1 + 36 + 4 + 1 + 1 + 8 + 1 ) * WITNESS_SCALE_FACTOR + 2 + WEIGHT_REVOKED_OUTPUT as usize ) ;
1085
1113
}
1086
1114
}
0 commit comments