Skip to content

Implement to and from for PublicKey and NodeId #2180

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2023

Conversation

benthecarman
Copy link
Contributor

@benthecarman benthecarman commented Apr 13, 2023

These types should be pretty much synonymous


impl From<NodeId> for PublicKey {
fn from(node_id: NodeId) -> PublicKey {
PublicKey::from_slice( &node_id.0).unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't synonymous because the unwrap here is reachable. NodeIds were introduced because the pubkey validation is relatively expensive (took several seconds to read a network graph from disk).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to TryFrom

@codecov-commenter
Copy link

codecov-commenter commented Apr 13, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.01 ⚠️

Comparison is base (157af6e) 91.36% compared to head (e1b50cf) 91.35%.

❗ Current head e1b50cf differs from pull request most recent head 7a37e2c. Consider uploading reports for the commit 7a37e2c to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2180      +/-   ##
==========================================
- Coverage   91.36%   91.35%   -0.01%     
==========================================
  Files         102      102              
  Lines       50369    50374       +5     
  Branches    50369    50374       +5     
==========================================
+ Hits        46018    46021       +3     
- Misses       4351     4353       +2     
Impacted Files Coverage Δ
lightning/src/routing/gossip.rs 89.96% <0.00%> (-0.32%) ⬇️

... and 3 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

tnull
tnull previously approved these changes Apr 13, 2023
dunxen
dunxen previously approved these changes Apr 13, 2023
impl FromStr for NodeId {
type Err = secp256k1::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let pubkey = PublicKey::from_str(s)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is pretty ineffecient, can we just do the hex conversion directly?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't currently have a non-test hex dependency, and it seems kinda wasteful to add one :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How should we do this conversion then? I think bitcoin_hashes has one too

Copy link
Collaborator

Choose a reason for hiding this comment

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

bitcoin_hashes just implements it itself, its like 5 LoC to just walk the chars and to_digit(16) them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idk what I missed the first time around but looks like we did have bitcoin_hashes' version available so i used that

@benthecarman benthecarman dismissed stale reviews from dunxen and tnull via 37cd606 April 13, 2023 17:54
@benthecarman benthecarman force-pushed the impl-pk-to-node-id branch 2 times, most recently from 6ed9f88 to ba7119b Compare April 13, 2023 19:15
TheBlueMatt
TheBlueMatt previously approved these changes Apr 13, 2023
dunxen
dunxen previously approved these changes Apr 13, 2023
@benthecarman benthecarman dismissed stale reviews from dunxen and TheBlueMatt via 7a37e2c April 13, 2023 19:53
@TheBlueMatt TheBlueMatt merged commit accfdae into lightningdevkit:main Apr 14, 2023
@benthecarman benthecarman deleted the impl-pk-to-node-id branch April 14, 2023 15:47
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.

5 participants