@@ -268,6 +268,16 @@ pub(super) enum HTLCFailReason {
268
268
}
269
269
}
270
270
271
+ impl HTLCFailReason {
272
+ pub ( super ) fn reason ( failure_code : u16 , data : Vec < u8 > ) -> Self {
273
+ Self :: Reason { failure_code, data }
274
+ }
275
+
276
+ pub ( super ) fn from_failure_code ( failure_code : u16 ) -> Self {
277
+ Self :: Reason { failure_code, data : Vec :: new ( ) }
278
+ }
279
+ }
280
+
271
281
struct ReceiveError {
272
282
err_code : u16 ,
273
283
err_data : Vec < u8 > ,
@@ -1844,7 +1854,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1844
1854
1845
1855
for htlc_source in failed_htlcs. drain ( ..) {
1846
1856
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1847
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1857
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1848
1858
}
1849
1859
1850
1860
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1902,7 +1912,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1902
1912
for htlc_source in failed_htlcs. drain ( ..) {
1903
1913
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1904
1914
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
1905
- self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1915
+ self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1906
1916
}
1907
1917
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1908
1918
// There isn't anything we can do if we get an update failure - we're already
@@ -3063,7 +3073,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3063
3073
} ;
3064
3074
3065
3075
failed_forwards. push( ( htlc_source, payment_hash,
3066
- HTLCFailReason :: Reason { failure_code : $err_code, data : $err_data } ,
3076
+ HTLCFailReason :: reason ( $err_code, $err_data) ,
3067
3077
reason
3068
3078
) ) ;
3069
3079
continue ;
@@ -3171,7 +3181,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3171
3181
}
3172
3182
let ( failure_code, data) = self . get_htlc_temp_fail_err_and_data ( 0x1000 |7 , short_chan_id, chan. get ( ) ) ;
3173
3183
failed_forwards. push ( ( htlc_source, payment_hash,
3174
- HTLCFailReason :: Reason { failure_code, data } ,
3184
+ HTLCFailReason :: reason ( failure_code, data) ,
3175
3185
HTLCDestination :: NextHopChannel { node_id : Some ( chan. get ( ) . get_counterparty_node_id ( ) ) , channel_id : forward_chan_id }
3176
3186
) ) ;
3177
3187
continue ;
@@ -3318,7 +3328,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3318
3328
incoming_packet_shared_secret: $htlc. prev_hop. incoming_packet_shared_secret,
3319
3329
phantom_shared_secret,
3320
3330
} ) , payment_hash,
3321
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3331
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3322
3332
HTLCDestination :: FailedPayment { payment_hash: $payment_hash } ,
3323
3333
) ) ;
3324
3334
}
@@ -3725,7 +3735,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3725
3735
3726
3736
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3727
3737
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3728
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3738
+ self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver ) ;
3729
3739
}
3730
3740
3731
3741
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3762,7 +3772,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3762
3772
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3763
3773
self . fail_htlc_backwards_internal (
3764
3774
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
3765
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3775
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3766
3776
HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3767
3777
}
3768
3778
}
@@ -3832,7 +3842,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3832
3842
} ;
3833
3843
3834
3844
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3835
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver) ;
3845
+ self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code, onion_failure_data) , receiver) ;
3836
3846
}
3837
3847
}
3838
3848
@@ -4158,7 +4168,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4158
4168
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4159
4169
self . fail_htlc_backwards_internal (
4160
4170
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
4161
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
4171
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
4162
4172
HTLCDestination :: FailedPayment { payment_hash } ) ;
4163
4173
}
4164
4174
}
@@ -4856,7 +4866,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4856
4866
} ;
4857
4867
for htlc_source in dropped_htlcs. drain ( ..) {
4858
4868
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4859
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
4869
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4860
4870
}
4861
4871
4862
4872
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5001,7 +5011,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5001
5011
let chan_err: ChannelError = ChannelError :: Close ( "Got update_fail_malformed_htlc with BADONION not set" . to_owned ( ) ) ;
5002
5012
try_chan_entry ! ( self , Err ( chan_err) , chan) ;
5003
5013
}
5004
- try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: Reason { failure_code : msg. failure_code, data : Vec :: new ( ) } ) , chan) ;
5014
+ try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: from_failure_code ( msg. failure_code) ) , chan) ;
5005
5015
Ok ( ( ) )
5006
5016
} ,
5007
5017
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
@@ -5307,7 +5317,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5307
5317
} else {
5308
5318
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5309
5319
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5310
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5320
+ self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5311
5321
}
5312
5322
} ,
5313
5323
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -5976,9 +5986,8 @@ where
5976
5986
if let Ok ( ( channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs) ) = res {
5977
5987
for ( source, payment_hash) in timed_out_pending_htlcs. drain ( ..) {
5978
5988
let ( failure_code, data) = self . get_htlc_inbound_temp_fail_err_and_data ( 0x1000 |14 /* expiry_too_soon */ , & channel) ;
5979
- timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: Reason {
5980
- failure_code, data,
5981
- } , HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
5989
+ timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: reason ( failure_code, data) ,
5990
+ HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
5982
5991
}
5983
5992
if let Some ( channel_ready) = channel_ready_opt {
5984
5993
send_channel_ready ! ( self , pending_msg_events, channel, channel_ready) ;
@@ -6065,10 +6074,9 @@ where
6065
6074
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
6066
6075
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array ( height) ) ;
6067
6076
6068
- timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) , HTLCFailReason :: Reason {
6069
- failure_code : 0x4000 | 15 ,
6070
- data : htlc_msat_height_data
6071
- } , HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6077
+ timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) ,
6078
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
6079
+ HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6072
6080
false
6073
6081
} else { true }
6074
6082
} ) ;
@@ -7552,7 +7560,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7552
7560
for htlc_source in failed_htlcs. drain ( ..) {
7553
7561
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7554
7562
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7555
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7563
+ channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7556
7564
}
7557
7565
7558
7566
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments