@@ -269,6 +269,16 @@ pub(super) enum HTLCFailReason {
269
269
}
270
270
}
271
271
272
+ impl HTLCFailReason {
273
+ pub ( super ) fn reason ( failure_code : u16 , data : Vec < u8 > ) -> Self {
274
+ Self :: Reason { failure_code, data }
275
+ }
276
+
277
+ pub ( super ) fn from_failure_code ( failure_code : u16 ) -> Self {
278
+ Self :: Reason { failure_code, data : Vec :: new ( ) }
279
+ }
280
+ }
281
+
272
282
struct ReceiveError {
273
283
err_code : u16 ,
274
284
err_data : Vec < u8 > ,
@@ -1851,7 +1861,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1851
1861
1852
1862
for htlc_source in failed_htlcs. drain ( ..) {
1853
1863
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1854
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1864
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1855
1865
}
1856
1866
1857
1867
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1909,7 +1919,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1909
1919
for htlc_source in failed_htlcs. drain ( ..) {
1910
1920
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1911
1921
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
1912
- self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1922
+ self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1913
1923
}
1914
1924
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1915
1925
// There isn't anything we can do if we get an update failure - we're already
@@ -3070,7 +3080,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3070
3080
} ;
3071
3081
3072
3082
failed_forwards. push( ( htlc_source, payment_hash,
3073
- HTLCFailReason :: Reason { failure_code : $err_code, data : $err_data } ,
3083
+ HTLCFailReason :: reason ( $err_code, $err_data) ,
3074
3084
reason
3075
3085
) ) ;
3076
3086
continue ;
@@ -3178,7 +3188,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3178
3188
}
3179
3189
let ( failure_code, data) = self . get_htlc_temp_fail_err_and_data ( 0x1000 |7 , short_chan_id, chan. get ( ) ) ;
3180
3190
failed_forwards. push ( ( htlc_source, payment_hash,
3181
- HTLCFailReason :: Reason { failure_code, data } ,
3191
+ HTLCFailReason :: reason ( failure_code, data) ,
3182
3192
HTLCDestination :: NextHopChannel { node_id : Some ( chan. get ( ) . get_counterparty_node_id ( ) ) , channel_id : forward_chan_id }
3183
3193
) ) ;
3184
3194
continue ;
@@ -3325,7 +3335,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3325
3335
incoming_packet_shared_secret: $htlc. prev_hop. incoming_packet_shared_secret,
3326
3336
phantom_shared_secret,
3327
3337
} ) , payment_hash,
3328
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3338
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3329
3339
HTLCDestination :: FailedPayment { payment_hash: $payment_hash } ,
3330
3340
) ) ;
3331
3341
}
@@ -3738,7 +3748,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3738
3748
3739
3749
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3740
3750
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3741
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3751
+ self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver ) ;
3742
3752
}
3743
3753
3744
3754
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3775,7 +3785,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3775
3785
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3776
3786
self . fail_htlc_backwards_internal (
3777
3787
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
3778
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3788
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
3779
3789
HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3780
3790
}
3781
3791
}
@@ -3845,7 +3855,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3845
3855
} ;
3846
3856
3847
3857
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3848
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver) ;
3858
+ self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code, onion_failure_data) , receiver) ;
3849
3859
}
3850
3860
}
3851
3861
@@ -4171,7 +4181,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4171
4181
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4172
4182
self . fail_htlc_backwards_internal (
4173
4183
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
4174
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
4184
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
4175
4185
HTLCDestination :: FailedPayment { payment_hash } ) ;
4176
4186
}
4177
4187
}
@@ -4864,7 +4874,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4864
4874
} ;
4865
4875
for htlc_source in dropped_htlcs. drain ( ..) {
4866
4876
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4867
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
4877
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4868
4878
}
4869
4879
4870
4880
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5009,7 +5019,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5009
5019
let chan_err: ChannelError = ChannelError :: Close ( "Got update_fail_malformed_htlc with BADONION not set" . to_owned ( ) ) ;
5010
5020
try_chan_entry ! ( self , Err ( chan_err) , chan) ;
5011
5021
}
5012
- try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: Reason { failure_code : msg. failure_code, data : Vec :: new ( ) } ) , chan) ;
5022
+ try_chan_entry ! ( self , chan. get_mut( ) . update_fail_malformed_htlc( & msg, HTLCFailReason :: from_failure_code ( msg. failure_code) ) , chan) ;
5013
5023
Ok ( ( ) )
5014
5024
} ,
5015
5025
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
@@ -5316,7 +5326,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5316
5326
} else {
5317
5327
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5318
5328
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5319
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5329
+ self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5320
5330
}
5321
5331
} ,
5322
5332
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -5985,9 +5995,8 @@ where
5985
5995
if let Ok ( ( channel_ready_opt, mut timed_out_pending_htlcs, announcement_sigs) ) = res {
5986
5996
for ( source, payment_hash) in timed_out_pending_htlcs. drain ( ..) {
5987
5997
let ( failure_code, data) = self . get_htlc_inbound_temp_fail_err_and_data ( 0x1000 |14 /* expiry_too_soon */ , & channel) ;
5988
- timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: Reason {
5989
- failure_code, data,
5990
- } , HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
5998
+ timed_out_htlcs. push ( ( source, payment_hash, HTLCFailReason :: reason ( failure_code, data) ,
5999
+ HTLCDestination :: NextHopChannel { node_id : Some ( channel. get_counterparty_node_id ( ) ) , channel_id : channel. channel_id ( ) } ) ) ;
5991
6000
}
5992
6001
if let Some ( channel_ready) = channel_ready_opt {
5993
6002
send_channel_ready ! ( self , pending_msg_events, channel, channel_ready) ;
@@ -6074,10 +6083,9 @@ where
6074
6083
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
6075
6084
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array ( height) ) ;
6076
6085
6077
- timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) , HTLCFailReason :: Reason {
6078
- failure_code : 0x4000 | 15 ,
6079
- data : htlc_msat_height_data
6080
- } , HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6086
+ timed_out_htlcs. push ( ( HTLCSource :: PreviousHopData ( htlc. prev_hop . clone ( ) ) , payment_hash. clone ( ) ,
6087
+ HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data) ,
6088
+ HTLCDestination :: FailedPayment { payment_hash : payment_hash. clone ( ) } ) ) ;
6081
6089
false
6082
6090
} else { true }
6083
6091
} ) ;
@@ -7565,7 +7573,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7565
7573
for htlc_source in failed_htlcs. drain ( ..) {
7566
7574
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7567
7575
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7568
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7576
+ channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7569
7577
}
7570
7578
7571
7579
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments