@@ -424,6 +424,16 @@ pub(super) enum RAACommitmentOrder {
424424 RevokeAndACKFirst ,
425425}
426426
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+
427437// Note this is only exposed in cfg(test):
428438pub ( super ) struct ChannelHolder < Signer : Sign > {
429439 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
699709// |
700710// |__`pending_inbound_payments`
701711// | |
702- // | |__`claimable_htlcs `
712+ // | |__`claimable_payments `
703713// | |
704714// | |__`pending_outbound_payments`
705715// | |
@@ -787,14 +797,11 @@ pub struct ChannelManager<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
787797 /// See `ChannelManager` struct-level documentation for lock order requirements.
788798 pending_intercepted_htlcs : Mutex < HashMap < InterceptId , PendingAddHTLCInfo > > ,
789799
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.
795802 ///
796803 /// See `ChannelManager` struct-level documentation for lock order requirements.
797- claimable_htlcs : Mutex < HashMap < PaymentHash , ( events :: PaymentPurpose , Vec < ClaimableHTLC > ) > > ,
804+ claimable_payments : Mutex < ClaimablePayments > ,
798805
799806 /// The set of outbound SCID aliases across all our channels, including unconfirmed channels
800807 /// 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
16001607 pending_inbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
16011608 pending_outbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
16021609 forward_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1603- claimable_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1610+ claimable_payments : Mutex :: new ( ClaimablePayments { claimable_htlcs : HashMap :: new ( ) } ) ,
16041611 pending_intercepted_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
16051612 id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
16061613 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
34833490 payment_secret: $payment_data. payment_secret,
34843491 }
34853492 } ;
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)
34883495 . or_insert_with( || ( purpose( ) , Vec :: new( ) ) ) ;
34893496 if htlcs. len( ) == 1 {
34903497 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
35563563 check_total_value ! ( payment_data, payment_preimage) ;
35573564 } ,
35583565 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) {
35603567 hash_map:: Entry :: Vacant ( e) => {
35613568 let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
35623569 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
38513858 } ) ;
38523859 }
38533860
3854- self . claimable_htlcs . lock ( ) . unwrap ( ) . retain ( |payment_hash, ( _, htlcs) | {
3861+ self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . retain ( |payment_hash, ( _, htlcs) | {
38553862 if htlcs. is_empty ( ) {
38563863 // This should be unreachable
38573864 debug_assert ! ( false ) ;
@@ -3906,7 +3913,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
39063913 pub fn fail_htlc_backwards ( & self , payment_hash : & PaymentHash ) {
39073914 let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
39083915
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) ;
39103917 if let Some ( ( _, mut sources) ) = removed_source {
39113918 for htlc in sources. drain ( ..) {
39123919 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
42084215
42094216 let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
42104217
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) ;
42124219 if let Some ( ( payment_purpose, mut sources) ) = removed_source {
42134220 assert ! ( !sources. is_empty( ) ) ;
42144221
@@ -6280,7 +6287,7 @@ where
62806287 }
62816288
62826289 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) | {
62846291 htlcs. retain ( |htlc| {
62856292 // If height is approaching the number of blocks we think it takes us to get
62866293 // 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
71457152 }
71467153
71477154 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 ( ) ;
71497156 let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
71507157
71517158 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 ( ) {
71547161 payment_hash. write ( writer) ?;
71557162 ( previous_hops. len ( ) as u64 ) . write ( writer) ?;
71567163 for htlc in previous_hops. iter ( ) {
@@ -7827,7 +7834,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
78277834 pending_intercepted_htlcs : Mutex :: new ( pending_intercepted_htlcs. unwrap ( ) ) ,
78287835
78297836 forward_htlcs : Mutex :: new ( forward_htlcs) ,
7830- claimable_htlcs : Mutex :: new ( claimable_htlcs) ,
7837+ claimable_payments : Mutex :: new ( ClaimablePayments { claimable_htlcs } ) ,
78317838 outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
78327839 id_to_peer : Mutex :: new ( id_to_peer) ,
78337840 short_to_chan_info : FairRwLock :: new ( short_to_chan_info) ,
0 commit comments