@@ -287,6 +287,16 @@ pub(super) enum HTLCFailReason {
287
287
}
288
288
}
289
289
290
+ impl HTLCFailReason {
291
+ pub ( super ) fn reason ( failure_code : u16 , data : Vec < u8 > ) -> Self {
292
+ Self :: Reason { failure_code, data }
293
+ }
294
+
295
+ pub ( super ) fn from_failure_code ( failure_code : u16 ) -> Self {
296
+ Self :: Reason { failure_code, data : Vec :: new ( ) }
297
+ }
298
+ }
299
+
290
300
struct ReceiveError {
291
301
err_code : u16 ,
292
302
err_data : Vec < u8 > ,
@@ -1877,7 +1887,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1877
1887
1878
1888
for htlc_source in failed_htlcs. drain ( ..) {
1879
1889
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1880
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1890
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1881
1891
}
1882
1892
1883
1893
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1935,7 +1945,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1935
1945
for htlc_source in failed_htlcs. drain ( ..) {
1936
1946
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1937
1947
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
1938
- self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1948
+ self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1939
1949
}
1940
1950
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1941
1951
// There isn't anything we can do if we get an update failure - we're already
@@ -3140,7 +3150,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3140
3150
phantom_shared_secret : None ,
3141
3151
} ) ;
3142
3152
3143
- let failure_reason = HTLCFailReason :: Reason { failure_code : 0x4000 | 10 , data : Vec :: new ( ) } ;
3153
+ let failure_reason = HTLCFailReason :: from_failure_code ( 0x4000 | 10 ) ;
3144
3154
let destination = HTLCDestination :: UnknownNextHop { requested_forward_scid : short_channel_id } ;
3145
3155
self . fail_htlc_backwards_internal ( htlc_source, & payment. forward_info . payment_hash , failure_reason, destination) ;
3146
3156
} else { unreachable ! ( ) } // Only `PendingHTLCRouting::Forward`s are intercepted
@@ -3195,7 +3205,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3195
3205
} ;
3196
3206
3197
3207
failed_forwards. push( ( htlc_source, payment_hash,
3198
- HTLCFailReason :: Reason { failure_code : $err_code, data : $err_data } ,
3208
+ HTLCFailReason :: reason ( $err_code, $err_data) ,
3199
3209
reason
3200
3210
) ) ;
3201
3211
continue ;
@@ -3303,7 +3313,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3303
3313
}
3304
3314
let ( failure_code, data) = self . get_htlc_temp_fail_err_and_data ( 0x1000 |7 , short_chan_id, chan. get ( ) ) ;
3305
3315
failed_forwards. push ( ( htlc_source, payment_hash,
3306
- HTLCFailReason :: Reason { failure_code, data } ,
3316
+ HTLCFailReason :: reason ( failure_code, data) ,
3307
3317
HTLCDestination :: NextHopChannel { node_id : Some ( chan. get ( ) . get_counterparty_node_id ( ) ) , channel_id : forward_chan_id }
3308
3318
) ) ;
3309
3319
continue ;
@@ -3450,7 +3460,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3450
3460
incoming_packet_shared_secret: $htlc. prev_hop. incoming_packet_shared_secret,
3451
3461
phantom_shared_secret,
3452
3462
} ) , payment_hash,
3453
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3463
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3454
3464
HTLCDestination :: FailedPayment { payment_hash: $payment_hash } ,
3455
3465
) ) ;
3456
3466
}
@@ -3863,7 +3873,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3863
3873
3864
3874
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3865
3875
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3866
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3876
+ self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver) ;
3867
3877
}
3868
3878
3869
3879
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3900,7 +3910,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3900
3910
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3901
3911
self . fail_htlc_backwards_internal (
3902
3912
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
3903
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3913
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3904
3914
HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3905
3915
}
3906
3916
}
@@ -3970,7 +3980,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3970
3980
} ;
3971
3981
3972
3982
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3973
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver) ;
3983
+ self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code, onion_failure_data) , receiver) ;
3974
3984
}
3975
3985
}
3976
3986
@@ -4296,7 +4306,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4296
4306
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4297
4307
self . fail_htlc_backwards_internal (
4298
4308
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
4299
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
4309
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
4300
4310
HTLCDestination :: FailedPayment { payment_hash } ) ;
4301
4311
}
4302
4312
}
@@ -4989,7 +4999,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4989
4999
} ;
4990
5000
for htlc_source in dropped_htlcs. drain ( ..) {
4991
5001
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4992
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5002
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4993
5003
}
4994
5004
4995
5005
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5134,7 +5144,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5134
5144
let chan_err: ChannelError = ChannelError :: Close ( "Got update_fail_malformed_htlc with BADONION not set" . to_owned ( ) ) ;
5135
5145
try_chan_entry ! ( self , Err ( chan_err) , chan) ;
5136
5146
}
5137
- try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: Reason { failure_code : msg. failure_code, data : Vec :: new ( ) } ) , chan) ;
5147
+ try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: from_failure_code ( msg. failure_code) ) , chan) ;
5138
5148
Ok ( ( ) )
5139
5149
} ,
5140
5150
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
@@ -5240,7 +5250,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5240
5250
} ) ;
5241
5251
5242
5252
failed_intercept_forwards. push ( ( htlc_source, forward_info. payment_hash ,
5243
- HTLCFailReason :: Reason { failure_code : 0x4000 | 10 , data : Vec :: new ( ) } ,
5253
+ HTLCFailReason :: from_failure_code ( 0x4000 | 10 ) ,
5244
5254
HTLCDestination :: InvalidForward { requested_forward_scid : scid } ,
5245
5255
) ) ;
5246
5256
}
@@ -5495,7 +5505,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5495
5505
} else {
5496
5506
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5497
5507
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5498
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5508
+ self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5499
5509
}
5500
5510
} ,
5501
5511
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -6181,9 +6191,8 @@ where
6181
6191
if let Ok ( ( channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs) ) = res {
6182
6192
for ( source, payment_hash) in timed_out_pending_htlcs. drain ( ..) {
6183
6193
let ( failure_code, data) = self . get_htlc_inbound_temp_fail_err_and_data ( 0x1000 |14 /* expiry_too_soon */ , & channel) ;
6184
- timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: Reason {
6185
- failure_code, data,
6186
- } , HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
6194
+ timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: reason ( failure_code, data) ,
6195
+ HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
6187
6196
}
6188
6197
if let Some ( channel_ready) = channel_ready_opt {
6189
6198
send_channel_ready ! ( self , pending_msg_events, channel, channel_ready) ;
@@ -6269,10 +6278,10 @@ where
6269
6278
if height >= htlc. cltv_expiry - HTLC_FAIL_BACK_BUFFER {
6270
6279
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
6271
6280
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array ( height) ) ;
6272
- timed_out_htlcs . push ( ( HTLCSource :: PreviousHopData ( htlc . prev_hop . clone ( ) ) , payment_hash . clone ( ) , HTLCFailReason :: Reason {
6273
- failure_code : 0x4000 | 15 ,
6274
- data : htlc_msat_height_data
6275
- } , HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6281
+
6282
+ timed_out_htlcs . push ( ( HTLCSource :: PreviousHopData ( htlc . prev_hop . clone ( ) ) , payment_hash . clone ( ) ,
6283
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
6284
+ HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6276
6285
false
6277
6286
} else { true }
6278
6287
} ) ;
@@ -6295,7 +6304,7 @@ where
6295
6304
_ => unreachable ! ( ) ,
6296
6305
} ;
6297
6306
timed_out_htlcs. push ( ( prev_hop_data, htlc. forward_info . payment_hash ,
6298
- HTLCFailReason :: Reason { failure_code : 0x2000 | 2 , data : Vec :: new ( ) } ,
6307
+ HTLCFailReason :: from_failure_code ( 0x2000 | 2 ) ,
6299
6308
HTLCDestination :: InvalidForward { requested_forward_scid } ) ) ;
6300
6309
log_trace ! ( self . logger, "Timing out intercepted HTLC with requested forward scid {}" , requested_forward_scid) ;
6301
6310
false
@@ -7793,7 +7802,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7793
7802
for htlc_source in failed_htlcs. drain ( ..) {
7794
7803
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7795
7804
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7796
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7805
+ channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7797
7806
}
7798
7807
7799
7808
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments