@@ -1860,8 +1860,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1860
1860
} ;
1861
1861
1862
1862
for htlc_source in failed_htlcs. drain ( ..) {
1863
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
1863
1864
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1864
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1865
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason , receiver) ;
1865
1866
}
1866
1867
1867
1868
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1918,8 +1919,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1918
1919
log_debug ! ( self . logger, "Finishing force-closure of channel with {} HTLCs to fail" , failed_htlcs. len( ) ) ;
1919
1920
for htlc_source in failed_htlcs. drain ( ..) {
1920
1921
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1922
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
1921
1923
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
1922
- self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1924
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason , receiver) ;
1923
1925
}
1924
1926
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1925
1927
// There isn't anything we can do if we get an update failure - we're already
@@ -3484,7 +3486,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3484
3486
}
3485
3487
3486
3488
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3487
- self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
3489
+ self . fail_htlc_backwards_internal ( & htlc_source, & payment_hash, & failure_reason, destination) ;
3488
3490
}
3489
3491
self . forward_htlcs ( & mut phantom_receives) ;
3490
3492
@@ -3747,8 +3749,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3747
3749
} ) ;
3748
3750
3749
3751
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3752
+ let source = HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) ;
3753
+ let reason = HTLCFailReason :: from_failure_code ( 23 ) ;
3750
3754
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3751
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source . 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver ) ;
3755
+ self . fail_htlc_backwards_internal ( & source , & htlc_source. 1 , & reason , receiver) ;
3752
3756
}
3753
3757
3754
3758
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3783,10 +3787,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3783
3787
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3784
3788
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
3785
3789
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3786
- self . fail_htlc_backwards_internal (
3787
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , payment_hash ,
3788
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
3789
- HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3790
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
3791
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
3792
+ let receiver = HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ;
3793
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
3790
3794
}
3791
3795
}
3792
3796
}
@@ -3854,14 +3858,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3854
3858
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3855
3859
} ;
3856
3860
3861
+ let reason = HTLCFailReason :: reason ( failure_code, onion_failure_data) ;
3857
3862
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3858
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code , onion_failure_data ) , receiver) ;
3863
+ self . fail_htlc_backwards_internal ( & htlc_src, & payment_hash, & reason, receiver) ;
3859
3864
}
3860
3865
}
3861
3866
3862
3867
/// Fails an HTLC backwards to the sender of it to us.
3863
3868
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
3864
- fn fail_htlc_backwards_internal ( & self , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3869
+ fn fail_htlc_backwards_internal ( & self , source : & HTLCSource , payment_hash : & PaymentHash , onion_error : & HTLCFailReason , destination : HTLCDestination ) {
3865
3870
#[ cfg( debug_assertions) ]
3866
3871
{
3867
3872
// Ensure that the `channel_state` lock is not held when calling this function.
@@ -3880,13 +3885,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3880
3885
// from block_connected which may run during initialization prior to the chain_monitor
3881
3886
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
3882
3887
match source {
3883
- HTLCSource :: OutboundRoute { ref path, session_priv, payment_id, ref payment_params, .. } => {
3888
+ HTLCSource :: OutboundRoute { ref path, ref session_priv, ref payment_id, ref payment_params, .. } => {
3884
3889
let mut session_priv_bytes = [ 0 ; 32 ] ;
3885
3890
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3886
3891
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
3887
3892
let mut all_paths_failed = false ;
3888
3893
let mut full_failure_ev = None ;
3889
- if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
3894
+ if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
3890
3895
if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
3891
3896
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3892
3897
return ;
@@ -3899,7 +3904,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3899
3904
all_paths_failed = true ;
3900
3905
if payment. get ( ) . abandoned ( ) {
3901
3906
full_failure_ev = Some ( events:: Event :: PaymentFailed {
3902
- payment_id,
3907
+ payment_id : * payment_id ,
3903
3908
payment_hash : payment. get ( ) . payment_hash ( ) . expect ( "PendingOutboundPayments::RetriesExceeded always has a payment hash set" ) ,
3904
3909
} ) ;
3905
3910
payment. remove ( ) ;
@@ -3929,13 +3934,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3929
3934
if self . payment_is_probe ( payment_hash, & payment_id) {
3930
3935
if !payment_retryable {
3931
3936
events:: Event :: ProbeSuccessful {
3932
- payment_id,
3937
+ payment_id : * payment_id ,
3933
3938
payment_hash : payment_hash. clone ( ) ,
3934
3939
path : path. clone ( ) ,
3935
3940
}
3936
3941
} else {
3937
3942
events:: Event :: ProbeFailed {
3938
- payment_id,
3943
+ payment_id : * payment_id ,
3939
3944
payment_hash : payment_hash. clone ( ) ,
3940
3945
path : path. clone ( ) ,
3941
3946
short_channel_id,
@@ -3949,7 +3954,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3949
3954
retry. as_mut ( ) . map ( |r| r. payment_params . previously_failed_channels . push ( scid) ) ;
3950
3955
}
3951
3956
events:: Event :: PaymentPathFailed {
3952
- payment_id : Some ( payment_id) ,
3957
+ payment_id : Some ( * payment_id) ,
3953
3958
payment_hash : payment_hash. clone ( ) ,
3954
3959
payment_failed_permanently : !payment_retryable,
3955
3960
network_update,
@@ -3982,14 +3987,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3982
3987
3983
3988
if self . payment_is_probe ( payment_hash, & payment_id) {
3984
3989
events:: Event :: ProbeFailed {
3985
- payment_id,
3990
+ payment_id : * payment_id ,
3986
3991
payment_hash : payment_hash. clone ( ) ,
3987
3992
path : path. clone ( ) ,
3988
3993
short_channel_id : Some ( scid) ,
3989
3994
}
3990
3995
} else {
3991
3996
events:: Event :: PaymentPathFailed {
3992
- payment_id : Some ( payment_id) ,
3997
+ payment_id : Some ( * payment_id) ,
3993
3998
payment_hash : payment_hash. clone ( ) ,
3994
3999
payment_failed_permanently : false ,
3995
4000
network_update : None ,
@@ -4009,22 +4014,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4009
4014
pending_events. push ( path_failure) ;
4010
4015
if let Some ( ev) = full_failure_ev { pending_events. push ( ev) ; }
4011
4016
} ,
4012
- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret, phantom_shared_secret, outpoint } ) => {
4017
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint } ) => {
4013
4018
let err_packet = match onion_error {
4014
- HTLCFailReason :: Reason { failure_code, data } => {
4019
+ HTLCFailReason :: Reason { ref failure_code, ref data } => {
4015
4020
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with code {}" , log_bytes!( payment_hash. 0 ) , failure_code) ;
4016
4021
if let Some ( phantom_ss) = phantom_shared_secret {
4017
- let phantom_packet = onion_utils:: build_failure_packet ( & phantom_ss, failure_code, & data[ ..] ) . encode ( ) ;
4018
- let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( & phantom_ss, & phantom_packet) ;
4019
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4022
+ let phantom_packet = onion_utils:: build_failure_packet ( phantom_ss, * failure_code, & data[ ..] ) . encode ( ) ;
4023
+ let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( phantom_ss, & phantom_packet) ;
4024
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4020
4025
} else {
4021
- let packet = onion_utils:: build_failure_packet ( & incoming_packet_shared_secret, failure_code, & data[ ..] ) . encode ( ) ;
4022
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & packet)
4026
+ let packet = onion_utils:: build_failure_packet ( incoming_packet_shared_secret, * failure_code, & data[ ..] ) . encode ( ) ;
4027
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & packet)
4023
4028
}
4024
4029
} ,
4025
4030
HTLCFailReason :: LightningError { err } => {
4026
4031
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards with pre-built LightningError" , log_bytes!( payment_hash. 0 ) ) ;
4027
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & err. data )
4032
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & err. data )
4028
4033
}
4029
4034
} ;
4030
4035
@@ -4033,12 +4038,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4033
4038
if forward_htlcs. is_empty ( ) {
4034
4039
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4035
4040
}
4036
- match forward_htlcs. entry ( short_channel_id) {
4041
+ match forward_htlcs. entry ( * short_channel_id) {
4037
4042
hash_map:: Entry :: Occupied ( mut entry) => {
4038
- entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ;
4043
+ entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id : * htlc_id , err_packet } ) ;
4039
4044
} ,
4040
4045
hash_map:: Entry :: Vacant ( entry) => {
4041
- entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ) ;
4046
+ entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id: * htlc_id , err_packet } ) ) ;
4042
4047
}
4043
4048
}
4044
4049
mem:: drop ( forward_htlcs) ;
@@ -4050,7 +4055,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4050
4055
}
4051
4056
pending_events. push ( events:: Event :: HTLCHandlingFailed {
4052
4057
prev_channel_id : outpoint. to_channel_id ( ) ,
4053
- failed_next_destination : destination
4058
+ failed_next_destination : destination,
4054
4059
} ) ;
4055
4060
} ,
4056
4061
}
@@ -4179,10 +4184,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4179
4184
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
4180
4185
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
4181
4186
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4182
- self . fail_htlc_backwards_internal (
4183
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , & payment_hash ,
4184
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
4185
- HTLCDestination :: FailedPayment { payment_hash } ) ;
4187
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
4188
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
4189
+ let receiver = HTLCDestination :: FailedPayment { payment_hash } ;
4190
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
4186
4191
}
4187
4192
}
4188
4193
@@ -4506,7 +4511,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4506
4511
self . finalize_claims ( finalized_claims) ;
4507
4512
for failure in pending_failures. drain ( ..) {
4508
4513
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
4509
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4514
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
4510
4515
}
4511
4516
}
4512
4517
@@ -4874,7 +4879,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4874
4879
} ;
4875
4880
for htlc_source in dropped_htlcs. drain ( ..) {
4876
4881
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4877
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4882
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
4883
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason, receiver) ;
4878
4884
}
4879
4885
4880
4886
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5166,7 +5172,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5166
5172
{
5167
5173
for failure in pending_failures. drain ( ..) {
5168
5174
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5169
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5175
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
5170
5176
}
5171
5177
self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, user_channel_id, pending_forwards) ] ) ;
5172
5178
self . finalize_claims ( finalized_claim_htlcs) ;
@@ -5326,7 +5332,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5326
5332
} else {
5327
5333
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5328
5334
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5329
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5335
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
5336
+ self . fail_htlc_backwards_internal ( & htlc_update. source , & htlc_update. payment_hash , & reason, receiver) ;
5330
5337
}
5331
5338
} ,
5332
5339
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -6096,7 +6103,7 @@ where
6096
6103
self . handle_init_event_channel_failures ( failed_channels) ;
6097
6104
6098
6105
for ( source, payment_hash, reason, destination) in timed_out_htlcs. drain ( ..) {
6099
- self . fail_htlc_backwards_internal ( source, & payment_hash, reason, destination) ;
6106
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason, destination) ;
6100
6107
}
6101
6108
}
6102
6109
@@ -7573,7 +7580,8 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7573
7580
for htlc_source in failed_htlcs. drain ( ..) {
7574
7581
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7575
7582
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7576
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7583
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
7584
+ channel_manager. fail_htlc_backwards_internal ( & source, & payment_hash, & reason, receiver) ;
7577
7585
}
7578
7586
7579
7587
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments