Merge pull request #931 from luke-jr/dbg_loaderr

Wallet loading diagnostic prints to debug.log
This commit is contained in:
Gregory Maxwell 2012-03-18 20:11:09 -07:00
commit 0b99d1b574
2 changed files with 38 additions and 2 deletions

View File

@ -774,7 +774,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
// Get cursor // Get cursor
Dbc* pcursor = GetCursor(); Dbc* pcursor = GetCursor();
if (!pcursor) if (!pcursor)
{
printf("Error getting wallet database cursor\n");
return DB_CORRUPT; return DB_CORRUPT;
}
loop loop
{ {
@ -785,7 +788,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
if (ret == DB_NOTFOUND) if (ret == DB_NOTFOUND)
break; break;
else if (ret != 0) else if (ret != 0)
{
printf("Error reading next record from wallet database\n");
return DB_CORRUPT; return DB_CORRUPT;
}
// Unserialize // Unserialize
// Taking advantage of the fact that pair serialization // Taking advantage of the fact that pair serialization
@ -856,8 +862,16 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
ssValue >> pkey; ssValue >> pkey;
key.SetPubKey(vchPubKey); key.SetPubKey(vchPubKey);
key.SetPrivKey(pkey); key.SetPrivKey(pkey);
if (key.GetPubKey() != vchPubKey || !key.IsValid()) if (key.GetPubKey() != vchPubKey)
{
printf("Error reading wallet database: CPrivKey pubkey inconsistency\n");
return DB_CORRUPT; return DB_CORRUPT;
}
if (!key.IsValid())
{
printf("Error reading wallet database: invalid CPrivKey\n");
return DB_CORRUPT;
}
} }
else else
{ {
@ -865,11 +879,22 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
ssValue >> wkey; ssValue >> wkey;
key.SetPubKey(vchPubKey); key.SetPubKey(vchPubKey);
key.SetPrivKey(wkey.vchPrivKey); key.SetPrivKey(wkey.vchPrivKey);
if (key.GetPubKey() != vchPubKey || !key.IsValid()) if (key.GetPubKey() != vchPubKey)
{
printf("Error reading wallet database: CWalletKey pubkey inconsistency\n");
return DB_CORRUPT; return DB_CORRUPT;
}
if (!key.IsValid())
{
printf("Error reading wallet database: invalid CWalletKey\n");
return DB_CORRUPT;
}
} }
if (!pwallet->LoadKey(key)) if (!pwallet->LoadKey(key))
{
printf("Error reading wallet database: LoadKey failed\n");
return DB_CORRUPT; return DB_CORRUPT;
}
} }
else if (strType == "mkey") else if (strType == "mkey")
{ {
@ -878,7 +903,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
CMasterKey kMasterKey; CMasterKey kMasterKey;
ssValue >> kMasterKey; ssValue >> kMasterKey;
if(pwallet->mapMasterKeys.count(nID) != 0) if(pwallet->mapMasterKeys.count(nID) != 0)
{
printf("Error reading wallet database: duplicate CMasterKey id %u\n", nID);
return DB_CORRUPT; return DB_CORRUPT;
}
pwallet->mapMasterKeys[nID] = kMasterKey; pwallet->mapMasterKeys[nID] = kMasterKey;
if (pwallet->nMasterKeyMaxID < nID) if (pwallet->nMasterKeyMaxID < nID)
pwallet->nMasterKeyMaxID = nID; pwallet->nMasterKeyMaxID = nID;
@ -890,7 +918,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
vector<unsigned char> vchPrivKey; vector<unsigned char> vchPrivKey;
ssValue >> vchPrivKey; ssValue >> vchPrivKey;
if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey)) if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
{
printf("Error reading wallet database: LoadCryptedKey failed\n");
return DB_CORRUPT; return DB_CORRUPT;
}
fIsEncrypted = true; fIsEncrypted = true;
} }
else if (strType == "defaultkey") else if (strType == "defaultkey")
@ -924,7 +955,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
CScript script; CScript script;
ssValue >> script; ssValue >> script;
if (!pwallet->LoadCScript(script)) if (!pwallet->LoadCScript(script))
{
printf("Error reading wallet database: LoadCScript failed\n");
return DB_CORRUPT; return DB_CORRUPT;
}
} }
} }
pcursor->close(); pcursor->close();

View File

@ -370,12 +370,14 @@ bool AppInit2(int argc, char* argv[])
else if (nLoadWalletRet == DB_NEED_REWRITE) else if (nLoadWalletRet == DB_NEED_REWRITE)
{ {
strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n"; strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
printf("%s", strErrors.str().c_str());
wxMessageBox(strErrors.str(), "Bitcoin", wxOK | wxICON_ERROR); wxMessageBox(strErrors.str(), "Bitcoin", wxOK | wxICON_ERROR);
return false; return false;
} }
else else
strErrors << _("Error loading wallet.dat") << "\n"; strErrors << _("Error loading wallet.dat") << "\n";
} }
printf("%s", strErrors.str().c_str());
printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart); printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
RegisterWallet(pwalletMain); RegisterWallet(pwalletMain);