@@ -421,6 +421,7 @@ struct PendingInboundPayment {
421
421
422
422
/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
423
423
/// and later, also stores information for retrying the payment.
424
+ #[ derive( Debug ) ]
424
425
enum PendingOutboundPayment {
425
426
Legacy {
426
427
session_privs : HashSet < [ u8 ; 32 ] > ,
@@ -443,6 +444,30 @@ enum PendingOutboundPayment {
443
444
} ,
444
445
}
445
446
447
+ // Manually implement to ignore starting_block_height since regenerating the map will always wipe
448
+ // that and we don't consider that a failure.
449
+ impl PartialEq for PendingOutboundPayment {
450
+ fn eq ( & self , o : & Self ) -> bool {
451
+ match self {
452
+ PendingOutboundPayment :: Legacy { session_privs } => {
453
+ if let PendingOutboundPayment :: Legacy { session_privs : o_sp } = o {
454
+ o_sp == session_privs
455
+ } else { false }
456
+ } ,
457
+ PendingOutboundPayment :: Retryable { session_privs, payment_hash, payment_secret, pending_amt_msat, total_msat, .. } => {
458
+ if let PendingOutboundPayment :: Retryable { session_privs : o_sp, payment_hash : o_ph, payment_secret : o_ps, pending_amt_msat : o_pam, total_msat : o_tm, .. } = o {
459
+ o_sp == session_privs && payment_hash == o_ph && payment_secret == o_ps && pending_amt_msat == o_pam && total_msat == o_tm
460
+ } else { false }
461
+ } ,
462
+ PendingOutboundPayment :: Completed { session_privs } => {
463
+ if let PendingOutboundPayment :: Completed { session_privs : o_sp } = o {
464
+ o_sp == session_privs
465
+ } else { false }
466
+ }
467
+ }
468
+ }
469
+ }
470
+
446
471
impl PendingOutboundPayment {
447
472
fn is_retryable ( & self ) -> bool {
448
473
match self {
@@ -5837,10 +5862,11 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5837
5862
5838
5863
// pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
5839
5864
let mut pending_outbound_payments_no_retry: Option < HashMap < PaymentId , HashSet < [ u8 ; 32 ] > > > = None ;
5840
- let mut pending_outbound_payments = None ;
5865
+ let mut pending_outbound_payments: Option < HashMap < PaymentId , PendingOutboundPayment > > = Some ( HashMap :: new ( ) ) ;
5866
+ let mut pending_outbound_payments_real: Option < HashMap < PaymentId , PendingOutboundPayment > > = None ;
5841
5867
read_tlv_fields ! ( reader, {
5842
5868
( 1 , pending_outbound_payments_no_retry, option) ,
5843
- ( 3 , pending_outbound_payments , option) ,
5869
+ ( 3 , pending_outbound_payments_real , option) ,
5844
5870
} ) ;
5845
5871
if pending_outbound_payments. is_none ( ) && pending_outbound_payments_no_retry. is_none ( ) {
5846
5872
pending_outbound_payments = Some ( pending_outbound_payments_compat) ;
@@ -5853,8 +5879,11 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5853
5879
} else {
5854
5880
// We only rebuild the pending payments map if we were most recently serialized by
5855
5881
// 0.0.102+
5882
+ eprintln ! ( "Monitor count: {}" , args. channel_monitors. len( ) ) ;
5856
5883
for ( _, monitor) in args. channel_monitors {
5884
+ eprintln ! ( "GOT A MONITOR to check..." ) ;
5857
5885
for ( htlc_source, htlc) in monitor. get_pending_htlcs ( ) {
5886
+ eprintln ! ( "GOT A PENDING HTLC..." ) ;
5858
5887
if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
5859
5888
if path. is_empty ( ) { return Err ( DecodeError :: InvalidValue ) ; }
5860
5889
let path_amt = path. last ( ) . unwrap ( ) . fee_msat ;
@@ -5878,6 +5907,25 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5878
5907
}
5879
5908
}
5880
5909
}
5910
+ let mut cmper = HashMap :: new ( ) ;
5911
+ for ( key, entr) in pending_outbound_payments_real. unwrap ( ) . drain ( ) {
5912
+ match entr {
5913
+ PendingOutboundPayment :: Retryable { session_privs, .. } if session_privs. is_empty ( ) => {
5914
+ } ,
5915
+ PendingOutboundPayment :: Completed { session_privs } => {
5916
+ // If something completed, we'll reload it as retryable with full-value pending - we
5917
+ // should get a second fulfill, or something, I dunno we don't handle this really.
5918
+ assert ! ( !session_privs. is_empty( ) ) ;
5919
+ let e = pending_outbound_payments. as_mut ( ) . unwrap ( ) . remove ( & key) ;
5920
+ assert ! ( e. is_some( ) ) ;
5921
+ if let PendingOutboundPayment :: Retryable { session_privs : o_sp, .. } = e. unwrap ( ) {
5922
+ assert_eq ! ( session_privs, o_sp) ;
5923
+ }
5924
+ } ,
5925
+ _ => { cmper. insert ( key, entr) ; }
5926
+ }
5927
+ }
5928
+ assert_eq ! ( pending_outbound_payments, Some ( cmper) ) ;
5881
5929
}
5882
5930
5883
5931
let mut secp_ctx = Secp256k1 :: new ( ) ;
0 commit comments