@@ -206,6 +206,24 @@ impl Readable for PaymentId {
206
206
Ok ( PaymentId ( buf) )
207
207
}
208
208
}
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
+ }
209
227
/// Tracks the inbound corresponding to an outbound HTLC
210
228
#[ allow( clippy:: derive_hash_xor_eq) ] // Our Hash is faithful to the data, we just don't have SecretKey::hash
211
229
#[ derive( Clone , PartialEq , Eq ) ]
@@ -755,6 +773,9 @@ pub struct ChannelManager<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
755
773
pub ( super ) forward_htlcs : Mutex < HashMap < u64 , Vec < HTLCForwardInfo > > > ,
756
774
#[ cfg( not( test) ) ]
757
775
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 > > ,
758
779
759
780
/// The set of outbound SCID aliases across all our channels, including unconfirmed channels
760
781
/// 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
1667
1688
pending_inbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1668
1689
pending_outbound_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1669
1690
forward_htlcs : Mutex :: new ( HashMap :: new ( ) ) ,
1691
+ pending_intercepted_payments : Mutex :: new ( HashMap :: new ( ) ) ,
1670
1692
id_to_peer : Mutex :: new ( HashMap :: new ( ) ) ,
1671
1693
short_to_chan_info : FairRwLock :: new ( HashMap :: new ( ) ) ,
1672
1694
@@ -6878,8 +6900,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
6878
6900
_ => { } ,
6879
6901
}
6880
6902
}
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
+ }
6881
6909
write_tlv_fields ! ( writer, {
6882
6910
( 1 , pending_outbound_payments_no_retry, required) ,
6911
+ ( 2 , pending_intercepted_payments, option) ,
6883
6912
( 3 , pending_outbound_payments, required) ,
6884
6913
( 5 , self . our_network_pubkey, required) ,
6885
6914
( 7 , self . fake_scid_rand_bytes, required) ,
@@ -7193,12 +7222,14 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7193
7222
// pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
7194
7223
let mut pending_outbound_payments_no_retry: Option < HashMap < PaymentId , HashSet < [ u8 ; 32 ] > > > = None ;
7195
7224
let mut pending_outbound_payments = None ;
7225
+ let mut pending_intercepted_payments: Option < HashMap < InterceptId , PendingAddHTLCInfo > > = Some ( HashMap :: new ( ) ) ;
7196
7226
let mut received_network_pubkey: Option < PublicKey > = None ;
7197
7227
let mut fake_scid_rand_bytes: Option < [ u8 ; 32 ] > = None ;
7198
7228
let mut probing_cookie_secret: Option < [ u8 ; 32 ] > = None ;
7199
7229
let mut claimable_htlc_purposes = None ;
7200
7230
read_tlv_fields ! ( reader, {
7201
7231
( 1 , pending_outbound_payments_no_retry, option) ,
7232
+ ( 2 , pending_intercepted_payments, option) ,
7202
7233
( 3 , pending_outbound_payments, option) ,
7203
7234
( 5 , received_network_pubkey, option) ,
7204
7235
( 7 , fake_scid_rand_bytes, option) ,
@@ -7414,6 +7445,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7414
7445
inbound_payment_key : expanded_inbound_key,
7415
7446
pending_inbound_payments : Mutex :: new ( pending_inbound_payments) ,
7416
7447
pending_outbound_payments : Mutex :: new ( pending_outbound_payments. unwrap ( ) ) ,
7448
+ pending_intercepted_payments : Mutex :: new ( pending_intercepted_payments. unwrap ( ) ) ,
7417
7449
7418
7450
forward_htlcs : Mutex :: new ( forward_htlcs) ,
7419
7451
outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
0 commit comments