Skip to content

Commit b30e063

Browse files
committed
plugins/fetchinvoice: allow use of expired offers *for recurrence*.
We added this to the recurrence spec: the offer expiration only applies to the first request, not subsequent ones. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 559e3fc commit b30e063

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

plugins/fetchinvoice.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,16 @@ struct command_result *json_fetchinvoice(struct command *cmd,
863863
* - if the current time is after `offer_absolute_expiry`:
864864
* - MUST NOT respond to the offer.
865865
*/
866+
/* BOLT-recurrence #12:
867+
* - if the current time is after `offer_absolute_expiry`:
868+
* - MUST NOT make an initial response to the offer
869+
* (i.e. continuing an existing offer with recurrence is ok)
870+
*/
866871
if (sent->offer->offer_absolute_expiry
867-
&& time_now().ts.tv_sec > *sent->offer->offer_absolute_expiry)
872+
&& time_now().ts.tv_sec > *sent->offer->offer_absolute_expiry
873+
&& (!recurrence_counter || *recurrence_counter == 0)) {
868874
return command_fail(cmd, OFFER_EXPIRED, "Offer expired");
875+
}
869876

870877
/* BOLT #12:
871878
* The writer:

plugins/offers_invreq_hook.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,16 @@ static struct command_result *listoffers_done(struct command *cmd,
848848
json_tok_full(buf, offertok));
849849
}
850850

851+
/* BOLT-recurrence #12:
852+
* - if `offer_absolute_expiry` is present, and
853+
* `invreq_recurrence_counter` is either not present or equal to 0:
854+
* - MUST reject the invoice request if the current time is after
855+
* `offer_absolute_expiry`.
856+
*/
851857
if (ir->invreq->offer_absolute_expiry
858+
&& (!ir->invreq->invreq_recurrence_counter
859+
|| *ir->invreq->invreq_recurrence_counter == 0)
852860
&& time_now().ts.tv_sec >= *ir->invreq->offer_absolute_expiry) {
853-
/* FIXME: do deloffer to disable it */
854861
return fail_invreq(cmd, ir, "Offer expired");
855862
}
856863

tests/test_pay.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,6 +4725,26 @@ def test_fetchinvoice_recurrence(node_factory, bitcoind):
47254725
'recurrence_label': 'test paywindow'})
47264726

47274727

4728+
def test_recurrence_expired_offer(node_factory, bitcoind):
4729+
"""We *can* use an expired offer for successive recurrences"""
4730+
l1, l2 = node_factory.line_graph(2)
4731+
4732+
offer = l2.rpc.offer(amount='1msat',
4733+
description='paywindow test',
4734+
recurrence='20seconds',
4735+
absolute_expiry=int(time.time()) + 15)
4736+
ret = l1.rpc.fetchinvoice(offer=offer['bolt12'],
4737+
recurrence_counter=0,
4738+
recurrence_label='test_recurrence_expired_offer')
4739+
l1.rpc.pay(ret['invoice'], label='test_recurrence_expired_offer')
4740+
4741+
time.sleep(16)
4742+
ret = l1.rpc.fetchinvoice(offer=offer['bolt12'],
4743+
recurrence_counter=1,
4744+
recurrence_label='test_recurrence_expired_offer')
4745+
l1.rpc.pay(ret['invoice'], label='test_recurrence_expired_offer')
4746+
4747+
47284748
def test_fetchinvoice_autoconnect(node_factory, bitcoind):
47294749
"""We should autoconnect if we need to, to route."""
47304750

0 commit comments

Comments
 (0)