You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove pending_inbound_payments map from ChannelManager
LDK versions prior to 0.0.104 had stateful inbound payments written in this
map. In 0.0.104, we added support for stateless inbound payments with
deterministically generated payment secrets, and maintained deprecated support
for stateful inbound payments until 0.0.116. After 0.0.116, no further inbound
payments could have been written into this map.
// that we are the ultimate recipient of the given payment hash.
5897
5887
// Further, we must not expose whether we have any other HTLCs
5898
5888
// associated with the same payment_hash pending or not.
5899
-
let mut payment_secrets = self.pending_inbound_payments.lock().unwrap();
5900
-
match payment_secrets.entry(payment_hash) {
5901
-
hash_map::Entry::Vacant(_) => {
5902
-
match claimable_htlc.onion_payload {
5903
-
OnionPayload::Invoice { .. } => {
5904
-
let payment_data = payment_data.unwrap();
5905
-
let (payment_preimage, min_final_cltv_expiry_delta) = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
5906
-
Ok(result) => result,
5907
-
Err(()) => {
5908
-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
5909
-
fail_htlc!(claimable_htlc, payment_hash);
5910
-
}
5911
-
};
5912
-
if let Some(min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
5913
-
let expected_min_expiry_height = (self.current_best_block().height + min_final_cltv_expiry_delta as u32) as u64;
5914
-
if (cltv_expiry as u64) < expected_min_expiry_height {
5915
-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as its CLTV expiry was too soon (had {}, earliest expected {})",
let purpose = events::PaymentPurpose::SpontaneousPayment(preimage);
5929
-
check_total_value!(purpose);
5930
-
}
5931
-
}
5932
-
},
5933
-
hash_map::Entry::Occupied(inbound_payment) => {
5934
-
if let OnionPayload::Spontaneous(_) = claimable_htlc.onion_payload {
5935
-
log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash", &payment_hash);
5936
-
fail_htlc!(claimable_htlc, payment_hash);
5937
-
}
5889
+
match claimable_htlc.onion_payload {
5890
+
OnionPayload::Invoice { .. } => {
5938
5891
let payment_data = payment_data.unwrap();
5939
-
if inbound_payment.get().payment_secret != payment_data.payment_secret {
5940
-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret.", &payment_hash);
5941
-
fail_htlc!(claimable_htlc, payment_hash);
5942
-
} else if inbound_payment.get().min_value_msat.is_some() && payment_data.total_msat < inbound_payment.get().min_value_msat.unwrap() {
5943
-
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as it didn't match our minimum value (had {}, needed {}).",
let payment_claimable_generated = check_total_value!(purpose);
5953
-
if payment_claimable_generated {
5954
-
inbound_payment.remove_entry();
5892
+
let (payment_preimage, min_final_cltv_expiry_delta) = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
5893
+
Ok(result) => result,
5894
+
Err(()) => {
5895
+
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as payment verification failed", &payment_hash);
5896
+
fail_htlc!(claimable_htlc, payment_hash);
5897
+
}
5898
+
};
5899
+
if let Some(min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
5900
+
let expected_min_expiry_height = (self.current_best_block().height + min_final_cltv_expiry_delta as u32) as u64;
5901
+
if (cltv_expiry as u64) < expected_min_expiry_height {
5902
+
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as its CLTV expiry was too soon (had {}, earliest expected {})",
let pending_inbound_payments = self.pending_inbound_payments.lock().unwrap();
11877
11832
let claimable_payments = self.claimable_payments.lock().unwrap();
11878
11833
let pending_outbound_payments = self.pending_outbound_payments.pending_outbound_payments.lock().unwrap();
11879
11834
@@ -11945,11 +11900,10 @@ where
11945
11900
(self.highest_seen_timestamp.load(Ordering::Acquire) as u32).write(writer)?;
11946
11901
(self.highest_seen_timestamp.load(Ordering::Acquire) as u32).write(writer)?;
11947
11902
11948
-
(pending_inbound_payments.len() as u64).write(writer)?;
11949
-
for (hash, pending_payment) in pending_inbound_payments.iter() {
11950
-
hash.write(writer)?;
11951
-
pending_payment.write(writer)?;
11952
-
}
11903
+
// LDK versions prior to 0.0.104 wrote `pending_inbound_payments` here, with deprecated support
11904
+
// for stateful inbound payments maintained until 0.0.116, after which no further inbound
11905
+
// payments could have been written here.
11906
+
(0 as u64).write(writer)?;
11953
11907
11954
11908
// For backwards compat, write the session privs and their total length.
11955
11909
let mut num_pending_outbounds_compat: u64 = 0;
@@ -12463,12 +12417,13 @@ where
12463
12417
let _last_node_announcement_serial: u32 = Readable::read(reader)?; // Only used < 0.0.111
12464
12418
let highest_seen_timestamp: u32 = Readable::read(reader)?;
12465
12419
12420
+
// The last version where a pending inbound payment may have been added was 0.0.116.
12466
12421
let pending_inbound_payment_count: u64 = Readable::read(reader)?;
12467
-
let mut pending_inbound_payments: HashMap<PaymentHash, PendingInboundPayment> = hash_map_with_capacity(cmp::min(pending_inbound_payment_count as usize, MAX_ALLOC_SIZE/(3*32)));
12468
12422
for _ in 0..pending_inbound_payment_count {
12469
-
if pending_inbound_payments.insert(Readable::read(reader)?, Readable::read(reader)?).is_some() {
12470
-
return Err(DecodeError::InvalidValue);
12471
-
}
12423
+
let payment_hash: PaymentHash = Readable::read(reader)?;
12424
+
let logger = WithContext::from(&args.logger, None, None, Some(payment_hash));
12425
+
let inbound: PendingInboundPayment = Readable::read(reader)?;
log_error!(args.logger, "Failed to read claimable payment data for HTLC with payment hash {} - was not a pending inbound payment and didn't match our payment key", &payment_hash);
0 commit comments