From: Luke Dashjr Date: Sun, 11 Mar 2012 22:07:40 +0000 (-0400) Subject: Print more diagnostic info for the various DB_CORRUPT conditions X-Git-Tag: v0.4.0-unstable~129^2~1^2^2~2^2^2~48 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=1194f003504fa6e9d9f59012ec736ebc7c231360 Print more diagnostic info for the various DB_CORRUPT conditions --- diff --git a/src/db.cpp b/src/db.cpp index 783b079..7f9439b 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -798,7 +798,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) // Get cursor Dbc* pcursor = GetCursor(); if (!pcursor) + { + printf("Error getting wallet database cursor\n"); return DB_CORRUPT; + } loop { @@ -809,7 +812,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) if (ret == DB_NOTFOUND) break; else if (ret != 0) + { + printf("Error reading next record from wallet database\n"); return DB_CORRUPT; + } // Unserialize // Taking advantage of the fact that pair serialization @@ -879,19 +885,38 @@ int CWalletDB::LoadWallet(CWallet* pwallet) CPrivKey pkey; ssValue >> 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; + } + if (!key.IsValid()) + { + printf("Error reading wallet database: invalid CPrivKey\n"); + return DB_CORRUPT; + } } else { CWalletKey wkey; ssValue >> wkey; 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; + } + if (!key.IsValid()) + { + printf("Error reading wallet database: invalid CWalletKey\n"); + return DB_CORRUPT; + } } if (!pwallet->LoadKey(key)) + { + printf("Error reading wallet database: LoadKey failed\n"); return DB_CORRUPT; + } } else if (strType == "mkey") { @@ -900,7 +925,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) CMasterKey kMasterKey; ssValue >> kMasterKey; if(pwallet->mapMasterKeys.count(nID) != 0) + { + printf("Error reading wallet database: duplicate CMasterKey id %u\n", nID); return DB_CORRUPT; + } pwallet->mapMasterKeys[nID] = kMasterKey; if (pwallet->nMasterKeyMaxID < nID) pwallet->nMasterKeyMaxID = nID; @@ -912,7 +940,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet) vector vchPrivKey; ssValue >> vchPrivKey; if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey)) + { + printf("Error reading wallet database: LoadCryptedKey failed\n"); return DB_CORRUPT; + } fIsEncrypted = true; } else if (strType == "defaultkey")