-
Notifications
You must be signed in to change notification settings - Fork 376
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
Expose some useful tlv macros #1551
Conversation
Some structs had to become public so the macros can be used when exposed This change doesn't add docs and works around the missing docs by adding `msgs_macros` feature
…th any rust edition Previously, imports or usage of structs from different modules/submodules were using the `::module` syntax, which wouldn't work as expected if the macros are used in a rust edition > 2015 Mainly, the two macros `impl_writeable` and `impl_writeable_msg` are now exported and any other macro that was used inside of them. This also exposes some structs that the macros *might* construct for some macro arguments. This also adds some docs to the exposed structs which are missing docs + remove the `msgs_macros` feature which was used to workaround missing docs, though docs for the macros have not been added yet.
I wrote these comments before while misunderstanding what these macros do. Updated them.
Codecov Report
@@ Coverage Diff @@
## main #1551 +/- ##
==========================================
- Coverage 90.96% 90.94% -0.02%
==========================================
Files 80 80
Lines 43533 43610 +77
Branches 43533 43610 +77
==========================================
+ Hits 39599 39661 +62
- Misses 3934 3949 +15
Continue to review full report at Codecov.
|
…`use lightning::*;` when using them
0 > u64 is redundant because a u64 can't be less than zero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we should be as conservative as possible in what we export and what we tell users to use, as exporting things is a commitment to users to support it, and I don't think we want to support all of these macros individually. In general, I'm not sure if we want to expose impl_writeable_tlv_based
either, vs just exposing the tlv-stream write/read macros and letting users figure it out? Do you have a specific usecase in mind?
@@ -353,12 +395,14 @@ macro_rules! init_tlv_based_struct_field { | |||
}; | |||
} | |||
|
|||
/// Initializes the variables we are going to read the TLVs into. | |||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should prefix this with a _
and make the docs just say something about not using this directly.
@@ -254,10 +293,13 @@ macro_rules! impl_writeable_msg { | |||
} | |||
} | |||
|
|||
/// Implements Readable/Writeable for a struct. Note that this macro doesn't handle messages | |||
/// containing TLV records. If your message contains TLVs, use `impl_writeable_msg!` instead. | |||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not and just expose the TLV stuff? New structs that want to implement writeable should do so as a tlv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, why should they do it as tlv??
A custom message (types 32768
-65535
) may have a non-tlv fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if users want to implement their own specific serialization they can do that, these macros don't really change much in terms of how much work that is. TLV streams, on the other hand, are very lightning specific and specific in requirements, so exposing that for users is more important IMO. In general, though, we are moving away from the "just write the fields" serialization and towards "TLV stream everything", so I'd prefer to just expose the future, not the past :)
/// (3, street_number, option), | ||
/// }); | ||
/// ``` | ||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, lets just expose impl_writeable_tlv_based
rather than this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a specific use case for impl_writeable_tlv_based
in mind. I didn't think someone would generally try to craft a custom message that is tlv only. I don't agree with exposing it though.
But for impl_writeable_msg
, I think this is more of a universal macro (encodes both tlv & non-tlv message fields).
Most probably, this is the one a custom message maker would try to use.
See a use case for impl_writeable_msg
here.
I think we should also make it so impl_writeable_msg
can handle required
, default
, and vec_type
tlv types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't want to get into the business of providing downstream users a general-purpose serialization framework. There are probably better options if that's what users want. I'm okay with exposing lightning-specific stuff like TLV streams, but I'm not super happy with downstream users using our serialization stuff for their own objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine.
So what macros should be exposed??
I'm thinking {decode,encoder}_tlv_stream
(for non varint prefixed uses) and {read,write}_tlv_fields
(for varint prefixed uses).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually maybe lets skip write_tlv_fields
? Its really just writing a tlv stream with a length prefix, which isn't a "lightning thing" so much as a "LDK thing". In general, I'd really like to see a user who wants to use this stuff before we start exposing willy-nilly, but writing a TLV stream is understandable enough that I think we should just do it.
@@ -146,15 +158,17 @@ macro_rules! check_missing_tlv { | |||
}}; | |||
} | |||
|
|||
/// Implements deserialization for a single TLV record. | |||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets prefix this with a _
and have the docs just say that you shouldnt use this.
@@ -120,16 +130,18 @@ macro_rules! check_tlv_order { | |||
}}; | |||
} | |||
|
|||
/// Errors if there are missing required TLV types after the last seen type. | |||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, _ and dont use.
@@ -94,16 +102,18 @@ macro_rules! encode_varint_length_prefixed_tlv { | |||
} } | |||
} | |||
|
|||
/// Errors if there are missing required TLV types between the last seen type and the type currently being processed. | |||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, _ and dont use.
@meryacine Are you still interested in continuing this PR? Would be great to have the serialization macros exported to be used downstream. No worries if not, in this case I'd consider opening a new PR to the same effect. |
@tnull Yeah sure. I ended up copying what I needed from these macros and modified them a bit that's why the PR got staled.
Are we talking about |
Well, I'm currently implementing serialization manually, so the macros would mostly improve brevity and readability. It would therefore be great to have |
This unfortunately needs a rebase now. |
Closing as superseded by #1823. |
This exposes the 2 macros
impl_writeable_msg!
&impl_writeable!
and any macros/structs called/used inside them.Also all the imports (
use
s) in the macros are prefixed with$crate
(essentially, making them absolute paths) so the macro works fine with any rust edition (2015 and others).I have added some docs for the
export
ed macros &pub
ed structs based on my understanding of them.Let me know if I should expose more/less macros or edit docs.
Addressing #1539