@@ -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 ,
@@ -1182,12 +1183,13 @@ impl ChannelMonitor {
1182
1183
}
1183
1184
writer. write_all ( & byte_utils:: be64_to_array ( * amount) ) ?;
1184
1185
} ,
1185
- & InputMaterial :: RemoteHTLC { ref script, ref key, ref preimage, ref amount } => {
1186
+ & InputMaterial :: RemoteHTLC { ref script, ref key, ref preimage, ref amount, ref locktime } => {
1186
1187
writer. write_all ( & [ 1 ; 1 ] ) ?;
1187
1188
script. write ( writer) ?;
1188
1189
key. write ( writer) ?;
1189
1190
preimage. write ( writer) ?;
1190
1191
writer. write_all ( & byte_utils:: be64_to_array ( * amount) ) ?;
1192
+ writer. write_all ( & byte_utils:: be32_to_array ( * locktime) ) ?;
1191
1193
} ,
1192
1194
& InputMaterial :: LocalHTLC { ref script, ref sigs, ref preimage, ref amount } => {
1193
1195
writer. write_all ( & [ 2 ; 1 ] ) ?;
@@ -1722,7 +1724,7 @@ impl ChannelMonitor {
1722
1724
} ) ;
1723
1725
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) ;
1724
1726
let mut per_input_material = HashMap :: with_capacity ( 1 ) ;
1725
- per_input_material. insert ( single_htlc_tx. input [ 0 ] . previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * payment_preimage) , amount : htlc. amount_msat / 1000 } ) ;
1727
+ per_input_material. insert ( single_htlc_tx. input [ 0 ] . previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * payment_preimage) , amount : htlc. amount_msat / 1000 , locktime : 0 } ) ;
1726
1728
match self . pending_claim_requests . entry ( single_htlc_tx. txid ( ) ) {
1727
1729
hash_map:: Entry :: Occupied ( _) => { } ,
1728
1730
hash_map:: Entry :: Vacant ( entry) => { entry. insert ( ClaimTxBumpMaterial { height_timer, feerate_previous : used_feerate, soonest_timelock : htlc. cltv_expiry , per_input_material} ) ; }
@@ -1763,7 +1765,7 @@ impl ChannelMonitor {
1763
1765
//TODO: track SpendableOutputDescriptor
1764
1766
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) ;
1765
1767
let mut per_input_material = HashMap :: with_capacity ( 1 ) ;
1766
- per_input_material. insert ( timeout_tx. input [ 0 ] . previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : None , amount : htlc. amount_msat / 1000 } ) ;
1768
+ per_input_material. insert ( timeout_tx. input [ 0 ] . previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : None , amount : htlc. amount_msat / 1000 , locktime : htlc . cltv_expiry } ) ;
1767
1769
match self . pending_claim_requests . entry ( timeout_tx. txid ( ) ) {
1768
1770
hash_map:: Entry :: Occupied ( _) => { } ,
1769
1771
hash_map:: Entry :: Vacant ( entry) => { entry. insert ( ClaimTxBumpMaterial { height_timer, feerate_previous : used_feerate, soonest_timelock : htlc. cltv_expiry , per_input_material } ) ; }
@@ -1807,7 +1809,7 @@ impl ChannelMonitor {
1807
1809
for ( input, info) in spend_tx. input . iter_mut ( ) . zip ( inputs_info. iter ( ) ) {
1808
1810
let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, input, info. 1 , ( info. 0 ) . 0 . to_vec( ) ) ;
1809
1811
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) ;
1810
- per_input_material. insert ( input. previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * ( info. 0 ) ) , amount : info. 1 } ) ;
1812
+ per_input_material. insert ( input. previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * ( info. 0 ) ) , amount : info. 1 , locktime : 0 } ) ;
1811
1813
}
1812
1814
match self . pending_claim_requests . entry ( spend_tx. txid ( ) ) {
1813
1815
hash_map:: Entry :: Occupied ( _) => { } ,
@@ -2626,7 +2628,10 @@ impl ChannelMonitor {
2626
2628
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 { & [ ] } ) ;
2627
2629
amt += * amount;
2628
2630
} ,
2629
- & InputMaterial :: RemoteHTLC { .. } => { } ,
2631
+ & InputMaterial :: RemoteHTLC { ref preimage, ref amount, .. } => {
2632
+ inputs_witnesses_weight += Self :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
2633
+ amt += * amount;
2634
+ } ,
2630
2635
& InputMaterial :: LocalHTLC { .. } => { return None ; }
2631
2636
}
2632
2637
}
@@ -2662,7 +2667,21 @@ impl ChannelMonitor {
2662
2667
bumped_tx. input [ i] . witness . push ( script. clone ( ) . into_bytes ( ) ) ;
2663
2668
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 { "" } , outp. vout, outp. txid, new_feerate) ;
2664
2669
} ,
2665
- & InputMaterial :: RemoteHTLC { .. } => { } ,
2670
+ & InputMaterial :: RemoteHTLC { ref script, ref key, ref preimage, ref amount, ref locktime } => {
2671
+ if !preimage. is_some ( ) { bumped_tx. lock_time = * locktime } ;
2672
+ let sighash_parts = bip143:: SighashComponents :: new ( & bumped_tx) ;
2673
+ let sighash = hash_to_message ! ( & sighash_parts. sighash_all( & bumped_tx. input[ i] , & script, * amount) [ ..] ) ;
2674
+ let sig = self . secp_ctx . sign ( & sighash, & key) ;
2675
+ bumped_tx. input [ i] . witness . push ( sig. serialize_der ( ) . to_vec ( ) ) ;
2676
+ bumped_tx. input [ i] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
2677
+ if let & Some ( preimage) = preimage {
2678
+ bumped_tx. input [ i] . witness . push ( preimage. clone ( ) . 0 . to_vec ( ) ) ;
2679
+ } else {
2680
+ bumped_tx. input [ i] . witness . push ( vec ! [ 0 ] ) ;
2681
+ }
2682
+ bumped_tx. input [ i] . witness . push ( script. clone ( ) . into_bytes ( ) ) ;
2683
+ 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" } , outp. vout, outp. txid, new_feerate) ;
2684
+ } ,
2666
2685
& InputMaterial :: LocalHTLC { .. } => {
2667
2686
//TODO : Given that Local Commitment Transaction and HTLC-Timeout/HTLC-Success are counter-signed by peer, we can't
2668
2687
// RBF them. Need a Lightning specs change and package relay modification :
@@ -2932,11 +2951,13 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
2932
2951
let key = Readable :: read ( reader) ?;
2933
2952
let preimage = Readable :: read ( reader) ?;
2934
2953
let amount = Readable :: read ( reader) ?;
2954
+ let locktime = Readable :: read ( reader) ?;
2935
2955
InputMaterial :: RemoteHTLC {
2936
2956
script,
2937
2957
key,
2938
2958
preimage,
2939
- amount
2959
+ amount,
2960
+ locktime
2940
2961
}
2941
2962
} ,
2942
2963
2 => {
0 commit comments