Skip to content

Commit 0d114e3

Browse files
committed
blockstorage: Add Assume for fKnown / snapshot chainstate
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.
1 parent 7973a67 commit 0d114e3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/node/blockstorage.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,16 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
853853
LOCK(cs_LastBlockFile);
854854

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

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

0 commit comments

Comments
 (0)