@@ -1894,7 +1894,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1894
1894
1895
1895
for htlc_source in failed_htlcs. drain ( ..) {
1896
1896
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1897
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1897
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1898
1898
}
1899
1899
1900
1900
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1952,7 +1952,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1952
1952
for htlc_source in failed_htlcs. drain ( ..) {
1953
1953
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1954
1954
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : channel_id } ;
1955
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1955
+ self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1956
1956
}
1957
1957
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1958
1958
// There isn't anything we can do if we get an update failure - we're already
@@ -3499,7 +3499,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3499
3499
}
3500
3500
3501
3501
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3502
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_source, & payment_hash, failure_reason, destination) ;
3502
+ self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
3503
3503
}
3504
3504
self . forward_htlcs ( & mut phantom_receives) ;
3505
3505
@@ -3723,7 +3723,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3723
3723
3724
3724
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3725
3725
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3726
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3726
+ self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3727
3727
}
3728
3728
3729
3729
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3757,7 +3757,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3757
3757
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3758
3758
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
3759
3759
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3760
- self . fail_htlc_backwards_internal ( channel_state . take ( ) . unwrap ( ) ,
3760
+ self . fail_htlc_backwards_internal (
3761
3761
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
3762
3762
HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3763
3763
HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
@@ -3829,10 +3829,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3829
3829
} ,
3830
3830
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3831
3831
} ;
3832
- let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3833
-
3834
3832
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3835
- self . fail_htlc_backwards_internal ( channel_state , htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver)
3833
+ self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver)
3836
3834
} ,
3837
3835
HTLCSource :: OutboundRoute { session_priv, payment_id, path, payment_params, .. } => {
3838
3836
let mut session_priv_bytes = [ 0 ; 32 ] ;
@@ -3880,12 +3878,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3880
3878
}
3881
3879
3882
3880
/// Fails an HTLC backwards to the sender of it to us.
3883
- /// Note that while we take a channel_state lock as input, we do *not* assume consistency here.
3884
- /// There are several callsites that do stupid things like loop over a list of payment_hashes
3885
- /// to fail and take the channel_state lock for each iteration (as we take ownership and may
3886
- /// drop it). In other words, no assumptions are made that entries in claimable_htlcs point to
3887
- /// still-available channels.
3888
- fn fail_htlc_backwards_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < Signer > > , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3881
+ /// Note that while this function pushes events as well as FailHTLC's to fail htlcs for
3882
+ /// designated channels, no assumptions are made that the channels are still available.
3883
+ fn fail_htlc_backwards_internal ( & self , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3889
3884
//TODO: There is a timing attack here where if a node fails an HTLC back to us they can
3890
3885
//identify whether we sent it or not based on the (I presume) very different runtime
3891
3886
//between the branches here. We should make this async and move it into the forward HTLCs
@@ -3924,7 +3919,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3924
3919
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3925
3920
return ;
3926
3921
}
3927
- mem:: drop ( channel_state_lock) ;
3928
3922
let mut retry = if let Some ( payment_params_data) = payment_params {
3929
3923
let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
3930
3924
Some ( RouteParameters {
@@ -4048,7 +4042,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4048
4042
}
4049
4043
}
4050
4044
mem:: drop ( forward_htlcs) ;
4051
- mem:: drop ( channel_state_lock) ;
4052
4045
let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
4053
4046
if let Some ( time) = forward_event {
4054
4047
pending_events. push ( events:: Event :: PendingHTLCsForwardable {
@@ -4148,7 +4141,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4148
4141
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
4149
4142
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
4150
4143
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4151
- self . fail_htlc_backwards_internal ( channel_state . take ( ) . unwrap ( ) ,
4144
+ self . fail_htlc_backwards_internal (
4152
4145
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
4153
4146
HTLCFailReason :: Reason { failure_code : 0x4000 |15 , data : htlc_msat_height_data } ,
4154
4147
HTLCDestination :: FailedPayment { payment_hash } ) ;
@@ -4432,7 +4425,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4432
4425
self . finalize_claims ( finalized_claims) ;
4433
4426
for failure in pending_failures. drain ( ..) {
4434
4427
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
4435
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4428
+ self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4436
4429
}
4437
4430
}
4438
4431
@@ -4792,7 +4785,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4792
4785
} ;
4793
4786
for htlc_source in dropped_htlcs. drain ( ..) {
4794
4787
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4795
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
4788
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
4796
4789
}
4797
4790
4798
4791
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -4994,7 +4987,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4994
4987
for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
4995
4988
let mut forward_event = None ;
4996
4989
if !pending_forwards. is_empty ( ) {
4997
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
4998
4990
let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
4999
4991
if forward_htlcs. is_empty ( ) {
5000
4992
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) )
@@ -5081,7 +5073,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5081
5073
{
5082
5074
for failure in pending_failures. drain ( ..) {
5083
5075
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5084
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5076
+ self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5085
5077
}
5086
5078
self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, pending_forwards) ] ) ;
5087
5079
self . finalize_claims ( finalized_claim_htlcs) ;
@@ -5238,7 +5230,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5238
5230
} else {
5239
5231
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5240
5232
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5241
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5233
+ self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5242
5234
}
5243
5235
} ,
5244
5236
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -5977,7 +5969,7 @@ where
5977
5969
self . handle_init_event_channel_failures ( failed_channels) ;
5978
5970
5979
5971
for ( source, payment_hash, reason, destination) in timed_out_htlcs. drain ( ..) {
5980
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, reason, destination) ;
5972
+ self . fail_htlc_backwards_internal ( source, & payment_hash, reason, destination) ;
5981
5973
}
5982
5974
}
5983
5975
@@ -7336,7 +7328,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7336
7328
for htlc_source in failed_htlcs. drain ( ..) {
7337
7329
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7338
7330
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7339
- channel_manager. fail_htlc_backwards_internal ( channel_manager . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7331
+ channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7340
7332
}
7341
7333
7342
7334
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments