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

lnrpc+lncli: add send support for custom data records #3900

Merged
merged 1 commit into from
Jan 14, 2020

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Jan 10, 2020

With the introduction of custom record sending and receiving, it became possible to attach arbitrary data to a payment. One obvious use case is attaching a human-readable message to a payment. Especially in the case of spontaneous key send payments, this can give the receiver some context on the payment.

For example: tipping. Usually people sending a tip would want to include some information on who they are or what the tip is for. For Lightning this may be even more desired than for other payment methods, because payments are anonymous by default.

Attaching and retrieving the message was already possible before, but this PR makes it easier to do so by introducing an additional lncli flag --data to attach one or more custom records:

lncli sendpayment -d 0274e7fb33eafd74fe1acb6db7680bb4aa78e9c839a6e954e38abfad680f645ef7 -a 100 --key_send --data 323442=00,3234556=ffff080812

To specify a string value, the standard command line tool xxd can be used (the example record id here is the 3-byte ascii string 'tip' converted to an integer):

--data 7629168=$(echo -n "Thank you!" | xxd -pu -c 10000)

(The -c parameter is to prevent xxd from inserting line breaks)

Note: The available onion blob space of 1300 bytes is used for routing info and custom records. The bigger the size of the custom records, the fewer bytes remain for routing info and the shorter the maximum route length will be.

@joostjager joostjager added onion routing payments Related to invoices/payments tlv labels Jan 10, 2020
@joostjager joostjager changed the title lnrpc+lncli: add support for sender message lnrpc+lncli: add support for (key) sender message Jan 10, 2020
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

I thought this was intended to allow users to set arbitrary kv tlv pairs on the command line rather than carve out a new record for messages.

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

What is probably the most important accomplishment of this PR however is that it makes an attempt to standardize an unofficial field for payment messages.

I'm not convinced this should happen within lnd until there is some actual standardization, especially a field that knowingly collides with whatsat.

@joostjager
Copy link
Contributor Author

joostjager commented Jan 13, 2020

Message record id updated to a different random number.

My thought was that if we don't pick a field and provide a few hooks to make it easy to use (string flag on lncli and string type invoice htlc field), payment messages are less likely to be used. The payment message functionality can serve as a demonstrator of everything else that is possible using custom records. it seemed nice to me to get people thinking about that.

But as @Roasbeef suggests, we can also generalize this to just a new lncli flag. The question though is what a good format is. Any thoughts on that?

lncli sendpayment --data=34378273:"hello world!",124343:0feab32827cba23

It gets complicated with the spaces and special chars. Also not sure what different shells do there. In my bash, at least the data argument comes through as one block, but the quotes have disappeared.

@joostjager joostjager changed the title lnrpc+lncli: add support for (key) sender message lnrpc+lncli: add send support for custom data records Jan 14, 2020
@joostjager
Copy link
Contributor Author

Removed hard-coded record and replaced by generic --data flag.

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM 🏈

@Roasbeef Roasbeef added this to the 0.10.0 milestone Jan 14, 2020
@joostjager joostjager modified the milestones: 0.10.0, 0.9.0 Jan 14, 2020
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🎄

Very simple yet powerful PR!

@Roasbeef Roasbeef merged commit 3799f16 into lightningnetwork:master Jan 14, 2020
@curly60e
Copy link

curly60e commented Jun 6, 2020

With the introduction of custom record sending and receiving, it became possible to attach arbitrary data to a payment. One obvious use case is attaching a human-readable message to a payment. Especially in the case of spontaneous key send payments, this can give the receiver some context on the payment.

For example: tipping. Usually people sending a tip would want to include some information on who they are or what the tip is for. For Lightning this may be even more desired than for other payment methods, because payments are anonymous by default.

Attaching and retrieving the message was already possible before, but this PR makes it easier to do so by introducing an additional lncli flag --data to attach one or more custom records:

lncli sendpayment -d 0274e7fb33eafd74fe1acb6db7680bb4aa78e9c839a6e954e38abfad680f645ef7 -a 100 --key_send --data 323442=00,3234556=ffff080812

To specify a string value, the standard command line tool xxd can be used (the example record id here is the 3-byte ascii string 'tip' converted to an integer):

--data 7629168=$(echo -n "Thank you!" | xxd -pu -c 10000)

(The -c parameter is to prevent xxd from inserting line breaks)

Note: The available onion blob space of 1300 bytes is used for routing info and custom records. The bigger the size of the custom records, the fewer bytes remain for routing info and the shorter the maximum route length will...

This is the only method to send a message over lightning?

There is a short command method like a standard?

@cfromknecht
Copy link
Contributor

Currently yes, there is no standardized way of sending messages apart from these custom data records. Note that this require sender and receiver to be aware of the record type and format. There isn't any BOLT standard on how to do so, though some folks have implemented their own protocols on top of this primitive. Personally I wouldn't expect to see a messaging standard integrated into LND any time soon given now nascent these higher-level specifications are.

@joostjager joostjager mentioned this pull request May 31, 2021
2 tasks
@drmartinberger
Copy link

Dear lnd developers @Roasbeef @cfromknecht,

I am investigating custom data records attached to a Lightning Payment as should be available in lnd with this PR #3900. Thank you for that!

@joostjager was mentioning:

Note: The available onion blob space of 1300 bytes is used for routing info and custom records. The bigger the size of the custom records, the fewer bytes remain for routing info and the shorter the maximum route length will be.

Do you have an idea or experience, how many bytes can be consumed by the custom_records field and still getting a routeable onion payment? Do you have an estimate x if one wants to route a payment with custom data record via y hops, there usually remain 1300/y*x bytes for the data?

Can you point me to any sources to learn more on that? Any other way to transport encrypted custom data with a lightning payment, maybe compatible with other lightning implementations?

Thank you!

Cheers, Martin

@bitromortac
Copy link
Collaborator

Perhaps you could constrain your route length to about the diameter of the network, lncli getnetworkinfo shows me a value of 12, or a bit less, which should be plenty. Here some comment about the maximal number of hops in an onion.

@drmartinberger
Copy link

Perhaps you could constrain your route length to about the diameter of the network, lncli getnetworkinfo shows me a value of 12, or a bit less, which should be plenty. Here some comment about the maximal number of hops in an onion.

Thanks @bitromortac for your hint. If I understand your mentioned comment correctly, in a route with x non-exist hops there should remain at most 1300-37-x*65 bytes for a custom data record (assuming larger legacy hop payloads), right?

@bitromortac
Copy link
Collaborator

Right, but you can assume a base data size of 47 bytes as legacy onions will be phased out soon. If no other data is transported in there this should be the limit.

@ZoltanAB
Copy link

If I make a payment using lncli payinvoice ... --data 65536=$myuniquehex, is there any way to (later) easily find all payments that matches that hex?
Listing all payments (lncli listpayments) and manually comparing the hex is not the ideal solution when you might have hundreds of thousands of payments but only 5-10 has $myuniquehex. Any advise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
onion routing payments Related to invoices/payments tlv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants