wallet: Move salvagewallet into wallettool #18918

pull achow101 wants to merge 11 commits into bitcoin:master from achow101:wallettool-salvagewallet changing 18 files +237 −273
  1. achow101 commented at 11:12 pm on May 8, 2020: member

    Removes the -salvagewallet startup option and adds a salvage command to the bitcoin-wallet tool. As such, -salvagewallet is removed. Additionally, the automatic salvage that is done if the wallet file fails to load is removed.

    Lastly the salvage code entirely is moved out entirely into bitcoin-wallet from walletdb.{cpp/h} and db.{cpp/h}.

  2. fanquake added the label Wallet on May 8, 2020
  3. in test/functional/wallet_basic.py:408 in a7274c441a outdated
    403@@ -404,8 +404,6 @@ def run_test(self):
    404             '-reindex',
    405             '-zapwallettxes=1',
    406             '-zapwallettxes=2',
    407-            # disabled until issue is fixed: https://github.com/bitcoin/bitcoin/issues/7463
    408-            # '-salvagewallet',
    


    MarcoFalke commented at 0:02 am on May 9, 2020:
    Would be nice to keep this test or at least document that salvagewallet will throw away your keys: #7379

    ryanofsky commented at 7:46 pm on May 15, 2020:

    In commit “wallet: remove -salvagewallet” (8ef1b45b4d3de71214da1a6bc6e09f6e9a14d7d4)

    Would be nice to keep this test or at least document that salvagewallet will throw away your keys: #7379 @MarcoFalke could you describe the test or comment you would add? It sounds there is a good suggestion here, but I don’t understand it’s asking for


    MarcoFalke commented at 9:28 pm on May 15, 2020:

    @MarcoFalke could you describe the test or comment you would add? It sounds there is a good suggestion here, but I don’t understand it’s asking for

    The new functionality has zero tests. I was hoping we could call wallet-tool salvage instead of bitcoind -salvagewallet here. Just because the test is commented out, doesn’t mean it should be removed.

    If the test still fails occasionally with the wallet-tool, then it can be commented out again.


    achow101 commented at 10:05 pm on May 15, 2020:

    The behavior of salvage shouldn’t be any different, so it will probably still fail as the previous -salvagewallet did.

    It’s also not clear to me what a salvage test should even look like.


    achow101 commented at 11:56 pm on May 15, 2020:
    I’ve added a placeholder test with a todo that mentions the issue in tool_wallet.py.
  4. MarcoFalke commented at 0:03 am on May 9, 2020: member
    Concept ACK
  5. DrahtBot commented at 7:22 am on May 9, 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:

    • #18971 (wallet: Refactor the classes in wallet/db.{cpp/h} by achow101)
    • #18836 (wallet: upgradewallet fixes and additional tests by achow101)
    • #18618 (gui: Drop RecentRequestsTableModel dependency to WalletModel by promag)
    • #18608 (refactor: Remove CAddressBookData::destdata by ryanofsky)

    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 force-pushed on May 12, 2020
  7. laanwj commented at 6:25 pm on May 13, 2020: member
    Concept ACK. Agree that this belongs in the wallet tool, not bitcoind.
  8. jonasschnelli commented at 6:34 pm on May 13, 2020: contributor
    Concept ACK, … finally. Follows the concept of #8745. There was already an attempt to add salvage to the wallet tool in #15307
  9. DrahtBot added the label Needs rebase on May 13, 2020
  10. achow101 force-pushed on May 14, 2020
  11. DrahtBot removed the label Needs rebase on May 14, 2020
  12. in src/wallet/wallettool.cpp:112 in 67e30b2b42 outdated
    103@@ -103,11 +104,205 @@ static void WalletShowInfo(CWallet* wallet_instance)
    104     tfm::format(std::cout, "Address Book: %zu\n", wallet_instance->m_address_book.size());
    105 }
    106 
    107+/* End of headers, beginning of key/value data */
    108+static const char *HEADER_END = "HEADER=END";
    109+/* End of key/value data */
    110+static const char *DATA_END = "DATA=END";
    111+
    112 static bool SalvageWallet(fs::path path)
    


    ryanofsky commented at 8:25 pm on May 15, 2020:

    In commit “walletool: Move salvage wallet implementation into wallettool” (67e30b2b42b4d710739e6fe303cbca69be68032c)

    Would be nice to move this to src/wallet/salvage.{h,cpp} so wallet tool file does not become monolithic and so salvage functionality can be more easily tested and improved and perhaps accessible to future RPC or GUI recovery features


    achow101 commented at 11:46 pm on May 15, 2020:
    I’ve added a salvage.{cpp/h} and put the salvage stuff in there.
  13. ryanofsky commented at 9:15 pm on May 15, 2020: member

    Started reviewing 67e30b2b42b4d710739e6fe303cbca69be68032c but finding it difficult to compare old and new behavior with all the code moving and changing at the same time. Also wondering if the ReadKeyValue code duplication can be avoided, because it seems likely to doom this feature to obsolescence if updates to that function need to be mirrored here. It makes me wonder what the plan for salvage wallet is. Is the plan to wall it off, deprecate it, and remove it? It seems like -salvagewallet was implemented in a really convoluted way, but if we did want to implement in a sustainable way, we would still implement it as a load option and not as a standalone copy of loading code. (It could still be exposed through wallet tool either way.)

    But overall this seems promising, and great to get rid of some of the convoluted callback & enum status code. I will spend more time with this and maybe try to come up with a MOVEONLY version that could be easier to review.

  14. achow101 force-pushed on May 15, 2020
  15. achow101 commented at 11:49 pm on May 15, 2020: member

    I’ve changed the final refactor commit into several smaller moves and changes. The final approach for salvage is also slightly different.

    Instead of having all of the salvage logic wallettool.cpp, I’ve moved instead put it in a RecoverDatabaseFile function in new salvage.{cpp/h} files. Additionally, instead of copying ReadKeyValue, I’ve exposed it and CWalletScanState in walletdb.h so that they can be called from salvage.cpp. Lastly these changes are done in separate commits to make it easier to review.

  16. achow101 force-pushed on May 15, 2020
  17. in src/wallet/walletdb.cpp:927 in 1372aba35f outdated
    923@@ -924,7 +924,7 @@ bool WalletBatch::VerifyEnvironment(const fs::path& wallet_path, bilingual_str&
    924 
    925 bool WalletBatch::VerifyDatabaseFile(const fs::path& wallet_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr)
    926 {
    927-    return BerkeleyBatch::VerifyDatabaseFile(wallet_path, warnings, errorStr, WalletBatch::Recover);
    


    Empact commented at 1:38 am on May 16, 2020:
    WalletBatch::Recover two-argument version is unused as of commit: 1372aba35fa91dd2fb4103ed7081a057f9794564

    Empact commented at 1:44 am on May 16, 2020:
    Nevermind, I see you got it in 61a1e5702d0dfd3cfb6d4deb28df516a7243e196
  18. in src/wallet/salvage.cpp:126 in 2dc91a80b2 outdated
    121+        bool fReadOK;
    122+        {
    123+            // Required in LoadKeyMetadata():
    124+            LOCK(dummyWallet.cs_wallet);
    125+            fReadOK = ReadKeyValue(&dummyWallet, ssKey, ssValue,
    126+                                   dummyWss, strType, strErr);
    


    Empact commented at 1:47 am on May 16, 2020:
    Given the CWalletScanState isn’t used, how about exposing a more limited version of ReadKeyValue instead?

    achow101 commented at 4:46 pm on May 18, 2020:
    I’ve done that instead.
  19. in src/wallet/db.cpp:416 in 1372aba35f outdated
    423-        }
    424-        if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
    425-        {
    426-            errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile);
    427+        if (!env->Verify(walletFile)) {
    428+            errorStr = strprintf(_("%s corrupt. Try using the wallet tool bitcoin-wallet to salvage"), walletFile);
    


    Sjors commented at 10:25 am on May 18, 2020:
    In 1372aba35fa91dd2fb4103ed7081a057f9794564: maybe add “or restore from a backup.”

    achow101 commented at 4:48 pm on May 18, 2020:
    Done
  20. Sjors commented at 10:30 am on May 18, 2020: member

    Concept ACK. Needs a release note.

    Travis is unhappy (as is my local build):

    0In file included from ./wallet/scriptpubkeyman.h:16:
    13519./wallet/walletdb.h:314:112: error: member access into incomplete type 'CWallet'
    23520             CWalletScanState &wss, std::string& strType, std::string& strErr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet);
    

    #10540 makes the case for running in aggressive mode by default and having an option to run in aggressive mode. So maybe drop b816866e6756cb3800d51b8e943e5c408f5e6e0f?

    The test problem described in #7463 (comment) seems to be specific to aggressive mode (cc @jnewbery). Perhaps we can at least add a test for non-aggressive mode? The original test wasn’t very interesting. Is there a way to programatically damage a wallet, or can we add a wallet payload that needs salvaging to the test suite? That’s useful for review as well.

  21. jnewbery commented at 3:53 pm on May 18, 2020: member
    Concept ACK
  22. achow101 force-pushed on May 18, 2020
  23. achow101 force-pushed on May 18, 2020
  24. in src/wallet/wallettool.cpp:107 in e3fe339148 outdated
    103@@ -103,6 +104,11 @@ static void WalletShowInfo(CWallet* wallet_instance)
    104     tfm::format(std::cout, "Address Book: %zu\n", wallet_instance->m_address_book.size());
    105 }
    106 
    107+static bool SalvageWallet(const fs::path path)
    


    Empact commented at 5:34 pm on May 18, 2020:
    nit: could pass this through by reference

    achow101 commented at 6:34 pm on May 21, 2020:
    Done
  25. in src/wallet/db.cpp:414 in 259a744096 outdated
    411@@ -419,18 +412,8 @@ bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<bi
    412     if (fs::exists(walletDir / walletFile))
    413     {
    414         std::string backup_filename;
    


    Empact commented at 5:41 pm on May 18, 2020:
    nit: this is no longer used

    achow101 commented at 6:34 pm on May 21, 2020:
    Removed
  26. in src/wallet/db.cpp:345 in 259a744096 outdated
    422-                walletFile, backup_filename, walletDir));
    423-        }
    424-        if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
    425-        {
    426-            errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile);
    427+        if (!env->Verify(walletFile)) {
    


    Empact commented at 5:42 pm on May 18, 2020:
    nit: How about returning the verify result so we can log the error: https://docs.oracle.com/cd/E17276_01/html/api_reference/C/dbverify.html

    achow101 commented at 5:46 pm on May 21, 2020:
    I don’t think the results of verify are meaningful.
  27. in src/wallet/db.cpp:352 in dca31bd5bc outdated
    347@@ -342,8 +348,55 @@ bool BerkeleyBatch::Recover(const fs::path& file_path, void *callbackDataIn, boo
    348         return false;
    349     }
    350 
    351-    std::vector<BerkeleyEnvironment::KeyValPair> salvagedData;
    352-    bool fSuccess = env->Salvage(newFilename, salvagedData);
    353+    std::vector<KeyValPair> salvagedData;
    354+    bool fSuccess = false; //env->Salvage(newFilename, salvagedData);
    


    Empact commented at 5:45 pm on May 18, 2020:
    nit: I’m not sure this comment is helpful

    achow101 commented at 6:34 pm on May 21, 2020:
    Removed
  28. Empact commented at 5:59 pm on May 18, 2020: member
    Concept ACK
  29. Sjors commented at 8:42 am on May 19, 2020: member
    0wallet/walletdb.cpp:594:12: error: calling function 'ReadKeyValue' requires holding mutex 'pwallet->cs_wallet' exclusively [-Werror,-Wthread-safety-analysis]
    11647    return ReadKeyValue(pwallet, ssKey, ssValue, dummy_wss, strType, strErr);
    
  30. achow101 force-pushed on May 19, 2020
  31. in src/wallet/wallettool.cpp:127 in 502024795a outdated
    107+{
    108+    CWallet dummy_wallet(nullptr, WalletLocation(), WalletDatabase::CreateDummy());
    109+    std::string backup_filename;
    110+    return WalletBatch::Recover(path, (void*)&dummy_wallet, WalletBatch::RecoverKeysOnlyFilter, backup_filename);
    111+}
    112+
    


    ryanofsky commented at 10:06 pm on May 19, 2020:

    In commit “wallettool: Add a salvage command” (502024795a32c4600a294da10ad908f796e0cdac)

    Note for reviewers: this is just a copy of existing CWallet::Verify code

    https://github.com/bitcoin/bitcoin/blob/51825aea7fa068877ea77e3121def58005df3510/src/wallet/wallet.cpp#L3697-L3704

    removed in the next commit “wallet: remove -salvagewallet” (7116e0c73514438ba240827aaddf922d0c1c9d84)

  32. in test/functional/tool_wallet.py:207 in 7116e0c735 outdated
    202@@ -203,6 +203,10 @@ def test_getwalletinfo_on_different_wallet(self):
    203         assert_equal(shasum_after, shasum_before)
    204         self.log.debug('Wallet file shasum unchanged\n')
    205 
    206+    def test_salvage(self):
    207+        # TODO: We should implement a test for this. But such a test should be after we fix https://github.com/bitcoin/bitcoin/issues/7463
    


    ryanofsky commented at 10:14 pm on May 19, 2020:

    In commit “wallet: remove -salvagewallet” (7116e0c73514438ba240827aaddf922d0c1c9d84)

    This is ok, but it’d be possible (and nice) to have a test that invokes salvagewallet tool doing basic checks like does it exit successfully.


    achow101 commented at 5:16 pm on May 25, 2020:
    I’ve added a very basic test that just checks it runs and exits without error on a new wallet.
  33. in src/wallet/db.h:85 in dca31bd5bc outdated
    66@@ -67,15 +67,6 @@ class BerkeleyEnvironment
    67     fs::path Directory() const { return strPath; }
    68 
    69     bool Verify(const std::string& strFile);
    70-    /**
    71-     * Salvage data from a file that Verify says is bad.
    72-     * fAggressive sets the DB_AGGRESSIVE flag (see berkeley DB->verify() method documentation).
    73-     * Appends binary key/value pairs to vResult, returns true if successful.
    74-     * NOTE: reads the entire database into memory, so cannot be used
    75-     * for huge databases.
    


    ryanofsky commented at 10:34 pm on May 19, 2020:

    In commit “Move BerkeleyEnvironment::Salvage into BerkeleyBatch::Recover” (dca31bd5bc820da889394d15a9337ef96262ee4c)

    This comment (especially the part about loading to memory) makes code easier to understand and IMO would be good to move to the new location in the verify function. Skip if it is a pain though


    achow101 commented at 6:39 pm on May 21, 2020:
    I’ve added a rewording of this comment back in.
  34. ryanofsky approved
  35. ryanofsky commented at 11:11 pm on May 19, 2020: member

    Code review ACK 5276a811e1f42eea2a6c6b679a3f1b418e414d34. Beautiful job with this PR! Not only are the changes much easier to review than last time I looked at this (my --color-diff=dimmed_zebra pager thanks you), but the code cleanups are fantastic: getting rid of callbacks inside of callbacks and void pointers, and weird return values, and unused options, and randomly placed static methods, and methods that shouldn’t be methods, and so on.

    Thank you for taking this on and being so responsive to suggestions.

  36. ryanofsky commented at 11:17 pm on May 19, 2020: member
    To all reviewers who concepted ACKed here, I’d encourage reviewing the code, too. This PR is really well structured and easy to understand and after the first commit is just a series of moves and simplifications with no other changes. Very easy.
  37. MarcoFalke commented at 5:40 pm on May 21, 2020: member

    To all reviewers who concepted ACKed here

    Ok, I hereby commit to reviewing this when the previous review comments have been addressed.

  38. achow101 force-pushed on May 21, 2020
  39. achow101 force-pushed on May 21, 2020
  40. in src/wallet/wallettool.cpp:140 in 7f6a5f3fff outdated
    139+            std::shared_ptr<CWallet> wallet_instance = LoadWallet(name, path);
    140+            if (!wallet_instance) return false;
    141+            WalletShowInfo(wallet_instance.get());
    142+            wallet_instance->Flush(true);
    143+        } else if (command == "salvage") {
    144+            SalvageWallet(path);
    


    MarcoFalke commented at 12:44 pm on May 22, 2020:

    in commit 7f6a5f3fff6e71108289ba9c9bfc5a938a081a79:

    Why ignore the return value?


    achow101 commented at 5:16 pm on May 25, 2020:
    Changed to return it.
  41. in src/wallet/db.cpp:358 in 6c3afd67d2 outdated
    355+     * key/value pairs are appendedto salvagedData which are then written out to a new wallet file.
    356+     * NOTE: reads the entire database into memory, so cannot be used
    357+     * for huge databases.
    358+     */
    359+    std::vector<KeyValPair> salvagedData;
    360+    bool fSuccess = false;
    


    MarcoFalke commented at 1:08 pm on May 22, 2020:

    in commit 6c3afd67d2:

    Why is this set all the way up here? The outcome is only needed to remember whether the end of the stream was reached or not. I think it should be defined after the last write to keyHex, but still before this code block:

    Also, you could leave it uninitialized because every if branch will initialize it. If none does the initialization, at least a sanitizer could yell at us and hint at the bug.

    0    bool fSuccess;
    1    if (keyHex != DATA_END) {
    2        LogPrintf("Salvage: WARNING: Unexpected end of file while reading salvage output.\n");
    3        fSuccess = false;
    4    } else {
    5        fSuccess = (result == 0);
    6    }
    

    achow101 commented at 4:39 pm on May 22, 2020:
    It was to reduce the amount of changes being done in a move commit.

    achow101 commented at 5:18 pm on May 25, 2020:
    Changed.
  42. in src/wallet/walletdb.h:292 in 6d05dff02b outdated
    293@@ -294,4 +294,7 @@ class WalletBatch
    294 //! Compacts BDB state so that wallet.dat is self-contained (if there are changes)
    295 void MaybeCompactWalletDB();
    296 
    297+//! Unserialize a give Key-Value pair and load it into the wallet
    298+bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr);
    


    MarcoFalke commented at 1:13 pm on May 22, 2020:

    in commit 6d05dff02b:

    wallet is a reference to an object (like all other params in this function), so it should probably be passed as one.

    Not sure about the lock annotation, but it is a bit confusing to lock cs_wallet, and then call a function that locks it again immediately after

    0bool ReadKeyValue(CWallet& wallet, CDataStream& ssKey, CDataStream& ssValue, std::string& strType, std::string& strErr) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
    

    achow101 commented at 4:40 pm on May 22, 2020:
    The annotation causes a compile error as CWallet is not yet defined.

    MarcoFalke commented at 4:58 pm on May 22, 2020:
    Fair enough
  43. in src/wallet/walletdb.cpp:909 in 6d05dff02b outdated
    908@@ -902,8 +909,7 @@ bool WalletBatch::RecoverKeysOnlyFilter(void *callbackData, CDataStream ssKey, C
    909     {
    


    MarcoFalke commented at 1:18 pm on May 22, 2020:

    in commit 6d05dff02be9e113ac6f835:

    The now unused CWalletScanState dummyWss; a few lines up should now be removed.


    achow101 commented at 5:18 pm on May 25, 2020:
    Removed
  44. MarcoFalke approved
  45. MarcoFalke commented at 1:29 pm on May 22, 2020: member

    ACK 94541050b8, only found style nits 💉

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK 94541050b8, only found style nits 💉
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUhGmQv+Mh8MY93W8aKewBmutaNXryt7hD5cskayCFIuYmD79NAthz5T6LRPVJJ6
     8m/Um8cpR1riPqmxQ+dlU2lsxVEcCs4NcGDZxv2vXUjxITyhjVDYX106KJMTEnDNe
     9uBvmsVjpFSE48Vi5gPgmzb2SDfmCSBCg//uWol/8gGmpMaX3ffdM5Xe9EjJfxC60
    10lVqT8mAReuQhFItYymqN8M919mddxAwJSnpRpbt8lIZpyoq2xVEAWvh7Jq1udCae
    11JGyWENYkkaDMBTPgbdfPvTJNlkvsBkyVsXicd42PXnT7N6d18w19LgXZYcClp5N4
    12QNiY7izurFhAfW4ujiWJzYenPNGRFK7xlqy/t+BZbfVXaNNDB3gTmqp4FGQ13rSE
    130vyFZQ69QGI5e3UnSBCFWCnYyDHpItkSQ2CyXMRCsnLBMAZjUWkfOhbhZHusQxEA
    14DubuoJmYJt7T9xs9vqARAMEbjW6tEMQizZxl7GGXlOzzZmv3hNLdtM6V3U99U94S
    1528quPr/u
    16=Ghf5
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash fd61ba44cfca59f816c1a6d9c69adc6b6e328cc4036fc94ab1ab7e6e91ee289d -

  46. ryanofsky approved
  47. ryanofsky commented at 5:51 pm on May 22, 2020: member
    Code review ACK 94541050b84e166b6fcbaf6c30b263903dcc25f5. Changes since last review just rebase, and adding code comment and release note
  48. MarcoFalke added this to the milestone 0.21.0 on May 22, 2020
  49. in src/wallet/db.cpp:337 in 94541050b8 outdated
    333@@ -410,100 +334,23 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, bilingual_str&
    334     return true;
    335 }
    336 
    337-bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr, BerkeleyEnvironment::recoverFunc_type recoverFunc)
    338+bool BerkeleyBatch::VerifyDatabaseFile(const fs::path& file_path, std::vector<bilingual_str>& warnings, bilingual_str& errorStr)
    


    Empact commented at 6:38 pm on May 22, 2020:
    This warnings argument is now unused.

    jonatack commented at 2:53 pm on May 25, 2020:
    521e731e seconding @Empact’s observation that warnings can be removed with the other changes to VerifyDatabaseFile in this commit

    achow101 commented at 5:18 pm on May 25, 2020:
    Removed
  50. meshcollider added this to the "Blockers" column in a project

  51. in src/wallet/db.cpp:346 in 94541050b8 outdated
    355-        }
    356-        if (r == BerkeleyEnvironment::VerifyResult::RECOVER_FAIL)
    357-        {
    358-            errorStr = strprintf(_("%s corrupt, salvage failed"), walletFile);
    359+        if (!env->Verify(walletFile)) {
    360+            errorStr = strprintf(_("%s corrupt. Try using the wallet tool bitcoin-wallet to salvage or restoring a backup"), walletFile);
    


    jonatack commented at 2:03 pm on May 25, 2020:
    521e731 user-facing nit if you retouch: s/backup/backup./

    achow101 commented at 5:19 pm on May 25, 2020:
    Done
  52. in src/wallet/salvage.cpp:45 in 94541050b8 outdated
    40+        return false;
    41+    }
    42+
    43+    /**
    44+     * Salvage data from a file. The DB_AGGRESSIVE flag is being used (see berkeley DB->verify() method documentation).
    45+     * key/value pairs are appendedto salvagedData which are then written out to a new wallet file.
    


    jonatack commented at 2:14 pm on May 25, 2020:
    6c3afd67 nit: s/appendedto/appended to/

    achow101 commented at 5:19 pm on May 25, 2020:
    Done
  53. in src/wallet/walletdb.h:291 in 94541050b8 outdated
    287@@ -294,4 +288,7 @@ class WalletBatch
    288 //! Compacts BDB state so that wallet.dat is self-contained (if there are changes)
    289 void MaybeCompactWalletDB();
    290 
    291+//! Unserialize a give Key-Value pair and load it into the wallet
    


    jonatack commented at 2:22 pm on May 25, 2020:
    6d05dff nit: s/give/given/

    achow101 commented at 5:19 pm on May 25, 2020:
    Done
  54. in src/wallet/wallettool.cpp:10 in 94541050b8 outdated
     6@@ -7,6 +7,7 @@
     7 #include <util/translation.h>
     8 #include <wallet/wallet.h>
     9 #include <wallet/walletutil.h>
    10+#include <wallet/salvage.h>
    


    jonatack commented at 2:35 pm on May 25, 2020:
    39a82fed nit: sort

    achow101 commented at 5:19 pm on May 25, 2020:
    Done
  55. in src/wallet/salvage.cpp:149 in 94541050b8 outdated
    144+            fSuccess = false;
    145+    }
    146+    ptxn->commit(0);
    147+    pdbCopy->close(0);
    148+
    149+    return fSuccess;
    


    jonatack commented at 3:06 pm on May 25, 2020:
    35a1f948 RecoverDatabaseFile contains a fair amount of code to set and return bool fSuccess, but the value returned doesn’t appear to be used. Is this logic needed?

    achow101 commented at 5:19 pm on May 25, 2020:
    The return value is being checked now.
  56. jonatack commented at 3:15 pm on May 25, 2020: member

    Concept ACK/almost ACK 94541050b84e16. Code review, builds are clean and tests are green, but attempting to run bitcoin-wallet -regtest -wallet=test salvage returns DB_ENV->dbrename: method not permitted before handle's open method. The same command with info runs fine. I’ve never used the salvage command before, so help using it is welcome. Functional tests would be really good here. A few comments below; feel free to ignore any nits.

    Edit: re-attempt with a new wallet

     0$ bitcoin-wallet -regtest -wallet=new create
     1Topping up keypool...
     2Wallet info
     3===========
     4Encrypted: no
     5HD (hd seed available): yes
     6Keypool Size: 2000
     7Transactions: 0
     8Address Book: 0
     9$ bitcoin-wallet -regtest -wallet=new info
    10Wallet info
    11===========
    12Encrypted: no
    13HD (hd seed available): yes
    14Keypool Size: 2000
    15Transactions: 0
    16Address Book: 0
    17$ bitcoin-wallet -regtest -wallet=new salvage
    18DB_ENV->dbrename: method not permitted before handle's open method
    
  57. wallettool: Add a salvage command c87770915b
  58. Add basic test for bitcoin-wallet salvage cdd955e580
  59. wallet: remove -salvagewallet d321046f4b
  60. walletdb: don't automatically salvage when corruption is detected 8ebcbc85c6
  61. walletdb: remove fAggressive from Salvage
    The only call to Salvage set fAggressive = true so remove that parameter
    and always use DB_AGGRESSIVE
    07250b8dce
  62. Move BerkeleyEnvironment::Salvage into BerkeleyBatch::Recover ced95d0e43
  63. Expose a version of ReadKeyValue and use it in RecoverKeysOnlyFilter
    We need this exposed for BerkeleyBatch::Recover to be moved out.
    2741774214
  64. Make BerkeleyBatch::Recover and WalletBatch::RecoverKeysOnlyFilter standalone
    Instead of having these be class static functions, just make them be
    standalone. Also removes WalletBatch::Recover which just passed through
    to BerkeleyBatch::Recover.
    b426c7764d
  65. Move RecoverDatabaseFile and RecoverKeysOnlyFilter into salvage.{cpp/h} 9ea2d258b4
  66. Move RecoverKeysOnlyFilter into RecoverDataBaseFile ea337f2d03
  67. Add release notes about salvage changes 84ae0578b6
  68. achow101 force-pushed on May 25, 2020
  69. achow101 commented at 5:21 pm on May 25, 2020: member

    but attempting to run bitcoin-wallet -regtest -wallet=test salvage returns DB_ENV->dbrename: method not permitted before handle's open method.

    Fixed. Turns out we still have to go through the whole WalletDatbase::Create and VerifyEnvironment song and dance before recovery can be done.

    Also added a basic functional test to check that salvage on a new wallet does not have issues. It does not check whether salvaged actually worked or did anything useful.

  70. jonatack commented at 5:45 pm on May 25, 2020: member
    Thanks – at 84ae0578b6c the bitcoin-wallet salvage command now runs and exits. Yay! but it doesn’t leave any feedback. A message that the wallet was successfully salvaged might be reassuring?
  71. jonatack commented at 5:54 pm on May 25, 2020: member
    ACK 84ae0578b6c68dda145ca65fef510ce0fdac0d7b feedback taken, and compared to my previous review, the bitcoin-wallet salvage command now seems to run and it exits without raising. The new test passes at both 9454105 and 84ae057 so as a sanity check I’d agree there is room for improvement, if possible.
  72. in src/wallet/wallettool.cpp:120 in 84ae0578b6
    115+        WalletBatch::VerifyEnvironment(path, error_string);
    116+    } catch (const fs::filesystem_error& e) {
    117+        error_string = Untranslated(strprintf("Error loading wallet. %s", fsbridge::get_filesystem_error_message(e)));
    118+    }
    119+    if (!error_string.original.empty()) {
    120+        tfm::format(std::cerr, "Failed to open wallet for salvage :%s\n", error_string.original);
    


    jonatack commented at 8:56 am on May 26, 2020:

    Tests for the different exceptions would be great. Not sure on this, or on the need for an EOL \n in line 117 just above.

    0        tfm::format(std::cerr, "Failed to open wallet for salvage: %s\n", error_string.original);
    

    achow101 commented at 4:47 pm on May 26, 2020:
    Will fix if I have to push another change.
  73. MarcoFalke commented at 11:51 am on May 26, 2020: member

    re-ACK 84ae0578b6 🏉

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3re-ACK 84ae0578b6 🏉
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUjebwv/XkWDTfbKudR9e0H8atjyYFTG7ra0mC6wBPs6Apbj4CIhGGrrVeT/zEYu
     8PUPAUO6/RJVD+nBPQTCajQ+/a7kkaRzR9W+Huu+1xXXJEbTzCME7Zld8uMMY750F
     99X9VSKOR9JAqmaICejkZ6bk6lMY9HL2+VumYejhYKX0UTYiGAOspBX0hND68EFuR
    10eSh+OF5BnFj0g89kiZpp8QNDZGXAQ94Tl9tOV5SSD8I941Ncwgnt0LG20hTGOZ04
    11XN19zVW+f27yN/SuHO9powmwwIq/G3urif6eCnRxDHSGkc+9r/xa4SPXnv/SRcxn
    12i82alb+6+4N0UoNIr3gPtaxZQ/fhGHiWO9Q8s+p+/Tk2gK4ssjobBwrc4uAMhVmN
    13dmmQSQPmaR5Hi0PLKtiM3z98lXI29kbUxk/51vEhLH4sNs1i0TyEcwLgMcezO5/q
    14RIYhBStpCVQtJ+LxVUzB0zHK+A/jCM9Q56aw7ZS0ly6LHwmVPD1VvzNDQKhCWUpm
    15AANRPTgR
    16=FqzM
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash c579e4ed85c7c252470d4ad60a04790a109bf7cc4aabcc2e2094bbf1b5c53880 -

  74. practicalswift commented at 6:12 pm on May 26, 2020: contributor
    Concept ACK: thanks for doing this! :)
  75. ryanofsky approved
  76. ryanofsky commented at 6:46 pm on May 26, 2020: member
    Code review ACK 84ae0578b6c68dda145ca65fef510ce0fdac0d7b. Lot of small changes since previous review: added verify step before salvage, added basic test in new commit, removed unused scanstate variable and warnings parameter, tweaked various comments and strings, moved fsuccess variable declaration
  77. meshcollider commented at 2:21 am on May 27, 2020: contributor
    Concept / light code review ACK 84ae0578b6c68dda145ca65fef510ce0fdac0d7b
  78. meshcollider merged this on May 27, 2020
  79. meshcollider closed this on May 27, 2020

  80. sidhujag referenced this in commit 8a7e0acc95 on May 27, 2020
  81. fanquake removed this from the "Blockers" column in a project

  82. Fabcien referenced this in commit 2f67ce4b94 on Dec 7, 2020
  83. Fabcien referenced this in commit 8d0d228389 on Dec 7, 2020
  84. deadalnix referenced this in commit 41c9876fb5 on Dec 7, 2020
  85. deadalnix referenced this in commit 6877a3d971 on Dec 7, 2020
  86. deadalnix referenced this in commit 186cb7d122 on Dec 7, 2020
  87. deadalnix referenced this in commit e4b696038a on Dec 7, 2020
  88. Fabcien referenced this in commit f6e4ac7f80 on Dec 7, 2020
  89. Fabcien referenced this in commit 61875704da on Dec 7, 2020
  90. Fabcien referenced this in commit ddb5baf776 on Dec 7, 2020
  91. Fabcien referenced this in commit d284a192c0 on Dec 7, 2020
  92. Fabcien referenced this in commit fef833edd9 on Dec 7, 2020
  93. 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