@@ -1853,8 +1853,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1853
1853
} ;
1854
1854
1855
1855
for htlc_source in failed_htlcs. drain ( ..) {
1856
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
1856
1857
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1857
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1858
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason , receiver) ;
1858
1859
}
1859
1860
1860
1861
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1911,8 +1912,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1911
1912
log_debug ! ( self . logger, "Finishing force-closure of channel with {} HTLCs to fail" , failed_htlcs. len( ) ) ;
1912
1913
for htlc_source in failed_htlcs. drain ( ..) {
1913
1914
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1915
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
1914
1916
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
1915
- self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1917
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason , receiver) ;
1916
1918
}
1917
1919
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1918
1920
// There isn't anything we can do if we get an update failure - we're already
@@ -3471,7 +3473,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3471
3473
}
3472
3474
3473
3475
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3474
- self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
3476
+ self . fail_htlc_backwards_internal ( & htlc_source, & payment_hash, & failure_reason, destination) ;
3475
3477
}
3476
3478
self . forward_htlcs ( & mut phantom_receives) ;
3477
3479
@@ -3734,8 +3736,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3734
3736
} ) ;
3735
3737
3736
3738
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3739
+ let source = HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) ;
3740
+ let reason = HTLCFailReason :: from_failure_code ( 23 ) ;
3737
3741
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3738
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source . 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver ) ;
3742
+ self . fail_htlc_backwards_internal ( & source , & htlc_source. 1 , & reason , receiver) ;
3739
3743
}
3740
3744
3741
3745
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3770,10 +3774,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3770
3774
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3771
3775
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
3772
3776
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3773
- self . fail_htlc_backwards_internal (
3774
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , payment_hash ,
3775
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
3776
- HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3777
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
3778
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
3779
+ let receiver = HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ;
3780
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
3777
3781
}
3778
3782
}
3779
3783
}
@@ -3841,14 +3845,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3841
3845
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3842
3846
} ;
3843
3847
3848
+ let reason = HTLCFailReason :: reason ( failure_code, onion_failure_data) ;
3844
3849
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3845
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code , onion_failure_data ) , receiver) ;
3850
+ self . fail_htlc_backwards_internal ( & htlc_src, & payment_hash, & reason, receiver) ;
3846
3851
}
3847
3852
}
3848
3853
3849
3854
/// Fails an HTLC backwards to the sender of it to us.
3850
3855
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
3851
- fn fail_htlc_backwards_internal ( & self , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3856
+ fn fail_htlc_backwards_internal ( & self , source : & HTLCSource , payment_hash : & PaymentHash , onion_error : & HTLCFailReason , destination : HTLCDestination ) {
3852
3857
#[ cfg( debug_assertions) ]
3853
3858
{
3854
3859
// Ensure that the `channel_state` lock is not held when calling this function.
@@ -3867,13 +3872,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3867
3872
// from block_connected which may run during initialization prior to the chain_monitor
3868
3873
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
3869
3874
match source {
3870
- HTLCSource :: OutboundRoute { ref path, session_priv, payment_id, ref payment_params, .. } => {
3875
+ HTLCSource :: OutboundRoute { ref path, ref session_priv, ref payment_id, ref payment_params, .. } => {
3871
3876
let mut session_priv_bytes = [ 0 ; 32 ] ;
3872
3877
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3873
3878
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
3874
3879
let mut all_paths_failed = false ;
3875
3880
let mut full_failure_ev = None ;
3876
- if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
3881
+ if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
3877
3882
if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
3878
3883
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3879
3884
return ;
@@ -3886,7 +3891,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3886
3891
all_paths_failed = true ;
3887
3892
if payment. get ( ) . abandoned ( ) {
3888
3893
full_failure_ev = Some ( events:: Event :: PaymentFailed {
3889
- payment_id,
3894
+ payment_id : * payment_id ,
3890
3895
payment_hash : payment. get ( ) . payment_hash ( ) . expect ( "PendingOutboundPayments::RetriesExceeded always has a payment hash set" ) ,
3891
3896
} ) ;
3892
3897
payment. remove ( ) ;
@@ -3916,13 +3921,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3916
3921
if self . payment_is_probe ( payment_hash, & payment_id) {
3917
3922
if !payment_retryable {
3918
3923
events:: Event :: ProbeSuccessful {
3919
- payment_id,
3924
+ payment_id : * payment_id ,
3920
3925
payment_hash : payment_hash. clone ( ) ,
3921
3926
path : path. clone ( ) ,
3922
3927
}
3923
3928
} else {
3924
3929
events:: Event :: ProbeFailed {
3925
- payment_id,
3930
+ payment_id : * payment_id ,
3926
3931
payment_hash : payment_hash. clone ( ) ,
3927
3932
path : path. clone ( ) ,
3928
3933
short_channel_id,
@@ -3936,7 +3941,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3936
3941
retry. as_mut ( ) . map ( |r| r. payment_params . previously_failed_channels . push ( scid) ) ;
3937
3942
}
3938
3943
events:: Event :: PaymentPathFailed {
3939
- payment_id : Some ( payment_id) ,
3944
+ payment_id : Some ( * payment_id) ,
3940
3945
payment_hash : payment_hash. clone ( ) ,
3941
3946
payment_failed_permanently : !payment_retryable,
3942
3947
network_update,
@@ -3969,14 +3974,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3969
3974
3970
3975
if self . payment_is_probe ( payment_hash, & payment_id) {
3971
3976
events:: Event :: ProbeFailed {
3972
- payment_id,
3977
+ payment_id : * payment_id ,
3973
3978
payment_hash : payment_hash. clone ( ) ,
3974
3979
path : path. clone ( ) ,
3975
3980
short_channel_id : Some ( scid) ,
3976
3981
}
3977
3982
} else {
3978
3983
events:: Event :: PaymentPathFailed {
3979
- payment_id : Some ( payment_id) ,
3984
+ payment_id : Some ( * payment_id) ,
3980
3985
payment_hash : payment_hash. clone ( ) ,
3981
3986
payment_failed_permanently : false ,
3982
3987
network_update : None ,
@@ -3996,22 +4001,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3996
4001
pending_events. push ( path_failure) ;
3997
4002
if let Some ( ev) = full_failure_ev { pending_events. push ( ev) ; }
3998
4003
} ,
3999
- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret, phantom_shared_secret, outpoint } ) => {
4004
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint } ) => {
4000
4005
let err_packet = match onion_error {
4001
- HTLCFailReason :: Reason { failure_code, data } => {
4006
+ HTLCFailReason :: Reason { ref failure_code, ref data } => {
4002
4007
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with code {}" , log_bytes!( payment_hash. 0 ) , failure_code) ;
4003
4008
if let Some ( phantom_ss) = phantom_shared_secret {
4004
- let phantom_packet = onion_utils:: build_failure_packet ( & phantom_ss, failure_code, & data[ ..] ) . encode ( ) ;
4005
- let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( & phantom_ss, & phantom_packet) ;
4006
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4009
+ let phantom_packet = onion_utils:: build_failure_packet ( phantom_ss, * failure_code, & data[ ..] ) . encode ( ) ;
4010
+ let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( phantom_ss, & phantom_packet) ;
4011
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4007
4012
} else {
4008
- let packet = onion_utils:: build_failure_packet ( & incoming_packet_shared_secret, failure_code, & data[ ..] ) . encode ( ) ;
4009
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & packet)
4013
+ let packet = onion_utils:: build_failure_packet ( incoming_packet_shared_secret, * failure_code, & data[ ..] ) . encode ( ) ;
4014
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & packet)
4010
4015
}
4011
4016
} ,
4012
4017
HTLCFailReason :: LightningError { err } => {
4013
4018
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards with pre-built LightningError" , log_bytes!( payment_hash. 0 ) ) ;
4014
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & err. data )
4019
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & err. data )
4015
4020
}
4016
4021
} ;
4017
4022
@@ -4020,12 +4025,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4020
4025
if forward_htlcs. is_empty ( ) {
4021
4026
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4022
4027
}
4023
- match forward_htlcs. entry ( short_channel_id) {
4028
+ match forward_htlcs. entry ( * short_channel_id) {
4024
4029
hash_map:: Entry :: Occupied ( mut entry) => {
4025
- entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ;
4030
+ entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id : * htlc_id , err_packet } ) ;
4026
4031
} ,
4027
4032
hash_map:: Entry :: Vacant ( entry) => {
4028
- entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ) ;
4033
+ entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id: * htlc_id , err_packet } ) ) ;
4029
4034
}
4030
4035
}
4031
4036
mem:: drop ( forward_htlcs) ;
@@ -4037,7 +4042,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4037
4042
}
4038
4043
pending_events. push ( events:: Event :: HTLCHandlingFailed {
4039
4044
prev_channel_id : outpoint. to_channel_id ( ) ,
4040
- failed_next_destination : destination
4045
+ failed_next_destination : destination,
4041
4046
} ) ;
4042
4047
} ,
4043
4048
}
@@ -4166,10 +4171,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4166
4171
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
4167
4172
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
4168
4173
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4169
- self . fail_htlc_backwards_internal (
4170
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , & payment_hash ,
4171
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
4172
- HTLCDestination :: FailedPayment { payment_hash } ) ;
4174
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
4175
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
4176
+ let receiver = HTLCDestination :: FailedPayment { payment_hash } ;
4177
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
4173
4178
}
4174
4179
}
4175
4180
@@ -4498,7 +4503,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4498
4503
self . finalize_claims ( finalized_claims) ;
4499
4504
for failure in pending_failures. drain ( ..) {
4500
4505
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
4501
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4506
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
4502
4507
}
4503
4508
}
4504
4509
@@ -4866,7 +4871,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4866
4871
} ;
4867
4872
for htlc_source in dropped_htlcs. drain ( ..) {
4868
4873
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4869
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4874
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
4875
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason, receiver) ;
4870
4876
}
4871
4877
4872
4878
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5157,7 +5163,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5157
5163
{
5158
5164
for failure in pending_failures. drain ( ..) {
5159
5165
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5160
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5166
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
5161
5167
}
5162
5168
self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, pending_forwards) ] ) ;
5163
5169
self . finalize_claims ( finalized_claim_htlcs) ;
@@ -5317,7 +5323,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5317
5323
} else {
5318
5324
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5319
5325
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5320
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5326
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
5327
+ self . fail_htlc_backwards_internal ( & htlc_update. source , & htlc_update. payment_hash , & reason, receiver) ;
5321
5328
}
5322
5329
} ,
5323
5330
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -6087,7 +6094,7 @@ where
6087
6094
self . handle_init_event_channel_failures ( failed_channels) ;
6088
6095
6089
6096
for ( source, payment_hash, reason, destination) in timed_out_htlcs. drain ( ..) {
6090
- self . fail_htlc_backwards_internal ( source, & payment_hash, reason, destination) ;
6097
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason, destination) ;
6091
6098
}
6092
6099
}
6093
6100
@@ -7560,7 +7567,8 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7560
7567
for htlc_source in failed_htlcs. drain ( ..) {
7561
7568
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7562
7569
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7563
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7570
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
7571
+ channel_manager. fail_htlc_backwards_internal ( & source, & payment_hash, & reason, receiver) ;
7564
7572
}
7565
7573
7566
7574
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments