wallet: Cleanup wallettool salvage and walletdb extraneous declarations #19457

pull achow101 wants to merge 3 commits into bitcoin:master from achow101:walletdb-statics-followup changing 4 files +26 −43
  1. achow101 commented at 6:46 pm on July 6, 2020: member

    Followup to #19324 addressing some comments.

    Removes the SalvageWallet function in wallettool and instead directly calls RecoverDatabaseFile as suggested in #19324 (review)

    Removes the LogPrintfs and tfm::formats in RecoverDatabaseFile as noted in #19324 (review)

    Removes the declarations of VerifyEnvironment and VerifyDatabaseFile that were forgotten in walletdb.h as noted in #19324 (comment)

  2. achow101 force-pushed on Jul 6, 2020
  3. DrahtBot commented at 7:24 pm on July 6, 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:

    • #19619 (Remove wallet.dat path handling from wallet.cpp, rpcwallet.cpp by ryanofsky)
    • #19137 (wallettool: Add dump and createfromdump commands by achow101)
    • #19077 (wallet: Add sqlite as an alternative wallet database and use it for new descriptor wallets 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.

  4. DrahtBot added the label Wallet on Jul 6, 2020
  5. in src/wallet/salvage.cpp:25 in e3243b232a outdated
    22     std::string filename;
    23     std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename);
    24 
    25     if (!env->Open(true /* retry */)) {
    26-        tfm::format(std::cerr, "Error initializing wallet database environment %s!", env->Directory());
    27+        error = strprintf(_("Error initializing wallet database environment %s!"), env->Directory());
    


    MarcoFalke commented at 9:37 am on July 7, 2020:
    Any reason to ask translators to waste effort when these were previously untranslated and the new translations are unused?

    achow101 commented at 2:42 pm on July 7, 2020:
    Since these are utility functions, we might add them to the gui in the future. Or maybe add a gui to the wallettool to make it more user friendly. I wanted to make sure that we could use these in the gui if we wanted to.

    laanwj commented at 1:11 pm on July 15, 2020:
    I’d prefer to err on the side of not adding a translation message if it’s not currently used. This can always be done when necessary.

    achow101 commented at 3:36 pm on July 15, 2020:
    I’ve changed these to use Untranslated.
  6. achow101 force-pushed on Jul 15, 2020
  7. ryanofsky approved
  8. ryanofsky commented at 8:24 pm on July 21, 2020: member
    Code review ACK 7dcb47bf89729d3959efd18a9d6808175b6b85ca. Nice simple cleanups!
  9. in src/wallet/wallettool.cpp:135 in 7dcb47bf89 outdated
    131+            std::vector<bilingual_str> warnings;
    132+            bool ret = RecoverDatabaseFile(path, error, warnings);
    133+            if (!ret) {
    134+                if (warnings.size() > 0) {
    135+                    for (const auto warning : warnings) {
    136+                        tfm::format(std::cerr, "%s\n", warning.original);
    


    MarcoFalke commented at 5:41 am on July 22, 2020:

    style nit in commit “wallettool: …”

    A range based for loop does not need to be guarded by a size check, so you can remove the if (warnings.size() > 0)


    achow101 commented at 4:34 pm on July 22, 2020:
    Fixed.
  10. MarcoFalke commented at 5:42 am on July 22, 2020: member

    looked at the diff and couldn’t find any issues ACK 7dcb47bf89729d3959efd18a9d6808175b6b85ca

    Though, my test (#19078) still fails with the same error as before (#19079)

  11. DrahtBot added the label Needs rebase on Jul 22, 2020
  12. Call RecoverDatabaseFile directly from wallettool
    When using the salvage command, call RecoverDatabaseFile directly
    instead of SalvageWallet. Also removes SalvageWallet as it is no longer
    needed.
    
    SalvageWallet was doing an additional verify on the database which would
    caause the salvage to sometimes fail. This is not needed.
    06e263a4e3
  13. achow101 force-pushed on Jul 22, 2020
  14. achow101 commented at 4:35 pm on July 22, 2020: member
    Rebased. I’ve also added a commit that fixes the first error in #19078
  15. DrahtBot removed the label Needs rebase on Jul 22, 2020
  16. in src/wallet/walletdb.cpp:292 in 21349ec568 outdated
    285@@ -286,7 +286,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
    286             // LoadToWallet call below creates a new CWalletTx that fill_wtx
    287             // callback fills with transaction metadata.
    288             auto fill_wtx = [&](CWalletTx& wtx, bool new_tx) {
    289-                assert(new_tx);
    290+                if (!new_tx) {
    291+                    return false;
    


    ryanofsky commented at 7:17 pm on July 24, 2020:

    In commit “Return false instead of asserting when a loaded tx isn’t new” (21349ec568abd5b25b6ca722aa6a9df3037fa4e8)

    This definitely needs a comment. I don’t understand when this condition happens. Does it indicate corruption or is it a thing expected to happen in certain cases? Comment doesn’t need to be involved but should give a clue about what is happening here, since by itself this is enigmatic.


    MarcoFalke commented at 7:24 am on July 25, 2020:
    The assert has been added in https://github.com/bitcoin/bitcoin/commit/65b9d8f8ddb5a838454efc8bdd6576f0deb65f6d?w=1 , assuming that adding it does not change behavior. Making it a return false would restore the previous behavior instead of crashing.

    achow101 commented at 0:26 am on July 27, 2020:

    This condition can happen with corruption. It means that the db has the same tx in multiple records which shouldn’t happen. However this isn’t something we should be asserting for because it isn’t a critical error where money can be lost. It should be recoverable with rescan, else zapwallettxs will fix it.

    I’ve added a comment indicating this.


    MarcoFalke commented at 5:27 am on July 27, 2020:
    This shouldn’t be corruption, or at least it seems to happen in normal operation. All that the test in #19078 does is call getnewaddress and sendmany

    achow101 commented at 3:25 pm on July 27, 2020:
    The fact that #19078 is hitting this is probably a result of the aggressive salvage which, afaik, sometimes creates corruption when there isn’t corruption. It’s probably from BDB shuffling data around (as part of the normal btree operations) and leaving behind records that are marked as deleted but not actually deleted. So the aggressive salvage still finds these “deleted” records.

    ryanofsky commented at 8:07 pm on August 12, 2020:

    In commit “Return false instead of asserting when a loaded tx isn’t new” (fbe8816f1a95e266b59b39327da4374a0442e279)

    The fact that #19078 is hitting this is probably a result of the aggressive salvage

    Maybe this change is ultimately the right one, but until we clearly understand what is happening I think it would be better to either drop this commit and follow up in a separate PR, or update the commit to ensure the error is not ignored like:

     0--- a/src/wallet/walletdb.cpp
     1+++ b/src/wallet/walletdb.cpp
     2@@ -256,6 +256,7 @@ public:
     3     std::map<std::pair<uint256, CKeyID>, CKey> m_descriptor_keys;
     4     std::map<std::pair<uint256, CKeyID>, std::pair<CPubKey, std::vector<unsigned char>>> m_descriptor_crypt_keys;
     5     std::map<uint160, CHDChain> m_hd_chains;
     6+    bool corrupt = false;
     7 
     8     CWalletScanState() {
     9     }
    10@@ -289,6 +290,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
    11                 if (!new_tx) {
    12                     // There's probably some corruption here since the tx we just tried to load was already in the wallet
    13                     // This error is recoverable with zapwallettxs and is not a major failure
    14+                    wss.corrupt = true;
    15                     return false;
    16                 }
    17                 ssValue >> wtx;
    18@@ -730,7 +732,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
    19             {
    20                 // losing keys is considered a catastrophic error, anything else
    21                 // we assume the user can live with:
    22-                if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY) {
    23+                if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY || wss.corrupt) {
    24                     result = DBErrors::CORRUPT;
    25                 } else if (strType == DBKeys::FLAGS) {
    26                     // reading the wallet flags can only fail if unknown flags are present
    
  17. ryanofsky commented at 7:20 pm on July 24, 2020: member

    Code review ACK ba259cf5f9118fb8909dbff2ddef29bff26bc32b not including last commit (see review comment). Only changes since last review are rebasing, removing redundant if, and adding new commit.

    • 06e263a4e368671ebb4e4a77c1447ebd5104a488 Call RecoverDatabaseFile directly from wallettool (1/4)
    • b27b5f73072e1ecbd4de79361fc5609274ed78c2 wallettool: Have RecoverDatabaseFile return errors and warnings (2/4)
    • ba259cf5f9118fb8909dbff2ddef29bff26bc32b walletdb: Remove unused static functions from walletdb.h (3/4)
    • 21349ec568abd5b25b6ca722aa6a9df3037fa4e8 Return false instead of asserting when a loaded tx isn’t new (4/4)
  18. in src/wallet/salvage.cpp:26 in b27b5f7307 outdated
    23     std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename);
    24 
    25     bilingual_str open_err;
    26     if (!env->Open(open_err)) {
    27-        tfm::format(std::cerr, "%s\n", open_err.original);
    28+        error = strprintf(Untranslated("Error initializing wallet database environment %s!"), env->Directory());
    


    MarcoFalke commented at 7:28 am on July 25, 2020:

    in commit b27b5f7307:

    why is open_error ignored and overwritten?


    achow101 commented at 0:23 am on July 27, 2020:
    Dunno. I’ve restored the previous behavior.
  19. MarcoFalke commented at 7:28 am on July 25, 2020: member

    weak review ACK 21349ec568 📜

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3weak review ACK 21349ec568 📜
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUhrVwwAqvcAfQINATTjkFLBIrq8pOifNArW0AAhU8bJESR0qaPTLBK34fOwDopt
     8V2tXquE0yfWB0z50u06NprOTIzFoFr3WOqc00ezt1oIafNorbKUp2BW3Ms29vACu
     9/ruIRBjXs5msoDPEIx11eQs0/K2SMXLQ/YV8fyLj+HE3dLx1EMzpCyNhh9vEXUYe
    10oEPaBhKTNSGiWgxbFHF0xN9EPgM9eop0s6yCmCviCb808z0z5sFHbc9nTlEDtuoI
    11+N7jgcuiWrnUK9UrBtYQ4YZp+7s9Eg1eEz3y5cLhFDOIbKRMBUL9u3bZsQkOXOhb
    12bsvk4z1DEZUQ8Pg5Rbb+0z398mCJu8TZMbPtRGV/PDfJVJrN1nYmru5wB5XNf7JM
    13bzSATvjhgcRBPDWSYhzHWXt0vxSbA9xjwITmcbCIryJogpWSo1SUbxCzlPaFMHvu
    14hWq9HlrpuVxbcAEzyHdUfyLa+6rsTIFSn1Z/8GItTJYHfHx7zaw+FGsz/m+06LWt
    15Z3r1uwY4
    16=kRMa
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash 3fdf6b1f1067c03925b9d722351cb047b182e9c7b0e592c72a748edce0c99d97 -

  20. wallettool: Have RecoverDatabaseFile return errors and warnings
    Instead of logging or printing these errors and warnings, return them to
    the caller.
    9f536d4fe9
  21. walletdb: Remove unused static functions from walletdb.h
    VerifyEnvironment and VerifyDatabaseFile were removed, but their
    declarations weren't. Remove those.
    0e279fe489
  22. achow101 force-pushed on Jul 27, 2020
  23. achow101 force-pushed on Jul 27, 2020
  24. ryanofsky approved
  25. ryanofsky commented at 8:17 pm on August 12, 2020: member

    Code review ACK fbe8816f1a95e266b59b39327da4374a0442e279. First three commits are great, but last commit is not my favorite, and I’d prefer to improve it as suggested or move it to a separate PR to follow up later.

    Changes since last review are passing along error string in the recover commit, and adding a comment to last commit.

  26. achow101 force-pushed on Aug 13, 2020
  27. achow101 commented at 0:12 am on August 13, 2020: member
    I’ve dropped the last commit. I agree it doesn’t fit well here and can be for a followup.
  28. meshcollider commented at 9:51 pm on August 13, 2020: contributor
    Code review ACK 0e279fe4899beae8630264ef1fe420dd71f29d5d
  29. ryanofsky approved
  30. ryanofsky commented at 10:02 pm on August 13, 2020: member
    Code review ACK 0e279fe4899beae8630264ef1fe420dd71f29d5d, just dropped last commit
  31. in src/wallet/wallettool.cpp:133 in 0e279fe489
    125@@ -147,7 +126,18 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
    126             WalletShowInfo(wallet_instance.get());
    127             wallet_instance->Flush(true);
    128         } else if (command == "salvage") {
    129-            return SalvageWallet(path);
    130+            bilingual_str error;
    131+            std::vector<bilingual_str> warnings;
    132+            bool ret = RecoverDatabaseFile(path, error, warnings);
    133+            if (!ret) {
    134+                for (const auto warning : warnings) {
    


    fanquake commented at 7:20 am on August 14, 2020:

    Are there any followups queued for this file, or did you want to fix this now?

    0wallet/wallettool.cpp:133:33: warning: loop variable 'warning' of type 'const bilingual_str' creates a copy from type 'const bilingual_str' [-Wrange-loop-analysis]
    1                for (const auto warning : warnings) {
    2                                ^
    3wallet/wallettool.cpp:133:22: note: use reference type 'const bilingual_str &' to prevent copying
    4                for (const auto warning : warnings) {
    5                     ^~~~~~~~~~~~~~~~~~~~
    61 warning generated.
    
  32. MarcoFalke merged this on Aug 14, 2020
  33. MarcoFalke closed this on Aug 14, 2020

  34. MarcoFalke commented at 1:25 pm on August 14, 2020: member
    @ryanofsky Are you going to submit this patch as a pull: #19457 (review) ?
  35. sidhujag referenced this in commit 7ca36ff047 on Aug 16, 2020
  36. ryanofsky commented at 8:08 pm on August 24, 2020: member

    @ryanofsky Are you going to submit this patch as a pull: #19457 (comment) ?

    Sure, created #19793

  37. deadalnix referenced this in commit 11d97206b1 on Jun 8, 2021
  38. deadalnix referenced this in commit d37ccaecae on Jun 8, 2021
  39. deadalnix referenced this in commit 1d26b7dbb6 on Jun 8, 2021
  40. 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-07-03 10:13 UTC

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