Skip to content

Commit 79b9ee8

Browse files
committed
f simpler expiry check + test
1 parent 7f5c6bd commit 79b9ee8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lightning-invoice/src/payment.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ where
253253
) -> Result<PaymentId, PaymentError> {
254254
debug_assert!(invoice.amount_milli_satoshis().is_some() ^ amount_msats.is_some());
255255
let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
256+
if invoice.is_expired() {
257+
log_trace!(self.logger, "Invoice expired prior to first send for payment {}", log_bytes!(payment_hash.0));
258+
return Err(PaymentError::Invoice("Invoice expired prior to send"));
259+
}
256260
let retry_data_payment_id = loop {
257261
let mut payment_cache = self.payment_cache.lock().unwrap();
258262
match payment_cache.entry(payment_hash) {
@@ -269,10 +273,6 @@ where
269273
final_value_msat: invoice.amount_milli_satoshis().or(amount_msats).unwrap(),
270274
final_cltv_expiry_delta: invoice.min_final_cltv_expiry() as u32,
271275
};
272-
if has_expired(&params) {
273-
log_trace!(self.logger, "Invoice expired prior to first send for payment {}", log_bytes!(payment_hash.0));
274-
return Err(PaymentError::Invoice("Invoice expired prior to send"));
275-
}
276276
let first_hops = self.payer.first_hops();
277277
let route = self.router.find_route(
278278
&payer,
@@ -752,7 +752,6 @@ mod tests {
752752
let payment_preimage = PaymentPreimage([1; 32]);
753753
let invoice = invoice(payment_preimage);
754754
let payment_id = Some(invoice_payer.pay_invoice(&invoice).unwrap());
755-
std::thread::sleep(Duration::from_secs(4));
756755
assert_eq!(*payer.attempts.borrow(), 1);
757756

758757
let mut retry_data = TestRouter::retry_for_invoice(&invoice);

0 commit comments

Comments
 (0)