@@ -206,6 +206,24 @@ impl Readable for PaymentId {
206206 Ok ( PaymentId ( buf) )
207207 }
208208}
209+
210+ /// An identifier used to uniquely identify an intercepted HTLC to LDK.
211+ /// (C-not exported) as we just use [u8; 32] directly
212+ #[ derive( Hash , Copy , Clone , PartialEq , Eq , Debug ) ]
213+ pub struct InterceptId ( pub [ u8 ; 32 ] ) ;
214+
215+ impl Writeable for InterceptId {
216+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
217+ self . 0 . write ( w)
218+ }
219+ }
220+
221+ impl Readable for InterceptId {
222+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
223+ let buf: [ u8 ; 32 ] = Readable :: read ( r) ?;
224+ Ok ( InterceptId ( buf) )
225+ }
226+ }
209227/// Tracks the inbound corresponding to an outbound HTLC
210228#[ allow( clippy:: derive_hash_xor_eq) ] // Our Hash is faithful to the data, we just don't have SecretKey::hash
211229#[ derive( Clone , PartialEq , Eq ) ]
@@ -755,6 +773,9 @@ pub struct ChannelManager<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
755773 pub ( super ) forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
756774 #[ cfg( not( test) ) ]
757775 forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
776+ /// Storage for HTLCs that have been intercepted and bubbled up to the user. We hold them here
777+ /// until the user tells us what we should to with them.
778+ pending_intercepted_htlcs : Mutex < HashMap < InterceptId , PendingAddHTLCInfo > > ,
758779
759780 /// The set of outbound SCID aliases across all our channels, including unconfirmed channels
760781 /// and some closed channels which reached a usable state prior to being closed. This is used
@@ -1667,6 +1688,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
16671688 pending_inbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
16681689 pending_outbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
16691690 forward_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1691+ pending_intercepted_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
16701692 id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
16711693 short_to_chan_info : FairRwLock :: new ( HashMap :: new ( ) ) ,
16721694
@@ -6876,8 +6898,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
68766898 _ => { } ,
68776899 }
68786900 }
6901+
6902+ let mut pending_intercepted_payments = None ;
6903+ let our_pending_intercepts = self . pending_intercepted_htlcs . lock ( ) . unwrap ( ) ;
6904+ if our_pending_intercepts. len ( ) != 0 {
6905+ pending_intercepted_payments = Some ( our_pending_intercepts) ;
6906+ }
68796907 write_tlv_fields ! ( writer, {
68806908 ( 1 , pending_outbound_payments_no_retry, required) ,
6909+ ( 2 , pending_intercepted_payments, option) ,
68816910 ( 3 , pending_outbound_payments, required) ,
68826911 ( 5 , self . our_network_pubkey, required) ,
68836912 ( 7 , self . fake_scid_rand_bytes, required) ,
@@ -7191,12 +7220,14 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
71917220 // pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
71927221 let mut pending_outbound_payments_no_retry: Option < HashMap < PaymentId , HashSet < [ u8 ; 32 ] > > > = None ;
71937222 let mut pending_outbound_payments = None ;
7223+ let mut pending_intercepted_payments: Option < HashMap < InterceptId , PendingAddHTLCInfo > > = Some ( HashMap :: new ( ) ) ;
71947224 let mut received_network_pubkey: Option < PublicKey > = None ;
71957225 let mut fake_scid_rand_bytes: Option < [ u8 ; 32 ] > = None ;
71967226 let mut probing_cookie_secret: Option < [ u8 ; 32 ] > = None ;
71977227 let mut claimable_htlc_purposes = None ;
71987228 read_tlv_fields ! ( reader, {
71997229 ( 1 , pending_outbound_payments_no_retry, option) ,
7230+ ( 2 , pending_intercepted_payments, option) ,
72007231 ( 3 , pending_outbound_payments, option) ,
72017232 ( 5 , received_network_pubkey, option) ,
72027233 ( 7 , fake_scid_rand_bytes, option) ,
@@ -7412,6 +7443,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
74127443 inbound_payment_key : expanded_inbound_key,
74137444 pending_inbound_payments : Mutex :: new ( pending_inbound_payments) ,
74147445 pending_outbound_payments : Mutex :: new ( pending_outbound_payments. unwrap ( ) ) ,
7446+ pending_intercepted_htlcs : Mutex :: new ( pending_intercepted_payments. unwrap ( ) ) ,
74157447
74167448 forward_htlcs : Mutex :: new ( forward_htlcs) ,
74177449 outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
0 commit comments