Skip to content

Commit 86ce844

Browse files
committed
blockstorage, refactor: pass GetFirstStoredBlock() start_block by reference
instead of by pointer, so as to not accept a nullptr.
1 parent ed12c0a commit 86ce844

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/index/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool BaseIndex::Init()
7575
if (!m_best_block_index) {
7676
// index is not built yet
7777
// make sure we have all block data back to the genesis
78-
prune_violation = m_chainstate->m_blockman.GetFirstStoredBlock(active_chain.Tip()) != active_chain.Genesis();
78+
prune_violation = m_chainstate->m_blockman.GetFirstStoredBlock(*active_chain.Tip()) != active_chain.Genesis();
7979
}
8080
// in case the index has a best block set and is not fully synced
8181
// check if we have the required blocks to continue building the index

src/node/blockstorage.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,10 @@ bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
390390
return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
391391
}
392392

393-
const CBlockIndex* BlockManager::GetFirstStoredBlock(const CBlockIndex* start_block)
393+
const CBlockIndex* BlockManager::GetFirstStoredBlock(const CBlockIndex& start_block)
394394
{
395395
AssertLockHeld(::cs_main);
396-
assert(start_block);
397-
const CBlockIndex* last_block = start_block;
396+
const CBlockIndex* last_block = &start_block;
398397
while (last_block->pprev && (last_block->pprev->nStatus & BLOCK_HAVE_DATA)) {
399398
last_block = last_block->pprev;
400399
}

src/node/blockstorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class BlockManager
179179
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
180180

181181
//! Find the first block that is not pruned
182-
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
182+
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex& start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
183183

184184
/** True if any block files have ever been pruned. */
185185
bool m_have_pruned = false;

src/rpc/blockchain.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,9 @@ static RPCHelpMan pruneblockchain()
760760
CChain& active_chain = active_chainstate.m_chain;
761761

762762
int heightParam = request.params[0].get_int();
763-
if (heightParam < 0)
763+
if (heightParam < 0) {
764764
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height.");
765+
}
765766

766767
// Height value more than a billion is too high to be a block height, and
767768
// too low to be a block time (corresponds to timestamp from Sep 2001).
@@ -786,7 +787,7 @@ static RPCHelpMan pruneblockchain()
786787
}
787788

788789
PruneBlockFilesManual(active_chainstate, height);
789-
const CBlockIndex* block = CHECK_NONFATAL(active_chain.Tip());
790+
const CBlockIndex& block{*CHECK_NONFATAL(active_chain.Tip())};
790791
const CBlockIndex* last_block{active_chainstate.m_blockman.GetFirstStoredBlock(block)};
791792

792793
return static_cast<uint64_t>(last_block->nHeight);
@@ -1215,7 +1216,7 @@ RPCHelpMan getblockchaininfo()
12151216
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
12161217
obj.pushKV("pruned", node::fPruneMode);
12171218
if (node::fPruneMode) {
1218-
obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(&tip)->nHeight);
1219+
obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(tip)->nHeight);
12191220

12201221
// if 0, execution bypasses the whole if block.
12211222
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};

0 commit comments

Comments
 (0)