@@ -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 PendingInterceptedHTLCs that have been intercepted and bubbled up to the user. We
777+ /// hold them here until the user tells us what we should to with them.
778+ pending_intercepted_payments : 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_payments : Mutex :: new ( HashMap :: new ( ) ) ,
16701692 id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
16711693 short_to_chan_info : FairRwLock :: new ( HashMap :: new ( ) ) ,
16721694
@@ -6878,8 +6900,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
68786900 _ => { } ,
68796901 }
68806902 }
6903+
6904+ let mut pending_intercepted_payments = None ;
6905+ let our_pending_intercepts = self . pending_intercepted_payments . lock ( ) . unwrap ( ) ;
6906+ if our_pending_intercepts. len ( ) != 0 {
6907+ pending_intercepted_payments = Some ( our_pending_intercepts) ;
6908+ }
68816909 write_tlv_fields ! ( writer, {
68826910 ( 1 , pending_outbound_payments_no_retry, required) ,
6911+ ( 2 , pending_intercepted_payments, option) ,
68836912 ( 3 , pending_outbound_payments, required) ,
68846913 ( 5 , self . our_network_pubkey, required) ,
68856914 ( 7 , self . fake_scid_rand_bytes, required) ,
@@ -7193,12 +7222,14 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
71937222 // pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
71947223 let mut pending_outbound_payments_no_retry: Option < HashMap < PaymentId , HashSet < [ u8 ; 32 ] > > > = None ;
71957224 let mut pending_outbound_payments = None ;
7225+ let mut pending_intercepted_payments: Option < HashMap < InterceptId , PendingAddHTLCInfo > > = Some ( HashMap :: new ( ) ) ;
71967226 let mut received_network_pubkey: Option < PublicKey > = None ;
71977227 let mut fake_scid_rand_bytes: Option < [ u8 ; 32 ] > = None ;
71987228 let mut probing_cookie_secret: Option < [ u8 ; 32 ] > = None ;
71997229 let mut claimable_htlc_purposes = None ;
72007230 read_tlv_fields ! ( reader, {
72017231 ( 1 , pending_outbound_payments_no_retry, option) ,
7232+ ( 2 , pending_intercepted_payments, option) ,
72027233 ( 3 , pending_outbound_payments, option) ,
72037234 ( 5 , received_network_pubkey, option) ,
72047235 ( 7 , fake_scid_rand_bytes, option) ,
@@ -7414,6 +7445,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
74147445 inbound_payment_key : expanded_inbound_key,
74157446 pending_inbound_payments : Mutex :: new ( pending_inbound_payments) ,
74167447 pending_outbound_payments : Mutex :: new ( pending_outbound_payments. unwrap ( ) ) ,
7448+ pending_intercepted_payments : Mutex :: new ( pending_intercepted_payments. unwrap ( ) ) ,
74177449
74187450 forward_htlcs : Mutex :: new ( forward_htlcs) ,
74197451 outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
0 commit comments