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
refactor: interfaces, make 'createTransaction' less error-prone #807
base: master
Are you sure you want to change the base?
refactor: interfaces, make 'createTransaction' less error-prone #807
Conversation
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. |
a44999c
to
dfbd145
Compare
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
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.
tACK dfbd145
This PR solves the error described in #805, even #806 fixes other 2 related errors.
wallet/interfaces.cpp:289:57: runtime error: implicit conversion from type 'int' of value -1 (32-bit, signed) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned)
I agree with the reasoning behind the removal of some arguments and the unreachable exception.
Out of curiosity, could you please add some refs on "The input-output 'change_pos' ref arg from createTransaction, which has been a source of bugs in the past.", if possible?
Are there other components/ functions that you think could be moved into the new util_spend.h
file (perhaps as a follow-up)?
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.
Out of curiosity, could you please add some refs on "The input-output 'change_pos' ref arg from createTransaction, which has been a source of bugs in the past.", if possible?
Sure, bitcoin/bitcoin#29065.
Are there other components/ functions that you think could be moved into the new util_spend.h file (perhaps as a follow-up)?
Not off the top of my head. Matter of continue breaking the GUI classes dependency on wallet.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.
cr ACK dfbd145
Internally, 'createTransaction' only returns the fee when the transaction creation process succeeds. This error can be reintroduced in the future in a cleaner manner when the feature becomes available at the backend level.
dfbd145
to
7fb81d2
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.
Rebased after #806 merge.
While introducing a new |
src/wallet/util_spend.h
Outdated
|
||
#include <optional> | ||
|
||
struct CreatedTransactionResult |
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 commit "refactor: move CreatedTransactionResult to an util file" (6d59564)
Would suggest maybe moving this struct to wallet/types.h
instead of introducing a new header. That file is meant to hold wallet types that are used outside of the wallet library. (For context see bitcoin/bitcoin#29415 (comment) which talks about wallet/types.h, node/types.h, and common/types.h files).
Or if you would prefer to use a separate header, would suggest spend_types.h
instead of util_spend.h
so it is grouped with spend.h
and spend.cpp
alphabetically, and to be clear the header should only contain types, not spending functions which would probably be inappropriate to call from the GUI. Would also suggest keeping the wallet::
namespace for consistency. If you look at other wallet types used in the GUI like AddressPurpose, isminetype, and CCoinControl, they are all in the wallet namespace.
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.
Would suggest maybe moving this struct to wallet/types.h instead of introducing a new header. That file is meant to hold wallet types that are used outside of the wallet library. (For context see bitcoin/bitcoin#29415 (comment) which talks about wallet/types.h, node/types.h, and common/types.h files).
Nice, sure. I'm on the same boat, I just wrote this without thinking on a general convention.
So it can be used by external modules without requiring wallet.h dependency.
Bundle all function's outputs inside the util::Result returned object. Reasons for the refactoring: - The 'change_pos' ref argument has been a source of bugs in the past. - The 'fee' ref argument is currently only set when the transaction creation process succeeds.
7fb81d2
to
4d941b5
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.
updated per feedback. Thanks @ryanofsky!
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
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 4d941b5
- Changes from my last review:
CreatedTransactionResult
struct moved as suggested by @ryanofsky explaining reasoning behind the convention. I like the idea of keeping the namespace, not only for consistency but for clarity and making the code more readable. I think it would be good to document this somewhere, perhaps in the developer notes to begin with (?).
nit: on 2nd. commit (95aaaa4), you forgot to remove the change from the makefile as it's not longer needed.
Bundle all function's outputs inside the
util::Result
returned object.Removals:
createTransaction
, which has been a source of bugs in the past.createTransaction
, which is currently only set when the transaction creation process succeeds.AmountWithFeeExceedsBalance
error (more info about its re-introduction at wallet: re-activate the not triggered "AmountWithFeeExceedsBalance" error bitcoin/bitcoin#25269).Additionally, this PR moves the
CreatedTransactionResult
struct into its own file. This change is made to avoid further expanding the GUI dependencies onwallet.h
. Structurally, the GUI should only access the model/interfaces and never the wallet directly.