Skip to content

Commit 5da523c

Browse files
committed
merge bitcoin#24403: Avoid implicit-integer-sign-change in VerifyLoadedChainstate
1 parent 5069a0b commit 5da523c

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

src/node/chainstate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
261261
bool fReset,
262262
bool fReindexChainState,
263263
const Consensus::Params& consensus_params,
264-
unsigned int check_blocks,
265-
unsigned int check_level,
264+
int check_blocks,
265+
int check_level,
266266
std::function<int64_t()> get_unix_time_seconds,
267267
std::function<void(bool)> notify_bls_state)
268268
{

src/node/chainstate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
143143
bool fReset,
144144
bool fReindexChainState,
145145
const Consensus::Params& consensus_params,
146-
unsigned int check_blocks,
147-
unsigned int check_level,
146+
int check_blocks,
147+
int check_level,
148148
std::function<int64_t()> get_unix_time_seconds,
149149
std::function<void(bool)> notify_bls_state = nullptr);
150150

src/validation.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,15 +4434,17 @@ bool CVerifyDB::VerifyDB(
44344434
{
44354435
AssertLockHeld(cs_main);
44364436

4437-
if (chainstate.m_chain.Tip() == nullptr || chainstate.m_chain.Tip()->pprev == nullptr)
4437+
if (chainstate.m_chain.Tip() == nullptr || chainstate.m_chain.Tip()->pprev == nullptr) {
44384438
return true;
4439+
}
44394440

44404441
// begin tx and let it rollback
44414442
auto dbTx = evoDb.BeginTransaction();
44424443

44434444
// Verify blocks in the best chain
4444-
if (nCheckDepth <= 0 || nCheckDepth > chainstate.m_chain.Height())
4445+
if (nCheckDepth <= 0 || nCheckDepth > chainstate.m_chain.Height()) {
44454446
nCheckDepth = chainstate.m_chain.Height();
4447+
}
44464448
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
44474449
LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
44484450
CCoinsViewCache coins(&coinsview);
@@ -4457,14 +4459,15 @@ bool CVerifyDB::VerifyDB(
44574459

44584460
for (pindex = chainstate.m_chain.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) {
44594461
const int percentageDone = std::max(1, std::min(99, (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
4460-
if (reportDone < percentageDone/10) {
4462+
if (reportDone < percentageDone / 10) {
44614463
// report every 10% step
44624464
LogPrintf("[%d%%]...", percentageDone); /* Continued */
4463-
reportDone = percentageDone/10;
4465+
reportDone = percentageDone / 10;
44644466
}
44654467
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
4466-
if (pindex->nHeight <= chainstate.m_chain.Height()-nCheckDepth)
4468+
if (pindex->nHeight <= chainstate.m_chain.Height() - nCheckDepth) {
44674469
break;
4470+
}
44684471
if ((fPruneMode || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
44694472
// If pruning or running under an assumeutxo snapshot, only go
44704473
// back as far as we have data.
@@ -4473,12 +4476,14 @@ bool CVerifyDB::VerifyDB(
44734476
}
44744477
CBlock block;
44754478
// check level 0: read from disk
4476-
if (!ReadBlockFromDisk(block, pindex, consensus_params))
4479+
if (!ReadBlockFromDisk(block, pindex, consensus_params)) {
44774480
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
4481+
}
44784482
// check level 1: verify block validity
4479-
if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params))
4483+
if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params)) {
44804484
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
44814485
pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
4486+
}
44824487
// check level 2: verify undo validity
44834488
if (nCheckLevel >= 2 && pindex) {
44844489
CBlockUndo undo;
@@ -4506,8 +4511,9 @@ bool CVerifyDB::VerifyDB(
45064511
}
45074512
if (ShutdownRequested()) return true;
45084513
}
4509-
if (pindexFailure)
4514+
if (pindexFailure) {
45104515
return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainstate.m_chain.Height() - pindexFailure->nHeight + 1, nGoodTransactions);
4516+
}
45114517

45124518
// store block count as we move pindex at check level >= 4
45134519
int block_count = chainstate.m_chain.Height() - pindex->nHeight;
@@ -4516,10 +4522,10 @@ bool CVerifyDB::VerifyDB(
45164522
if (nCheckLevel >= 4) {
45174523
while (pindex != chainstate.m_chain.Tip()) {
45184524
const int percentageDone = std::max(1, std::min(99, 100 - (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * 50)));
4519-
if (reportDone < percentageDone/10) {
4525+
if (reportDone < percentageDone / 10) {
45204526
// report every 10% step
45214527
LogPrintf("[%d%%]...", percentageDone); /* Continued */
4522-
reportDone = percentageDone/10;
4528+
reportDone = percentageDone / 10;
45234529
}
45244530
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
45254531
pindex = chainstate.m_chain.Next(pindex);

test/functional/rpc_blockchain.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ def set_test_params(self):
7171
def run_test(self):
7272
self.mine_chain()
7373
self._test_max_future_block_time()
74-
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1', '-txindex=0']) # Set extra args with pruning after rescan is complete
74+
self.restart_node(
75+
0,
76+
extra_args=[
77+
"-stopatheight=207",
78+
"-checkblocks=-1", # Check all blocks
79+
"-prune=1", # Set pruning after rescan is complete
80+
'-txindex=0',
81+
],
82+
)
7583

7684
# Actual tests
7785
self._test_getblockchaininfo()

0 commit comments

Comments
 (0)