Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Add HolderCommitmentPoint struct to track commitment points - #3086

Merged
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment
Jun 10, 2024
Merged

Add HolderCommitmentPoint struct to track commitment points#3086
valentinewallace merged 4 commits into
lightningdevkit:mainfrom
alecchendev:2024-05-holder-commitment

Conversation

@alecchendev

Copy link
Copy Markdown
Contributor

This is the first of several upcoming PRs to complete async signing. This adds the HolderCommitmentPoint struct to consolidate our logic getting commitment points, which will make things easier when this operation returns a result type in an upcoming PR. This refactor helps prepare for async signing, but still assumes the signer is synchronous.

I left a bunch of TODOs that should get removed in upcoming PRs, let me know if they're too much.

@codecov-commenter

codecov-commenter commented May 30, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 92.40506% with 12 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (df01208) to head (cf545b4).
Report is 99 commits behind head on main.

FilesPatch %Lines
lightning/src/ln/channel.rs92.40%6 Missing and 6 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #3086 +/- ##
==========================================
+ Coverage 89.90% 91.83% +1.92% 
==========================================
Files 117 119 +2 Lines 97105 113897 +16792 Branches 97105 113897 +16792 ==========================================
+ Hits 87303 104596 +17293 + Misses 7243 6976 -267 + Partials 2559 2325 -234 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 95894e4 to 83c1fa9CompareMay 30, 2024 23:36
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

#[derive(Debug, Copy, Clone)]
enum HolderCommitmentPoint {
Uninitialized { transaction_number: u64 },

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.

Why even have this variant given we always immediately call request_next? ISTM we could drop the panics below if we just elided this and requested in new?

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.

#3109 should hopefully provide more context for this now

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.

Right...related question, how are y'all handling the ChannelSigner::pubkeys call? Are you just blocking for the initial signer setup there or are you doing something more clever to preload the pubkeys (that could also apply to the initial commitment point)?

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.

Oh woops thought i responded to this - we basically preload pubkeys upon the creation of a node for all channels, so what we use for that probably can't directly help with the first commitment point. We could make it so that for async signing you need to pass the initial per commitment point into ChannelManager::create_channel or accept_inbound_channel to avoid doing the Uninitialized variant - and on our side we'd just have to wait for the response there which isn't a ton different from how we're waiting already

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 83c1fa9 to 65b3898CompareJune 6, 2024 23:25
@alecchendev

alecchendev commented Jun 6, 2024

Copy link
Copy Markdown
ContributorAuthor

squashed because this is still in it's early phases. the major changes were:

  • merged HolderCommitmentPoint::request_next into advance
  • now return an option from current_point which gets rid of the panics, but in several cases I don't want to handle this case in this PR, so i've left some .expect("TODO")s for upcoming PRs. going to open the first PR resolving some of these within the hour, which should provide more context to this

Since this is a pretty big change, my goal is to make this easy to review as possible by splitting it up into separate PRs - some of this is a bit hard (-> .expect("TODO") is my best solution at the moment...), let me know if there are better/preferred ways of doing these things

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

I almost wonder if we shouldn't introduce the machinery here with nothing fallible so that we don't any any extra expects and then add those in the next PR where we have to actually handle them anyway? We could even do dances like let next_point = Some(advance()); match next_point { None => future code, .. } to land things progressively.

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 3 times, most recently from e22f940 to 9bc514eCompareJune 10, 2024 00:59
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

Dropped the Uninitialized variant, made current_point infallible

@TheBlueMattTheBlueMatt left a comment

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.

LGTM, please squash the fixups and lets land this!

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 9bc514e to e947e84CompareJune 10, 2024 15:20
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

squashed!

@valentinewallace
valentinewallace self-requested a review June 10, 2024 16:52
valentinewallace
valentinewallace previously approved these changes Jun 10, 2024

@valentinewallacevalentinewallace 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.

Nothing blocking!

Comment threadlightning/src/ln/channel.rs Outdated
Comment on lines +6537 to +6549
if self.context.signer_pending_funding {
// TODO: set signer_pending_channel_ready
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
return None;
}

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.

Looks like this check exists already about 60 lines up?

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.

oops just moved the log + TODO up there

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.

sike, just removed the one above, i realized in the next PR we should only set signer_pending_channel_ready after we've passed all the other checks

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.

sike x2, causes a bug, presumably because it causes us to do this check after modifying state

Comment on lines +1124 to +1134
PendingNext { transaction_number: u64, current: PublicKey },
Available { transaction_number: u64, current: PublicKey, next: PublicKey },

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.

IMO these could use some docs at some point, but feel free to hold off if it would make more sense to add them in following PRs.

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.

oh true, i'll add some interim docs and probably expand them more in an upcoming PR

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.

done

@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch 2 times, most recently from 317426a to 74297f4CompareJune 10, 2024 18:42
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like tests are failing: thread 'ln::async_signer_tests::test_async_commitment_signature_for_funding_signed_0conf' panicked at lightning/src/ln/async_signer_tests.rs:238:9:

This includes when building TxCreationKeys, as well as for open_channel
and accept_channel messages. Note: this is only for places where we are
retrieving the current per commitment point, which excludes
channel_reestablish.
@alecchendev
alecchendevforce-pushed the 2024-05-holder-commitment branch from 74297f4 to cf545b4CompareJune 10, 2024 20:07
@alecchendev

Copy link
Copy Markdown
ContributorAuthor

looks to be this, should be fixed now

Comment on lines +1132 to +1133
/// Our current commitment point is ready, we've cached our next point,
/// and we are not pending a new one.

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: are "we've cached our next point" and "we are not pending a new one" the same thing? If so, I think one of the clauses could be removed since it sounds like separate things atm


fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);

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.

Trying to understand the + 2. The bolts seem to read like our transaction number will never be > INITIAL_COMMITMENT_NUMBER, let me know what I'm missing here!

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.

ah oops, this should actually be - 2, to assert we have always advanced our commitment point twice before we ever call here

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.

Ah that makes sense lol

fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
debug_assert!(self.context.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER + 2);
// TODO: handle non-available case when get_per_commitment_point becomes async

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.

For my understanding, is this referring to when we implement this TODO to add the new HolderCommitmentPoint variant (which I think means that current_point() will become Optional)?

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.

yep! technically it should never be unavailable by the time we get here, but figured i'd leave a note to think about it again when things change

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.

It seems like PendingNext would also work here, so the assertion below still doesn't totally make sense to me, but it probably gets clearer in the follow-ups.

@valentinewallace
valentinewallace merged commit f2237a7 into lightningdevkit:mainJun 10, 2024
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

@alecchendev@codecov-commenter@TheBlueMatt@valentinewallace