Remove wallet.dat path handling from wallet.cpp, rpcwallet.cpp #19619

pull ryanofsky wants to merge 8 commits into bitcoin:master from ryanofsky:pr/path changing 30 files +291 −270
  1. ryanofsky commented at 1:21 pm on July 29, 2020: member

    Get rid of file path handling in wallet application code and move it down to database layer.

    There is no change in behavior except for some changed error messages.

    Motivation for this change is to make code more understandable, but also to prepare for adding SQLite support in #19077 so SQLite implementation can be contained at the database layer and wallet loading code does not need to become more complicated.

  2. fanquake added the label Wallet on Jul 29, 2020
  3. fanquake requested review from achow101 on Jul 29, 2020
  4. hebasto commented at 2:15 pm on July 29, 2020: member
    Concept ACK.
  5. DrahtBot commented at 2:28 pm on July 29, 2020: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19425 (refactor: Get rid of more redundant chain methods by ryanofsky)
    • #19245 ([WIP DONOTMERGE] Replace boost::filesystem with std::filesystem (in c++17) by kiminuo)
    • #19137 (wallettool: Add dump and createfromdump commands by achow101)
    • #19101 (refactor: remove ::vpwallets and related global variables by ryanofsky)
    • #18904 (Don’t call lsn_reset in periodic flush by bvbfan)
    • #18836 (wallet: upgradewallet fixes and additional tests by achow101)
    • #18608 (refactor: Remove CAddressBookData::destdata by ryanofsky)
    • #16546 (External signer support - Wallet Box edition by Sjors)

    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.

  6. achow101 commented at 7:20 pm on July 29, 2020: member

    Could the second commit be split up a bit? It seems to be doing a lot and several functions are being renamed and removed.

    From what I understand, the second commit adds DatabaseOptions and DatabaseStatus. Then CreateWalletDatabase is renamed to MakeWalletDatabase and all of the various checks (file existence checks and database verify) are pushed into that function with DatabaseOptions informing the function what to actually do. And lastly MakeWalletDatabase becomes a separate distinct step that callers must do instead of letting CWallet::Create (renamed from CreateWalletFromFile) handle internally.

    From this, I think you could add a few more commits:

    • Introduction of DatabaseOptions and DatabaseStatus to consolidate the current options and status
    • Moving everything into MakeWalletDatabase
    • Separating MakeWalletDatabase from CWallet::Create
  7. ryanofsky commented at 8:15 pm on July 29, 2020: member

    Could the second commit be split up a bit? It seems to be doing a lot and several functions are being renamed and removed.

    Sure, I think I can split up like you’re suggesting. The main change is introducing the MakeBerkeleyDatabase function. Then that function is called various places to get rid of path operations. So I think introducing MakeBerkeleyDatabase could be one commit, and then this can be followed by more commits calling it from RPC code, and then gui code, and then wallet tool code

  8. ryanofsky commented at 8:18 pm on July 29, 2020: member

    Oh, also I didn’t want this PR to depend on #19099, but this would be a little smaller with #19099 merged frist, because then there would be no need to change interfaces/node and walletinitinterface code here


    Rebased 8994145cb336862a51151cbaa2e222e3e2a5be96 -> 0e4cb50e3c86c3093b18fe2dfb47f563db32afef (pr/path.2 -> pr/path.3, compare) due to conflict with #19102

  9. DrahtBot added the label Needs rebase on Jul 30, 2020
  10. ryanofsky force-pushed on Jul 30, 2020
  11. DrahtBot removed the label Needs rebase on Jul 31, 2020
  12. luke-jr commented at 1:44 am on July 31, 2020: member
    I can see why we’d want to move anything about “wallet.dat” or the “wallet is a directory” stuff into the database layer, but IMO it doesn’t make sense to hide the path the wallet is located within…
  13. meshcollider commented at 11:46 am on July 31, 2020: contributor
    Concept ACK, as a logical separation I think it makes sense to have database-format-specific stuff like this at a lower layer than the logical use of a generic database in the rest of the code.
  14. ryanofsky force-pushed on Aug 5, 2020
  15. ryanofsky commented at 3:12 am on August 5, 2020: member

    re: #19619 (comment)

    Could the second commit be split up a bit? It seems to be doing a lot and several functions are being renamed and removed.

    Took some work, but I split this up into smaller commits that should make it more obvious nothing is changing.


    re: #19619 (comment)

    I can see why we’d want to move anything about “wallet.dat” or the “wallet is a directory” stuff into the database layer, but IMO it doesn’t make sense to hide the path the wallet is located within…

    I don’t think anything has been hidden here. Database object now has a filename method and error messages are more specific than before including full paths rather than path fragments.


    Updated 0e4cb50e3c86c3093b18fe2dfb47f563db32afef -> 4c2638281446efc7b23559925866238808a87c71 (pr/path.3 -> pr/path.4, compare) splitting up later commits and making a few minor cleanups

  16. in src/wallet/bdb.cpp:830 in 9b15bf35d9 outdated
    823@@ -824,3 +824,50 @@ std::unique_ptr<DatabaseBatch> BerkeleyDatabase::MakeBatch(const char* mode, boo
    824 {
    825     return MakeUnique<BerkeleyBatch>(*this, mode, flush_on_close);
    826 }
    827+
    828+std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error)
    829+{
    830+    status = DatabaseStatus::SUCCESS;
    


    achow101 commented at 5:37 pm on August 5, 2020:
    I think the non-BDB specific parts of this should be part of MakeDatabase. It would make this easier to handle in #19077

    ryanofsky commented at 6:05 pm on August 6, 2020:

    re: #19619 (review)

    I think the non-BDB specific parts of this should be part of MakeDatabase. It would make this easier to handle in #19077

    You’re right, moved this code since it didn’t really support detecting the database format.

  17. in src/wallet/db.h:144 in 6dd329f45a outdated
    139@@ -142,6 +140,9 @@ class WalletDatabase
    140 
    141     virtual void ReloadDbEnv() = 0;
    142 
    143+    /** Return path to main database file for logs and error messages. */
    144+    virtual std::string Filename() = 0;
    


    achow101 commented at 5:38 pm on August 5, 2020:
    There is a m_file_path variable in WalletDatabase that does this. If we add Filename, we should remove that.

    ryanofsky commented at 6:05 pm on August 6, 2020:

    re: #19619 (review)

    There is a m_file_path variable in WalletDatabase that does this. If we add Filename, we should remove that.

    Thanks, cleaned this up.

  18. in src/wallet/db.h:150 in 450ec1e34b outdated
    146@@ -147,9 +147,6 @@ class WalletDatabase
    147     unsigned int nLastFlushed;
    148     int64_t nLastWalletUpdate;
    149 
    150-    /** Verifies the environment and database file */
    151-    virtual bool Verify(bilingual_str& error) = 0;
    


    achow101 commented at 5:41 pm on August 5, 2020:
    It seems like #19077 still needs Verify. Even if we don’t necessarily use this outside of database specific code paths, I think it’s still useful to keep it part of WalletDatabase.

    ryanofsky commented at 6:05 pm on August 6, 2020:

    re: #19619 (review)

    It seems like #19077 still needs Verify. Even if we don’t necessarily use this outside of database specific code paths, I think it’s still useful to keep it part of WalletDatabase.

    Will take a look. The thought was that the API should either support offline verification at load time or online verification after the database is loaded, or and that load-time verification was probably preferable because:

    • It’s the type of verification we use right now
    • It requires less from the database implementation. If the database provides an online verification function, you can use that during or after loading, but if it only provides an offline function you can’t use that after loading.
    • Verifying by default (while having option to turn it off) seems safer and less likely to lead to bugs like new RPCs or wallet tool subcommands loading the database and forgetting to verify.
    • It can make wallet loading code simpler since there’s one less step to perform.

    achow101 commented at 8:07 pm on August 7, 2020:
    I think we can require that verify is an online verification function and call it from MakeDatabase rather than MakeBerkeleyDatabase.

    ryanofsky commented at 1:55 am on August 17, 2020:

    re: #19619 (review)

    I think we can require that verify is an online verification function and call it from MakeDatabase rather than MakeBerkeleyDatabase.

    Agree we can add an extra method to the interface, but would want to know advantages to doing this. Sticking with a verify option instead of a verify method seems more flexible for implementations, and simpler and less error prone for callers (https://github.com/bitcoin/bitcoin/pull/19619#discussion_r466593575).


    achow101 commented at 4:46 pm on August 17, 2020:
    The main idea is that the verify is an option for all WalletDatabase implementations and always done within MakeDatabase so that there isn’t an implementation that doesn’t do this verification. I think we should be requiring that all WalletDatabase implementations have some kind of online verification, and if a database doesn’t provide this, perhaps we shouldn’t be using it.

    ryanofsky commented at 1:44 am on September 1, 2020:

    re: #19619 (review)

    The main idea is that the verify is an option for all WalletDatabase implementations and always done within MakeDatabase so that there isn’t an implementation that doesn’t do this verification. I think we should be requiring that all WalletDatabase implementations have some kind of online verification, and if a database doesn’t provide this, perhaps we shouldn’t be using it.

    This can change in the future, but I don’t think we should require something we don’t need to require, or complicate an API with a method that doesn’t need to be exist, is likely to be forgotten or called inconsistently, and that we even saw being used inconsistently in a recent PR #19324 (review)

  19. DrahtBot added the label Needs rebase on Aug 7, 2020
  20. ryanofsky force-pushed on Aug 7, 2020
  21. ryanofsky commented at 5:24 pm on August 7, 2020: member
    Rebased 4c2638281446efc7b23559925866238808a87c71 -> 977bfc5aef22c21ff9612068faf0672bf0f022eb (pr/path.4 -> pr/path.5, compare) due to conflict with #19098, and updated with MakeDatabase suggestion
  22. DrahtBot removed the label Needs rebase on Aug 7, 2020
  23. achow101 commented at 11:26 pm on August 10, 2020: member
    ACK 977bfc5aef22c21ff9612068faf0672bf0f022eb
  24. DrahtBot added the label Needs rebase on Aug 14, 2020
  25. ryanofsky force-pushed on Aug 14, 2020
  26. ryanofsky commented at 5:01 pm on August 14, 2020: member
    Rebased 977bfc5aef22c21ff9612068faf0672bf0f022eb -> f190f67ca7b3315c9dc46bf882dbc96af778b607 (pr/path.5 -> pr/path.6, compare) due to conflict with #19457
  27. DrahtBot removed the label Needs rebase on Aug 14, 2020
  28. in src/wallet/wallettool.cpp:115 in f190f67ca7 outdated
    111+        std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, /* create= */ true);
    112         if (wallet_instance) {
    113             WalletShowInfo(wallet_instance.get());
    114             wallet_instance->Close();
    115         }
    116     } else if (command == "info" || command == "salvage") {
    


    achow101 commented at 5:20 pm on August 14, 2020:
    Might as well remove this else if as it’s pointless now.

    ryanofsky commented at 1:56 am on August 17, 2020:

    re: #19619 (review)

    Might as well remove this else if as it’s pointless now.

    Don’t want to increase scope of this PR, but agree wallet tool command dispatching can be simplified later.

  29. in src/wallet/salvage.cpp:31 in f190f67ca7 outdated
    17@@ -18,6 +18,13 @@ typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyVa
    18 
    19 bool RecoverDatabaseFile(const fs::path& file_path, bilingual_str& error, std::vector<bilingual_str>& warnings)
    20 {
    21+    DatabaseOptions options;
    22+    DatabaseStatus status;
    23+    options.require_existing = true;
    24+    options.verify = false;
    25+    std::unique_ptr<WalletDatabase> database = MakeDatabase(file_path, options, status, error);
    26+    if (!database) return false;
    


    achow101 commented at 5:25 pm on August 14, 2020:
    I think we need to close and destroy the database. Having it created and potentially open now could interfere with the salvage below. We only want to do this for the path existence check.

    ryanofsky commented at 1:56 am on August 17, 2020:

    re: #19619 (review)

    I think we need to close and destroy the database. Having it created and potentially open now could interfere with the salvage below.

    I’m not sure exactly what change is being asked for here. Closing an unopened database won’t do anything. Goal of this commit is to remove path manipulation from wallet tool while changing it minimally (and nudging code in good future directions), so happy to make any change consistent with that.

    We only want to do this for the path existence check.

    I don’t think this is right. I think other checks done before opening a database should be done before salvaging a database. Not just checking path existence, but also checking load status and lock status.

    I expect having the database object here to be more useful in the future. It’s beyond the scope of this PR, but recovery code below should be able to go through the database object instead of bypassing it.


    achow101 commented at 4:49 pm on August 17, 2020:

    What I was asking for was to have a database = nullptr here so that database isn’t valid further down.

    If we do want to do the salvage through WalletDatabase (I’m not sure that we should though), then I would expect that all of this recovery code ends up back in bdb.cpp/h.


    ryanofsky commented at 1:45 am on September 1, 2020:

    re: #19619 (review)

    What I was asking for was to have a database = nullptr here so that database isn’t valid further down.

    If we do want to do the salvage through WalletDatabase (I’m not sure that we should though), then I would expect that all of this recovery code ends up back in bdb.cpp/h.

    No harm other than verbosity, but it seems nonsensical to reset the database pointer while the database is being recovered. Also, unless this function is supposed to be berkeley-specific the dbenv->dbrename and db.verify berkely code below will need to move to bdb.cpp. The ReadKeyValue code below shouldn’t move to bdb.cpp because that is higher level wallet code.

  30. in src/wallet/bdb.h:148 in ee5bb1bb09 outdated
    143@@ -144,6 +144,9 @@ class BerkeleyDatabase : public WalletDatabase
    144     /** Verifies the environment and database file */
    145     bool Verify(bilingual_str& error);
    146 
    147+    /** Return path to main database filename */
    148+    std::string Filename() override { return (env->Directory() / strFile).string(); }
    


    promag commented at 0:39 am on August 15, 2020:

    ee5bb1bb09d9834edb6cd15d233be504f00615db

    Could be const?


    ryanofsky commented at 1:54 am on August 17, 2020:

    re: #19619 (review)

    ee5bb1b

    Could be const?

    I don’t like virtual methods to be const. I don’t think a superclass declaration should prevent subclasses from being able to modify their own state, expose this implementation detail to callers, and allow callers to pass around viral const references which constrain present and future subclass implementations. Adding const in cases like this doesn’t have benefits that I’m aware of and seems likely to lead to code churn (removing viral consts) or confusing workarounds (adding mutable/const_casts) going forward.

  31. in src/wallet/wallet.cpp:3801 in ee5bb1bb09 outdated
    3728@@ -3727,23 +3729,23 @@ std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, cons
    3729     return MakeDatabase(wallet_path, options, status, error_string);
    3730 }
    3731 
    3732-std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, uint64_t wallet_creation_flags)
    3733+std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings)
    


    promag commented at 0:46 am on August 15, 2020:

    ee5bb1bb09d9834edb6cd15d233be504f00615db

    Why not take name from database? Is it intentional to allow independent names and filenames?


    ryanofsky commented at 1:56 am on August 17, 2020:

    re: #19619 (review)

    ee5bb1b

    Why not take name from database? Is it intentional to allow independent names and filenames?

    Yes it’s intentional. Database objects don’t have names. They aren’t passed names, can’t construct names, and don’t need names because they don’t need to route GUI or RPC requests, unlike wallet objects.

  32. promag commented at 0:53 am on August 15, 2020: member

    Concept ACK.

    Motivation for this change is to make code more understandable, but also to prepare for adding SQLite support in #19077 so SQLite implementation can be contained at the database layer and wallet loading code does not need to become more complicated.

    So now we have MakeWalletDatabase and then CWallet::Create(database) which makes perfect sense to me.

  33. in src/wallet/load.cpp:45 in aac063f28e outdated
    41@@ -42,16 +42,16 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
    42     std::set<fs::path> wallet_paths;
    43 
    44     for (const auto& wallet_file : wallet_files) {
    45-        WalletLocation location(wallet_file);
    46+        fs::path path = fs::absolute(wallet_file, GetWalletDir());
    


    hebasto commented at 8:33 am on August 15, 2020:

    aac063f28e4ed48180c2ba7a51706af969ca1e55, nit

    0        const fs::path path = fs::absolute(wallet_file, GetWalletDir());
    

    hebasto commented at 8:34 am on August 15, 2020:
    aac063f28e4ed48180c2ba7a51706af969ca1e55 Add #include <fs.h> ?

    ryanofsky commented at 1:55 am on August 17, 2020:

    re: #19619 (review)

    aac063f, nit

    Thanks, added

  34. in src/wallet/rpcwallet.cpp:2502 in aac063f28e outdated
    2498@@ -2499,21 +2499,22 @@ static UniValue loadwallet(const JSONRPCRequest& request)
    2499             }.Check(request);
    2500 
    2501     WalletContext& context = EnsureWalletContext(request.context);
    2502-    WalletLocation location(request.params[0].get_str());
    2503+    std::string name(request.params[0].get_str());
    


    hebasto commented at 8:36 am on August 15, 2020:

    aac063f28e4ed48180c2ba7a51706af969ca1e55, nit

    0    const std::string name(request.params[0].get_str());
    

    ryanofsky commented at 1:55 am on August 17, 2020:

    re: #19619 (review)

    aac063f, nit

    Thanks, added

  35. hebasto changes_requested
  36. hebasto commented at 8:54 am on August 15, 2020: member

    Commit 134f1807e51a8b64c813bf994c8752d55ff3469f “wallet: Add MakeDatabase function” confuses me:

    1. bool IsBerkeleyBtree() declaration is added to wallet/bdb.h but its definition remains in wallet/walletutil.cpp

    2. std::unique_ptr<WalletDatabase> MakeDatabase() declaration is added to wallet/db.h but its definition is added to wallet/walletdb.cpp

    If this made on purpose, mind explaining such code organization?

  37. in src/wallet/bdb.cpp:840 in 134f1807e5 outdated
    835+
    836+std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error)
    837+{
    838+    std::unique_ptr<BerkeleyDatabase> db;
    839+    {
    840+        LOCK(cs_db);
    


    hebasto commented at 9:07 am on August 15, 2020:
    134f1807e51a8b64c813bf994c8752d55ff3469f Why locking is required here? Doesn’t GetWalletEnv() do this job?

    ryanofsky commented at 12:01 pm on August 17, 2020:

    re: #19619 (review)

    134f1807e51a8b64c813bf994c8752d55ff3469f Why locking is required here? Doesn’t GetWalletEnv() do this job?

    Added comment. The lock needs to cover both GetWalletEnv and the Database constructor to prevent a race condition. In the future I think all these little functions should be inlined so code is clearer, but that’s not really possible without more cleanup and anyway would not be directly related to path code consolidation which is the goal of this PR

  38. ryanofsky force-pushed on Aug 17, 2020
  39. ryanofsky commented at 1:01 pm on August 17, 2020: member

    Thanks for reviews!

    Rebased f190f67ca7b3315c9dc46bf882dbc96af778b607 -> 1233419c88c31f21e1b59b4e3f0cdad34d92413b (pr/path.6 -> pr/path.7, compare) due to silent conflict with #15937 and updated with a few code review suggestions.

    re: #19619 (comment)

    Commit 134f180 “wallet: Add MakeDatabase function” confuses me:

    […]

    If this made on purpose, mind explaining such code organization?

    This PR is not trying to change code organization, just consolidate path manipulation code in the wallet. But here is the desired organization:

    • db.h, db.cpp: should contain Database and Batch classes, DatabaseStatus and DatabaseOptions type definitions, and MakeDatabase() function referencing the class and types
    • bdb.h, bdb.cpp: should contain BerkeleyDatabase and BerkeleyBatch classes and MakeBerkeleyDatabase() and ExistsBerkeleyDatabase() functions
    • sqlite.h, sqlite.cpp: should contain SqliteDatabase and SqliteBatch classes and MakeSqliteDatabase() and ExistsSqliteDatabase() functions
    • walletutil.h, walletutil.cpp: should be removed. BerkeleyBTree() should be dropped and inlined or moved to bdb.h / bdb.cpp, other functions similarly should be dropped or moved.

    I’m ok with changing code organization in this PR if it doesn’t increase size of this PR, but otherwise think it should be left to a separate moveonly PR. Otherwise this PR is just trying to change things as little as possible and not make the circular include linter angry, so it is using forward declarations in the interim some places to avoid the need to move code right now.

  40. achow101 commented at 10:48 pm on August 17, 2020: member
    ACK 1233419c88c31f21e1b59b4e3f0cdad34d92413b Since last only rebase and some suggestions. My comments on this aren’t really blocking.
  41. laanwj added this to the "Blockers" column in a project

  42. in src/wallet/rpcwallet.cpp:2519 in 83e4ead991 outdated
    2518+    fs::path path(fs::absolute(name, GetWalletDir()));
    2519 
    2520-    if (!location.Exists()) {
    2521-        throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + location.GetName() + " not found.");
    2522-    } else if (fs::is_directory(location.GetPath())) {
    2523+    if (fs::symlink_status(path).type() == fs::file_not_found) {
    


    MarcoFalke commented at 3:41 pm on August 27, 2020:

    in commit 83e4ead9917735b2ba92c8a35fe37504206ffe32

    please don’t change behavior in refactoring commits.

    Previously:

    0test_framework.authproxy.JSONRPCException: Wallet  not found. (-18)
    

    Now:

    0test_framework.authproxy.JSONRPCException: Directory  does not contain a wallet.dat file. (-18)
    

    MarcoFalke commented at 3:47 pm on August 27, 2020:
    I sort of liked that the functionality was wrapped in one function. This avoids issues exactly like this

    ryanofsky commented at 6:34 pm on September 3, 2020:

    I sort of liked that the functionality was wrapped in one function. This avoids issues exactly like this

    Replied #19619#pullrequestreview-479302679

  43. DrahtBot added the label Needs rebase on Aug 31, 2020
  44. in src/wallet/rpcwallet.cpp:2517 in dde9986ce7 outdated
    2532     bilingual_str error;
    2533     std::vector<bilingual_str> warnings;
    2534     std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, name, options, status, error, warnings);
    2535-    if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original);
    2536+    if (!wallet) {
    2537+        RPCErrorCode code = status == DatabaseStatus::FAILED_NOT_FOUND || status == DatabaseStatus::FAILED_BAD_FORMAT ? RPC_WALLET_NOT_FOUND : RPC_WALLET_ERROR;
    


    meshcollider commented at 11:05 am on August 31, 2020:
    Why treat FAILED_BAD_FORMAT as a not-found error?

    ryanofsky commented at 1:43 am on September 1, 2020:

    re: #19619 (review)

    Why treat FAILED_BAD_FORMAT as a not-found error?

    I added a code comment. I can change to different error code, but FAILED_BAD_FORMAT is returned when the wallet directory exists but doesn’t have a wallet.dat file. RPC_WALLET_NOT_FOUND was what the previous code returned in this case so this is not a change in behavior.

  45. meshcollider commented at 11:12 am on August 31, 2020: contributor
    • 83e4ead9917735b2ba92c8a35fe37504206ffe32 Remove WalletLocation class
    • 44f3cf2ba538259ad1f7b02322e5dd96adca1bf1 wallet: Add MakeDatabase function
    • 7fdfb3951be14c5ab52f2ddf03a384f13649c00b refactor: Use DatabaseStatus and DatabaseOptions types
    • 7c2f3b691727de3d2d488e4cc8aea050c28ba9d1 wallet: Remove Verify and IsLoaded methods
    • 66d3c200d4225cd6134ee8ffd385ec6fc7961dd8 refactor: Pass wallet database into CWallet::Create
    • dde9986ce70215ba1393194e9ec1955eff3a710b wallet: Remove path checking code from loadwallet RPC
    • 668568b453060e13a3cc402507fcbda21d3f6785 wallet: Remove path checking code from createwallet RPC
    • 1233419c88c31f21e1b59b4e3f0cdad34d92413b wallet: Remove path checking code from bitcoin-wallet tool

    Initial read through looks good to me, modulo MarcoFalke’s comment on the first commit. Once rebased I will re-review.

  46. Sjors commented at 12:35 pm on August 31, 2020: member

    Concept ACK. On macOS wallet_multiwallet.py fails for me with:

    02020-08-31T12:20:37.628000Z TestFramework (INFO): Concurrent wallet loading
    12020-08-31T12:20:38.768000Z TestFramework (ERROR): Assertion failed
    2Traceback (most recent call last):
    3  File "/Users/sjors/dev/bitcoin/test/functional/test_framework/test_framework.py", line 118, in main
    4    self.run_test()
    5  File "test/functional/wallet_multiwallet.py", line 242, in run_test
    6    assert_equal(got_loading_error, True)
    
  47. ryanofsky force-pushed on Sep 1, 2020
  48. DrahtBot removed the label Needs rebase on Sep 1, 2020
  49. ryanofsky commented at 12:32 pm on September 1, 2020: member

    Rebased 1233419c88c31f21e1b59b4e3f0cdad34d92413b -> 83a8f51da5bb86c39f030e027100f0eb5f1f52ad (pr/path.7 -> pr/path.8, compare) due to conflicts with #19099 and #19671

    For some reason github won’t let me reply directly to these comments above:

    re: #19619 (review)

    please don’t change behavior in refactoring commits.

    Good catch. It wasn’t my intention to change behavior in this commit. I think I was paying more attention to the error code than error text. But the new text actually makes a little more sense than the old text, so I just noted the change in the commit message. Both these error messages are replaced anyway in later commit “Remove path checking code from loadwallet RPC”.

    re: #19619 (review)

    I sort of liked that the functionality was wrapped in one function. This avoids issues exactly like this

    Context for this comment may have been lost so I’m not sure what it is referring to. If it is referring to the removed WalletLocation code in loadwallet, the PR is inlining operations that were happening across three functions (loadwallet, WalletLocation::WalletLocation, WalletLocation::Exists) into a straightforward path check done one place..

    re: #19619 (comment)

    Concept ACK. On macOS wallet_multiwallet.py fails for me with:

    Does the failure happen reliably? This is known to be a flaky check: #19300 (review)

  50. achow101 commented at 5:24 pm on September 1, 2020: member
    ACK 83a8f51da5bb86c39f030e027100f0eb5f1f52ad
  51. Remove WalletLocation class
    This removes a source of complexity and indirection that makes it harder to
    understand path checking code. Path checks will be simplified in upcoming
    commits.
    
    There is no change in behavior in this commit other than a slightly more
    descriptive error message in `loadwallet` if the default "" wallet can't be
    found. (The error message is improved more in upcoming commit "wallet: Remove
    path checking code from loadwallet RPC".)
    288b4ffb6b
  52. wallet: Add MakeDatabase function
    New function is not currently called but will be called in upcoming commits. It
    moves database path checking, and existence checking, and already-loaded
    checking, and verification into a single function so this logic does not need
    to be repeated all over higher level wallet code, and so higher level code does
    not need to change when SQLite support is added in
    https://github.com/bitcoin/bitcoin/pull/19077. This also lets higher level
    wallet code make fewer assumptions about the contents of wallet directories.
    
    This commit just adds the new function and does not change behavior in any way.
    b5b414151a
  53. refactor: Use DatabaseStatus and DatabaseOptions types
    No changes in behavior. Just replaces arguments and return types
    0d94e60625
  54. wallet: Remove Verify and IsLoaded methods
    Checks are now consolidated in MakeBerkeleyDatabase function instead of
    happening in higher level code.
    
    This commit does not change behavior except for error messages which now
    include more complete information.
    3c815cfe54
  55. refactor: Pass wallet database into CWallet::Create
    No changes in behavior
    8b5e7297c0
  56. wallet: Remove path checking code from loadwallet RPC
    This commit does not change behavior except for error messages which now
    include more complete information.
    a987438e9d
  57. wallet: Remove path checking code from createwallet RPC
    This commit does not change behavior except for error messages which now
    include more complete information.
    77d5bb72b8
  58. wallet: Remove path checking code from bitcoin-wallet tool
    This commit does not change behavior except for error messages which now
    include more complete information.
    7bf6dfbb48
  59. in src/wallet/rpcwallet.cpp:2671 in 4dba0c5ac6 outdated
    2676-        case WalletCreationStatus::ENCRYPTION_FAILED:
    2677-            throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error.original);
    2678-        case WalletCreationStatus::SUCCESS:
    2679-            break;
    2680-        // no default case, so the compiler can warn about missing cases
    2681+    std::shared_ptr<CWallet> wallet = CreateWallet(*context.chain, request.params[0].get_str(), options, status, error, warnings);
    


    hebasto commented at 3:37 pm on September 3, 2020:

    4dba0c5ac68223b218b33d49e3621ea863042a07, nit:

    0    const auto wallet = CreateWallet(*context.chain, request.params[0].get_str(), options, status, error, warnings);
    

    ryanofsky commented at 6:32 pm on September 3, 2020:

    re: #19619 (review)

    4dba0c5, nit:

    Disagree with the suggestion. I do like auto when writing the type would be very verbose (iterators) or when type would be just be repeated (new, make_shared, MakeUnique expressions). But this isn’t one of those cases, and using auto here would hide information that helps clarify the code


    hebasto commented at 8:41 am on September 4, 2020:

    Ok. Using auto is a matter of taste or philosophy.

    But what is wrong with const?


    ryanofsky commented at 3:03 pm on September 4, 2020:

    Ok. Using auto is a matter of taste or philosophy.

    But what is wrong with const?

    I don’t have a problem with it, but it isn’t my preference to tag every variable that could possibly be tagged const with const. It’s clarifying and helpful and some cases, and noise in other cases. In these specific cases, I think shared_ptr<CWallet> helps readability, auto does not help readability, const does not help readability. If there needs to be more consts, probably better to write a developer guideline and linter than discuss in review comments.


    hebasto commented at 3:04 pm on September 4, 2020:
    ok
  60. in src/wallet/wallet.cpp:206 in 8c14ac6886 outdated
    150@@ -151,12 +151,13 @@ namespace {
    151 std::shared_ptr<CWallet> LoadWalletInternal(interfaces::Chain& chain, const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings)
    152 {
    153     try {
    154-        if (!MakeWalletDatabase(name, options, status, error)) {
    155+        std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error);
    


    hebasto commented at 3:52 pm on September 3, 2020:

    8c14ac68863bb4727f774315d9b0e3820543252a, nit:

    0        auto database = MakeWalletDatabase(name, options, status, error);
    

    ryanofsky commented at 6:35 pm on September 3, 2020:

    re: #19619 (review)

    8c14ac6, nit:

    Disagree with auto here, see previous comment

  61. in src/wallet/wallet.cpp:212 in 8c14ac6886 outdated
    157             error = Untranslated("Wallet file verification failed.") + Untranslated(" ") + error;
    158             return nullptr;
    159         }
    160 
    161-        std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, name, error, warnings);
    162+        std::shared_ptr<CWallet> wallet = CWallet::Create(chain, name, std::move(database), options.create_flags, error, warnings);
    


    hebasto commented at 3:52 pm on September 3, 2020:

    8c14ac68863bb4727f774315d9b0e3820543252a, nit:

    0        const auto wallet = CWallet::Create(chain, name, std::move(database), options.create_flags, error, warnings);
    

    ryanofsky commented at 6:35 pm on September 3, 2020:

    re: #19619 (review)

    8c14ac6, nit:

    Disagree with auto here, see previous comment

  62. in src/wallet/wallet.cpp:257 in 8c14ac6886 outdated
    204@@ -204,7 +205,8 @@ std::shared_ptr<CWallet> CreateWallet(interfaces::Chain& chain, const std::strin
    205     }
    206 
    207     // Wallet::Verify will check if we're trying to create a wallet with a duplicate name.
    208-    if (!MakeWalletDatabase(name, options, status, error)) {
    209+    std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error);
    


    hebasto commented at 3:54 pm on September 3, 2020:

    8c14ac68863bb4727f774315d9b0e3820543252a, nit:

    0    auto database = MakeWalletDatabase(name, options, status, error);
    

    ryanofsky commented at 6:36 pm on September 3, 2020:

    re: #19619 (review)

    8c14ac6, nit:

    Disagree with auto here, see previous comment

  63. in src/wallet/wallet.cpp:272 in 8c14ac6886 outdated
    219@@ -218,7 +220,7 @@ std::shared_ptr<CWallet> CreateWallet(interfaces::Chain& chain, const std::strin
    220     }
    221 
    222     // Make the wallet
    223-    std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, name, error, warnings, wallet_creation_flags);
    224+    std::shared_ptr<CWallet> wallet = CWallet::Create(chain, name, std::move(database), wallet_creation_flags, error, warnings);
    


    hebasto commented at 3:55 pm on September 3, 2020:

    8c14ac68863bb4727f774315d9b0e3820543252a, nit:

    0    const auto wallet = CWallet::Create(chain, name, std::move(database), wallet_creation_flags, error, warnings);
    

    ryanofsky commented at 6:35 pm on September 3, 2020:

    re: #19619 (review)

    8c14ac6, nit:

    Disagree with auto here, see previous comment

  64. in src/wallet/load.cpp:77 in 8c14ac6886 outdated
    74+            DatabaseStatus status;
    75+            options.verify = false; // No need to verify, assuming verified earlier in VerifyWallets()
    76             bilingual_str error;
    77             std::vector<bilingual_str> warnings;
    78-            std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, walletFile, error, warnings);
    79+            std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error);
    


    hebasto commented at 3:56 pm on September 3, 2020:

    8c14ac68863bb4727f774315d9b0e3820543252a, nit:

    0            auto database = MakeWalletDatabase(name, options, status, error);
    

    ryanofsky commented at 6:35 pm on September 3, 2020:

    re: #19619 (review)

    8c14ac6, nit:

    Disagree with auto here, see previous comment

  65. in src/wallet/salvage.cpp:30 in 83a8f51da5 outdated
    17@@ -18,6 +18,13 @@ typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyVa
    18 
    19 bool RecoverDatabaseFile(const fs::path& file_path, bilingual_str& error, std::vector<bilingual_str>& warnings)
    20 {
    21+    DatabaseOptions options;
    22+    DatabaseStatus status;
    23+    options.require_existing = true;
    24+    options.verify = false;
    25+    std::unique_ptr<WalletDatabase> database = MakeDatabase(file_path, options, status, error);
    


    hebasto commented at 4:12 pm on September 3, 2020:

    83a8f51da5bb86c39f030e027100f0eb5f1f52ad, nit:

    0    auto database = MakeDatabase(file_path, options, status, error);
    

    ryanofsky commented at 6:36 pm on September 3, 2020:

    re: #19619 (review)

    83a8f51, nit:

    Disagree with auto here, see previous comment

  66. hebasto approved
  67. hebasto commented at 4:48 pm on September 3, 2020: member
    ACK 83a8f51da5bb86c39f030e027100f0eb5f1f52ad, tested on Linux Mint 20 (x86_64).
  68. DrahtBot added the label Needs rebase on Sep 3, 2020
  69. ryanofsky force-pushed on Sep 3, 2020
  70. ryanofsky commented at 7:47 pm on September 3, 2020: member

    Rebased 83a8f51da5bb86c39f030e027100f0eb5f1f52ad -> 7bf6dfbb484adfda3b8df26ee3e2ebda239dd263 (pr/path.8 -> pr/path.9, compare) due to conflict with #19754

    Thanks for reviews! Reminder to anyone interested that sqlite PR #19077 currently depends on this. And so far achow and hebasto have acked, and meshcollider, promag, and sjors have concept acked this.

  71. DrahtBot removed the label Needs rebase on Sep 3, 2020
  72. achow101 commented at 0:25 am on September 4, 2020: member
    ACK 7bf6dfbb484adfda3b8df26ee3e2ebda239dd263
  73. hebasto approved
  74. hebasto commented at 8:38 am on September 4, 2020: member
    re-ACk 7bf6dfbb484adfda3b8df26ee3e2ebda239dd263
  75. meshcollider commented at 11:45 pm on September 6, 2020: contributor
    Code re-review and functional test run ACK 7bf6dfbb484adfda3b8df26ee3e2ebda239dd263
  76. meshcollider merged this on Sep 6, 2020
  77. meshcollider closed this on Sep 6, 2020

  78. meshcollider removed this from the "Blockers" column in a project

  79. sidhujag referenced this in commit 53b6e698d1 on Sep 9, 2020
  80. deadalnix referenced this in commit 0ae7f22b6a on Oct 5, 2021
  81. deadalnix referenced this in commit 9c7a754d59 on Oct 5, 2021
  82. deadalnix referenced this in commit 97efc9047e on Oct 5, 2021
  83. deadalnix referenced this in commit 35feef8b43 on Oct 5, 2021
  84. deadalnix referenced this in commit 3d15c53ac9 on Oct 5, 2021
  85. deadalnix referenced this in commit 18aeb323c5 on Oct 5, 2021
  86. deadalnix referenced this in commit 19a93bbcd6 on Oct 5, 2021
  87. deadalnix referenced this in commit 5dc21608b9 on Oct 5, 2021
  88. DrahtBot 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: 2024-11-17 06:12 UTC

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