@@ -4057,7 +4057,7 @@ CVerifyDB::~CVerifyDB()
4057
4057
uiInterface.ShowProgress (" " , 100 , false );
4058
4058
}
4059
4059
4060
- bool CVerifyDB::VerifyDB (
4060
+ VerifyDBResult CVerifyDB::VerifyDB (
4061
4061
Chainstate& chainstate,
4062
4062
const Consensus::Params& consensus_params,
4063
4063
CCoinsView& coinsview,
@@ -4066,7 +4066,7 @@ bool CVerifyDB::VerifyDB(
4066
4066
AssertLockHeld (cs_main);
4067
4067
4068
4068
if (chainstate.m_chain .Tip () == nullptr || chainstate.m_chain .Tip ()->pprev == nullptr ) {
4069
- return true ;
4069
+ return VerifyDBResult::SUCCESS ;
4070
4070
}
4071
4071
4072
4072
// Verify blocks in the best chain
@@ -4106,19 +4106,22 @@ bool CVerifyDB::VerifyDB(
4106
4106
CBlock block;
4107
4107
// check level 0: read from disk
4108
4108
if (!ReadBlockFromDisk (block, pindex, consensus_params)) {
4109
- return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4109
+ LogPrintf (" Verification error: ReadBlockFromDisk failed at %d, hash=%s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4110
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4110
4111
}
4111
4112
// check level 1: verify block validity
4112
4113
if (nCheckLevel >= 1 && !CheckBlock (block, state, consensus_params)) {
4113
- return error (" %s: *** found bad block at %d, hash=%s (%s)\n " , __func__,
4114
- pindex->nHeight , pindex->GetBlockHash ().ToString (), state.ToString ());
4114
+ LogPrintf (" Verification error: found bad block at %d, hash=%s (%s)\n " ,
4115
+ pindex->nHeight , pindex->GetBlockHash ().ToString (), state.ToString ());
4116
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4115
4117
}
4116
4118
// check level 2: verify undo validity
4117
4119
if (nCheckLevel >= 2 && pindex) {
4118
4120
CBlockUndo undo;
4119
4121
if (!pindex->GetUndoPos ().IsNull ()) {
4120
4122
if (!UndoReadFromDisk (undo, pindex)) {
4121
- return error (" VerifyDB(): *** found bad undo data at %d, hash=%s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4123
+ LogPrintf (" Verification error: found bad undo data at %d, hash=%s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4124
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4122
4125
}
4123
4126
}
4124
4127
}
@@ -4130,7 +4133,8 @@ bool CVerifyDB::VerifyDB(
4130
4133
assert (coins.GetBestBlock () == pindex->GetBlockHash ());
4131
4134
DisconnectResult res = chainstate.DisconnectBlock (block, pindex, coins);
4132
4135
if (res == DISCONNECT_FAILED) {
4133
- return error (" VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4136
+ LogPrintf (" Verification error: irrecoverable inconsistency in block data at %d, hash=%s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4137
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4134
4138
}
4135
4139
if (res == DISCONNECT_UNCLEAN) {
4136
4140
nGoodTransactions = 0 ;
@@ -4142,14 +4146,16 @@ bool CVerifyDB::VerifyDB(
4142
4146
skipped_l3_checks = true ;
4143
4147
}
4144
4148
}
4145
- if (ShutdownRequested ()) return true ;
4149
+ if (ShutdownRequested ()) return VerifyDBResult::SUCCESS ;
4146
4150
}
4147
4151
if (pindexFailure) {
4148
- return error (" VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n " , chainstate.m_chain .Height () - pindexFailure->nHeight + 1 , nGoodTransactions);
4152
+ LogPrintf (" Verification error: coin database inconsistencies found (last %i blocks, %i good transactions before that)\n " , chainstate.m_chain .Height () - pindexFailure->nHeight + 1 , nGoodTransactions);
4153
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4149
4154
}
4150
4155
if (skipped_l3_checks) {
4151
4156
LogPrintf (" Skipped verification of level >=3 (insufficient database cache size). Consider increasing -dbcache.\n " );
4152
4157
}
4158
+
4153
4159
// store block count as we move pindex at check level >= 4
4154
4160
int block_count = chainstate.m_chain .Height () - pindex->nHeight ;
4155
4161
@@ -4165,18 +4171,21 @@ bool CVerifyDB::VerifyDB(
4165
4171
uiInterface.ShowProgress (_ (" Verifying blocks…" ).translated , percentageDone, false );
4166
4172
pindex = chainstate.m_chain .Next (pindex);
4167
4173
CBlock block;
4168
- if (!ReadBlockFromDisk (block, pindex, consensus_params))
4169
- return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4174
+ if (!ReadBlockFromDisk (block, pindex, consensus_params)) {
4175
+ LogPrintf (" Verification error: ReadBlockFromDisk failed at %d, hash=%s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4176
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4177
+ }
4170
4178
if (!chainstate.ConnectBlock (block, state, pindex, coins)) {
4171
- return error (" VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)" , pindex->nHeight , pindex->GetBlockHash ().ToString (), state.ToString ());
4179
+ LogPrintf (" Verification error: found unconnectable block at %d, hash=%s (%s)\n " , pindex->nHeight , pindex->GetBlockHash ().ToString (), state.ToString ());
4180
+ return VerifyDBResult::CORRUPTED_BLOCK_DB;
4172
4181
}
4173
- if (ShutdownRequested ()) return true ;
4182
+ if (ShutdownRequested ()) return VerifyDBResult::SUCCESS ;
4174
4183
}
4175
4184
}
4176
4185
4177
4186
LogPrintf (" Verification: No coin database inconsistencies in last %i blocks (%i transactions)\n " , block_count, nGoodTransactions);
4178
4187
4179
- return true ;
4188
+ return VerifyDBResult::SUCCESS ;
4180
4189
}
4181
4190
4182
4191
/* * Apply the effects of a block on the utxo cache, ignoring that it may already have been applied. */
0 commit comments