@@ -424,6 +424,16 @@ pub(super) enum RAACommitmentOrder {
424
424
RevokeAndACKFirst ,
425
425
}
426
426
427
+ /// Information about claimable or being-claimed payments
428
+ struct ClaimablePayments {
429
+ /// Map from payment hash to the payment data and any HTLCs which are to us and can be
430
+ /// failed/claimed by the user.
431
+ ///
432
+ /// Note that, no consistency guarantees are made about the channels given here actually
433
+ /// existing anymore by the time you go to read them!
434
+ claimable_htlcs : HashMap < PaymentHash , ( events:: PaymentPurpose , Vec < ClaimableHTLC > ) > ,
435
+ }
436
+
427
437
// Note this is only exposed in cfg(test):
428
438
pub ( super ) struct ChannelHolder < Signer : Sign > {
429
439
pub ( super ) by_id : HashMap < [ u8 ; 32 ] , Channel < Signer > > ,
@@ -699,7 +709,7 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
699
709
// |
700
710
// |__`pending_inbound_payments`
701
711
// | |
702
- // | |__`claimable_htlcs `
712
+ // | |__`claimable_payments `
703
713
// | |
704
714
// | |__`pending_outbound_payments`
705
715
// | |
@@ -787,14 +797,11 @@ pub struct ChannelManager<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
787
797
/// See `ChannelManager` struct-level documentation for lock order requirements.
788
798
pending_intercepted_htlcs : Mutex < HashMap < InterceptId , PendingAddHTLCInfo > > ,
789
799
790
- /// Map from payment hash to the payment data and any HTLCs which are to us and can be
791
- /// failed/claimed by the user.
792
- ///
793
- /// Note that, no consistency guarantees are made about the channels given here actually
794
- /// existing anymore by the time you go to read them!
800
+ /// The sets of payments which are claimable or currently being claimed. See
801
+ /// [`ClaimablePayments`]' individual field docs for more info.
795
802
///
796
803
/// See `ChannelManager` struct-level documentation for lock order requirements.
797
- claimable_htlcs : Mutex < HashMap < PaymentHash , ( events :: PaymentPurpose , Vec < ClaimableHTLC > ) > > ,
804
+ claimable_payments : Mutex < ClaimablePayments > ,
798
805
799
806
/// The set of outbound SCID aliases across all our channels, including unconfirmed channels
800
807
/// and some closed channels which reached a usable state prior to being closed. This is used
@@ -1600,7 +1607,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1600
1607
pending_inbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1601
1608
pending_outbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1602
1609
forward_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1603
- claimable_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1610
+ claimable_payments : Mutex :: new ( ClaimablePayments { claimable_htlcs : HashMap :: new ( ) } ) ,
1604
1611
pending_intercepted_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1605
1612
id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
1606
1613
short_to_chan_info : FairRwLock :: new ( HashMap :: new ( ) ) ,
@@ -3483,8 +3490,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3483
3490
payment_secret: $payment_data. payment_secret,
3484
3491
}
3485
3492
} ;
3486
- let mut claimable_htlcs = self . claimable_htlcs . lock( ) . unwrap( ) ;
3487
- let ( _, htlcs) = claimable_htlcs. entry( payment_hash)
3493
+ let mut claimable_payments = self . claimable_payments . lock( ) . unwrap( ) ;
3494
+ let ( _, htlcs) = claimable_payments . claimable_htlcs. entry( payment_hash)
3488
3495
. or_insert_with( || ( purpose( ) , Vec :: new( ) ) ) ;
3489
3496
if htlcs. len( ) == 1 {
3490
3497
if let OnionPayload :: Spontaneous ( _) = htlcs[ 0 ] . onion_payload {
@@ -3556,7 +3563,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3556
3563
check_total_value ! ( payment_data, payment_preimage) ;
3557
3564
} ,
3558
3565
OnionPayload :: Spontaneous ( preimage) => {
3559
- match self . claimable_htlcs . lock ( ) . unwrap ( ) . entry ( payment_hash) {
3566
+ match self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . entry ( payment_hash) {
3560
3567
hash_map:: Entry :: Vacant ( e) => {
3561
3568
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3562
3569
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
@@ -3851,7 +3858,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3851
3858
} ) ;
3852
3859
}
3853
3860
3854
- self . claimable_htlcs . lock ( ) . unwrap ( ) . retain ( |payment_hash, ( _, htlcs) | {
3861
+ self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . retain ( |payment_hash, ( _, htlcs) | {
3855
3862
if htlcs. is_empty ( ) {
3856
3863
// This should be unreachable
3857
3864
debug_assert ! ( false ) ;
@@ -3906,7 +3913,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3906
3913
pub fn fail_htlc_backwards ( & self , payment_hash : & PaymentHash ) {
3907
3914
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3908
3915
3909
- let removed_source = self . claimable_htlcs . lock ( ) . unwrap ( ) . remove ( payment_hash) ;
3916
+ let removed_source = self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . remove ( payment_hash) ;
3910
3917
if let Some ( ( _, mut sources) ) = removed_source {
3911
3918
for htlc in sources. drain ( ..) {
3912
3919
let mut htlc_msat_height_data = htlc. value . to_be_bytes ( ) . to_vec ( ) ;
@@ -4208,7 +4215,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4208
4215
4209
4216
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
4210
4217
4211
- let removed_source = self . claimable_htlcs . lock ( ) . unwrap ( ) . remove ( & payment_hash) ;
4218
+ let removed_source = self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . remove ( & payment_hash) ;
4212
4219
if let Some ( ( payment_purpose, mut sources) ) = removed_source {
4213
4220
assert ! ( !sources. is_empty( ) ) ;
4214
4221
@@ -6280,7 +6287,7 @@ where
6280
6287
}
6281
6288
6282
6289
if let Some ( height) = height_opt {
6283
- self . claimable_htlcs . lock ( ) . unwrap ( ) . retain ( |payment_hash, ( _, htlcs) | {
6290
+ self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . retain ( |payment_hash, ( _, htlcs) | {
6284
6291
htlcs. retain ( |htlc| {
6285
6292
// If height is approaching the number of blocks we think it takes us to get
6286
6293
// our commitment transaction confirmed before the HTLC expires, plus the
@@ -7145,12 +7152,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
7145
7152
}
7146
7153
7147
7154
let pending_inbound_payments = self . pending_inbound_payments . lock ( ) . unwrap ( ) ;
7148
- let claimable_htlcs = self . claimable_htlcs . lock ( ) . unwrap ( ) ;
7155
+ let claimable_payments = self . claimable_payments . lock ( ) . unwrap ( ) ;
7149
7156
let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
7150
7157
7151
7158
let mut htlc_purposes: Vec < & events:: PaymentPurpose > = Vec :: new ( ) ;
7152
- ( claimable_htlcs. len ( ) as u64 ) . write ( writer) ?;
7153
- for ( payment_hash, ( purpose, previous_hops) ) in claimable_htlcs. iter ( ) {
7159
+ ( claimable_payments . claimable_htlcs . len ( ) as u64 ) . write ( writer) ?;
7160
+ for ( payment_hash, ( purpose, previous_hops) ) in claimable_payments . claimable_htlcs . iter ( ) {
7154
7161
payment_hash. write ( writer) ?;
7155
7162
( previous_hops. len ( ) as u64 ) . write ( writer) ?;
7156
7163
for htlc in previous_hops. iter ( ) {
@@ -7827,7 +7834,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7827
7834
pending_intercepted_htlcs : Mutex :: new ( pending_intercepted_htlcs. unwrap ( ) ) ,
7828
7835
7829
7836
forward_htlcs : Mutex :: new ( forward_htlcs) ,
7830
- claimable_htlcs : Mutex :: new ( claimable_htlcs) ,
7837
+ claimable_payments : Mutex :: new ( ClaimablePayments { claimable_htlcs } ) ,
7831
7838
outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
7832
7839
id_to_peer : Mutex :: new ( id_to_peer) ,
7833
7840
short_to_chan_info : FairRwLock :: new ( short_to_chan_info) ,
0 commit comments