Skip to content

Commit

Permalink
Fix rescan entire wallet when finding corrupt transaction on load. No…
Browse files Browse the repository at this point in the history
…w removes corrupt tx and re adds it with GetTransaction.
  • Loading branch information
blackjok3r committed Jan 18, 2019
1 parent cad982a commit 06ff993
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
using namespace std;

static uint64_t nAccountingEntryNumber = 0;
static list<uint256> deadTxns;

//
// CWalletDB
Expand Down Expand Up @@ -484,8 +485,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
CValidationState state;
auto verifier = libzcash::ProofVerifier::Strict();
if (!(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()))
{
fprintf(stderr, "Removing corrupt tx from wallet.%s\n", hash.ToString().c_str());
deadTxns.push_back(hash);
return false;

}
// Undo serialize changes in 31600
if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
{
Expand Down Expand Up @@ -933,9 +937,6 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
{
// Leave other errors alone, if we try to fix them we might make things worse.
fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
if (strType == "tx")
// Rescan if there is a bad transaction record:
SoftSetBoolArg("-rescan", true);
}
}
if (!strErr.empty())
Expand All @@ -950,6 +951,24 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
result = DB_CORRUPT;
}

if (!deadTxns.empty())
{
int32_t reAdded = 0;
BOOST_FOREACH (uint256& hash, deadTxns) {
if (!EraseTx(hash))
fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str());
uint256 blockhash; CTransaction tx;
if (GetTransaction(hash,tx,blockhash,true))
{
CWalletTx wtx(pwallet,tx);
pwallet->AddToWallet(wtx, true, NULL);
reAdded++;
}
}
fprintf(stderr, "Cleared %lu corrupted transactions from wallet. Readded %i known transactions.\n",deadTxns.size(),reAdded);
deadTxns.clear();
}

if (fNoncriticalErrors && result == DB_LOAD_OK)
result = DB_NONCRITICAL_ERROR;

Expand Down

0 comments on commit 06ff993

Please sign in to comment.