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 CWallet::AvailableCoins method signature #1859

Closed

Conversation

furszy
Copy link

@furszy furszy commented Sep 20, 2020

Purely an aesthetic improvement, no functional changes. Combining parameters that should had been coded into CoinControl wrapper class in the first place.

@furszy furszy self-assigned this Sep 20, 2020
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

This does not compile.
The signature of CreateTransaction needs to be updated in WalletModel::prepareTransaction too.

@furszy
Copy link
Author

furszy commented Sep 20, 2020

yeah, doing it. I forgot that my environment had qt disabled.

@furszy furszy force-pushed the 2020_cleanup_availableCoins_signature branch from d8c9e92 to c712a46 Compare September 20, 2020 15:07
@furszy
Copy link
Author

furszy commented Sep 20, 2020

updated.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Aside from a couple bugs, I am not sure about the concept.
It seems to make the code more complex, because these flags don't really belong to the coinControl object.
Most of the times these are used when CC is null.
And when coinControl is not null, and we have coins selected, then we don't care about specific flags because we simply want to skip everything except the selection, at this line:

if (fCoinsSelected && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint((*it).first, i)))
    continue;

src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
@furszy
Copy link
Author

furszy commented Sep 21, 2020

Aside from a couple bugs, I am not sure about the concept.
It seems to make the code more complex, because these flags don't really belong to the coinControl object.

Essentially made this to be able to add more features and don't continue extending the method signature. It has so many arguments with default values that it's easy to call this method wrongly without noticing it.

The two options to solve this: (1) use the CoinControl wrapper, (2) create a new struct for the extra arguments that we are passing one by one to AvailableCoins (and similar methods).

I'm more inclined to the first one because the CoinControl was essentially built for that reason. Add certain coins filtering capabilities in a single object and not pass them as arguments (making the AvailableCoins and CreateTransaction method signatures unreadable as well).
But.. as a middle step, could move it to the second option if this change adds an unnecessary complexity for now. This PR is a bridge to get other things implemented, not trying to change much things here as there are going to be a lot of changes in the area already.

@random-zebra
Copy link

CoinControl was essentially built for that reason

Well, the purpose of CCoinControl is to provide an interface to manage a set of outpoints (setSelected). Using it to store the arguments for AvailableCoins is a stretch in my opinion.
In fact, thinking about it (idea for future refactoring), we shouldn't even call AvailableCoins when there are coins selected in coinControl. We should just get the COutputs from the COutpoints directly.

Anyway the added complexity of (1) is kinda highlighted by these sneaky bugs on something that was supposed to be "purely an aesthetic improvement, no functional changes".

So, yeah, I would definitely prefer (2) over (1).
Or, as alternative solution for the time being, simply don't use default arguments and explicitely add them at every call.

@furszy
Copy link
Author

furszy commented Sep 21, 2020

In fact, thinking about it (idea for future refactoring), we shouldn't even call AvailableCoins when there are coins selected in coinControl. We should just get the COutputs from the COutpoints directly.

Indeed, good idea. That will make a nice speed difference in the tx creation process for users with lot of txs that manually selected the utxo to spend.

#-

Going with (2) for now then. It's more organized and readable.

@furszy
Copy link
Author

furszy commented Nov 17, 2020

Closing this one, made a complete overhaul of the area in #1977

@furszy furszy closed this Nov 17, 2020
@Fuzzbawls Fuzzbawls removed this from the 5.0.0 milestone Dec 4, 2020
@furszy furszy deleted the 2020_cleanup_availableCoins_signature branch November 29, 2022 14:10
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.

3 participants