@@ -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
@@ -3463,7 +3465,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3463
3465
}
3464
3466
3465
3467
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3466
- self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
3468
+ self . fail_htlc_backwards_internal ( & htlc_source, & payment_hash, & failure_reason, destination) ;
3467
3469
}
3468
3470
self . forward_htlcs ( & mut phantom_receives) ;
3469
3471
@@ -3726,8 +3728,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3726
3728
} ) ;
3727
3729
3728
3730
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3731
+ let source = HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) ;
3732
+ let reason = HTLCFailReason :: from_failure_code ( 23 ) ;
3729
3733
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3730
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source . 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver ) ;
3734
+ self . fail_htlc_backwards_internal ( & source , & htlc_source. 1 , & reason , receiver) ;
3731
3735
}
3732
3736
3733
3737
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3762,10 +3766,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3762
3766
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3763
3767
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
3764
3768
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3765
- self . fail_htlc_backwards_internal (
3766
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , payment_hash ,
3767
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
3768
- HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3769
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
3770
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
3771
+ let receiver = HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ;
3772
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
3769
3773
}
3770
3774
}
3771
3775
}
@@ -3833,14 +3837,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3833
3837
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3834
3838
} ;
3835
3839
3840
+ let reason = HTLCFailReason :: reason ( failure_code, onion_failure_data) ;
3836
3841
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3837
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code , onion_failure_data ) , receiver) ;
3842
+ self . fail_htlc_backwards_internal ( & htlc_src, & payment_hash, & reason, receiver) ;
3838
3843
}
3839
3844
}
3840
3845
3841
3846
/// Fails an HTLC backwards to the sender of it to us.
3842
3847
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
3843
- fn fail_htlc_backwards_internal ( & self , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3848
+ fn fail_htlc_backwards_internal ( & self , source : & HTLCSource , payment_hash : & PaymentHash , onion_error : & HTLCFailReason , destination : HTLCDestination ) {
3844
3849
#[ cfg( debug_assertions) ]
3845
3850
{
3846
3851
// Ensure that the `channel_state` lock is not held when calling this function.
@@ -3859,13 +3864,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3859
3864
// from block_connected which may run during initialization prior to the chain_monitor
3860
3865
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
3861
3866
match source {
3862
- HTLCSource :: OutboundRoute { ref path, session_priv, payment_id, ref payment_params, .. } => {
3867
+ HTLCSource :: OutboundRoute { ref path, ref session_priv, ref payment_id, ref payment_params, .. } => {
3863
3868
let mut session_priv_bytes = [ 0 ; 32 ] ;
3864
3869
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3865
3870
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
3866
3871
let mut all_paths_failed = false ;
3867
3872
let mut full_failure_ev = None ;
3868
- if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
3873
+ if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
3869
3874
if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
3870
3875
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3871
3876
return ;
@@ -3878,7 +3883,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3878
3883
all_paths_failed = true ;
3879
3884
if payment. get ( ) . abandoned ( ) {
3880
3885
full_failure_ev = Some ( events:: Event :: PaymentFailed {
3881
- payment_id,
3886
+ payment_id : * payment_id ,
3882
3887
payment_hash : payment. get ( ) . payment_hash ( ) . expect ( "PendingOutboundPayments::RetriesExceeded always has a payment hash set" ) ,
3883
3888
} ) ;
3884
3889
payment. remove ( ) ;
@@ -3908,13 +3913,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3908
3913
if self . payment_is_probe ( payment_hash, & payment_id) {
3909
3914
if !payment_retryable {
3910
3915
events:: Event :: ProbeSuccessful {
3911
- payment_id,
3916
+ payment_id : * payment_id ,
3912
3917
payment_hash : payment_hash. clone ( ) ,
3913
3918
path : path. clone ( ) ,
3914
3919
}
3915
3920
} else {
3916
3921
events:: Event :: ProbeFailed {
3917
- payment_id,
3922
+ payment_id : * payment_id ,
3918
3923
payment_hash : payment_hash. clone ( ) ,
3919
3924
path : path. clone ( ) ,
3920
3925
short_channel_id,
@@ -3928,7 +3933,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3928
3933
retry. as_mut ( ) . map ( |r| r. payment_params . previously_failed_channels . push ( scid) ) ;
3929
3934
}
3930
3935
events:: Event :: PaymentPathFailed {
3931
- payment_id : Some ( payment_id) ,
3936
+ payment_id : Some ( * payment_id) ,
3932
3937
payment_hash : payment_hash. clone ( ) ,
3933
3938
payment_failed_permanently : !payment_retryable,
3934
3939
network_update,
@@ -3961,14 +3966,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3961
3966
3962
3967
if self . payment_is_probe ( payment_hash, & payment_id) {
3963
3968
events:: Event :: ProbeFailed {
3964
- payment_id,
3969
+ payment_id : * payment_id ,
3965
3970
payment_hash : payment_hash. clone ( ) ,
3966
3971
path : path. clone ( ) ,
3967
3972
short_channel_id : Some ( scid) ,
3968
3973
}
3969
3974
} else {
3970
3975
events:: Event :: PaymentPathFailed {
3971
- payment_id : Some ( payment_id) ,
3976
+ payment_id : Some ( * payment_id) ,
3972
3977
payment_hash : payment_hash. clone ( ) ,
3973
3978
payment_failed_permanently : false ,
3974
3979
network_update : None ,
@@ -3988,22 +3993,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3988
3993
pending_events. push ( path_failure) ;
3989
3994
if let Some ( ev) = full_failure_ev { pending_events. push ( ev) ; }
3990
3995
} ,
3991
- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret, phantom_shared_secret, outpoint } ) => {
3996
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint } ) => {
3992
3997
let err_packet = match onion_error {
3993
- HTLCFailReason :: Reason { failure_code, data } => {
3998
+ HTLCFailReason :: Reason { ref failure_code, ref data } => {
3994
3999
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with code {}" , log_bytes!( payment_hash. 0 ) , failure_code) ;
3995
4000
if let Some ( phantom_ss) = phantom_shared_secret {
3996
- let phantom_packet = onion_utils:: build_failure_packet ( & phantom_ss, failure_code, & data[ ..] ) . encode ( ) ;
3997
- let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( & phantom_ss, & phantom_packet) ;
3998
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4001
+ let phantom_packet = onion_utils:: build_failure_packet ( phantom_ss, * failure_code, & data[ ..] ) . encode ( ) ;
4002
+ let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( phantom_ss, & phantom_packet) ;
4003
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
3999
4004
} else {
4000
- let packet = onion_utils:: build_failure_packet ( & incoming_packet_shared_secret, failure_code, & data[ ..] ) . encode ( ) ;
4001
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & packet)
4005
+ let packet = onion_utils:: build_failure_packet ( incoming_packet_shared_secret, * failure_code, & data[ ..] ) . encode ( ) ;
4006
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & packet)
4002
4007
}
4003
4008
} ,
4004
4009
HTLCFailReason :: LightningError { err } => {
4005
4010
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards with pre-built LightningError" , log_bytes!( payment_hash. 0 ) ) ;
4006
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & err. data )
4011
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & err. data )
4007
4012
}
4008
4013
} ;
4009
4014
@@ -4012,12 +4017,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4012
4017
if forward_htlcs. is_empty ( ) {
4013
4018
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4014
4019
}
4015
- match forward_htlcs. entry ( short_channel_id) {
4020
+ match forward_htlcs. entry ( * short_channel_id) {
4016
4021
hash_map:: Entry :: Occupied ( mut entry) => {
4017
- entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ;
4022
+ entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id : * htlc_id , err_packet } ) ;
4018
4023
} ,
4019
4024
hash_map:: Entry :: Vacant ( entry) => {
4020
- entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ) ;
4025
+ entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id: * htlc_id , err_packet } ) ) ;
4021
4026
}
4022
4027
}
4023
4028
mem:: drop ( forward_htlcs) ;
@@ -4029,7 +4034,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4029
4034
}
4030
4035
pending_events. push ( events:: Event :: HTLCHandlingFailed {
4031
4036
prev_channel_id : outpoint. to_channel_id ( ) ,
4032
- failed_next_destination : destination
4037
+ failed_next_destination : destination,
4033
4038
} ) ;
4034
4039
} ,
4035
4040
}
@@ -4151,10 +4156,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4151
4156
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
4152
4157
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
4153
4158
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4154
- self . fail_htlc_backwards_internal (
4155
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , & payment_hash ,
4156
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
4157
- HTLCDestination :: FailedPayment { payment_hash } ) ;
4159
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
4160
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
4161
+ let receiver = HTLCDestination :: FailedPayment { payment_hash } ;
4162
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
4158
4163
}
4159
4164
}
4160
4165
@@ -4482,7 +4487,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4482
4487
self . finalize_claims ( finalized_claims) ;
4483
4488
for failure in pending_failures. drain ( ..) {
4484
4489
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
4485
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4490
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
4486
4491
}
4487
4492
}
4488
4493
@@ -4850,7 +4855,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4850
4855
} ;
4851
4856
for htlc_source in dropped_htlcs. drain ( ..) {
4852
4857
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4853
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
4858
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
4859
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason, receiver) ;
4854
4860
}
4855
4861
4856
4862
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5141,7 +5147,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5141
5147
{
5142
5148
for failure in pending_failures. drain ( ..) {
5143
5149
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5144
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5150
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
5145
5151
}
5146
5152
self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, pending_forwards) ] ) ;
5147
5153
self . finalize_claims ( finalized_claim_htlcs) ;
@@ -5301,7 +5307,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5301
5307
} else {
5302
5308
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5303
5309
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5304
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5310
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
5311
+ self . fail_htlc_backwards_internal ( & htlc_update. source , & htlc_update. payment_hash , & reason, receiver) ;
5305
5312
}
5306
5313
} ,
5307
5314
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -6071,7 +6078,7 @@ where
6071
6078
self . handle_init_event_channel_failures ( failed_channels) ;
6072
6079
6073
6080
for ( source, payment_hash, reason, destination) in timed_out_htlcs. drain ( ..) {
6074
- self . fail_htlc_backwards_internal ( source, & payment_hash, reason, destination) ;
6081
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason, destination) ;
6075
6082
}
6076
6083
}
6077
6084
@@ -7536,7 +7543,8 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7536
7543
for htlc_source in failed_htlcs. drain ( ..) {
7537
7544
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7538
7545
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7539
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7546
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
7547
+ channel_manager. fail_htlc_backwards_internal ( & source, & payment_hash, & reason, receiver) ;
7540
7548
}
7541
7549
7542
7550
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments