Skip to content

Commit 94d4bc3

Browse files
shaavancodex
andcommitted
[plumb] Add forced async invoice refresh selection
Async receive offers currently decide static invoice refreshes from timer-based freshness only. Channel changes need a separate selector so callers can rebuild server-side invoices without waiting for the normal age threshold. Add a cache helper that returns used and pending offers for forced invoice refresh. Ready offers stay on the existing offer rotation path because they have not been returned to the application yet. AI-assisted: planning and writing commit Co-Authored-By: OpenAI Codex <codex@openai.com>
1 parent 9df5c9d commit 94d4bc3

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

lightning/src/offers/async_receive_offer_cache.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,32 @@ impl AsyncReceiveOfferCache {
469469
})
470470
}
471471

472+
/// Returns cached offers whose static invoices should be refreshed after a local channel change.
473+
pub(super) fn offers_needing_forced_invoice_refresh(
474+
&self,
475+
) -> impl Iterator<Item = (&Offer, Nonce, &Responder)> {
476+
self.offers_with_idx().filter_map(move |(_, offer)| {
477+
let needs_invoice_update = match offer.status {
478+
// Used offers may already be published by the application. Keep their server-side
479+
// invoices aligned with our current channels instead of waiting for the timer
480+
// threshold.
481+
OfferStatus::Used { .. } => true,
482+
// Pending offers have already been sent to the server, but are not confirmed yet.
483+
// Re-sending them is safe and matches the normal timer retry behavior.
484+
OfferStatus::Pending => true,
485+
// Ready offers have not been handed to the application yet. They are rotated by the
486+
// offer-refresh path, so forcing invoice updates for them would mostly create extra
487+
// server churn without helping published offers.
488+
OfferStatus::Ready { .. } => false,
489+
};
490+
if needs_invoice_update {
491+
Some((&offer.offer, offer.offer_nonce, &offer.update_static_invoice_path))
492+
} else {
493+
None
494+
}
495+
})
496+
}
497+
472498
/// Should be called when we receive a [`StaticInvoicePersisted`] message from the static invoice
473499
/// server, which indicates that a new offer was persisted by the server and they are ready to
474500
/// serve the corresponding static invoice to payers on our behalf.

0 commit comments

Comments
 (0)