@@ -387,6 +387,7 @@ enum InputMaterial {
387
387
key : SecretKey ,
388
388
preimage : Option < PaymentPreimage > ,
389
389
amount : u64 ,
390
+ locktime : u32 ,
390
391
} ,
391
392
LocalHTLC {
392
393
script : Script ,
@@ -1175,12 +1176,13 @@ impl ChannelMonitor {
1175
1176
}
1176
1177
writer. write_all ( & byte_utils:: be64_to_array ( * amount) ) ?;
1177
1178
} ,
1178
- & InputMaterial :: RemoteHTLC { ref script, ref key, ref preimage, ref amount } => {
1179
+ & InputMaterial :: RemoteHTLC { ref script, ref key, ref preimage, ref amount, ref locktime } => {
1179
1180
writer. write_all ( & [ 1 ; 1 ] ) ?;
1180
1181
script. write ( writer) ?;
1181
1182
key. write ( writer) ?;
1182
1183
preimage. write ( writer) ?;
1183
1184
writer. write_all ( & byte_utils:: be64_to_array ( * amount) ) ?;
1185
+ writer. write_all ( & byte_utils:: be32_to_array ( * locktime) ) ?;
1184
1186
} ,
1185
1187
& InputMaterial :: LocalHTLC { ref script, ref sigs, ref preimage, ref amount } => {
1186
1188
writer. write_all ( & [ 2 ; 1 ] ) ?;
@@ -1708,7 +1710,7 @@ impl ChannelMonitor {
1708
1710
} ) ;
1709
1711
log_trace ! ( self , "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}" , single_htlc_tx. input[ 0 ] . previous_output. txid, single_htlc_tx. input[ 0 ] . previous_output. vout, height_timer) ;
1710
1712
let mut per_input_material = HashMap :: with_capacity ( 1 ) ;
1711
- per_input_material. insert ( single_htlc_tx. input [ 0 ] . previous_output . vout , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * payment_preimage) , amount : htlc. amount_msat / 1000 } ) ;
1713
+ per_input_material. insert ( single_htlc_tx. input [ 0 ] . previous_output . vout , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * payment_preimage) , amount : htlc. amount_msat / 1000 , locktime : 0 } ) ;
1712
1714
match self . our_claim_txn_waiting_first_conf . entry ( single_htlc_tx. input [ 0 ] . previous_output . clone ( ) ) {
1713
1715
hash_map:: Entry :: Occupied ( _) => { } ,
1714
1716
hash_map:: Entry :: Vacant ( entry) => { entry. insert ( ClaimTxBumpMaterial { height_timer, first_seen_height : height, feerate_previous : used_feerate, soonest_timelock : htlc. cltv_expiry , per_input_material} ) ; }
@@ -1749,7 +1751,7 @@ impl ChannelMonitor {
1749
1751
//TODO: track SpendableOutputDescriptor
1750
1752
log_trace ! ( self , "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}" , timeout_tx. input[ 0 ] . previous_output. txid, timeout_tx. input[ 0 ] . previous_output. vout, height_timer) ;
1751
1753
let mut per_input_material = HashMap :: with_capacity ( 1 ) ;
1752
- per_input_material. insert ( timeout_tx. input [ 0 ] . previous_output . vout , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : None , amount : htlc. amount_msat / 1000 } ) ;
1754
+ per_input_material. insert ( timeout_tx. input [ 0 ] . previous_output . vout , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : None , amount : htlc. amount_msat / 1000 , locktime : htlc . cltv_expiry } ) ;
1753
1755
match self . our_claim_txn_waiting_first_conf . entry ( timeout_tx. input [ 0 ] . previous_output . clone ( ) ) {
1754
1756
hash_map:: Entry :: Occupied ( _) => { } ,
1755
1757
hash_map:: Entry :: Vacant ( entry) => { entry. insert ( ClaimTxBumpMaterial { height_timer, first_seen_height : height, feerate_previous : used_feerate, soonest_timelock : htlc. cltv_expiry , per_input_material } ) ; }
@@ -1793,7 +1795,7 @@ impl ChannelMonitor {
1793
1795
for ( input, info) in spend_tx. input . iter_mut ( ) . zip ( inputs_info. iter ( ) ) {
1794
1796
let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, input, info. 1 , ( info. 0 ) . 0 . to_vec( ) ) ;
1795
1797
log_trace ! ( self , "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}" , input. previous_output. txid, input. previous_output. vout, height_timer) ;
1796
- per_input_material. insert ( input. previous_output . vout , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * ( info. 0 ) ) , amount : info. 1 } ) ;
1798
+ per_input_material. insert ( input. previous_output . vout , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * ( info. 0 ) ) , amount : info. 1 , locktime : 0 } ) ;
1797
1799
}
1798
1800
match self . our_claim_txn_waiting_first_conf . entry ( spend_tx. input [ 0 ] . previous_output . clone ( ) ) {
1799
1801
hash_map:: Entry :: Occupied ( _) => { } ,
@@ -2600,7 +2602,10 @@ impl ChannelMonitor {
2600
2602
inputs_witnesses_weight += Self :: get_witnesses_weight ( if !is_htlc { & [ InputDescriptors :: RevokedOutput ] } else if script. len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT { & [ InputDescriptors :: RevokedOfferedHTLC ] } else if script. len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT { & [ InputDescriptors :: RevokedReceivedHTLC ] } else { & [ ] } ) ;
2601
2603
amt += * amount;
2602
2604
} ,
2603
- & InputMaterial :: RemoteHTLC { .. } => { return None ; } ,
2605
+ & InputMaterial :: RemoteHTLC { ref preimage, ref amount, .. } => {
2606
+ inputs_witnesses_weight += Self :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
2607
+ amt += * amount;
2608
+ } ,
2604
2609
& InputMaterial :: LocalHTLC { .. } => { return None ; }
2605
2610
}
2606
2611
}
@@ -2637,7 +2642,21 @@ impl ChannelMonitor {
2637
2642
bumped_tx. input [ i] . witness . push ( script. clone ( ) . into_bytes ( ) ) ;
2638
2643
log_trace ! ( self , "Going to broadcast bumped Penalty Transaction {} claiming revoked {} output {} from {} with new feerate {}" , bumped_tx. txid( ) , if !is_htlc { "to_local" } else if script. len( ) == OFFERED_HTLC_SCRIPT_WEIGHT { "offered" } else if script. len( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT { "received" } else { "" } , vout, outp. txid, new_feerate) ;
2639
2644
} ,
2640
- & InputMaterial :: RemoteHTLC { .. } => { } ,
2645
+ & InputMaterial :: RemoteHTLC { ref script, ref key, ref preimage, ref amount, ref locktime } => {
2646
+ if !preimage. is_some ( ) { bumped_tx. lock_time = * locktime } ;
2647
+ let sighash_parts = bip143:: SighashComponents :: new ( & bumped_tx) ;
2648
+ let sighash = hash_to_message ! ( & sighash_parts. sighash_all( & bumped_tx. input[ i] , & script, * amount) [ ..] ) ;
2649
+ let sig = self . secp_ctx . sign ( & sighash, & key) ;
2650
+ bumped_tx. input [ i] . witness . push ( sig. serialize_der ( ) . to_vec ( ) ) ;
2651
+ bumped_tx. input [ i] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
2652
+ if let & Some ( preimage) = preimage {
2653
+ bumped_tx. input [ i] . witness . push ( preimage. clone ( ) . 0 . to_vec ( ) ) ;
2654
+ } else {
2655
+ bumped_tx. input [ i] . witness . push ( vec ! [ 0 ] ) ;
2656
+ }
2657
+ bumped_tx. input [ i] . witness . push ( script. clone ( ) . into_bytes ( ) ) ;
2658
+ log_trace ! ( self , "Going to broadcast bumped Claim Transaction {} claiming remote {} htlc output {} from {} with new feerate {}" , bumped_tx. txid( ) , if preimage. is_some( ) { "offered" } else { "received" } , vout, outp. txid, new_feerate) ;
2659
+ } ,
2641
2660
& InputMaterial :: LocalHTLC { .. } => {
2642
2661
//TODO : Given that Local Commitment Transaction and HTLC-Timeout/HTLC-Success are counter-signed by peer, we can't
2643
2662
// RBF them. Need a Lightning specs change and package relay modification :
@@ -2908,11 +2927,13 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
2908
2927
let key = Readable :: read ( reader) ?;
2909
2928
let preimage = Readable :: read ( reader) ?;
2910
2929
let amount = Readable :: read ( reader) ?;
2930
+ let locktime = Readable :: read ( reader) ?;
2911
2931
InputMaterial :: RemoteHTLC {
2912
2932
script,
2913
2933
key,
2914
2934
preimage,
2915
- amount
2935
+ amount,
2936
+ locktime
2916
2937
}
2917
2938
} ,
2918
2939
2 => {
0 commit comments