-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Refactor and document CoinControl #26066
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
wallet: Refactor and document CoinControl #26066
Conversation
These changes improve the code quality and implement the recommended practices described in the developer notes - source code organization. Concept ACK |
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 ae67293
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
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.
In dba7f9b:
Why only change IsSelected
and HasSelected
and not the setters? Should be consistent.
Saying that, even if we are consistent on the renaming, I'm not so sure about it. Do you think that PreSelect(outpoint)
/IsPreSelected(outpoint)
is more understandable than Select(outpoint)
/IsSelected(output)
?
At least in my view, it doesn't look more readable than before.
Would instead aim for a good docstring and done.
ae67293
to
69b67d5
Compare
@furszy I've slightly improved the docstring of Is it better? |
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.
Yeah @aureleoules better 👍🏼 .
69b67d5
to
4d77ada
Compare
All cleaned-up @furszy! |
d0156a0
to
9d4cfd6
Compare
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 9d4cfd6
src/wallet/coincontrol.h
Outdated
* Pre-selects the given output. | ||
* The output will be included in the transaction even if it's not the most optimal choice. |
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: would remove the "pre-selects" term and go directly with something like "store the given outpoint."
I don't think that the "pre" term here provides information to readers. (the second paragraph is great to express what the process will do with the selected outpoint)
(same for the others methods as well).
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.
How about this?
* Pre-selects the given output. | |
* The output will be included in the transaction even if it's not the most optimal choice. | |
* Lock-in the selected output for spending. | |
* The output will be included in the transaction even if it's not the most optimal choice. |
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.
yeah, sounds good 👌🏼 .
|
||
private: | ||
std::set<COutPoint> setSelected; | ||
std::set<COutPoint> m_preset_inputs; | ||
std::map<COutPoint, CTxOut> m_external_txouts; |
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: you've done such a fabulous job documenting the header methods (no good deed goes unpunished!) that I think I understand an external input is one that does not belong to the wallet.
If you find yourself in the code again, is there any chance to get a comment on this data structure describing what it is? Something like //! Map of inputs that do not belong to the wallet
(if that is indeed the correct definition). Actually... just for my own learning, is that the correct definition?
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!
And yes you are correct :) The wallet would not know how to sign these inputs but they are in the utxo set.
ACK 9d4cfd6, reviewed diff and ran unit + functional tests I'm very new to the project but this was a great PR to review, especially after the changes that came in from earlier code review. Thanks for the comments you added on all the function definitions. Can confirm that they are helpful to new eyes and as far as I can tell, the changes are a nice cleanup that make things easier to read, understand, and follow the recommended practices (as mentioned in an earlier comment). |
9d4cfd6
to
287719a
Compare
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 287719a
287719a
to
8031f47
Compare
sorry I failed my rebase @furszy |
or well, not ACK :p. |
Should be all good now, I've actually renamed |
8031f47
to
5db911a
Compare
ACK 5db911a |
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 5db911a
I think this is ready for merging? @w0xlt if you could reACK that would be great 😄. |
5db911a
to
3f1a6d9
Compare
-BEGIN VERIFY SCRIPT- sed -i 's/setSelected/m_selected_inputs/g' src/wallet/coincontrol.h src/wallet/coincontrol.cpp -END VERIFY SCRIPT-
Move definitions to coincontrol.cpp and add documentation.
b76fbbe
to
c975c42
Compare
c975c42
to
daba957
Compare
Rebased |
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 daba957
m_external_txouts.emplace(outpoint, txout); | ||
} | ||
|
||
void CCoinControl::UnSelect(const COutPoint& output) |
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: If it’s not too much of a bother, and if you have to touch the code again, I would consider it an improvement to change UnSelect
to Unselect
. The first time I scanned that passage, the capitalized “S” in the middle of the word made me think that it was actually just “Select”. Even more nitty, I’d use the adjective “unselected” to refer to things that were not picked in the first place, I would prefer “to deselect” to refer to removing things from a selection.
void CCoinControl::UnSelect(const COutPoint& output) | |
void CCoinControl::Deselect(const COutPoint& output) |
m_selected_inputs.erase(output); | ||
} | ||
|
||
void CCoinControl::UnSelectAll() |
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 with the same reasoning as above:
void CCoinControl::UnSelectAll() | |
void CCoinControl::DeselectAll() |
ACK daba957 |
daba957 refactor: Make ListSelected return vector (Sebastian Falbesoner) 9477662 wallet: Move CoinCointrol definitions to .cpp (Aurèle Oulès) 1db23da wallet: Use std::optional for GetExternalOutput and fixups (Aurèle Oulès) becc45b scripted-diff: Rename setSelected->m_selected_inputs (Aurèle Oulès) Pull request description: - Moves CoinControl function definitions from `coincontrol.h` to `coincontrol.cpp` - Adds more documentation - Renames class member for an improved comprehension - Use `std::optional` for `GetExternalOutput` ACKs for top commit: achow101: ACK daba957 Xekyo: ACK daba957 Tree-SHA512: 3bf2dc834a3246c2f53f8c55154258e605fcb169431d3f7b156931f33c7e3b1ae28e03e16b37f9140a827890eb7798be485b2c36bfc23ff29bb01763f289a07c
coincontrol.h
tocoincontrol.cpp
std::optional
forGetExternalOutput