Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CounterpartyCommitmentSecrets public #1299

Conversation

Tibo-lg
Copy link
Contributor

@Tibo-lg Tibo-lg commented Feb 8, 2022

I'm working on implementation and specifications of DLC channels (not on LN for now) and I thought it'd be a good idea to reuse the secret commitment scheme, and thus would like to reuse the CounterpartyCommitmentSecrets struct in my code.

I mainly added some comments, let me know if something is off.

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2022

Codecov Report

Merging #1299 (131cb8c) into main (d29ae18) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 131cb8c differs from pull request most recent head 23b32ef. Consider uploading reports for the commit 23b32ef to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1299      +/-   ##
==========================================
- Coverage   90.51%   90.49%   -0.02%     
==========================================
  Files          71       71              
  Lines       39012    39012              
==========================================
- Hits        35310    35304       -6     
- Misses       3702     3708       +6     
Impacted Files Coverage Δ
lightning/src/ln/chan_utils.rs 95.51% <100.00%> (ø)
lightning-invoice/src/de.rs 81.06% <0.00%> (-0.21%) ⬇️
lightning/src/ln/functional_tests.rs 97.20% <0.00%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d29ae18...23b32ef. Read the comment docs.

@Tibo-lg Tibo-lg force-pushed the make-counterpartycommitmentsecrets-public branch from 12d5dc2 to 8fdf255 Compare February 8, 2022 23:48
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from the wrong link.

/// Can only fail if idx is < get_min_seen_secret
pub(crate) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
/// Returns the secret at index `idx`.
/// Returns `None` if idx is < [CounterpartyCommitmentSecrets::get_min_secret].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that CI is failing cause this link is bad - its get_min_seen_secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed sorry, I doubled check locally it should be good now 🤞

@Tibo-lg Tibo-lg force-pushed the make-counterpartycommitmentsecrets-public branch from 8fdf255 to 76cb45c Compare February 9, 2022 02:00
TheBlueMatt
TheBlueMatt previously approved these changes Feb 9, 2022
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits on the doc style

@@ -197,7 +200,9 @@ impl CounterpartyCommitmentSecrets {
res
}

pub(crate) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> {
/// Inserts the secret `secret` at index `idx`. Returns Ok(()) if the secret
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can leave off the leading non-ticked words "secret" and "index". Likewise elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done I hope I got them all

@@ -197,7 +200,9 @@ impl CounterpartyCommitmentSecrets {
res
}

pub(crate) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), ()> {
/// Inserts the secret `secret` at index `idx`. Returns Ok(()) if the secret
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ticks around Ok(())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// Can only fail if idx is < get_min_seen_secret
pub(crate) fn get_secret(&self, idx: u64) -> Option<[u8; 32]> {
/// Returns the secret at index `idx`.
/// Returns `None` if idx is < [CounterpartyCommitmentSecrets::get_min_seen_secret].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ticks around identifiers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (I think it was only idx on second line missing?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: [`CounterpartyCommitmentSecrets::get_min_seen_secret`]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed thanks, need to read up more on doc formatting.

@@ -173,7 +174,9 @@ impl CounterpartyCommitmentSecrets {
48
}

pub(crate) fn get_min_seen_secret(&self) -> u64 {
/// Return the minimum index of all stored secrets. Note that indexes start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Return/Returns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Tibo-lg Tibo-lg force-pushed the make-counterpartycommitmentsecrets-public branch from 76cb45c to 131cb8c Compare February 9, 2022 23:59
@@ -140,10 +140,10 @@ pub fn build_closing_transaction(to_holder_value_sat: u64, to_counterparty_value
/// Implements the per-commitment secret storage scheme from
/// [BOLT 3](https://github.com/lightningnetwork/lightning-rfc/blob/dcbf8583976df087c79c3ce0b535311212e6812d/03-transactions.md#efficient-per-commitment-secret-storage).
///
/// Allows us to keep track of all of the revocation secrets of counterarties in just 50*32 bytes
/// Allows us to keep track of all of the revocation secrets of counter parties in just 50*32 bytes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI fixed a typo here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

counterparty is one word, not two, so I believe counterparties would be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed, my spellchecker didn't like counterparties I guess I'll have to teach him :)

@Tibo-lg Tibo-lg force-pushed the make-counterpartycommitmentsecrets-public branch from 131cb8c to 23b32ef Compare February 10, 2022 01:36
TheBlueMatt
TheBlueMatt previously approved these changes Feb 10, 2022
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, one more nit, but feel free to ignore it, it doesn't matter that much.

@@ -140,10 +140,10 @@ pub fn build_closing_transaction(to_holder_value_sat: u64, to_counterparty_value
/// Implements the per-commitment secret storage scheme from
/// [BOLT 3](https://github.com/lightningnetwork/lightning-rfc/blob/dcbf8583976df087c79c3ce0b535311212e6812d/03-transactions.md#efficient-per-commitment-secret-storage).
///
/// Allows us to keep track of all of the revocation secrets of counterarties in just 50*32 bytes
/// Allows us to keep track of all of the revocation secrets of counterparties in just 50*32 bytes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, lol, this shoulnd't be plural anyway. s/counterparties/our counterparty/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

@Tibo-lg Tibo-lg force-pushed the make-counterpartycommitmentsecrets-public branch from 23b32ef to b901df2 Compare February 10, 2022 03:19
TheBlueMatt
TheBlueMatt previously approved these changes Feb 10, 2022
@Tibo-lg Tibo-lg force-pushed the make-counterpartycommitmentsecrets-public branch from b901df2 to ba289b8 Compare February 10, 2022 06:25
@TheBlueMatt TheBlueMatt merged commit 9be8a66 into lightningdevkit:main Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants