-
Notifications
You must be signed in to change notification settings - Fork 38.7k
refactor: Update XOnlyPubKey::GetKeyIDs() to return a pair of pubkeys
#32332
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32332. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
hodlinator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was nerd-sniped by this PR decreasing heap usage. Otherwise these kinds of refactorings are a bit frowned upon.
src/pubkey.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code should use snake_case for variables according to developer-notes.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
src/pubkey.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you instead return std::array<CKeyID, 2> the data is still on the stack and you don't need to touch signingprovider.h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
feca203 to
4041cbf
Compare
|
@hodlinator yes, this decreases heap usage, but I don't think there are any relevant performance gains. |
hodlinator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 4041cbf3c6ce1dfafc4e4c2d1fe834ce52bbc879
src/pubkey.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Grepped for std::array<\w+,\w+ and only found 2 other occurrences (vs 89 for std::array<\w+, \w+).
| std::array<CKeyID,2> XOnlyPubKey::GetKeyIDs() const | |
| std::array<CKeyID, 2> XOnlyPubKey::GetKeyIDs() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in acf73d3
src/pubkey.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could use cbegin/cend here and below:
| full_pubkey.Set(b, b + 33); | |
| full_pubkey.Set(std::cbegin(b), std::cend(b)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in acf73d3
src/pubkey.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could be more precise:
| /** Returns two CKeyIDs for the CPubKeys that could have been used to create this XOnlyPubKey. | |
| /** Returns CKeyIDs for the even and odd CPubKeys that could have been used to create this XOnlyPubKey. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in acf73d3
src/pubkey.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - casing inconsistency:
| return std::array<CKeyID, 2>{ id_even_pubkey, id_odd_pubKey }; | |
| return std::array<CKeyID, 2>{ id_even_pubkey, id_odd_pubkey }; |
Edit: could just drop _pub[kK]ey as we are in the XOnlyPubKey:
| return std::array<CKeyID, 2>{ id_even_pubkey, id_odd_pubKey }; | |
| return std::array<CKeyID, 2>{ id_even, id_odd }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1718177
hodlinator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 1718177
Tiny refactor that clarifies the XOnlyPubKey::GetKeyIDs() interface by explicitly returning 2 ids (making heap-usage less likely as a bonus). Also documents even/odd Y values.
Only trivial changes since first ACK (please resolve).
rkrux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1718177
Usually minor refactoring changes are avoided but I don't seem to mind this change. It does increase the readability marginally as I like seeing an array of size two in the return type instead of vector while going through the callers of GetKeyIDs function.
Both array & vector satisfy the requirements of the CPP Container as well.
|
-0 I don't think such refactorings are meaningfully useful. While it may improve readability a bit, I don't think the difference is enough to justify making this change. Such refactorings both can cause merge conflicts with other higher priority work, and also make git blame a little bit harder. |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
Currently,
XOnlyPubKey::GetKeyIDs()hasvectoras return type, but always returns a pair of public key IDs.This PR changes the code for readability reasons.
There may be negligible efficiency gains, but the goal is to make the code more readable and to make the intent of the function clear.
There is no change in behavior.