8000 wallet: simplify ListCoins implementation by furszy · Pull Request #25659 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

wallet: simplify ListCoins implementation #25659

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

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

furszy
Copy link
Member
@furszy furszy commented Jul 21, 2022

Focused on the following changes:

  1. Removed the entire locked coins lookup that was inside ListCoins by including them directly on the AvailableCoins result (where we were skipping them before).
  2. Unified both FindNonChangeParentOutput functions (only called from ListCoins)

@DrahtBot
Copy link
Contributor
DrahtBot commented Jul 21, 2022

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 aureleoules, theStack, achow101
Concept ACK josibake
Stale ACK w0xlt

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:

  • #26699 (wallet, gui: bugfix, getAvailableBalance skips selected coins by furszy)
  • #26365 (wallet: GetEffectiveBalance by willcl-ark)
  • #25979 ([WIP] wallet: standardize change output detection process by furszy)

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.

Copy link
Contributor
@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

ACK 6451afa.

  • Verified that default values have not been changed in the AvailableCoinsParams struct.
  • I understand that skipped coins are skipped in the AvailableCoins function instead of being post-processed to avoid iterating over all coins again.
  • ListCoins is now much more readable.

@furszy furszy force-pushed the 2022_wallet_clean_listCoins branch from 6451afa to adfdd02 Compare July 25, 2022 13:33
@furszy
Copy link
Member Author
furszy commented Jul 25, 2022

Thanks for the feedback @aureleoules!
nit pushed inside adfdd02. Inlined the assert + declaration using the Assert() helper function.

I understand that skipped coins are skipped in the AvailableCoins function instead of being post-processed to avoid iterating over all coins again.

On master, by default, we skip the locked coins inside AvailableCoins, which forces ListCoins to do a secondary lookup only to fetch them.
As AvailableCoins walks-through the entire wallet txs map (which includes the locked coins), this PR adds a filter option to include the locked coins in the result, instead of discard them, so ListCoins doesn't need to do the secondary lookup after calling AvailableCoins.

Copy link
Contributor
@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

tACK adfdd02

The removed code seems redundant and not discarding the locked coins in AvailableCoins is a better solution.

@furszy
Copy link
Member Author
furszy commented Jul 29, 2022

Rebased on master due conflicts with recently merged 24584.

Ready to go again.

@furszy
Copy link
Member Author
furszy commented Aug 5, 2022

rebased

@theStack
Copy link
Contributor
theStack commented Aug 9, 2022

Concept ACK

Copy link
Contributor
@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

reACK e8b9bd8

Copy link
Member
@josibake josibake left a comment

Choose a reason for hiding this comment

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

Concept ACK on simplifying ListCoins but a little concerned with the general trend of making AvailableCoins a general purpose wallet traversal tool. I'm more thinking out loud here, so feel free to ignore me.

It seems we've added a few flags recently to AvailableCoins to remove additional lookups in other wallet functions and simplify code, which is great, but I'm worried that instead of simplifying we are instead obfuscating complexity and expanding the responsibility of AvailableCoins to do too many things.

This is more of a meta concern and not really a criticism of this PR, so don't want to block if other reviewers feel strongly this is the right way to go. Personally, I'm more in favor of leaving it as is for now and instead starting a discussion on a more holistic solution. If we do decide to keep increasing the responsibility of AvailableCoins, I'd recommend we leave the function signature as is and not wrap params in a struct so as to keep complexity explicit rather than hidden.

@achow101
Copy link
Member

Are you still working on this?

@achow101
Copy link
Member

Closing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened.

@achow101 achow101 closed this Nov 10, 2022
@furszy
Copy link
Member Author
furszy commented Nov 27, 2022

@achow101 please re-open it. Will rebase it, it will be smaller now.

@achow101 achow101 reopened this Nov 27, 2022
@furszy furszy force-pushed the 2022_wallet_clean_listCoins branch from e8b9bd8 to 65e5d15 Compare November 27, 2022 23:27
@furszy
Copy link
Member Author
furszy commented Nov 28, 2022

rebased, status updated.

achow101 added a commit that referenced this pull request Jan 3, 2023
9622fe6 test: move coins result test to wallet_tests.cpp (furszy)
f69347d test: extend and simplify availablecoins_tests (furszy)
212ccdf wallet: AvailableCoins, add arg to include/skip locked coins (furszy)

Pull request description:

  Negative PR with extended test coverage :).

  1) Cleaned duplicated code and added coverage for the 'AvailableCoins' incremental result.

  2) The class `AvailableCoinsTestingSetup` inside `availablecoins_tests.cpp` is a plain copy
  of `ListCoinsTestingSetup` that is inside `wallet_tests.cpp`.

      So, deleted the file and moved the `BasicOutputTypesTest` test case to `wallet_tests.cpp`.

  3) Added arg to include/skip locked coins from the `AvailableCoins` result. This is needed for point (1) as otherwise the wallet will spend the coins that we recently created due its closeness to the recipient amount.
  Note: this last point comes from #25659 where I'm using the same functionality to clean/speedup another flow as well.

ACKs for top commit:
  achow101:
    ACK 9622fe6
  theStack:
    ACK 9622fe6
  aureleoules:
    reACK 9622fe6, nice cleanup!

Tree-SHA512: 1ed9133120bfe8815455d1ad317bb0ff96e11a0cc34ee8098716ab9b001749168fa649212b2fa14b330c1686cb1f29039ff1f88ae306db68881b0428c038f388
furszy added 2 commits January 3, 2023 17:25
< 6D40 div class="Details-content--hidden mt-2">
Can remove the locked coins lookup if we include them directly
inside the AvailableCoins result
The function is only used in ListCoins.
@furszy furszy force-pushed the 2022_wallet_clean_listCoins branch from 64494e6 to a2ac6f9 Compare January 3, 2023 20:27
@furszy
Copy link
Member Author
furszy commented Jan 3, 2023

rebased post #25789 merge. Now this PR purely cleans up an ugly flow.

@DrahtBot DrahtBot changed the title wallet: simplify ListCoins implementation wallet: simplify ListCoins implementation Jan 3, 2023
Copy link
Contributor
@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

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

ACK a2ac6f9, LGTM

I verified the call to AvailableCoins takes the same coin controls params as AvailableCoinsListUnspent except for skip_locked which is now false and fAllowWatchOnly to allow the removal of the large and redundant chunk of code below.

@furszy furszy requested a review from w0xlt January 11, 2023 11:52
Copy link
Contributor
@theStack theStack left a comment

Choose a reason for hiding this comment

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

Code-review ACK a2ac6f9

As discussed in IRC, note that the first commit is more than just a refactor, as it introduces some changes in behaviour regarding locked coins, since the filtering in AvailableCoins is much more detailled than the manual loop in ListCoins that is replaced:

  • locked unsafe coins are are included on master, but excluded on the PR (CCoinControl's m_include_unsafe_inputs is false by default)
  • locked immature coinbase coins are included on master, but excluded on the PR (CoinFilterParams' include_immature_coinbase is false by default)
  • locked coins that are unconfirmed but not in the mempool are included in the master, but excluded on the PR (no option available to pass that, but I'm not sure how to even reach such a state)

However, all of those behaviour changes seem to make sense, the commit could be seen as a bugfix. It doesn't make much sense to display unsafe or immature coins for selection in the GUI (that's the only place where ListCoins is currently used, via the listCoins interface). For a follow-up candidate, would be nice to add a proper test for ListCoins which would have detected the behaviour changes.

@furszy
Copy link
Member Author
furszy commented Jan 17, 2023

Thanks for the detailed review @theStack!

@achow101
Copy link
Member

ACK a2ac6f9

However, all of those behaviour changes seem to make sense, the commit could be seen as a bugfix. It doesn't make much sense to display unsafe or immature coins for selection in the GUI

Additionally all locked coins are not able to be selected in the GUI, so this does not materially affect what users are able to choose. However it does affect what is displayed to users.

@achow101 achow101 merged commit 8ae2808 into bitcoin:master Jan 18, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 19, 2023
a2ac6f9 wallet: unify FindNonChangeParentOutput functions (furszy)
b3f4e82 wallet: simplify ListCoins implementation (furszy)

Pull request description:

  Focused on the following changes:

  1) Removed the entire locked coins lookup that was inside `ListCoins` by including them directly on the `AvailableCoins` result (where we were skipping them before).
  2) Unified both `FindNonChangeParentOutput` functions (only called from `ListCoins`)

ACKs for top commit:
  achow101:
    ACK a2ac6f9
  aureleoules:
    ACK a2ac6f9, LGTM
  theStack:
    Code-review ACK a2ac6f9

Tree-SHA512: f72b21ee1600c5992559b5dcd8ff260527afac2ec696737f998343a0850b84d439e7f86ea52a14cc0cddabf132a30bf5b52fb34950578ac323083d4375b937f1
@furszy furszy deleted the 2022_wallet_clean_listCoins branch May 27, 2023 01:49
@bitcoin bitcoin locked and limited conversation to collaborators May 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0