@@ -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
}
@@ -3717,7 +3727,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3717
3727
3718
3728
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3719
3729
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3720
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3730
+ self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver ) ;
3721
3731
}
3722
3732
3723
3733
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3754,7 +3764,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3754
3764
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3755
3765
self . fail_htlc_backwards_internal (
3756
3766
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
3757
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3767
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3758
3768
HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3759
3769
}
3760
3770
}
@@ -3824,7 +3834,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3824
3834
} ;
3825
3835
3826
3836
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3827
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver) ;
3837
+ self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code, onion_failure_data) , receiver) ;
3828
3838
}
3829
3839
}
3830
3840
@@ -4143,7 +4153,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4143
4153
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4144
4154
self . fail_htlc_backwards_internal (
4145
4155
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
4146
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
4156
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
4147
4157
HTLCDestination :: FailedPayment { payment_hash } ) ;
4148
4158
}
4149
4159
}
@@ -4840,7 +4850,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4840
4850
} ;
4841
4851
for htlc_source in dropped_htlcs. drain ( ..) {
4842
4852
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4843
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
4853
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4844
4854
}
4845
4855
4846
4856
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -4985,7 +4995,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4985
4995
let chan_err: ChannelError = ChannelError :: Close ( "Got update_fail_malformed_htlc with BADONION not set" . to_owned ( ) ) ;
4986
4996
try_chan_entry ! ( self , Err ( chan_err) , chan) ;
4987
4997
}
4988
- try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: Reason { failure_code : msg. failure_code, data : Vec :: new ( ) } ) , chan) ;
4998
+ try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: from_failure_code ( msg. failure_code) ) , chan) ;
4989
4999
Ok ( ( ) )
4990
5000
} ,
4991
5001
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
@@ -5291,7 +5301,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5291
5301
} else {
5292
5302
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5293
5303
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5294
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5304
+ self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5295
5305
}
5296
5306
} ,
5297
5307
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -5960,9 +5970,8 @@ where
5960
5970
if let Ok ( ( channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs) ) = res {
5961
5971
for ( source, payment_hash) in timed_out_pending_htlcs. drain ( ..) {
5962
5972
let ( failure_code, data) = self . get_htlc_inbound_temp_fail_err_and_data ( 0x1000 |14 /* expiry_too_soon */ , & channel) ;
5963
- timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: Reason {
5964
- failure_code, data,
5965
- } , HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
5973
+ timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: reason ( failure_code, data) ,
5974
+ HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
5966
5975
}
5967
5976
if let Some ( channel_ready) = channel_ready_opt {
5968
5977
send_channel_ready ! ( self , pending_msg_events, channel, channel_ready) ;
@@ -6049,10 +6058,9 @@ where
6049
6058
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
6050
6059
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array ( height) ) ;
6051
6060
6052
- timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) , HTLCFailReason :: Reason {
6053
- failure_code : 0x4000 | 15 ,
6054
- data : htlc_msat_height_data
6055
- } , HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6061
+ timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) ,
6062
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
6063
+ HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6056
6064
false
6057
6065
} else { true }
6058
6066
} ) ;
@@ -7528,7 +7536,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7528
7536
for htlc_source in failed_htlcs. drain ( ..) {
7529
7537
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7530
7538
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7531
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7539
+ channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7532
7540
}
7533
7541
7534
7542
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments