@@ -403,16 +403,6 @@ pub(super) struct ChannelHolder<Signer: Sign> {
403
403
/// SCIDs being added once the funding transaction is confirmed at the channel's required
404
404
/// confirmation depth.
405
405
pub ( super ) short_to_chan_info : HashMap < u64 , ( PublicKey , [ u8 ; 32 ] ) > ,
406
- /// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
407
- ///
408
- /// Note that because we may have an SCID Alias as the key we can have two entries per channel,
409
- /// though in practice we probably won't be receiving HTLCs for a channel both via the alias
410
- /// and via the classic SCID.
411
- ///
412
- /// Note that while this is held in the same mutex as the channels themselves, no consistency
413
- /// guarantees are made about the existence of a channel with the short id here, nor the short
414
- /// ids in the PendingHTLCInfo!
415
- pub ( super ) forward_htlcs : HashMap < u64 , Vec < HTLCForwardInfo > > ,
416
406
/// Map from payment hash to the payment data and any HTLCs which are to us and can be
417
407
/// failed/claimed by the user.
418
408
///
@@ -724,6 +714,16 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
724
714
/// Locked *after* channel_state.
725
715
pending_outbound_payments : Mutex < HashMap < PaymentId , PendingOutboundPayment > > ,
726
716
717
+ /// SCID/SCID Alias -> forward infos. Key of 0 means payments received.
718
+ ///
719
+ /// Note that because we may have an SCID Alias as the key we can have two entries per channel,
720
+ /// though in practice we probably won't be receiving HTLCs for a channel both via the alias
721
+ /// and via the classic SCID.
722
+ ///
723
+ /// Note that no consistency guarantees are made about the existence of a channel with the
724
+ /// `short_channel_id` here, nor the `short_channel_id` in the `PendingHTLCInfo`!
725
+ pub ( super ) forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
726
+
727
727
/// The set of outbound SCID aliases across all our channels, including unconfirmed channels
728
728
/// and some closed channels which reached a usable state prior to being closed. This is used
729
729
/// only to avoid duplicates, and is not persisted explicitly to disk, but rebuilt from the
@@ -1601,13 +1601,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1601
1601
channel_state : Mutex :: new ( ChannelHolder {
1602
1602
by_id : HashMap :: new ( ) ,
1603
1603
short_to_chan_info : HashMap :: new ( ) ,
1604
- forward_htlcs : HashMap :: new ( ) ,
1605
1604
claimable_htlcs : HashMap :: new ( ) ,
1606
1605
pending_msg_events : Vec :: new ( ) ,
1607
1606
} ) ,
1608
1607
outbound_scid_aliases : Mutex :: new ( HashSet :: new ( ) ) ,
1609
1608
pending_inbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1610
1609
pending_outbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1610
+ forward_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1611
1611
id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
1612
1612
1613
1613
our_network_key : keys_manager. get_node_secret ( Recipient :: Node ) . unwrap ( ) ,
@@ -3095,7 +3095,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3095
3095
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3096
3096
let channel_state = & mut * channel_state_lock;
3097
3097
3098
- for ( short_chan_id, mut pending_forwards) in channel_state . forward_htlcs . drain ( ) {
3098
+ for ( short_chan_id, mut pending_forwards) in self . forward_htlcs . lock ( ) . unwrap ( ) . drain ( ) {
3099
3099
if short_chan_id != 0 {
3100
3100
let forward_chan_id = match channel_state. short_to_chan_info . get ( & short_chan_id) {
3101
3101
Some ( ( _cp_id, chan_id) ) => chan_id. clone ( ) ,
@@ -4029,17 +4029,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4029
4029
} ;
4030
4030
4031
4031
let mut forward_event = None ;
4032
- if channel_state_lock. forward_htlcs . is_empty ( ) {
4032
+ let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
4033
+ if forward_htlcs. is_empty ( ) {
4033
4034
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4034
4035
}
4035
- match channel_state_lock . forward_htlcs . entry ( short_channel_id) {
4036
+ match forward_htlcs. entry ( short_channel_id) {
4036
4037
hash_map:: Entry :: Occupied ( mut entry) => {
4037
4038
entry. get_mut ( ) . push ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ;
4038
4039
} ,
4039
4040
hash_map:: Entry :: Vacant ( entry) => {
4040
4041
entry. insert ( vec ! ( HTLCForwardInfo :: FailHTLC { htlc_id, err_packet } ) ) ;
4041
4042
}
4042
4043
}
4044
+ mem:: drop ( forward_htlcs) ;
4043
4045
mem:: drop ( channel_state_lock) ;
4044
4046
let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
4045
4047
if let Some ( time) = forward_event {
@@ -4987,11 +4989,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4987
4989
let mut forward_event = None ;
4988
4990
if !pending_forwards. is_empty ( ) {
4989
4991
let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
4990
- if channel_state. forward_htlcs . is_empty ( ) {
4992
+ let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
4993
+ if forward_htlcs. is_empty ( ) {
4991
4994
forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) )
4992
4995
}
4993
4996
for ( forward_info, prev_htlc_id) in pending_forwards. drain ( ..) {
4994
- match channel_state . forward_htlcs . entry ( match forward_info. routing {
4997
+ match forward_htlcs. entry ( match forward_info. routing {
4995
4998
PendingHTLCRouting :: Forward { short_channel_id, .. } => short_channel_id,
4996
4999
PendingHTLCRouting :: Receive { .. } => 0 ,
4997
5000
PendingHTLCRouting :: ReceiveKeysend { .. } => 0 ,
@@ -6680,8 +6683,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
6680
6683
}
6681
6684
}
6682
6685
6683
- ( channel_state. forward_htlcs . len ( ) as u64 ) . write ( writer) ?;
6684
- for ( short_channel_id, pending_forwards) in channel_state. forward_htlcs . iter ( ) {
6686
+ let forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
6687
+ ( forward_htlcs. len ( ) as u64 ) . write ( writer) ?;
6688
+ for ( short_channel_id, pending_forwards) in forward_htlcs. iter ( ) {
6685
6689
short_channel_id. write ( writer) ?;
6686
6690
( pending_forwards. len ( ) as u64 ) . write ( writer) ?;
6687
6691
for forward in pending_forwards {
@@ -7290,14 +7294,14 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7290
7294
channel_state : Mutex :: new ( ChannelHolder {
7291
7295
by_id,
7292
7296
short_to_chan_info,
7293
- forward_htlcs,
7294
7297
claimable_htlcs,
7295
7298
pending_msg_events : Vec :: new ( ) ,
7296
7299
} ) ,
7297
7300
inbound_payment_key : expanded_inbound_key,
7298
7301
pending_inbound_payments : Mutex :: new ( pending_inbound_payments) ,
7299
7302
pending_outbound_payments : Mutex :: new ( pending_outbound_payments. unwrap ( ) ) ,
7300
7303
7304
+ forward_htlcs : Mutex :: new ( forward_htlcs) ,
7301
7305
outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
7302
7306
id_to_peer : Mutex :: new ( id_to_peer) ,
7303
7307
fake_scid_rand_bytes : fake_scid_rand_bytes. unwrap ( ) ,
0 commit comments