-
Notifications
You must be signed in to change notification settings - Fork 38.8k
wallet: Cleanup wallettool salvage and walletdb extraneous declarations #19457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e7fcfd5 to
e3243b2
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
e3243b2 to
7dcb47b
Compare
ryanofsky
left a comment
There was a problem hiding this 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!
maflcko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
7dcb47b to
21349ec
Compare
|
Rebased. I've also added a commit that fixes the first error in #19078 |
ryanofsky
left a comment
There was a problem hiding this 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)
src/wallet/walletdb.cpp
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
maflcko
left a comment
There was a problem hiding this 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 -
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.
80e1772 to
fbe8816
Compare
ryanofsky
left a comment
There was a problem hiding this 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.
src/wallet/walletdb.cpp
Outdated
There was a problem hiding this comment.
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 presentfbe8816 to
0e279fe
Compare
|
I've dropped the last commit. I agree it doesn't fit well here and can be for a followup. |
meshcollider
left a comment
There was a problem hiding this 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
ryanofsky
left a comment
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.|
@ryanofsky Are you going to submit this patch as a pull: #19457 (comment) ? |
…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
Sure, created #19793 |
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
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
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
Followup to #19324 addressing some comments.
Removes the
SalvageWalletfunction in wallettool and instead directly callsRecoverDatabaseFileas suggested in #19324 (comment)Removes the
LogPrintfs andtfm::formats inRecoverDatabaseFileas noted in #19324 (comment)Removes the declarations of
VerifyEnvironmentandVerifyDatabaseFilethat were forgotten inwalletdb.has noted in #19324 (comment)