[MOVEONLY] Move some static functions out of wallet.h/cpp #10976

pull ryanofsky wants to merge 3 commits into bitcoin:master from ryanofsky:pr/wmove changing 13 files +418 −351
  1. ryanofsky commented at 12:06 PM on August 2, 2017: contributor

    This just moves some static wallet fee and init functions out of wallet/wallet.cpp and into new wallet/fees.cpp and wallet/init.cpp source files. There is one commit updating declarations and callers, followed by two MOVEONLY commits actually moving the function bodies.

    This change is desirable because wallet.h/cpp are monolithic and hard to navigate, so pulling things out and grouping together pieces of related functionality should improve the organization.

    Another motivation is the wallet process separation work in #10973, where (at least initially) parameter parsing and fee estimation are still done in the main process rather than the wallet process, and having functions that run in different processes scrambled up throughout wallet.cpp is unnecessarily confusing.

  2. ryanofsky commented at 12:14 PM on August 2, 2017: contributor

    @laanwj, if you think this change is a good idea, it might be worth merging before 0.15 is branched, since it moves some functions around. I don't think it conflicts with other tagged prs, but if it does I'd be happy to rebase this on top of them.

  3. ryanofsky force-pushed on Aug 2, 2017
  4. MarcoFalke added the label Refactoring on Aug 2, 2017
  5. MarcoFalke added the label Wallet on Aug 2, 2017
  6. jnewbery commented at 4:59 PM on August 2, 2017: member

    Seems to be largely the same as #10767 ?

  7. ryanofsky commented at 5:32 PM on August 2, 2017: contributor

    Seems to be largely the same as #10767 ?

    This covers fee code as well as init code, and I think the cleanups in #10767 are good but also that it's nice to start with a PR that's 100% MOVEONLY (or as close as possible). This way both the cleanup changes and moveonly changes are simpler to evaluate, and the MOVEONLY changes have (hopefully) a chance of getting merged before the branch.

  8. in src/wallet/rpcwallet.cpp:29 in 4298d90a9e outdated
      25 | @@ -27,6 +26,8 @@
      26 |  #include "wallet/wallet.h"
      27 |  #include "wallet/walletdb.h"
      28 |  
      29 | +#include <init.h>  // For StartShutdown
    


    jnewbery commented at 9:44 PM on August 2, 2017:

    why?


    ryanofsky commented at 7:44 PM on August 14, 2017:

    This is needed to pull in src/init.h instead of src/wallet/init.h. Probably all of our code should be using <> instead of "" because we don't generally include relative to current directory.

  9. jnewbery commented at 9:48 PM on August 2, 2017: member

    ACK 4298d90a9e3ea04e74d85ee995bf58e6aa8a0587.

    I'd prefer to name the new files walletinit.cpp and walletinit.h just to avoid any ambiguity with src/init.cpp

  10. jonasschnelli commented at 9:36 AM on August 3, 2017: contributor

    Concept ACK

  11. in src/wallet/init.h:22 in 4298d90a9e outdated
      17 | +//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
      18 | +//  This function will perform salvage on the wallet if requested, as long as only one wallet is
      19 | +//  being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
      20 | +bool WalletVerify();
      21 | +
      22 | +//! Load wallet databases
    


    promag commented at 1:58 PM on August 6, 2017:

    Nit, new comment so add missing period? The other comments without periods are move-only.


    ryanofsky commented at 8:21 PM on August 14, 2017:

    Added in aee0e0f6857a18d0e93825a2bb475c55446cfa85

  12. promag cross-referenced this on Aug 6, 2017 from issue scripted-diff: stop using the gArgs wrappers by benma
  13. promag commented at 2:46 PM on August 6, 2017: member

    The only static function staying is CreateWalletFromFile() which is a factory for CWallet and requires access to private members, so makes sense to keep it there.

    Agree with @jnewbery regarding file names, but to be consistent to rpcwallet.*, initwallet.* sounds better.

    ACK 4298d90.

  14. jnewbery commented at 10:25 PM on August 6, 2017: member

    @laanwj - as @ryanofsky says, this is another move/refactor PR that would be good to get in before branching v0.15, to help with backporting. But maybe there are already too many of those competing for your attention!

    (I'd still like the files to be renamed initwallet.{cpp,h} before this gets merged)

  15. MarcoFalke commented at 10:53 PM on August 6, 2017: member

    We can always backport the commits right after release of 0.15.0 to the 0.15 branch. No need to rush, imo.

  16. Move some static functions out of wallet.h/cpp
    This commit just moves a few function declarations and updates callers.
    Function bodies are moved in two followup MOVEONLY commits.
    
    This change is desirable because wallet.h/cpp are monolithic and hard to
    navigate, so pulling things out and grouping together pieces of related
    functionality should improve the organization.
    
    Another proximate motivation is the wallet process separation work in
    https://github.com/bitcoin/bitcoin/pull/10973, where (at least initially)
    parameter parsing and fee estimation are still done in the main process rather
    than the wallet process, and having functions that run in different processes
    scrambled up throughout wallet.cpp is unnecessarily confusing.
    d97fe2016c
  17. MOVEONLY: Fee functions wallet/wallet.cpp -> wallet/fees.cpp e7fe3208a8
  18. MOVEONLY: Init functions wallet/wallet.cpp -> wallet/init.cpp f01103c1e0
  19. jnewbery cross-referenced this on Aug 14, 2017 from issue [wallet] Clarify wallet initialization / destruction interface by jnewbery
  20. ryanofsky commented at 8:28 PM on August 14, 2017: contributor

    Rebased 4298d90a9e3ea04e74d85ee995bf58e6aa8a0587 -> 5461f69fe9e503be734c33d7b57035214bafba53 (pr/wmove.2 -> pr/wmove.3) because of conflicts with gArgs PR. Added 1 commit 5461f69fe9e503be734c33d7b57035214bafba53 -> aee0e0f6857a18d0e93825a2bb475c55446cfa85 (pr/wmove.3 -> pr/wmove.4, compare) Squashed aee0e0f6857a18d0e93825a2bb475c55446cfa85 -> f01103c1e0a204fc7f40a06755f6c3adb5480cf8 (pr/wmove.4 -> pr/wmove.5)

    I'd prefer to name the new files walletinit.cpp and walletinit.h just to avoid any ambiguity with src/init.cpp

    to be consistent to rpcwallet.*, initwallet.* sounds better.

    I don't think this is a good rationale for renaming. Including relative to current directory is generally bad practice in c and c++, because it makes code harder to understand, and can lead to accidental breakages or strange requirements like filenames throughout the directory tree having to be globally unique. In bitcoin, we mostly avoid including relative to current directory (hence #include "policy/fees.h" and #include "wallet/feebumper.h" instead of #include "fees.h" and #include "feebumper.h"). In other large codebases, including relative to current directory is forbidden outright.

    In the src/wallet directory, there are currently 7 header files. 5 of them have no redundant wallet prefix or suffix, 1 of them has a redundant wallet prefix, and 1 has a redundant wallet suffix. In other bitcoin source directories like src/policy, src/primitives, and src/rpc, there are no redundant prefixes or suffixes at all. I would prefer also not to add redundant prefixes or suffixes here.

  21. ryanofsky force-pushed on Aug 14, 2017
  22. jnewbery commented at 9:01 PM on August 14, 2017: member

    it makes code harder to understand

    Can you explain this?

    In fact, there are only a couple of places where non-test files are not named uniquely within the directory tree:

    → find -name *cpp -printf '%f\n' | sort | uniq -c | sort
    ...
          1 zmqpublishnotifier.cpp
          2 base58.cpp
          2 crypto_tests.cpp
          2 lockedpool.cpp
          2 net.cpp
          2 protocol.cpp
    → find -name base58.cpp
    ./src/base58.cpp
    ./src/bench/base58.cpp
    → find -name crypto_tests.cpp
    ./src/wallet/test/crypto_tests.cpp
    ./src/test/crypto_tests.cpp
    → find -name lockedpool.cpp
    ./src/support/lockedpool.cpp
    ./src/bench/lockedpool.cpp
    → find -name net.cpp
    ./src/net.cpp
    ./src/rpc/net.cpp
    → find -name protocol.cpp
    ./src/rpc/protocol.cpp
    ./src/protocol.cpp
    

    I prefer walletinit.cpp, but I'll defer to yours and others' C++ expertise on this.

  23. ryanofsky commented at 9:10 PM on August 14, 2017: contributor

    it makes code harder to understand

    Can you explain this?

    #include "policy/fees.h" is easier to understand than #include "fees.h" because it provides more context.

    In fact, there are only a couple of places where non-test files are not named uniquely within the directory tree:

    I've never worked on any project that required source filenames to be globally unique, so I'm not surprised that you found source filenames are not globally unique in bitcoin.

  24. laanwj commented at 7:33 AM on August 15, 2017: member

    I don't think this is a good rationale for renaming. Including relative to current directory is generally bad practice in c and c++, because it makes code harder to understand,

    Unfortunately, relative inclusion is what we do in bitcoin by using #include "" instead of #include <> everywhere. Heck, there have been well-meaning PRs that change to #include "" for "consistency" (see #10752).

    I agree it's generally a bad idea. It can lead to confusion, as well as makes the compiler do a lot of 'probing' where files are (so slows down compilation). But not something we're going to get rid of from one moment to another. On the longer run I hope we do that.

    So: right now if you were to include "init.h" in "wallet.h", it gets "wallet/init.h" instead of the main one (which is what happens in rpcwallet). Yes, this is confusing. I'd also prefer unique naming of header files for now, for that reason. Another vote to rename it to walletinit.h.

  25. laanwj cross-referenced this on Aug 15, 2017 from issue Use quoted form when including primitives/transaction.h and wallet/wallet.h by practicalswift
  26. promag commented at 9:45 AM on August 15, 2017: member

    I also prefer <> includes with full project path instead of prefixes or whatever.

  27. laanwj commented at 10:03 AM on August 15, 2017: member

    I also prefer <> includes with full project path instead of prefixes or whatever.

    The funniest thing is that that's how we're using #include "". I would guess a script-diff that replaces "..." in #include lines with <...> would build with only few changes (maybe some exceptions such as including generated test data). We hardly, if ever use "" for actual relative include.

    Edit: working on this

  28. laanwj cross-referenced this on Aug 15, 2017 from issue refactor: Make all #includes relative to project root by laanwj
  29. ryanofsky commented at 6:57 PM on August 25, 2017: contributor

    Could this be merged? It has 2 code review acks and a concept ack and is mostly moveonly.

    #11053 in it's current form or one of the variations proposed in #11053 (comment) should moot whatever concerns there might be about includes going forward.

  30. jnewbery commented at 7:07 PM on August 25, 2017: member

    I withdraw my objection to the filename init.cpp. utACK

  31. laanwj merged this on Aug 25, 2017
  32. laanwj closed this on Aug 25, 2017

  33. laanwj referenced this in commit 07c92b98e2 on Aug 25, 2017
  34. MarcoFalke added this to the milestone 0.15.1 on Aug 25, 2017
  35. MarcoFalke added the label Needs backport on Aug 25, 2017
  36. in src/wallet/init.h:19 in d97fe2016c outdated
      14 | +//! Wallets parameter interaction
      15 | +bool WalletParameterInteraction();
      16 | +
      17 | +//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
      18 | +//  This function will perform salvage on the wallet if requested, as long as only one wallet is
      19 | +//  being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
    


    MarcoFalke commented at 8:15 PM on August 25, 2017:

    nit: doc string needs fixup

  37. MarcoFalke commented at 8:21 PM on August 25, 2017: member

    Post merge utACK f01103c1e0a204fc7f40a06755f6c3adb5480cf8. Might want to address the nit sometime

  38. MarcoFalke removed the label Needs backport on Oct 4, 2017
  39. MarcoFalke removed this from the milestone 0.15.1 on Oct 4, 2017
  40. PastaPastaPasta referenced this in commit 30eec06098 on Sep 19, 2019
  41. PastaPastaPasta referenced this in commit 9efa568833 on Dec 22, 2019
  42. PastaPastaPasta referenced this in commit d7df373a0b on Jan 2, 2020
  43. PastaPastaPasta referenced this in commit 1f29aae2eb on Jan 4, 2020
  44. PastaPastaPasta referenced this in commit ac94b9b4a8 on Jan 4, 2020
  45. PastaPastaPasta referenced this in commit 05ccd98663 on Jan 10, 2020
  46. PastaPastaPasta referenced this in commit c43d581347 on Jan 10, 2020
  47. PastaPastaPasta referenced this in commit fc4ab83c83 on Jan 10, 2020
  48. PastaPastaPasta referenced this in commit 20e8ce81db on Jan 12, 2020
  49. ckti referenced this in commit 052ebdb7fd on Mar 28, 2021
  50. random-zebra cross-referenced this on Apr 28, 2021 from issue [Wallet] Laggard wallet-related backports from btc 0.15 by random-zebra
  51. random-zebra referenced this in commit 2d50b6e3b9 on Jun 9, 2021
  52. gades referenced this in commit d4a6c7a3c6 on Jun 30, 2021
  53. gades referenced this in commit 2580656097 on Feb 5, 2022
  54. bitcoin locked this on Feb 15, 2022

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-05-20 06:55 UTC