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

refactor: interfaces, make 'createTransaction' less error-prone #807

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

furszy
Copy link
Member

@furszy furszy commented Mar 22, 2024

Bundle all function's outputs inside the util::Result returned object.

Removals:

Additionally, this PR moves the CreatedTransactionResult struct into its own file. This change is made to avoid further expanding the GUI dependencies on wallet.h. Structurally, the GUI should only access the model/interfaces and never the wallet directly.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 22, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, 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.

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin-core/gui/runs/22979285609

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a 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)?

Copy link
Member Author

@furszy furszy left a 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.

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a 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.
@furszy furszy force-pushed the 2024_gui_clean_createTransaction branch from dfbd145 to 7fb81d2 Compare April 18, 2024 11:47
Copy link
Member Author

@furszy furszy left a 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.

@hebasto
Copy link
Member

hebasto commented May 12, 2024

While introducing a new wallet/util_spend.h header, it seems reasonable to address all related IWYU warnings, no?

@hebasto
Copy link
Member

hebasto commented May 12, 2024

cc @achow101 @ryanofsky


#include <optional>

struct CreatedTransactionResult
Copy link
Contributor

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.

Copy link
Member Author

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.
@furszy furszy force-pushed the 2024_gui_clean_createTransaction branch from 7fb81d2 to 4d941b5 Compare May 16, 2024 21:00
Copy link
Member Author

@furszy furszy left a 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!

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin-core/gui/runs/25073685372

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants