Skip to content

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Jul 6, 2020

Followup to #19324 addressing some comments.

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

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

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

@achow101 achow101 force-pushed the walletdb-statics-followup branch from e7fcfd5 to e3243b2 Compare July 6, 2020 18:52
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 6, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 7dcb47bf89729d3959efd18a9d6808175b6b85ca. Nice simple cleanups!

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

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.
@achow101 achow101 force-pushed the walletdb-statics-followup branch from 7dcb47b to 21349ec Compare July 22, 2020 16:34
@achow101
Copy link
Member Author

Rebased. I've also added a commit that fixes the first error in #19078

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  • 06e263a 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert has been added in 65b9d8f?w=1 , assuming that adding it does not change behavior. Making it a return false would restore the previous behavior instead of crashing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@maflcko maflcko Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -256,6 +256,7 @@ public:
     std::map<std::pair<uint256, CKeyID>, CKey> m_descriptor_keys;
     std::map<std::pair<uint256, CKeyID>, std::pair<CPubKey, std::vector<unsigned char>>> m_descriptor_crypt_keys;
     std::map<uint160, CHDChain> m_hd_chains;
+    bool corrupt = false;
 
     CWalletScanState() {
     }
@@ -289,6 +290,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
                 if (!new_tx) {
                     // There's probably some corruption here since the tx we just tried to load was already in the wallet
                     // This error is recoverable with zapwallettxs and is not a major failure
+                    wss.corrupt = true;
                     return false;
                 }
                 ssValue >> wtx;
@@ -730,7 +732,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
             {
                 // losing keys is considered a catastrophic error, anything else
                 // we assume the user can live with:
-                if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY) {
+                if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY || wss.corrupt) {
                     result = DBErrors::CORRUPT;
                 } else if (strType == DBKeys::FLAGS) {
                     // reading the wallet flags can only fail if unknown flags are present

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weak review ACK 21349ec568 📜

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

weak review ACK 21349ec568 📜
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhrVwwAqvcAfQINATTjkFLBIrq8pOifNArW0AAhU8bJESR0qaPTLBK34fOwDopt
V2tXquE0yfWB0z50u06NprOTIzFoFr3WOqc00ezt1oIafNorbKUp2BW3Ms29vACu
/ruIRBjXs5msoDPEIx11eQs0/K2SMXLQ/YV8fyLj+HE3dLx1EMzpCyNhh9vEXUYe
oEPaBhKTNSGiWgxbFHF0xN9EPgM9eop0s6yCmCviCb808z0z5sFHbc9nTlEDtuoI
+N7jgcuiWrnUK9UrBtYQ4YZp+7s9Eg1eEz3y5cLhFDOIbKRMBUL9u3bZsQkOXOhb
bsvk4z1DEZUQ8Pg5Rbb+0z398mCJu8TZMbPtRGV/PDfJVJrN1nYmru5wB5XNf7JM
bzSATvjhgcRBPDWSYhzHWXt0vxSbA9xjwITmcbCIryJogpWSo1SUbxCzlPaFMHvu
hWq9HlrpuVxbcAEzyHdUfyLa+6rsTIFSn1Z/8GItTJYHfHx7zaw+FGsz/m+06LWt
Z3r1uwY4
=kRMa
-----END PGP SIGNATURE-----

Timestamp of file with hash 3fdf6b1f1067c03925b9d722351cb047b182e9c7b0e592c72a748edce0c99d97 -

achow101 added 2 commits July 26, 2020 20:22
Instead of logging or printing these errors and warnings, return them to
the caller.
VerifyEnvironment and VerifyDatabaseFile were removed, but their
declarations weren't. Remove those.
@achow101 achow101 force-pushed the walletdb-statics-followup branch 2 times, most recently from 80e1772 to fbe8816 Compare July 27, 2020 00:25
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -256,6 +256,7 @@ public:
     std::map<std::pair<uint256, CKeyID>, CKey> m_descriptor_keys;
     std::map<std::pair<uint256, CKeyID>, std::pair<CPubKey, std::vector<unsigned char>>> m_descriptor_crypt_keys;
     std::map<uint160, CHDChain> m_hd_chains;
+    bool corrupt = false;
 
     CWalletScanState() {
     }
@@ -289,6 +290,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
                 if (!new_tx) {
                     // There's probably some corruption here since the tx we just tried to load was already in the wallet
                     // This error is recoverable with zapwallettxs and is not a major failure
+                    wss.corrupt = true;
                     return false;
                 }
                 ssValue >> wtx;
@@ -730,7 +732,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
             {
                 // losing keys is considered a catastrophic error, anything else
                 // we assume the user can live with:
-                if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY) {
+                if (IsKeyType(strType) || strType == DBKeys::DEFAULTKEY || wss.corrupt) {
                     result = DBErrors::CORRUPT;
                 } else if (strType == DBKeys::FLAGS) {
                     // reading the wallet flags can only fail if unknown flags are present

@achow101 achow101 force-pushed the walletdb-statics-followup branch from fbe8816 to 0e279fe Compare August 13, 2020 00:12
@achow101
Copy link
Member Author

I've dropped the last commit. I agree it doesn't fit well here and can be for a followup.

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 0e279fe

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 0e279fe, just dropped last commit

std::vector<bilingual_str> warnings;
bool ret = RecoverDatabaseFile(path, error, warnings);
if (!ret) {
for (const auto warning : warnings) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

wallet/wallettool.cpp:133:33: warning: loop variable 'warning' of type 'const bilingual_str' creates a copy from type 'const bilingual_str' [-Wrange-loop-analysis]
                for (const auto warning : warnings) {
                                ^
wallet/wallettool.cpp:133:22: note: use reference type 'const bilingual_str &' to prevent copying
                for (const auto warning : warnings) {
                     ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

@maflcko maflcko merged commit 30dd562 into bitcoin:master Aug 14, 2020
@maflcko
Copy link
Member

maflcko commented Aug 14, 2020

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

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 16, 2020
…extraneous declarations

0e279fe walletdb: Remove unused static functions from walletdb.h (Andrew Chow)
9f536d4 wallettool: Have RecoverDatabaseFile return errors and warnings (Andrew Chow)
06e263a Call RecoverDatabaseFile directly from wallettool (Andrew Chow)

Pull request description:

  Followup to bitcoin#19324 addressing some comments.

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

  Removes the `LogPrintf`s and `tfm::format`s in `RecoverDatabaseFile` as noted in bitcoin#19324 (comment)

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

ACKs for top commit:
  meshcollider:
    Code review ACK 0e279fe
  ryanofsky:
    Code review ACK 0e279fe, just dropped last commit

Tree-SHA512: ffd01f30536c2eab4bf40ba363c3ea916ecef3c8f0c5262040b40498776ffb00f95240204a40e38415d6931800851d0a3fa63ee91efc1d329b60ac317da0363d
@ryanofsky
Copy link
Contributor

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

Sure, created #19793

deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 8, 2021
Summary:
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
cause the salvage to sometimes fail. This is not needed.

This is a backport of [[bitcoin/bitcoin#19457 | core#19457]] [1/3]
bitcoin/bitcoin@06e263a

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9639
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 8, 2021
Summary:
Instead of logging or printing these errors and warnings, return them to
the caller.

This is a backport of [[bitcoin/bitcoin#19457 | core#19457]] [2/3]
bitcoin/bitcoin@9f536d4

Depends on D9640

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9641
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 8, 2021
Summary:
VerifyEnvironment and VerifyDatabaseFile were removed in D8617/[[bitcoin/bitcoin#19324 | PR19324]], but their declarations weren't. Remove those.

This is a backport of [[bitcoin/bitcoin#19457 | core#19457]] [3/3]
bitcoin/bitcoin@0e279fe

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9079
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants