@@ -1886,8 +1886,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1886
1886
} ;
1887
1887
1888
1888
for htlc_source in failed_htlcs. drain ( ..) {
1889
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
1889
1890
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1890
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1891
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason , receiver) ;
1891
1892
}
1892
1893
1893
1894
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1944,8 +1945,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1944
1945
log_debug ! ( self . logger, "Finishing force-closure of channel with {} HTLCs to fail" , failed_htlcs. len( ) ) ;
1945
1946
for htlc_source in failed_htlcs. drain ( ..) {
1946
1947
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1948
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
1947
1949
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
1948
- self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
1950
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason , receiver) ;
1949
1951
}
1950
1952
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1951
1953
// There isn't anything we can do if we get an update failure - we're already
@@ -3152,7 +3154,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3152
3154
3153
3155
let failure_reason = HTLCFailReason :: from_failure_code ( 0x4000 | 10 ) ;
3154
3156
let destination = HTLCDestination :: UnknownNextHop { requested_forward_scid : short_channel_id } ;
3155
- self . fail_htlc_backwards_internal ( htlc_source, & payment. forward_info . payment_hash , failure_reason, destination) ;
3157
+ self . fail_htlc_backwards_internal ( & htlc_source, & payment. forward_info . payment_hash , & failure_reason, destination) ;
3156
3158
} else { unreachable ! ( ) } // Only `PendingHTLCRouting::Forward`s are intercepted
3157
3159
3158
3160
Ok ( ( ) )
@@ -3609,7 +3611,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3609
3611
}
3610
3612
3611
3613
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3612
- self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
3614
+ self . fail_htlc_backwards_internal ( & htlc_source, & payment_hash, & failure_reason, destination) ;
3613
3615
}
3614
3616
self . forward_htlcs ( & mut phantom_receives) ;
3615
3617
@@ -3872,8 +3874,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3872
3874
} ) ;
3873
3875
3874
3876
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3877
+ let source = HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) ;
3878
+ let reason = HTLCFailReason :: from_failure_code ( 23 ) ;
3875
3879
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3876
- self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source . 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 23 ) , receiver) ;
3880
+ self . fail_htlc_backwards_internal ( & source , & htlc_source. 1 , & reason , receiver) ;
3877
3881
}
3878
3882
3879
3883
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3908,10 +3912,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3908
3912
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3909
3913
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
3910
3914
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3911
- self . fail_htlc_backwards_internal (
3912
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , payment_hash ,
3913
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
3914
- HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
3915
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
3916
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
3917
+ let receiver = HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ;
3918
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
3915
3919
}
3916
3920
}
3917
3921
}
@@ -3979,14 +3983,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3979
3983
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3980
3984
} ;
3981
3985
3986
+ let reason = HTLCFailReason :: reason ( failure_code, onion_failure_data) ;
3982
3987
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3983
- self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: reason ( failure_code , onion_failure_data ) , receiver) ;
3988
+ self . fail_htlc_backwards_internal ( & htlc_src, & payment_hash, & reason, receiver) ;
3984
3989
}
3985
3990
}
3986
3991
3987
3992
/// Fails an HTLC backwards to the sender of it to us.
3988
3993
/// Note that we do not assume that channels corresponding to failed HTLCs are still available.
3989
- fn fail_htlc_backwards_internal ( & self , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3994
+ fn fail_htlc_backwards_internal ( & self , source : & HTLCSource , payment_hash : & PaymentHash , onion_error : & HTLCFailReason , destination : HTLCDestination ) {
3990
3995
#[ cfg( debug_assertions) ]
3991
3996
{
3992
3997
// Ensure that the `channel_state` lock is not held when calling this function.
@@ -4005,13 +4010,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4005
4010
// from block_connected which may run during initialization prior to the chain_monitor
4006
4011
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
4007
4012
match source {
4008
- HTLCSource :: OutboundRoute { ref path, session_priv, payment_id, ref payment_params, .. } => {
4013
+ HTLCSource :: OutboundRoute { ref path, ref session_priv, ref payment_id, ref payment_params, .. } => {
4009
4014
let mut session_priv_bytes = [ 0 ; 32 ] ;
4010
4015
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
4011
4016
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
4012
4017
let mut all_paths_failed = false ;
4013
4018
let mut full_failure_ev = None ;
4014
- if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
4019
+ if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
4015
4020
if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
4016
4021
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
4017
4022
return ;
@@ -4024,7 +4029,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4024
4029
all_paths_failed = true ;
4025
4030
if payment. get ( ) . abandoned ( ) {
4026
4031
full_failure_ev = Some ( events:: Event :: PaymentFailed {
4027
- payment_id,
4032
+ payment_id : * payment_id ,
4028
4033
payment_hash : payment. get ( ) . payment_hash ( ) . expect ( "PendingOutboundPayments::RetriesExceeded always has a payment hash set" ) ,
4029
4034
} ) ;
4030
4035
payment. remove ( ) ;
@@ -4054,13 +4059,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4054
4059
if self . payment_is_probe ( payment_hash, & payment_id) {
4055
4060
if !payment_retryable {
4056
4061
events:: Event :: ProbeSuccessful {
4057
- payment_id,
4062
+ payment_id : * payment_id ,
4058
4063
payment_hash : payment_hash. clone ( ) ,
4059
4064
path : path. clone ( ) ,
4060
4065
}
4061
4066
} else {
4062
4067
events:: Event :: ProbeFailed {
4063
- payment_id,
4068
+ payment_id : * payment_id ,
4064
4069
payment_hash : payment_hash. clone ( ) ,
4065
4070
path : path. clone ( ) ,
4066
4071
short_channel_id,
@@ -4074,7 +4079,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4074
4079
retry. as_mut ( ) . map ( |r| r. payment_params . previously_failed_channels . push ( scid) ) ;
4075
4080
}
4076
4081
events:: Event :: PaymentPathFailed {
4077
- payment_id : Some ( payment_id) ,
4082
+ payment_id : Some ( * payment_id) ,
4078
4083
payment_hash : payment_hash. clone ( ) ,
4079
4084
payment_failed_permanently : !payment_retryable,
4080
4085
network_update,
@@ -4107,14 +4112,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4107
4112
4108
4113
if self . payment_is_probe ( payment_hash, & payment_id) {
4109
4114
events:: Event :: ProbeFailed {
4110
- payment_id,
4115
+ payment_id : * payment_id ,
4111
4116
payment_hash : payment_hash. clone ( ) ,
4112
4117
path : path. clone ( ) ,
4113
4118
short_channel_id : Some ( scid) ,
4114
4119
}
4115
4120
} else {
4116
4121
events:: Event :: PaymentPathFailed {
4117
- payment_id : Some ( payment_id) ,
4122
+ payment_id : Some ( * payment_id) ,
4118
4123
payment_hash : payment_hash. clone ( ) ,
4119
4124
payment_failed_permanently : false ,
4120
4125
network_update : None ,
@@ -4134,22 +4139,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4134
4139
pending_events. push ( path_failure) ;
4135
4140
if let Some ( ev) = full_failure_ev { pending_events. push ( ev) ; }
4136
4141
} ,
4137
- HTLCSource :: PreviousHopData ( HTLCPreviousHopData { short_channel_id, htlc_id, incoming_packet_shared_secret, phantom_shared_secret, outpoint } ) => {
4142
+ HTLCSource :: PreviousHopData ( HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint } ) => {
4138
4143
let err_packet = match onion_error {
4139
- HTLCFailReason :: Reason { failure_code, data } => {
4144
+ HTLCFailReason :: Reason { ref failure_code, ref data } => {
4140
4145
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with code {}" , log_bytes!( payment_hash. 0 ) , failure_code) ;
4141
4146
if let Some ( phantom_ss) = phantom_shared_secret {
4142
- let phantom_packet = onion_utils:: build_failure_packet ( & phantom_ss, failure_code, & data[ ..] ) . encode ( ) ;
4143
- let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( & phantom_ss, & phantom_packet) ;
4144
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4147
+ let phantom_packet = onion_utils:: build_failure_packet ( phantom_ss, * failure_code, & data[ ..] ) . encode ( ) ;
4148
+ let encrypted_phantom_packet = onion_utils:: encrypt_failure_packet ( phantom_ss, & phantom_packet) ;
4149
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & encrypted_phantom_packet. data [ ..] )
4145
4150
} else {
4146
- let packet = onion_utils:: build_failure_packet ( & incoming_packet_shared_secret, failure_code, & data[ ..] ) . encode ( ) ;
4147
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & packet)
4151
+ let packet = onion_utils:: build_failure_packet ( incoming_packet_shared_secret, * failure_code, & data[ ..] ) . encode ( ) ;
4152
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & packet)
4148
4153
}
4149
4154
} ,
4150
4155
HTLCFailReason :: LightningError { err } => {
4151
4156
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards with pre-built LightningError" , log_bytes!( payment_hash. 0 ) ) ;
4152
- onion_utils:: encrypt_failure_packet ( & incoming_packet_shared_secret, & err. data )
4157
+ onion_utils:: encrypt_failure_packet ( incoming_packet_shared_secret, & err. data )
4153
4158
}
4154
4159
} ;
4155
4160
@@ -4158,12 +4163,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4158
4163
if forward_htlcs. is_empty ( ) {
4159
4164
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4160
4165
}
4161
- match forward_htlcs. entry ( short_channel_id) {
4166
+ match forward_htlcs. entry ( * short_channel_id) {
4162
4167
hash_map:: Entry :: Occupied ( mut entry) => {
4163
- entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ;
4168
+ entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id : * htlc_id , err_packet } ) ;
4164
4169
} ,
4165
4170
hash_map:: Entry :: Vacant ( entry) => {
4166
- entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ) ;
4171
+ entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id: * htlc_id , err_packet } ) ) ;
4167
4172
}
4168
4173
}
4169
4174
mem:: drop ( forward_htlcs) ;
@@ -4175,7 +4180,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4175
4180
}
4176
4181
pending_events. push ( events:: Event :: HTLCHandlingFailed {
4177
4182
prev_channel_id : outpoint. to_channel_id ( ) ,
4178
- failed_next_destination : destination
4183
+ failed_next_destination : destination,
4179
4184
} ) ;
4180
4185
} ,
4181
4186
}
@@ -4304,10 +4309,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4304
4309
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
4305
4310
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
4306
4311
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4307
- self . fail_htlc_backwards_internal (
4308
- HTLCSource :: PreviousHopData ( htlc . prev_hop ) , & payment_hash ,
4309
- HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ,
4310
- HTLCDestination :: FailedPayment { payment_hash } ) ;
4312
+ let source = HTLCSource :: PreviousHopData ( htlc . prev_hop ) ;
4313
+ let reason = HTLCFailReason :: reason ( 0x4000 | 15 , htlc_msat_height_data ) ;
4314
+ let receiver = HTLCDestination :: FailedPayment { payment_hash } ;
4315
+ self . fail_htlc_backwards_internal ( & source , & payment_hash, & reason , receiver ) ;
4311
4316
}
4312
4317
}
4313
4318
@@ -4631,7 +4636,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4631
4636
self . finalize_claims ( finalized_claims) ;
4632
4637
for failure in pending_failures. drain ( ..) {
4633
4638
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
4634
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4639
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
4635
4640
}
4636
4641
}
4637
4642
@@ -4999,7 +5004,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4999
5004
} ;
5000
5005
for htlc_source in dropped_htlcs. drain ( ..) {
5001
5006
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
5002
- self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5007
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
5008
+ self . fail_htlc_backwards_internal ( & htlc_source. 0 , & htlc_source. 1 , & reason, receiver) ;
5003
5009
}
5004
5010
5005
5011
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -5270,7 +5276,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5270
5276
}
5271
5277
5272
5278
for ( htlc_source, payment_hash, failure_reason, destination) in failed_intercept_forwards. drain ( ..) {
5273
- self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
5279
+ self . fail_htlc_backwards_internal ( & htlc_source, & payment_hash, & failure_reason, destination) ;
5274
5280
}
5275
5281
5276
5282
if !new_intercept_events. is_empty ( ) {
@@ -5345,7 +5351,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5345
5351
{
5346
5352
for failure in pending_failures. drain ( ..) {
5347
5353
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5348
- self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5354
+ self . fail_htlc_backwards_internal ( & failure. 0 , & failure. 1 , & failure. 2 , receiver) ;
5349
5355
}
5350
5356
self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, user_channel_id, pending_forwards) ] ) ;
5351
5357
self . finalize_claims ( finalized_claim_htlcs) ;
@@ -5505,7 +5511,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5505
5511
} else {
5506
5512
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5507
5513
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5508
- self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
5514
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
5515
+ self . fail_htlc_backwards_internal ( & htlc_update. source , & htlc_update. payment_hash , & reason, receiver) ;
5509
5516
}
5510
5517
} ,
5511
5518
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -6315,7 +6322,7 @@ where
6315
6322
self . handle_init_event_channel_failures ( failed_channels) ;
6316
6323
6317
6324
for ( source, payment_hash, reason, destination) in timed_out_htlcs. drain ( ..) {
6318
- self . fail_htlc_backwards_internal ( source, & payment_hash, reason, destination) ;
6325
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason, destination) ;
6319
6326
}
6320
6327
}
6321
6328
@@ -7802,7 +7809,8 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7802
7809
for htlc_source in failed_htlcs. drain ( ..) {
7803
7810
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7804
7811
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7805
- channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) , receiver) ;
7812
+ let reason = HTLCFailReason :: from_failure_code ( 0x4000 | 8 ) ;
7813
+ channel_manager. fail_htlc_backwards_internal ( & source, & payment_hash, & reason, receiver) ;
7806
7814
}
7807
7815
7808
7816
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments