-
Notifications
You must be signed in to change notification settings - Fork 407
Features module improvements #590
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
Features module improvements #590
Conversation
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.
Nice. Aside from a few macros which I find hard to read this is definitely way less error-prone.
5fd75de
to
cb299eb
Compare
fix build? :) |
Eeek! Let me rebase. I think I can move some of the behavior changes before the refactor to make reviewing easier. Will ping when ready. |
5b3a54c
to
bcd929d
Compare
@valentinewallace Should be good for review. All tests compile and pass now! I moved the commits around a bit, so the ordering on Github is 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.
I can't say I'm a huge fan of generalizing with_known_relevan_init_flags
- its a super awkward hack that we use cause the protocol isn't really prescriptive enough for what we need (which probably needs to be fixed upstream). Making it a first-class feature seems like the wrong direction.
Otherwise this looks great.
//! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md | ||
//! [messages]: ../msgs/index.html | ||
//! [`Features`]: struct.Features.html | ||
//! [`Context`]: sealed/trait.Context.html |
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 could really use docs on known vs supported, I think. Just the english words dont nearly convey what is going on.
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.
Added a paragraph explaining the distinction. Let me know whether it is clear.
bcd929d
to
771a749
Compare
Gotcha! Restricted it to |
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.
This is looking really good! Mainly just wondering about adding a few more sanity checks/docs
Needs rebase to address silent merge conflicts (new tests) and pick up the Github Actions config. |
The test_upfront_shutdown_script functional test clears this feature flag. However, the method used to clear the flag is implemented by bit toggling. Thus, if the flag is not set the method would actually set it. Implement the method using bit clearing instead.
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.
Needs rebase to address silent merge conflicts (new tests) and pick up the Github Actions config.
Done.
771a749
to
26fae5e
Compare
Codecov Report
@@ Coverage Diff @@
## master #590 +/- ##
==========================================
+ Coverage 91.10% 91.11% +0.01%
==========================================
Files 34 34
Lines 20447 20544 +97
==========================================
+ Hits 18628 18719 +91
- Misses 1819 1825 +6
Continue to review full report at Codecov.
|
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 26fae5e. Great work!
BasicMPP, | ||
], | ||
}); | ||
define_context!(ChannelContext { |
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.
Yes I think this works correctly even with C+
distinction for option_support_large_channel
, I mean it's up to us to encode as required features only at context declaration.
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.
Great reduction in error-proneness! & solid improvements to feature testing
26fae5e
to
7432b1c
Compare
Added 54607ff to address the loss of coverage in peer_handler.rs. Not sure why funtional_tests.rs saw a dip. |
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.
Can you squash the fixup commits and we can merge this? :)
The initial_routing_sync feature is set by peer_handler whenever a full sync of the network graph is desired. It is not explicitly set when creating features with InitFeatures::supported(). An upcoming refactor will change supported() to known(), which will return all features known by the implementation. Thus, the initial_routing_sync flag will need to be set by default. This commit makes the behavior change ahead of the refactor.
Each feature is represented by two bits within Features' flags field. Working with these flags requires bitwise operations, which can be error prone. Rather than directly checking and manipulating bits, encapsulate the bits within each feature trait and provide mechanisms for doing so. This removes the need to comment on which features correspond to bitwise expressions since the expressions use feature trait identifiers instead. With this approach, byte literals and expressions can be evaluated at compile time still. However, for these cases, knowing which byte within the flags that a feature corresponds to still must be determined by the implementor. Remove the special case where initial_routing_sync has no even bit. Now, it (bit 2) is considered known by the implementation.
Features for a given context are duplicated throughout the features module. Use a macro for defining a Context and the applicable features such that features only need to be defined for a Context in one place. The Context provides bitmasks for selecting known and unknown feature flags. BOLT 1 and BOLT 9 refer to features as "known" if a peer understands them. They also use the term "supported" to mean either optional or required. Update the features module to use similar terminology. - Define contexts in terms of required and optional features rather than just supported features - Define known features as those that are optional or required - Rename supported() constructor to known() For completeness, clear_optional_bit for each feature is now called clear_bits and clears both optional and required bits.
Refactoring the features module allowed for making code specific to certain contexts generalizable. Specifically, KNOWN_FEATURE_MASK is defined on Context instead of hardcoded in each method specialization. Thus, such methods are no longer required.
Converting from InitFeatures to other Features is accomplished using Features::with_known_relevant_init_flags. Define a more general to_context method which converts from Features of one Context to another. Additionally, ensure the source context only has known flags before selecting flags for the target context.
Include tests for requires_unknown_bits and supports_unknown_bits when an unknown even bit, odd bit, or neither is set. Refactor bit clearing such that tests and production code share the same code path. Fix a potential spec incompatibility (currently only exposed in testing code) where trailing zero bytes are not removed after a bit is cleared.
7432b1c
to
ee27e84
Compare
Yes! Done and should be good to go. |
Refactor the
features
module to be more generalized and less error prone when adding new features. Each feature trait is defined in terms of even and odd bits. EachContext
is defined in terms of features it supports.From this, methods in
Features
no longer need to be defined specially for each context nor need to have bitmasks modified when adding a new feature.Best reviewed one commit at a time.
Based on #589.