@@ -1209,9 +1209,11 @@ impl ChannelMonitor {
1209
1209
value: htlc. amount_msat / 1000 ,
1210
1210
} ) ,
1211
1211
} ;
1212
- single_htlc_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * ( single_htlc_tx. get_weight ( ) + Self :: get_witnesses_weight ( & [ if htlc. offered { InputDescriptors :: RevokedOfferedHTLC } else { InputDescriptors :: RevokedReceivedHTLC } ] ) ) / 1000 ;
1212
+ let predicted_weight = single_htlc_tx. get_weight ( ) + Self :: get_witnesses_weight ( & vec ! [ if htlc. offered { InputDescriptors :: RevokedOfferedHTLC } else { InputDescriptors :: RevokedReceivedHTLC } ] ) ;
1213
+ single_htlc_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * predicted_weight / 1000 ;
1213
1214
let sighash_parts = bip143:: SighashComponents :: new ( & single_htlc_tx) ;
1214
1215
sign_input ! ( sighash_parts, single_htlc_tx. input[ 0 ] , Some ( idx) , htlc. amount_msat / 1000 ) ;
1216
+ assert ! ( predicted_weight >= single_htlc_tx. get_weight( ) ) ;
1215
1217
txn_to_broadcast. push ( single_htlc_tx) ;
1216
1218
}
1217
1219
}
@@ -1261,7 +1263,8 @@ impl ChannelMonitor {
1261
1263
input : inputs,
1262
1264
output : outputs,
1263
1265
} ;
1264
- spend_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * ( spend_tx. get_weight ( ) + Self :: get_witnesses_weight ( & input_descriptors[ ..] ) ) / 1000 ;
1266
+ let predicted_weight = spend_tx. get_weight ( ) + Self :: get_witnesses_weight ( & input_descriptors) ;
1267
+ spend_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * predicted_weight / 1000 ;
1265
1268
1266
1269
let mut values_drain = values. drain ( ..) ;
1267
1270
let sighash_parts = bip143:: SighashComponents :: new ( & spend_tx) ;
@@ -1270,6 +1273,7 @@ impl ChannelMonitor {
1270
1273
let value = values_drain. next ( ) . unwrap ( ) ;
1271
1274
sign_input ! ( sighash_parts, input, htlc_idx, value) ;
1272
1275
}
1276
+ assert ! ( predicted_weight >= spend_tx. get_weight( ) ) ;
1273
1277
1274
1278
spendable_outputs. push ( SpendableOutputDescriptor :: StaticOutput {
1275
1279
outpoint : BitcoinOutPoint { txid : spend_tx. txid ( ) , vout : 0 } ,
@@ -1428,9 +1432,11 @@ impl ChannelMonitor {
1428
1432
value: htlc. amount_msat / 1000 ,
1429
1433
} ) ,
1430
1434
} ;
1431
- single_htlc_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * ( single_htlc_tx. get_weight ( ) + Self :: get_witnesses_weight ( & [ if htlc. offered { InputDescriptors :: OfferedHTLC } else { InputDescriptors :: ReceivedHTLC } ] ) ) / 1000 ;
1435
+ let predicted_weight = single_htlc_tx. get_weight ( ) + Self :: get_witnesses_weight ( & vec ! [ if htlc. offered { InputDescriptors :: OfferedHTLC } else { InputDescriptors :: ReceivedHTLC } ] ) ;
1436
+ single_htlc_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * predicted_weight / 1000 ;
1432
1437
let sighash_parts = bip143:: SighashComponents :: new ( & single_htlc_tx) ;
1433
1438
sign_input ! ( sighash_parts, single_htlc_tx. input[ 0 ] , htlc. amount_msat / 1000 , payment_preimage. 0 . to_vec( ) ) ;
1439
+ assert ! ( predicted_weight >= single_htlc_tx. get_weight( ) ) ;
1434
1440
spendable_outputs. push ( SpendableOutputDescriptor :: StaticOutput {
1435
1441
outpoint : BitcoinOutPoint { txid : single_htlc_tx. txid ( ) , vout : 0 } ,
1436
1442
output : single_htlc_tx. output [ 0 ] . clone ( ) ,
@@ -1478,7 +1484,8 @@ impl ChannelMonitor {
1478
1484
input : inputs,
1479
1485
output : outputs,
1480
1486
} ;
1481
- spend_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * ( spend_tx. get_weight ( ) + Self :: get_witnesses_weight ( & input_descriptors[ ..] ) ) / 1000 ;
1487
+ let predicted_weight = spend_tx. get_weight ( ) + Self :: get_witnesses_weight ( & input_descriptors) ;
1488
+ spend_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * predicted_weight / 1000 ;
1482
1489
1483
1490
let mut values_drain = values. drain ( ..) ;
1484
1491
let sighash_parts = bip143:: SighashComponents :: new ( & spend_tx) ;
@@ -1488,6 +1495,7 @@ impl ChannelMonitor {
1488
1495
sign_input ! ( sighash_parts, input, value. 0 , ( value. 1 ) . 0 . to_vec( ) ) ;
1489
1496
}
1490
1497
1498
+ assert ! ( predicted_weight >= spend_tx. get_weight( ) ) ;
1491
1499
spendable_outputs. push ( SpendableOutputDescriptor :: StaticOutput {
1492
1500
outpoint : BitcoinOutPoint { txid : spend_tx. txid ( ) , vout : 0 } ,
1493
1501
output : spend_tx. output [ 0 ] . clone ( ) ,
@@ -1562,7 +1570,8 @@ impl ChannelMonitor {
1562
1570
input : inputs,
1563
1571
output : outputs,
1564
1572
} ;
1565
- spend_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * ( spend_tx. get_weight ( ) + Self :: get_witnesses_weight ( & vec ! [ InputDescriptors :: RevokedOutput ] ) ) / 1000 ;
1573
+ let predicted_weight = spend_tx. get_weight ( ) + Self :: get_witnesses_weight ( & vec ! [ InputDescriptors :: RevokedOutput ] ) ;
1574
+ spend_tx. output [ 0 ] . value -= fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: HighPriority ) * predicted_weight / 1000 ;
1566
1575
1567
1576
let sighash_parts = bip143:: SighashComponents :: new ( & spend_tx) ;
1568
1577
@@ -1581,6 +1590,7 @@ impl ChannelMonitor {
1581
1590
spend_tx. input [ 0 ] . witness . push ( vec ! ( 1 ) ) ;
1582
1591
spend_tx. input [ 0 ] . witness . push ( redeemscript. into_bytes ( ) ) ;
1583
1592
1593
+ assert ! ( predicted_weight >= spend_tx. get_weight( ) ) ;
1584
1594
let outpoint = BitcoinOutPoint { txid : spend_tx. txid ( ) , vout : 0 } ;
1585
1595
let output = spend_tx. output [ 0 ] . clone ( ) ;
1586
1596
( Some ( spend_tx) , Some ( SpendableOutputDescriptor :: StaticOutput { outpoint, output } ) )
0 commit comments