@@ -1891,7 +1891,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1891
1891
1892
1892
for htlc_source in failed_htlcs. drain ( ..) {
1893
1893
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : * channel_id } ;
1894
- 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) ;
1894
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1895
1895
}
1896
1896
1897
1897
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -1949,7 +1949,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1949
1949
for htlc_source in failed_htlcs. drain ( ..) {
1950
1950
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
1951
1951
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : channel_id } ;
1952
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1952
+ self . fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
1953
1953
}
1954
1954
if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
1955
1955
// There isn't anything we can do if we get an update failure - we're already
@@ -3493,7 +3493,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3493
3493
}
3494
3494
3495
3495
for ( htlc_source, payment_hash, failure_reason, destination) in failed_forwards. drain ( ..) {
3496
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , htlc_source, & payment_hash, failure_reason, destination) ;
3496
+ self . fail_htlc_backwards_internal ( htlc_source, & payment_hash, failure_reason, destination) ;
3497
3497
}
3498
3498
self . forward_htlcs ( & mut phantom_receives) ;
3499
3499
@@ -3717,7 +3717,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3717
3717
3718
3718
for htlc_source in timed_out_mpp_htlcs. drain ( ..) {
3719
3719
let receiver = HTLCDestination :: FailedPayment { payment_hash : htlc_source. 1 } ;
3720
- 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 ) ;
3720
+ self . fail_htlc_backwards_internal ( HTLCSource :: PreviousHopData ( htlc_source. 0 . clone ( ) ) , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 23 , data : Vec :: new ( ) } , receiver ) ;
3721
3721
}
3722
3722
3723
3723
for ( err, counterparty_node_id) in handle_errors. drain ( ..) {
@@ -3751,7 +3751,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3751
3751
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
3752
3752
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
3753
3753
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
3754
- self . fail_htlc_backwards_internal ( channel_state . take ( ) . unwrap ( ) ,
3754
+ self . fail_htlc_backwards_internal (
3755
3755
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
3756
3756
HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ,
3757
3757
HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ) ;
@@ -3823,10 +3823,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3823
3823
} ,
3824
3824
hash_map:: Entry :: Vacant ( _) => ( 0x4000 |10 , Vec :: new ( ) )
3825
3825
} ;
3826
- let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
3827
-
3828
3826
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id } ;
3829
- self . fail_htlc_backwards_internal ( channel_state , htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver)
3827
+ self . fail_htlc_backwards_internal ( htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data } , receiver)
3830
3828
} ,
3831
3829
HTLCSource :: OutboundRoute { session_priv, payment_id, path, payment_params, .. } => {
3832
3830
let mut session_priv_bytes = [ 0 ; 32 ] ;
@@ -3874,12 +3872,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3874
3872
}
3875
3873
3876
3874
/// Fails an HTLC backwards to the sender of it to us.
3877
- /// Note that while we take a channel_state lock as input, we do *not* assume consistency here.
3878
- /// There are several callsites that do stupid things like loop over a list of payment_hashes
3879
- /// to fail and take the channel_state lock for each iteration (as we take ownership and may
3880
- /// drop it). In other words, no assumptions are made that entries in claimable_htlcs point to
3881
- /// still-available channels.
3882
- fn fail_htlc_backwards_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < Signer > > , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3875
+ /// Note that while this function pushes events as well as FailHTLC's to fail htlcs for
3876
+ /// designated channels, no assumptions are made that the channels are still available.
3877
+ fn fail_htlc_backwards_internal ( & self , source : HTLCSource , payment_hash : & PaymentHash , onion_error : HTLCFailReason , destination : HTLCDestination ) {
3883
3878
//TODO: There is a timing attack here where if a node fails an HTLC back to us they can
3884
3879
//identify whether we sent it or not based on the (I presume) very different runtime
3885
3880
//between the branches here. We should make this async and move it into the forward HTLCs
@@ -3918,7 +3913,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3918
3913
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3919
3914
return ;
3920
3915
}
3921
- mem:: drop ( channel_state_lock) ;
3922
3916
let mut retry = if let Some ( payment_params_data) = payment_params {
3923
3917
let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
3924
3918
Some ( RouteParameters {
@@ -4042,7 +4036,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4042
4036
}
4043
4037
}
4044
4038
mem:: drop ( forward_htlcs) ;
4045
- mem:: drop ( channel_state_lock) ;
4046
4039
let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
4047
4040
if let Some ( time) = forward_event {
4048
4041
pending_events. push ( events:: Event :: PendingHTLCsForwardable {
@@ -4142,7 +4135,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4142
4135
let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
4143
4136
htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
4144
4137
self . best_block . read ( ) . unwrap ( ) . height ( ) ) ) ;
4145
- self . fail_htlc_backwards_internal ( channel_state . take ( ) . unwrap ( ) ,
4138
+ self . fail_htlc_backwards_internal (
4146
4139
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
4147
4140
HTLCFailReason :: Reason { failure_code : 0x4000 |15 , data : htlc_msat_height_data } ,
4148
4141
HTLCDestination :: FailedPayment { payment_hash } ) ;
@@ -4426,7 +4419,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4426
4419
self . finalize_claims ( finalized_claims) ;
4427
4420
for failure in pending_failures. drain ( ..) {
4428
4421
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
4429
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4422
+ self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
4430
4423
}
4431
4424
}
4432
4425
@@ -4786,7 +4779,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4786
4779
} ;
4787
4780
for htlc_source in dropped_htlcs. drain ( ..) {
4788
4781
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id. clone ( ) ) , channel_id : msg. channel_id } ;
4789
- 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) ;
4782
+ self . fail_htlc_backwards_internal ( htlc_source. 0 , & htlc_source. 1 , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
4790
4783
}
4791
4784
4792
4785
let _ = handle_error ! ( self , result, * counterparty_node_id) ;
@@ -4988,7 +4981,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4988
4981
for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
4989
4982
let mut forward_event = None ;
4990
4983
if !pending_forwards. is_empty ( ) {
4991
- let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
4992
4984
let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
4993
4985
if forward_htlcs. is_empty ( ) {
4994
4986
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) )
@@ -5075,7 +5067,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5075
5067
{
5076
5068
for failure in pending_failures. drain ( ..) {
5077
5069
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5078
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5070
+ self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5079
5071
}
5080
5072
self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, pending_forwards) ] ) ;
5081
5073
self . finalize_claims ( finalized_claim_htlcs) ;
@@ -5232,7 +5224,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
5232
5224
} else {
5233
5225
log_trace ! ( self . logger, "Failing HTLC with hash {} from our monitor" , log_bytes!( htlc_update. payment_hash. 0 ) ) ;
5234
5226
let receiver = HTLCDestination :: NextHopChannel { node_id : counterparty_node_id, channel_id : funding_outpoint. to_channel_id ( ) } ;
5235
- 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) ;
5227
+ self . fail_htlc_backwards_internal ( htlc_update. source , & htlc_update. payment_hash , HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
5236
5228
}
5237
5229
} ,
5238
5230
MonitorEvent :: CommitmentTxConfirmed ( funding_outpoint) |
@@ -5971,7 +5963,7 @@ where
5971
5963
self . handle_init_event_channel_failures ( failed_channels) ;
5972
5964
5973
5965
for ( source, payment_hash, reason, destination) in timed_out_htlcs. drain ( ..) {
5974
- self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , source, & payment_hash, reason, destination) ;
5966
+ self . fail_htlc_backwards_internal ( source, & payment_hash, reason, destination) ;
5975
5967
}
5976
5968
}
5977
5969
@@ -7330,7 +7322,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7330
7322
for htlc_source in failed_htlcs. drain ( ..) {
7331
7323
let ( source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
7332
7324
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
7333
- 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) ;
7325
+ channel_manager. fail_htlc_backwards_internal ( source, & payment_hash, HTLCFailReason :: Reason { failure_code : 0x4000 | 8 , data : Vec :: new ( ) } , receiver) ;
7334
7326
}
7335
7327
7336
7328
//TODO: Broadcast channel update for closed channels, but only after we've made a
0 commit comments