lightning icon indicating copy to clipboard operation
lightning copied to clipboard

Display TLV data in listinvoices

Open Sjors opened this issue 3 years ago • 5 comments

When receiving a keysend payment I can see it under listinvoices. But this doesn't show any custom TLV fields.

I'm particularly interested in the fields used by Podcasting 2.0: https://github.com/satoshisstream/satoshis.stream/blob/main/TLV_registry.md#field-7629169

Sjors avatar Apr 07 '21 14:04 Sjors

We have one issue with this, namely that despite the name, TLV fields are not typed as such. They are just blobs of binary data, that are interpreted as integers, hashes, signatures, etc by any program that has more knowledge about the T in the acronym.

So a generic implementation would just show type, length (redundant really in JSON results) and a hex-encoded binary value. Would that still be acceptable?

cdecker avatar Apr 24 '21 12:04 cdecker

It's a start. I could probably pipe that through JQ and then some tools to decipher the hex value. Maybe plugins can do that too.

Sjors avatar Apr 24 '21 15:04 Sjors

We have one issue with this, namely that despite the name, TLV fields are not typed as such. They are just blobs of binary data, that are interpreted as integers, hashes, signatures, etc by any program that has more knowledge about the T in the acronym.

So a generic implementation would just show type, length (redundant really in JSON results) and a hex-encoded binary value. Would that still be acceptable?

The hex encoded strings are what we are parsing when pulling out the tlv payload on incoming keysend transactions for the Podcast Index node. It’s not difficult (bin2hex —> json_decode) and provides tremendous listener stats to see what podcast/episode was being listened to, and exactly what time stamp within it that the payment was sent.

The podcast industry currently works on “download stats” which are highly inaccurate. It’s basically guesswork. This would revolutionize that as a standard for listener metrics.

daveajones avatar Jul 04 '21 13:07 daveajones

#4610 is the first step towards this. It adds experimental support for extratlvs, i.e., hex-encoded TLVs that are not interpreted and stored internally yet, with opt-in to even TLV types on the command line. They are currently only being exposed in the invoice_payment hook for testing, but if the format looks ok to users we can add them to the corresponding notification, and start storing them in the DB as well, so listinvoices can retrieve and display them.

cdecker avatar Jul 04 '21 14:07 cdecker

a generic implementation would just show type, length (redundant really in JSON results) and a hex-encoded binary value. Would that still be acceptable?

I think that would be fine. It should be easy for consuming apps to interpret the TLV type and decode the hex values accordingly.

They are currently only being exposed in the invoice_payment hook for testing

That's already really helpful -- thanks for that! :)

I've written a small plugin for lightningd that watches for Podasting 2.0 TLVs in the invoice_payment hook and stores them in a local db so that they can be retrieved again later on: cln-podcast-payments.

It's not much but should be an acceptable workaround until Core Lightning can natively do that.

but if the format looks ok to users we can add them to the corresponding notification, and start storing them in the DB as well, so listinvoices can retrieve and display them.

That'd be great, imo! As I said, I feel like the binary format is fine enough. Having access to TLVs in listinvoices would make the use of a separate plugin obsolete and by that make everything easier for people to use.

cnixbtc avatar Oct 04 '22 21:10 cnixbtc

I wonder if this can now be considered as solved by https://github.com/ElementsProject/lightning/pull/5619. That PR adds the longest string extracted from TLVs into the invoice we use to track spontaneous payments.

cdecker avatar Nov 19 '22 15:11 cdecker

yes I see podcast keysend data in listinvoices now which is pretty cool Nov20-083149

jb55 avatar Nov 20 '22 16:11 jb55

Nice, I'll give this a try after the final v22.11 release.

Sjors avatar Nov 23 '22 12:11 Sjors

Great news, looking forward to integrate this into our BTCPay Lightning lib.

dennisreimann avatar Nov 23 '22 17:11 dennisreimann

I wonder if this can now be considered as solved by https://github.com/ElementsProject/lightning/pull/5619

@cdecker As far as I see, the description with the keysend: part contains only the 133773310 TLV key. Is there a way to also get access to the other custom TLV records?

dennisreimann avatar Dec 10 '22 08:12 dennisreimann