') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Move ChannelConfig static fields to ChannelHandshakeConfig by wpaulino · Pull Request #1529 · lightningdevkit/rust-lightning · GitHub
Skip to content

Move ChannelConfig static fields to ChannelHandshakeConfig - #1529

Merged
TheBlueMatt merged 3 commits into
lightningdevkit:mainfrom
wpaulino:move-channel-config-static-fields
Jun 13, 2022
Merged

Move ChannelConfig static fields to ChannelHandshakeConfig#1529
TheBlueMatt merged 3 commits into
lightningdevkit:mainfrom
wpaulino:move-channel-config-static-fields

Conversation

@wpaulino

@wpaulinowpaulino commented Jun 8, 2022

Copy link
Copy Markdown
Contributor

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
wpaulinoforce-pushed the move-channel-config-static-fields branch from 9c277b7 to 3bbd4f2CompareJune 8, 2022 22:42

@tnulltnull left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadlightning/src/util/config.rs Outdated
///
/// Default value: false.
pub announced_channel: bool,
/// Deprecated, use [`ChannelHandshakeConfig::announced_channel`] instead.

Copy link
Copy Markdown
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
Copy Markdown
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.

@tnulltnullJun 9, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

Comment threadlightning/src/util/config.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
@codecov-commenter

codecov-commenter commented Jun 9, 2022

Copy link
Copy Markdown

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 FilesCoverage Δ
lightning/src/util/config.rs61.62% <84.61%> (+18.49%)⬆️
lightning-invoice/src/utils.rs96.63% <100.00%> (ø)
lightning/src/ln/chanmon_update_fail_tests.rs97.71% <100.00%> (ø)
lightning/src/ln/channel.rs88.58% <100.00%> (-0.02%)⬇️
lightning/src/ln/functional_test_utils.rs95.23% <100.00%> (-0.19%)⬇️
lightning/src/ln/functional_tests.rs96.97% <100.00%> (-0.10%)⬇️
lightning/src/ln/onion_route_tests.rs97.51% <100.00%> (ø)
lightning/src/ln/payment_tests.rs99.24% <100.00%> (-0.01%)⬇️
lightning/src/ln/priv_short_conf_tests.rs96.60% <100.00%> (ø)
lightning/src/ln/shutdown_tests.rs96.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.

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
wpaulinoforce-pushed the move-channel-config-static-fields branch from 5ea51d2 to ec7ccf0CompareJune 9, 2022 23:32

@tnulltnull left a comment

Copy link
Copy Markdown
Contributor

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.

///
/// [`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

@tnulltnullJun 10, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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 freeto 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

@wpaulino@codecov-commenter@tnull@TheBlueMatt