-
Notifications
You must be signed in to change notification settings - Fork 405
Move ChannelConfig static fields to ChannelHandshakeConfig #1529
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
Move ChannelConfig static fields to ChannelHandshakeConfig #1529
Conversation
9c277b7
to
3bbd4f2
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.
Thanks! Just left some comments and questions.
Moreover: Not sure if its only me, but I find the current naming of variables in channel.rs
vs. their type unnecessarily confusing: there are many instances of variables simply named config
, which may refer to ChannelConfig
, UserConfig
, etc. depending on the context. Then there is the channel_options
field and corresponding variables, which is however a ChannelConfig
. Moreover, there are fields like own_channel_config
, which would make you think it would be a ChannelConfig
, but no, it's actually a ChannelHandshakeConfig
.
TLDR: Not sure if it needs to happen in this PR, but I personally would appreciate a refactoring that brings the naming of variables more in alignment with their types to improve readability.
lightning/src/util/config.rs
Outdated
/// | ||
/// Default value: false. | ||
pub announced_channel: bool, | ||
/// Deprecated, use [`ChannelHandshakeConfig::announced_channel`] 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.
Hm, if you deprecate this here, could you update the rest of the codebase to directly use the new location?
Also, instead of a comment, you probably want to mark this as deprecated:
#[deprecated(
since = "0.0.107",
note = "ChannelHandshakeConfig::announced_channel should be used instead.",
)]
(Yes, if you cannot update all instances where it is used immediately, this will produce annoying warning messages, which is however exactly the idea.)
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.
Hmm, I'd rather not have a ton of build warnings for a while, that's generally an easy way to build a culture of ignoring build warnings, which is pretty bad. Using the #[deprecated]
tag is important for public API stuff, but for internal stuff it's hopefully a bit less, though I agree still useful.
In any case, I think we can do better here. Instead of making these fields pub(crate)
, because we don't really care about users being able to serialize ChannelConfig
objects, I think, we can move the serialization to some struct LegacyChannelConfig { config: ChannelConfig, announced_channel: bool, ... }
object instead. That way, we can read it all the same, but the public interface remains clean and you can construct a full ChannelConfig
without using default()
and then modifying. Its a good bit more work cause we can't use the impl_writeable_tlv_based!()
macro anymore and have to write out the deserialization manually, but it should be doable.
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.
Hmm, I'd rather not have a ton of build warnings for a while, that's generally an easy way to build a culture of ignoring build warnings
Well, this is probably true if there is some baseline acceptance to warnings overall. I'd however argue that feeling the pain of 'deprecated' warnings on a regular basis can actually ensure the parts in question are not forgotten and get actually removed ASAP.
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, I don't disagree, just noting that in this case, because its a serialization backwards-compat thing, it'll stick around at least a year or two, so it'd kinda suck to have those warnings for that long :/
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.
Mh, I agree that in that timeframe it may be come a nuisance without much benefit. Maybe we could create something like a TODO.md
in which we keep track of TODOs that cannot be completed right away and where we define until when they are deferred? Or immediately create issues for them with a 'defer' tag and assign an estimated milestone some time in the future?
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 any case, I think we can do better here. Instead of making these fields pub(crate), because we don't really care about users being able to serialize ChannelConfig objects, I think, we can move the serialization to some struct LegacyChannelConfig { config: ChannelConfig, announced_channel: bool, ... } object instead. That way, we can read it all the same, but the public interface remains clean and you can construct a full ChannelConfig without using default() and then modifying. Its a good bit more work cause we can't use the impl_writeable_tlv_based!() macro anymore and have to write out the deserialization manually, but it should be doable.
Sounds good, I assume this means we can reset the serialization schema for the new ChannelConfig
then? Otherwise, we would want to document that the types 4 (announced_channel
) & 6 (commit_upfront_shutdown_key
) cannot be reused as it would break LegacyChannelConfig
serialization.
Maybe we could create something like a TODO.md in which we keep track of TODOs that cannot be completed right away and where we define until when they are deferred? Or immediately create issues for them with a 'defer' tag and assign an estimated milestone some time in the future?
👍 I would prefer the latter.
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.
Sounds good, I assume this means we can reset the serialization schema for the new ChannelConfig then?
Yea, actually I think just drop serialization support for ChannelConfig
entirely, only bother ever serializing the superset.
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.
Force pushed with the new changes since a good bit of the diff changed, PTAL. We now have a LegacyChannelConfig
which we still use within Channel
, but the actual values for announced_channel
and commit_upfront_shutdown_key
are set through ChannelHandshakeConfig
.
Codecov Report
@@ Coverage Diff @@
## main #1529 +/- ##
==========================================
- Coverage 90.94% 90.91% -0.03%
==========================================
Files 80 80
Lines 43426 43509 +83
Branches 43426 43509 +83
==========================================
+ Hits 39492 39557 +65
- Misses 3934 3952 +18
Continue to review full report at Codecov.
|
In the near future, we plan to allow users to update their `ChannelConfig` after the initial channel handshake. In order to reuse the same struct and expose it to users, we opt to move out all static fields that cannot be updated after the initial channel handshake.
As like the previous commit, `commit_upfront_shutdown_pubkey` is another static field that cannot change after the initial channel handshake. We therefore move it out from its existing place in `ChannelConfig`.
ChannelConfig now has its static fields removed. We introduce a new LegacyChannelConfig struct that maintains the serialization as previously defined by ChannelConfig to remain backwards compatible with clients running 0.0.107 and earlier.
5ea51d2
to
ec7ccf0
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.
LGTM, just two remarks, feel free to ignore.
@@ -265,30 +291,6 @@ pub struct ChannelConfig { | |||
/// | |||
/// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA | |||
pub cltv_expiry_delta: u16, | |||
/// Set to announce the channel publicly and notify all nodes that they can route via 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.
nit: If you split up the commits, you may want to move the removal of the moved parts to the 'move' commits. (Nevermind if you end up squashing it all.)
/// [`ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`] fields. | ||
#[derive(Copy, Clone, Debug)] | ||
pub(crate) struct LegacyChannelConfig { | ||
pub(crate) mutable: ChannelConfig, |
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.
Not too sure about this field name. Is mutability its core characteristic/function?
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, this is pretty awkward. Lets land this to keep things moving but I'd appreciate a followup to rename this. While we're at it, we can probably rename a few more things here - eg UserConfig::own_channel_config
makes no sense, its really the handshake config.
In the near future, we plan to allow users to update their
ChannelConfig
after the initial channel handshake. In order to reuse the same struct and expose it to users, we opt to move out all static fields that cannot be updated after the initial channel handshake.Motivated by #1527 (comment).
I also tested with
ldk-sample
to make sure upgradingv0.0.106 -> v0.0.107
and downgradingv0.0.107 -> v0.0.106
are allowed and the intended state is reflected properly.