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

Proposal: implement custom TLV records for spontaneous payments #273

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rdmitr
Copy link

@rdmitr rdmitr commented Mar 6, 2024

A very simple implementation of custom TLV records for keysend requests.

@@ -456,3 +456,12 @@ impl Default for ChannelConfig {
LdkChannelConfig::default().into()
}
}

/// Custom TLV entry.
pub struct TlvEntry {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the protocol the TLV entry is defined with a length
https://github.com/lightning/bolts/blob/master/01-messaging.md#type-length-value-format

Whats the reason of not including it here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that LDK is expecting type and value to set the tlv. I guess then the length is set by ldk when sending the message.
Maybe add a bit more info on the type and value describing the restrictions or characterizes of the props:
for example, for type:
type identifiers below 2^16 are reserved for use in this specification. type identifiers greater than or equal to 2^16 are available for custom records. (from the blip)

Copy link
Author

@rdmitr rdmitr Mar 11, 2024

Choose a reason for hiding this comment

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

In the protocol the TLV entry is defined with a length https://github.com/lightning/bolts/blob/master/01-messaging.md#type-length-value-format

Whats the reason of not including it here?

The length of the data buffer is used for that. I shall see if we can improve the representation, though

@@ -490,8 +490,11 @@ pub(crate) fn do_channel_full_cycle<K: KVStore + Sync + Send, E: ElectrumApi>(
// Test spontaneous/keysend payments
println!("\nA send_spontaneous_payment");
let keysend_amount_msat = 2500_000;
let keysend_payment_hash =
node_a.send_spontaneous_payment(keysend_amount_msat, node_b.node_id()).unwrap();
let tlv1 = TlvEntry { r#type: 131073, value: vec![0x00, 0x11, 0x22, 0x33] };
Copy link
Contributor

Choose a reason for hiding this comment

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

does this test validate that the counter-party node received the message?

@@ -1222,7 +1222,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {

/// Send a spontaneous, aka. "keysend", payment
pub fn send_spontaneous_payment(
&self, amount_msat: u64, node_id: PublicKey,
&self, amount_msat: u64, node_id: PublicKey, custom_tlvs: Vec<TlvEntry>,
Copy link
Contributor

Choose a reason for hiding this comment

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

are the custom_tlvs required in order to send a spontaneous payment?

Copy link
Author

Choose a reason for hiding this comment

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

Not really required but may be useful. But I see the point, we'll probably take tnull's suggestion to base this change off PR 270; probably once it's merged

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this! While adding custom TLV support is stretching our 'keep API minimal' guidelines, I see that it can be of value for certain usecases.

I however agree with @jbesraa's question above regarding the optionality of custom TLVs. Rather than just adding it to the API method, could you base this entire PR off #270 and add it as a new SpontaneousPayment::send_with_custom_tlvs variant to and keep the default send method untouched?

@TheBlueMatt
Copy link

Is there a use for this people want in the immediate future aside from the messages thing? Is the podcast streaming sats thing using the messages field or are there other fields it uses?

@rolznz
Copy link

rolznz commented Mar 11, 2024

Is there a use for this people want in the immediate future aside from the messages thing? Is the podcast streaming sats thing using the messages field or are there other fields it uses?

Yes, the main usecase is Podcasting 2.0: https://github.com/lightning/blips/blob/master/blip-0010.md

@TheBlueMatt
Copy link

Ah, damn, that uses a different TLV than other messages, okay, fair enough, hard to capture that in a single API that isn't full-blown custom TLVs 😭

@jbesraa
Copy link
Contributor

jbesraa commented Mar 12, 2024

should the TlvEntry be part of LDK? I think it would be nice to have there, and also change the function input
pub fn with_custom_tlvs(mut self, mut custom_tlvs: Vec<TlvEntry>) -> Result<Self, ()> {...}. Happy to open an issue and resolve it if so

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.

None yet

5 participants