@@ -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 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 > > ,
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_htlcs : 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
@@ -6876,8 +6898,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable for ChannelMana
6876
6898
_ => { } ,
6877
6899
}
6878
6900
}
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
+ }
6879
6907
write_tlv_fields ! ( writer, {
6880
6908
( 1 , pending_outbound_payments_no_retry, required) ,
6909
+ ( 2 , pending_intercepted_payments, option) ,
6881
6910
( 3 , pending_outbound_payments, required) ,
6882
6911
( 5 , self . our_network_pubkey, required) ,
6883
6912
( 7 , self . fake_scid_rand_bytes, required) ,
@@ -7191,12 +7220,14 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7191
7220
// pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
7192
7221
let mut pending_outbound_payments_no_retry: Option < HashMap < PaymentId , HashSet < [ u8 ; 32 ] > > > = None ;
7193
7222
let mut pending_outbound_payments = None ;
7223
+ let mut pending_intercepted_payments: Option < HashMap < InterceptId , PendingAddHTLCInfo > > = Some ( HashMap :: new ( ) ) ;
7194
7224
let mut received_network_pubkey: Option < PublicKey > = None ;
7195
7225
let mut fake_scid_rand_bytes: Option < [ u8 ; 32 ] > = None ;
7196
7226
let mut probing_cookie_secret: Option < [ u8 ; 32 ] > = None ;
7197
7227
let mut claimable_htlc_purposes = None ;
7198
7228
read_tlv_fields ! ( reader, {
7199
7229
( 1 , pending_outbound_payments_no_retry, option) ,
7230
+ ( 2 , pending_intercepted_payments, option) ,
7200
7231
( 3 , pending_outbound_payments, option) ,
7201
7232
( 5 , received_network_pubkey, option) ,
7202
7233
( 7 , fake_scid_rand_bytes, option) ,
@@ -7412,6 +7443,7 @@ impl<'a, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
7412
7443
inbound_payment_key : expanded_inbound_key,
7413
7444
pending_inbound_payments : Mutex :: new ( pending_inbound_payments) ,
7414
7445
pending_outbound_payments : Mutex :: new ( pending_outbound_payments. unwrap ( ) ) ,
7446
+ pending_intercepted_htlcs : Mutex :: new ( pending_intercepted_payments. unwrap ( ) ) ,
7415
7447
7416
7448
forward_htlcs : Mutex :: new ( forward_htlcs) ,
7417
7449
outbound_scid_aliases : Mutex :: new ( outbound_scid_aliases) ,
0 commit comments