Skip to content

Commit e97930f

Browse files
committed
TESTONLY: Supid hacky thing to show that it kinda sorta mostly works
1 parent 89cdc6e commit e97930f

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

lightning/src/ln/channelmanager.rs

+50-2
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ struct PendingInboundPayment {
421421

422422
/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
423423
/// and later, also stores information for retrying the payment.
424+
#[derive(Debug)]
424425
enum PendingOutboundPayment {
425426
Legacy {
426427
session_privs: HashSet<[u8; 32]>,
@@ -443,6 +444,30 @@ enum PendingOutboundPayment {
443444
},
444445
}
445446

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+
446471
impl PendingOutboundPayment {
447472
fn is_retryable(&self) -> bool {
448473
match self {
@@ -5837,10 +5862,11 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
58375862

58385863
// pending_outbound_payments_no_retry is for compatibility with 0.0.101 clients.
58395864
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;
58415867
read_tlv_fields!(reader, {
58425868
(1, pending_outbound_payments_no_retry, option),
5843-
(3, pending_outbound_payments, option),
5869+
(3, pending_outbound_payments_real, option),
58445870
});
58455871
if pending_outbound_payments.is_none() && pending_outbound_payments_no_retry.is_none() {
58465872
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>
58535879
} else {
58545880
// We only rebuild the pending payments map if we were most recently serialized by
58555881
// 0.0.102+
5882+
eprintln!("Monitor count: {}", args.channel_monitors.len());
58565883
for (_, monitor) in args.channel_monitors {
5884+
eprintln!("GOT A MONITOR to check...");
58575885
for (htlc_source, htlc) in monitor.get_pending_htlcs() {
5886+
eprintln!("GOT A PENDING HTLC...");
58585887
if let HTLCSource::OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
58595888
if path.is_empty() { return Err(DecodeError::InvalidValue); }
58605889
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>
58785907
}
58795908
}
58805909
}
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));
58815929
}
58825930

58835931
let mut secp_ctx = Secp256k1::new();

0 commit comments

Comments
 (0)