I'm writing a script in C that is mean to make the usage of my c-lightning wallet more convenient. And so I have to specify a limit of characters (l is a variable that stands for label):

puts("The label(a unique string or number)?");
        char l[15];
        fgets(l, 15, stdin);
        l[strcspn(l, "\n")] = 0;

I arbitrarily decided on 15 not knowing whether lightning-cli invoice would accept such long string. Although help invoice gives some info about the label:

The label must be a unique string or number (which is treated as a string, so "01" is different from "1"); it is never revealed to other nodes on the lightning network, but it can be used to query the status of this invoice.

it does not specify it's length nor its character set? Are UTF-8 characters accepted within the label or should I use only ASCII character set? What is the maximum size / number of characters of the label?

1 Answer 1


If you look at the source code you can find the data base schema of the SQLite3 database that is being used to store invoices at: https://github.com/ElementsProject/lightning/blob/426ff0abfff8b080b22095b9f0b670c7192f54ea/wallet/db.c#L185

This indicates that the label field is of type TEXT. According to the SQLite3 Documentation this means:

TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).

Of course you need to check the if lightningd can also handle such long strings. the labels are stored in invoice_details which which is defined at:


from there you can see that it is of type * json_escape which comes from rusty's ccan libraries and is defined at:


There it says:

/* Type differentiation for a correctly-escaped JSON string */
struct json_escape {
    /* NUL terminated string. */
    char s[1];

 * json_escape - escape a valid UTF-8 string.
 * @ctx: tal context to allocate from.
 * @str: the string to escape.
 * Allocates and returns a valid JSON string (without surrounding quotes).
struct json_escape *json_escape(const tal_t *ctx, const char *str TAKES);

To my understanding this indicates indeed that as long as you have memory and disc you should be able to store UTF-8 strings of arbitrary length.

  • Thank for this great answer. It is stated in json_escape.h: struct json_escape { char s[1]; }; . I'm a newbie to C, but doesn't it mean that the maximum size of the label is just one char? It wouldn't make sense but I think that the general syntax for declaring a string in C is: char variable_name [array_size];
    – John Smith
    Dec 26, 2021 at 20:06
  • 1
    No as mentioned in my answer invoice_details includes a pointer to that struct so effectively it is an array of those wrapped 1 element char arrays. I myself are a bit confused why it can be used to store utf8 but I guess they take the char as a byte and have the encoding in there. The reason for doing a one element array from the stack instead of a variable however is mysterious to me. Dec 26, 2021 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.