aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2024-03-20 15:08:40 -0400
committerMartin Zumsande <mzumsande@gmail.com>2024-05-08 18:19:47 -0400
commit0d114e3cb20cb9e03fc9ba8daf3d03436b491742 (patch)
tree6eeb9f065c3e3a3b2a12571b08d2afd5fe5071ed /src/node
parent7973a670915632b75a6aa16f24f98b936865c48f (diff)
downloadbitcoin-0d114e3cb20cb9e03fc9ba8daf3d03436b491742.tar.xz
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.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 576c07a833..9b8467c2f4 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -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};