-
Notifications
You must be signed in to change notification settings - Fork 411
Migrate some inner structs to TLVs #928
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
Migrate some inner structs to TLVs #928
Conversation
3de2cc5
to
dcd8561
Compare
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.
Code Review ACK dcd8561
Codecov Report
@@ Coverage Diff @@
## main #928 +/- ##
==========================================
+ Coverage 90.46% 91.71% +1.25%
==========================================
Files 60 60
Lines 30592 39136 +8544
==========================================
+ Hits 27674 35894 +8220
- Misses 2918 3242 +324
Continue to review full report at Codecov.
|
dcd8561
to
3d2d3dc
Compare
Rebased after #642 merge and added a commit to migrate sub-fields of PackageTemplate to TLVs. |
91b18cc
to
62495d0
Compare
Actually, I'm gonna add a ton more structs here. |
62495d0
to
43ab6ee
Compare
OK, fewer than I thought, but needed to tweak the macros, this should be good, let me know if I missed any. |
Tagging 0.0.15 as this is likely important for stabilizing serialization formats. |
lightning/src/ln/chan_utils.rs
Outdated
transaction_output_index | ||
}); | ||
impl HTLCOutputInCommitment { | ||
pub(crate) fn deserialization_dummy() -> Self { |
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.
For consistency elsewhere, could you name this null
?
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 ended up rewriting the macro stuff that required this so is now gone.
lightning/src/chain/transaction.rs
Outdated
@@ -73,6 +73,14 @@ impl OutPoint { | |||
vout: self.index as u32, | |||
} | |||
} | |||
|
|||
/// Creates a dummy BitcoinOutPoint, useful for serializing into. |
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.
s/serializing/deserializing
pub(crate) fn null() -> Self { | ||
Self { | ||
txid: Default::default(), | ||
index: 0 | ||
} | ||
} |
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.
Should we consider simply implementing Default
? I guess it exposes it outside the crate. Would be nice if traits could be implemented internally only.
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.
Yea, so initially I went down a rabbit hole on creating a whole trait for this stuff but I eventually just gave up and created a wrapper that deserializes into Option
s. This one is left because its used outside of the impl_writeable_tlv_based
macro, so its kinda a one-off.
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.
If a one-off, consider inlining.
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 found it to be a bit cleaner, but I'm happy to inline in channelmanager.rs if you prefer?
lightning/src/chain/package.rs
Outdated
amount | ||
}); | ||
impl_writeable_tlv_based!(HolderHTLCOutput, { | ||
(0, amount, 0), |
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 quite understand when a default value is needed.
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.
It isn't anymore :).
43ab6ee
to
78fdf48
Compare
78fdf48
to
2104d65
Compare
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.
Looks good other than some minor comments.
pub(crate) fn null() -> Self { | ||
Self { | ||
txid: Default::default(), | ||
index: 0 | ||
} | ||
} |
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.
If a one-off, consider inlining.
2104d65
to
d0fc7a3
Compare
Code Review ACK d0fc7a3 |
This also includes a `VecWriteWrapper` and `VecReadWrapper` which implements serialization for any `Readable`/`Writeable` type that is in a Vec. We do this instead of implementing `Readable`/`Writeable` directly as there isn't always a univerally-defined way to serialize a Vec and this makes things more explicit. Finally, this tweaks existing macros (and in the new macros) to support a trailing `,` after a list, eg `write_tlv_fields!(stream, {(0, a),}, {});` whereas previously the trailing `,` after the `(0, a)` would be a compile-error.
Note that enums are left alone as we can use the type byte already present for future compatibility.
d0fc7a3
to
ad20bc7
Compare
Squashed fixup commits and regenerated the graph for the new serialization:
|
Gonna merge post-CI, only diff was the URLs. |
This adds more TLVs to various serialized structs to provide more forward/backward compatibility.
I need to update the routing graph that is used in benchmarks to support this. Based on #642.