@@ -939,6 +939,29 @@ impl ChannelMonitor {
939
939
}
940
940
}
941
941
942
+ macro_rules! sign_input_timeout {
943
+ ( $sighash_parts: expr, $input: expr, $amount: expr) => {
944
+ {
945
+ let ( sig, redeemscript) = match self . key_storage {
946
+ KeyStorage :: PrivMode { ref htlc_base_key, .. } => {
947
+ let htlc = & per_commitment_option. unwrap( ) [ $input. sequence as usize ] ;
948
+ let redeemscript = chan_utils:: get_htlc_redeemscript_with_explicit_keys( htlc, & a_htlc_key, & b_htlc_key, & revocation_pubkey) ;
949
+ let sighash = ignore_error!( Message :: from_slice( & $sighash_parts. sighash_all( & $input, & redeemscript, $amount) [ ..] ) ) ;
950
+ let htlc_key = ignore_error!( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & htlc_base_key) ) ;
951
+ ( self . secp_ctx. sign( & sighash, & htlc_key) , redeemscript)
952
+ } ,
953
+ KeyStorage :: SigsMode { .. } => {
954
+ unimplemented!( ) ;
955
+ }
956
+ } ;
957
+ $input. witness. push( sig. serialize_der( & self . secp_ctx) . to_vec( ) ) ;
958
+ $input. witness[ 0 ] . push( SigHashType :: All as u8 ) ;
959
+ $input. witness. push( vec![ 0 ] ) ;
960
+ $input. witness. push( redeemscript. into_bytes( ) ) ;
961
+ }
962
+ }
963
+ }
964
+
942
965
for ( idx, htlc) in per_commitment_data. iter ( ) . enumerate ( ) {
943
966
if let Some ( payment_preimage) = self . payment_preimages . get ( & htlc. payment_hash ) {
944
967
let input = TxIn {
@@ -969,6 +992,29 @@ impl ChannelMonitor {
969
992
txn_to_broadcast. push ( single_htlc_tx) ;
970
993
}
971
994
}
995
+ if !htlc. offered {
996
+ let input = TxIn {
997
+ previous_output : BitcoinOutPoint {
998
+ txid : commitment_txid,
999
+ vout : htlc. transaction_output_index ,
1000
+ } ,
1001
+ script_sig : Script :: new ( ) ,
1002
+ sequence : idx as u32 ,
1003
+ witness : Vec :: new ( ) ,
1004
+ } ;
1005
+ let mut timeout_tx = Transaction {
1006
+ version : 2 ,
1007
+ lock_time : htlc. cltv_expiry ,
1008
+ input : vec ! [ input] ,
1009
+ output : vec ! ( TxOut {
1010
+ script_pubkey: self . destination_script. clone( ) ,
1011
+ value: htlc. amount_msat / 1000 ,
1012
+ } ) ,
1013
+ } ;
1014
+ let sighash_parts = bip143:: SighashComponents :: new ( & timeout_tx) ;
1015
+ sign_input_timeout ! ( sighash_parts, timeout_tx. input[ 0 ] , htlc. amount_msat / 1000 ) ;
1016
+ txn_to_broadcast. push ( timeout_tx) ;
1017
+ }
972
1018
}
973
1019
974
1020
if inputs. is_empty ( ) { return ( txn_to_broadcast, ( commitment_txid, watch_outputs) ) ; } // Nothing to be done...probably a false positive/local tx
0 commit comments