@@ -207,6 +207,24 @@ impl Readable for PaymentId {
207
207
Ok ( PaymentId ( buf) )
208
208
}
209
209
}
210
+
211
+ /// An identifier used to uniquely identify an intercepted HTLC to LDK.
212
+ /// (C-not exported) as we just use [u8; 32] directly
213
+ #[ derive( Hash , Copy , Clone , PartialEq , Eq , Debug ) ]
214
+ pub struct InterceptId ( pub [ u8 ; 32 ] ) ;
215
+
216
+ impl Writeable for InterceptId {
217
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
218
+ self . 0 . write ( w)
219
+ }
220
+ }
221
+
222
+ impl Readable for InterceptId {
223
+ fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
224
+ let buf: [ u8 ; 32 ] = Readable :: read ( r) ?;
225
+ Ok ( InterceptId ( buf) )
226
+ }
227
+ }
210
228
/// Tracks the inbound corresponding to an outbound HTLC
211
229
#[ allow( clippy:: derive_hash_xor_eq) ] // Our Hash is faithful to the data, we just don't have SecretKey::hash
212
230
#[ derive( Clone , PartialEq , Eq ) ]
@@ -751,6 +769,11 @@ pub struct ChannelManager<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
751
769
pub ( super ) forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
752
770
#[ cfg( not( test) ) ]
753
771
forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
772
+ /// Storage for HTLCs that have been intercepted and bubbled up to the user. We hold them here
773
+ /// until the user tells us what we should do with them.
774
+ ///
775
+ /// See `ChannelManager` struct-level documentation for lock order requirements.
776
+ pending_intercepted_htlcs : Mutex < HashMap < InterceptId , PendingAddHTLCInfo > > ,
754
777
755
778
/// Map from payment hash to the payment data and any HTLCs which are to us and can be
756
779
/// failed/claimed by the user.
@@ -1566,6 +1589,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1566
1589
pending_outbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1567
1590
forward_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1568
1591
claimable_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1592
+ pending_intercepted_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1569
1593
id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
1570
1594
short_to_chan_info : FairRwLock :: new ( HashMap :: new ( ) ) ,
1571
1595
@@ -6991,8 +7015,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
6991
7015
_ => { } ,
6992
7016
}
6993
7017
}
7018
+
7019
+ let mut pending_intercepted_htlcs = None ;
7020
+ let our_pending_intercepts = self . pending_intercepted_htlcs . lock ( ) . unwrap ( ) ;
7021
+ if our_pending_intercepts. len ( ) != 0 {
7022
+ pending_intercepted_htlcs = Some ( our_pending_intercepts) ;
7023
+ }
6994
7024
write_tlv_fields ! ( writer, {
6995
7025
( 1 , pending_outbound_payments_no_retry, required) ,
7026
+ ( 2 , pending_intercepted_htlcs, option) ,
6996
7027
( 3 , pending_outbound_payments, required) ,
6997
7028
( 5 , self . our_network_pubkey, required) ,
6998
7029
( 7 , self . fake_scid_rand_bytes, required) ,
@@ -7306,12 +7337,14 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7306
7337
// pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
7307
7338
let mut pending_outbound_payments_no_retry: Option < HashMap < PaymentId , HashSet < [ u8 ; 32 ] > > > = None ;
7308
7339
let mut pending_outbound_payments = None ;
7340
+ let mut pending_intercepted_htlcs: Option < HashMap < InterceptId , PendingAddHTLCInfo > > = Some ( HashMap :: new ( ) ) ;
7309
7341
let mut received_network_pubkey: Option < PublicKey > = None ;
7310
7342
let mut fake_scid_rand_bytes: Option < [ u8 ; 32 ] > = None ;
7311
7343
let mut probing_cookie_secret: Option < [ u8 ; 32 ] > = None ;
7312
7344
let mut claimable_htlc_purposes = None ;
7313
7345
read_tlv_fields ! ( reader, {
7314
7346
( 1 , pending_outbound_payments_no_retry, option) ,
7347
+ ( 2 , pending_intercepted_htlcs, option) ,
7315
7348
( 3 , pending_outbound_payments, option) ,
7316
7349
( 5 , received_network_pubkey, option) ,
7317
7350
( 7 , fake_scid_rand_bytes, option) ,
@@ -7534,6 +7567,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7534
7567
inbound_payment_key : expanded_inbound_key,
7535
7568
pending_inbound_payments : Mutex :: new ( pending_inbound_payments) ,
7536
7569
pending_outbound_payments : Mutex :: new ( pending_outbound_payments. unwrap ( ) ) ,
7570
+ pending_intercepted_htlcs : Mutex :: new ( pending_intercepted_htlcs. unwrap ( ) ) ,
7537
7571
7538
7572
forward_htlcs : Mutex :: new ( forward_htlcs) ,
7539
7573
claimable_htlcs : Mutex :: new ( claimable_htlcs) ,
0 commit comments