Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoice: allow creation of giant invoices. #4606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,19 @@ invoice_complete(struct invoice_info *info,
info->label->s);
}

/* If this requires a giant HTLC, most implementations cannot
* send that much; will need to split. */
/* BOLT #2:
* ### Adding an HTLC: `update_add_htlc`
*...
* - for channels with `chain_hash` identifying the Bitcoin blockchain:
* - MUST set the four most significant bytes of `amount_msat` to 0.
*/
if (info->b11->msat
&& amount_msat_greater(*info->b11->msat, chainparams->max_payment)) {
warning_mpp = true;
}

/* Get details */
details = wallet_invoice_details(info, wallet, invoice);

Expand Down Expand Up @@ -1135,14 +1148,6 @@ static struct command_result *json_invoice(struct command *cmd,
strlen(desc_val));
}

if (msatoshi_val
&& amount_msat_greater(*msatoshi_val, chainparams->max_payment)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"msatoshi cannot exceed %s",
type_to_string(tmpctx, struct amount_msat,
&chainparams->max_payment));
}

if (fallbacks) {
size_t i;
const jsmntok_t *t;
Expand Down
6 changes: 3 additions & 3 deletions tests/test_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def test_invoice(node_factory, chainparams):
assert 'routes' not in b11
assert 'warning_capacity' in inv

# Make sure no wumbo invoices
with pytest.raises(RpcError, match=r'msatoshi cannot exceed 4294967295msat'):
l2.rpc.invoice(4294967295 + 1, 'inv3', '?')
# Make sure wumbo invoices warn about mpp being needed.
inv = l2.rpc.invoice(4294967295 + 1, 'inv4', '?')
assert 'warning_mpp' in inv
l2.rpc.invoice(4294967295, 'inv3', '?')
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Github actions

/home/runner/work/lightning/lightning/contrib/pyln-client/pyln/client/lightning.py:388>]
test_invoice failed; it passed 0 out of the required 1 times.
	<class 'pyln.client.lightning.RpcError'>
	RPC call failed: method: invoice, payload: {'msatoshi': 4294967295, 'label': 'inv3', 'description': '?'}, error: {'code': 900, 'message': "Duplicate label 'inv3'"}
	[<TracebackEntry /home/runner/work/lightning/lightning/tests/test_invoices.py:60>, <TracebackEntry /home/runner/work/lightning/lightning/contrib/pyln-client/pyln/client/lightning.py:845>, <TracebackEntry /home/runner/work/lightning/lightning/contrib/pyln-testing/pyln/testing/utils.py:623>, <TracebackEntry /home/runner/work/lightning/lightning/contrib/pyln-client/pyln/client/lightning.py:388>]

This is a bit strange, why we don't see it in previous tests?

Copy link
Contributor Author

@rustyrussell rustyrussell Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we originally had it failing the first inv3 invoice creation, now it succeeds, so the next one fails.


# Test cltv option.
Expand Down