Skip to content

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

Merged

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Jun 8, 2022

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 upgrading v0.0.106 -> v0.0.107 and downgrading v0.0.107 -> v0.0.106 are allowed and the intended state is reflected properly.

@wpaulino wpaulino force-pushed the move-channel-config-static-fields branch from 9c277b7 to 3bbd4f2 Compare June 8, 2022 22:42
Copy link
Contributor

@tnull tnull left a 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.

///
/// Default value: false.
pub announced_channel: bool,
/// Deprecated, use [`ChannelHandshakeConfig::announced_channel`] instead.
Copy link
Contributor

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.)

Copy link
Collaborator

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.

Copy link
Contributor

@tnull tnull Jun 9, 2022

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.

Copy link
Collaborator

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 :/

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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-commenter
Copy link

codecov-commenter commented Jun 9, 2022

Codecov Report

Merging #1529 (ec7ccf0) into main (a551a62) will decrease coverage by 0.02%.
The diff coverage is 93.68%.

@@            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     
Impacted Files Coverage Δ
lightning/src/util/config.rs 61.62% <84.61%> (+18.49%) ⬆️
lightning-invoice/src/utils.rs 96.63% <100.00%> (ø)
lightning/src/ln/chanmon_update_fail_tests.rs 97.71% <100.00%> (ø)
lightning/src/ln/channel.rs 88.58% <100.00%> (-0.02%) ⬇️
lightning/src/ln/functional_test_utils.rs 95.23% <100.00%> (-0.19%) ⬇️
lightning/src/ln/functional_tests.rs 96.97% <100.00%> (-0.10%) ⬇️
lightning/src/ln/onion_route_tests.rs 97.51% <100.00%> (ø)
lightning/src/ln/payment_tests.rs 99.24% <100.00%> (-0.01%) ⬇️
lightning/src/ln/priv_short_conf_tests.rs 96.60% <100.00%> (ø)
lightning/src/ln/shutdown_tests.rs 96.51% <100.00%> (ø)
... and 7 more

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 a551a62...ec7ccf0. Read the comment docs.

wpaulino added 3 commits June 9, 2022 16:11
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.
@wpaulino wpaulino force-pushed the move-channel-config-static-fields branch from 5ea51d2 to ec7ccf0 Compare June 9, 2022 23:32
Copy link
Contributor

@tnull tnull left a 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
Copy link
Contributor

@tnull tnull Jun 10, 2022

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,
Copy link
Contributor

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?

Copy link
Collaborator

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.

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.

4 participants