Skip to content

Commit

Permalink
lightningd: deprecate invoice expiry suffixes.
Browse files Browse the repository at this point in the history
Makes types harder, and I've never personally used them.

Changelog-Deprecated: JSON-RPC: `invoice` `expiry` no longer allowed to be a string with suffix, use an integer number of seconds.
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Apr 1, 2022
1 parent bf4d9e3 commit 9784fa8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
6 changes: 2 additions & 4 deletions doc/lightning-invoice.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ viewable by any node you send this invoice to (unless *deschashonly* is
true as described below). It must be UTF-8, and cannot use *\\u* JSON
escape codes.

The *expiry* is optionally the time the invoice is valid for; without a
suffix it is interpreted as seconds, otherwise suffixes *s*, *m*, *h*,
*d*, *w* indicate seconds, minutes, hours, days and weeks respectively.
If no value is provided the default of 604800 (1w) is used.
The *expiry* is optionally the time the invoice is valid for, in seconds.
If no value is provided the default of 604800 (1 week) is used.

The *fallbacks* array is one or more fallback addresses to include in
the invoice (in order from most-preferred to least): note that these
Expand Down
5 changes: 4 additions & 1 deletion lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ static struct command_result *param_time(struct command *cmd, const char *name,
{ 'd', 24*60*60 },
{ 'w', 7*24*60*60 } };

if (!deprecated_apis)
return param_u64(cmd, name, buffer, tok, secs);

mul = 1;
if (timetok.end == timetok.start)
s = '\0';
Expand All @@ -1059,7 +1062,7 @@ static struct command_result *param_time(struct command *cmd, const char *name,
}

return command_fail_badparam(cmd, name, buffer, tok,
"should be a number with optional {s,m,h,d,w} suffix");
"should be a number");
}

static struct command_result *param_chanhints(struct command *cmd,
Expand Down
27 changes: 1 addition & 26 deletions tests/test_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,37 +437,12 @@ def test_invoice_expiry(node_factory, executor):
# all invoices are expired and should be deleted
assert len(l2.rpc.listinvoices()['invoices']) == 0

# Test expiry suffixes.
start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_s', description='description', expiry='1s')['bolt11']
inv = l2.rpc.invoice(msatoshi=123000, label='inv_s', description='description', expiry=1)['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_s')['invoices'])['expires_at']
assert expiry >= start + 1 and expiry <= end + 1

start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_m', description='description', expiry='1m')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_m')['invoices'])['expires_at']
assert expiry >= start + 60 and expiry <= end + 60

start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_h', description='description', expiry='1h')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_h')['invoices'])['expires_at']
assert expiry >= start + 3600 and expiry <= end + 3600

start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_d', description='description', expiry='1d')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_d')['invoices'])['expires_at']
assert expiry >= start + 24 * 3600 and expiry <= end + 24 * 3600

start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_w', description='description', expiry='1w')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_w')['invoices'])['expires_at']
assert expiry >= start + 7 * 24 * 3600 and expiry <= end + 7 * 24 * 3600


@pytest.mark.developer("Too slow without --dev-fast-gossip")
def test_waitinvoice(node_factory, executor):
Expand Down

0 comments on commit 9784fa8

Please sign in to comment.