Skip to content

Commit

Permalink
blockstorage: Add Assume for fKnown / snapshot chainstate
Browse files Browse the repository at this point in the history
fKnown is true during reindex (and only then), which deletes
any existing snapshot chainstate. As a result, this function can never
be called wth fKnown set and a snapshot chainstate.
Add an Assume for this, and make the code initializing a blockfile cursor
for the snapshot conditional on !fKnown.

This is a preparation for splitting the reindex logic out of
FindBlockPos in the following commits.
  • Loading branch information
mzumsande committed May 8, 2024
1 parent 7973a67 commit 0d114e3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,16 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
LOCK(cs_LastBlockFile);

const BlockfileType chain_type = BlockfileTypeForHeight(nHeight);
// Check that chain type is NORMAL if fKnown is true, because fKnown is only
// true during reindexing, and reindexing deletes snapshot chainstates, so
// chain_type will not be SNAPSHOT. Also check that cursor exists, because
// the normal cursor should never be null.
if (fKnown) {
Assume(chain_type == BlockfileType::NORMAL);
Assume(m_blockfile_cursors[chain_type]);
}

if (!m_blockfile_cursors[chain_type]) {
if (!fKnown && !m_blockfile_cursors[chain_type]) {
// If a snapshot is loaded during runtime, we may not have initialized this cursor yet.
assert(chain_type == BlockfileType::ASSUMED);
const auto new_cursor = BlockfileCursor{this->MaxBlockfileNum() + 1};
Expand Down

0 comments on commit 0d114e3

Please sign in to comment.