Skip to content

Conversation

noblepayne
Copy link

The keysend plugin uses > 1023 as the cutoff for description length when inserting an invoice. This was inconsistent with lightnind/invoice.c, which enforces the BOLT11 description field limit defined in common/bolt11.h.

This patch switches to using BOLT11_FIELD_BYTE_LIMIT directly. As a result, keysend no longer fails on descriptions between 641–1023 bytes, which previously caused unexpected failures.

A new regression test (test_keysend_description_size_limit) exercises boundary cases just below, at, and above the limit.

Changelog-None

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.

The keysend plugin previously used `> 1023` as the cutoff for
description length when inserting an invoice. This was
inconsistent with invoice.c, which enforces the BOLT11 description
field limit defined in `common/bolt11.h`.

This patch switches to using `BOLT11_FIELD_BYTE_LIMIT` directly.
As a result, keysend no longer fails on descriptions between
641–1023 bytes, which previously caused unexpected failures.

A new regression test (`test_keysend_description_size_limit`)
exercises boundary cases just below, at, and above the limit.

Changelog-None

Signed-off-by: Wes Payne <noblepayne@noblepayne.com>
@@ -563,7 +564,7 @@ static struct command_result *htlc_accepted_call(struct command *cmd,
(const char *)desc_field->value);
json_add_string(req->js, "description", desc);
/* Don't exceed max possible desc length! */
if (strlen(desc) > 1023)
if (strlen(desc) >= BOLT11_FIELD_BYTE_LIMIT)
Copy link
Author

Choose a reason for hiding this comment

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

Should this be > or >=? lightningd/invoice.c uses >, however the BOLT11 spec says:

Note that the maximum length of a Tagged Field's data is constricted by the maximum value of data_length. This is 1023 x 5 bits, or 639 bytes.

In common/bolt11.c BOLT11_FIELD_BYTE_LIMIT has a value of 640.

Far from an expert here and appreciate any insight. Happy to update as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant