wallet: cleanup cached amount and input mine check code #25543

pull furszy wants to merge 7 commits into bitcoin:master from furszy:2022_wallet_cleanup_1 changing 3 files +20 −48
  1. furszy commented at 1:27 PM on July 5, 2022: member

    Another wallet's code garbage collector work. Part of the mapWallet encapsulation goal.

    Focused on the following points:

    1. Remove always true fUseCache argument from CachedTxGetImmatureCredit, CachedTxGetImmatureWatchOnly and CachedTxGetAvailableCredit.
    2. Remove always false recalculate argument from GetCachableAmount.
    3. Merge CachedTxGetImmatureCredit and CachedTxGetImmatureWatchOnlyCredit as they do share the exact same code.
    4. Clean InputIsMine method; use GetWalletTx instead of access the wallet's map directly.
    5. Clean AllInputsMine method; use InputIsMine instead of duplicate the exact same code internally.
  2. wallet: remove always true 'fUseCache' from CachedTxGetImmatureCredit da8f62de2c
  3. wallet: remove always true 'fUseCache' from CachedTxGetImmatureWatchOnlyCredit 47b1012677
  4. wallet: remove always false 'recalculate' arg from GetCachableAmount 4f0ca9bff6
  5. wallet: remove always true 'fUseCache' arg from CachedTxGetAvailableCredit 04c6423f7b
  6. wallet: unify CachedTxGetImmatureCredit and CachedTxGetImmatureWatchOnlyCredit 0cb177263c
  7. wallet: clean InputIsMine code, use GetWalletTx bf310b0e8c
  8. fanquake added the label Wallet on Jul 5, 2022
  9. DrahtBot commented at 7:57 PM on July 5, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24699 (wallet: Improve AvailableCoins performance by reducing duplicated operations by achow101)

    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.

  10. in src/wallet/test/wallet_tests.cpp:359 in ba2fa8302d outdated
     356 |      // Invalidate the cached value, add the key, and make sure a new immature
     357 |      // credit amount is calculated.
     358 |      wtx.MarkDirty();
     359 |      AddKey(wallet, coinbaseKey);
     360 | -    BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx), 50*COIN);
     361 | +    BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx, ISMINE_SPENDABLE), 50*COIN);
    


    aureleoules commented at 6:13 PM on July 6, 2022:

    nit

        BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx, ISMINE_SPENDABLE), 50 * COIN);
    
  11. aureleoules commented at 6:13 PM on July 6, 2022: member

    ACK ba2fa8302dc3816d5b9584907135f91789846d65. Looks better! I checked that the refactor does not change the behavior of the code.

  12. theStack approved
  13. theStack commented at 8:36 PM on July 6, 2022: contributor

    Code-review ACK ba2fa8302dc3816d5b9584907135f91789846d65

    Nice refactoring!

  14. wallet: clean AllInputsMine code, use InputIsMine internally
    Instead of duplicate the exact same code twice.
    47ea70fbb8
  15. in src/wallet/receive.cpp:27 in ba2fa8302d outdated
      42 | -            return false; // invalid input!
      43 | -
      44 | -        if (!(wallet.IsMine(prev.tx->vout[txin.prevout.n]) & filter))
      45 | +    for (const CTxIn& txin : tx.vin) {
      46 | +        if (!(InputIsMine(wallet, txin) & filter))
      47 |              return false;
    


    jonatack commented at 8:44 PM on July 6, 2022:

    While here, could you add the missing brackets to the conditional per the developer notes, or hoist return false; to the same line?

    We require brackets with conditionals over one line due to CVE-2014-1266 (the Apple "goto fail" vulnerability, see also https://dwheeler.com/essays/apple-goto-fail).


    furszy commented at 9:09 PM on July 6, 2022:

    pushed

  16. furszy force-pushed on Jul 6, 2022
  17. furszy commented at 9:11 PM on July 6, 2022: member

    per feedback, have inlined AllInputsMine return statement.

  18. theStack approved
  19. theStack commented at 10:58 AM on July 7, 2022: contributor

    re-ACK 47ea70fbb85fefeb4de9d3142a11596d292eab9b

  20. furszy commented at 2:42 PM on July 20, 2022: member

    hey @jonatack @aureleoules, friendly ping here.

  21. aureleoules commented at 2:45 PM on July 20, 2022: member

    re-ACK 47ea70fbb85fefeb4de9d3142a11596d292eab9b

  22. achow101 commented at 8:49 PM on July 20, 2022: member

    ACK 47ea70fbb85fefeb4de9d3142a11596d292eab9b

  23. achow101 merged this on Jul 20, 2022
  24. achow101 closed this on Jul 20, 2022

  25. sidhujag referenced this in commit 52c3930767 on Jul 21, 2022
  26. furszy deleted the branch on May 27, 2023
  27. bitcoin locked this on May 26, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me