Skip to content

Make ChannelMonitor serialization slightly more upgradable #1045

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

This is the first two commits from #1034, which make the ChannelMonitor serialization slightly more upgradable and include an additional macro for tlv-based enum serialization using the MaybeReadable trait. I'd like some feedback about maybe including this in 0.0.100 to avoid additional serialization breakages in 0.0.101.

@codecov
Copy link

codecov bot commented Aug 14, 2021

Codecov Report

Merging #1045 (975c454) into main (a369f9e) will decrease coverage by 0.00%.
The diff coverage is 90.16%.

❗ Current head 975c454 differs from pull request most recent head ee43975. Consider uploading reports for the commit ee43975 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1045      +/-   ##
==========================================
- Coverage   90.96%   90.95%   -0.01%     
==========================================
  Files          64       64              
  Lines       32393    32447      +54     
==========================================
+ Hits        29467    29513      +46     
- Misses       2926     2934       +8     
Impacted Files Coverage Δ
lightning/src/util/ser_macros.rs 95.73% <80.00%> (-0.58%) ⬇️
lightning/src/util/ser.rs 92.20% <87.50%> (+0.08%) ⬆️
lightning/src/chain/onchaintx.rs 94.18% <94.11%> (-0.01%) ⬇️
lightning/src/chain/channelmonitor.rs 91.98% <94.73%> (+0.03%) ⬆️
lightning/src/ln/channelmanager.rs 86.11% <100.00%> (ø)
lightning/src/ln/functional_tests.rs 97.26% <0.00%> (-0.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a369f9e...ee43975. Read the comment docs.

@TheBlueMatt TheBlueMatt force-pushed the 2021-08-chanmon-ser-upgradability branch from 3843210 to 975c454 Compare August 15, 2021 22:49
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

LGTM

Took me a bit to realize MaybeReadable was more flexible in that its earlier use for ignoring FundingGenerationReady events was not for compatibility purposes as it is here.

pub(crate) struct VecReadWrapper<T: Readable>(pub Vec<T>);
impl<T: Readable> Readable for VecReadWrapper<T> {
pub(crate) struct VecReadWrapper<T>(pub Vec<T>);
impl<T: MaybeReadable> Readable for VecReadWrapper<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, this is not exercised at all for MaybeReadable types now but could be in the future. That way we don't need to write custom decoding for TLVs with a vec containing types implementing MaybeReadable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure I understand the comment. Obviously this PR is a bit awkward because it is just commits from #1034, which does use all the code in it. I tried a few ways to do VecReadWrapper that I thought were cleaner but always ended up hitting the "you may implement MaybeReadable and Readable for this type causing duplicate implementations" stuff every time.

Copy link
Contributor

Choose a reason for hiding this comment

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

No action necessary. Just pointing out this use case.

This makes it much simpler to deal with `MaybeReadable` types in
`Vec`s in TLVs as we can transparently deal with them as `vec`,
with the wrapper doing the Right Thing.

This requires we implement `MaybeReadable` for all `Readable` which
has some downstream implications, but nothing too bad.
This adds a new TLV-based enum serialization macro entitled
`impl_writeable_tlv_based_enum_upgradable`. As the name implies,
the new macro allows us to ignore odd-numbered variant entries.
Because the new macro implements only `MaybeReadable` and not
`Readable`, it is not applicable in many contexts, here only being
added for the two `OnchainEvent` structs.
@TheBlueMatt TheBlueMatt force-pushed the 2021-08-chanmon-ser-upgradability branch from 975c454 to ee43975 Compare August 16, 2021 17:35
@TheBlueMatt
Copy link
Collaborator Author

Squashed with one super-minor tweak as suggested by jeff, will take after CI:

$ git diff-tree -U1 975c454b ee43975b
diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs
index 33de8bde..af1bebe6 100644
--- a/lightning/src/util/ser_macros.rs
+++ b/lightning/src/util/ser_macros.rs
@@ -532,4 +532,4 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
 					}),*
-					_ if id % 2 == 1 => { Ok(None) }
-					_ => { return Err(DecodeError::UnknownRequiredFeature); },
+					_ if id % 2 == 1 => Ok(None),
+					_ => Err(DecodeError::UnknownRequiredFeature),
 				}
$

Took me a bit to realize MaybeReadable was more flexible in that its earlier use for ignoring FundingGenerationReady events was not for compatibility purposes as it is here.

Right, its kinda used for several things now, but at least its consistent in that the type is "maybe readable or maybe none"

@TheBlueMatt TheBlueMatt merged commit 64159b3 into lightningdevkit:main Aug 16, 2021
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.

3 participants