aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2024-06-07 13:05:06 +0200
committerTheCharlatan <seb.kung@gmail.com>2024-06-07 19:18:46 +0200
commitf68cba29b3be0dec7877022b18a193a3b78c1099 (patch)
tree8ee3af2a1a219b8434a48ad63f6cce9a9ae69364 /src/node
parent1b1c6dcca0cc891bd35d29b61628c39098cd94ce (diff)
downloadbitcoin-f68cba29b3be0dec7877022b18a193a3b78c1099.tar.xz
blockman: Replace m_reindexing with m_blockfiles_indexed
This is a just a mechanical change, renaming and inverting the meaning of the indexing variable. "m_blockfiles_indexed" is a more straightforward name for this variable because this variable just indicates whether or not <datadir>/blocks/blk?????.dat files have been indexed in the <datadir>/blocks/index LevelDB database. The name "m_reindexing" was more confusing, it could be true even if -reindex was not specified, and false when it was specified. Also, the previous name unnecessarily required thinking about the whole reindexing process just to understand simple checks in validation code about whether blocks were indexed. The motivation for this change is to follow up on previous commits, moving away from having multiple variables called "reindex" internally, and instead naming variables individually after what they do and represent.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp6
-rw-r--r--src/node/blockstorage.h11
-rw-r--r--src/node/chainstate.cpp6
3 files changed, 12 insertions, 11 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 4067ccee51..fb62e78138 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -551,7 +551,7 @@ bool BlockManager::LoadBlockIndexDB(const std::optional<uint256>& snapshot_block
// Check whether we need to continue reindexing
bool fReindexing = false;
m_block_tree_db->ReadReindexing(fReindexing);
- if (fReindexing) m_reindexing = true;
+ if (fReindexing) m_blockfiles_indexed = false;
return true;
}
@@ -1182,7 +1182,7 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
ImportingNow imp{chainman.m_blockman.m_importing};
// -reindex
- if (chainman.m_blockman.m_reindexing) {
+ if (!chainman.m_blockman.m_blockfiles_indexed) {
int nFile = 0;
// Map of disk positions for blocks with unknown parent (only used for reindex);
// parent hash -> child disk position, multiple children can have the same parent.
@@ -1205,7 +1205,7 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
nFile++;
}
WITH_LOCK(::cs_main, chainman.m_blockman.m_block_tree_db->WriteReindexing(false));
- chainman.m_blockman.m_reindexing = false;
+ chainman.m_blockman.m_blockfiles_indexed = true;
LogPrintf("Reindexing finished\n");
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
chainman.ActiveChainstate().LoadGenesisBlock();
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index bc09d102e2..108a08a72b 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -273,11 +273,12 @@ public:
std::atomic<bool> m_importing{false};
/**
- * Tracks if a reindex is currently in progress. Set to true when a reindex
- * is requested and false when reindexing completes. Its value is persisted
- * in the BlockTreeDB across restarts.
+ * Whether all blockfiles have been added to the block tree database.
+ * Normally true, but set to false when a reindex is requested and the
+ * database is wiped. The value is persisted in the database across restarts
+ * and will be false until reindexing completes.
*/
- std::atomic_bool m_reindexing{false};
+ std::atomic_bool m_blockfiles_indexed{true};
BlockMap m_block_index GUARDED_BY(cs_main);
@@ -358,7 +359,7 @@ public:
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }
static constexpr auto PRUNE_TARGET_MANUAL{std::numeric_limits<uint64_t>::max()};
- [[nodiscard]] bool LoadingBlocks() const { return m_importing || m_reindexing; }
+ [[nodiscard]] bool LoadingBlocks() const { return m_importing || !m_blockfiles_indexed; }
/** Calculate the amount of disk space the block & undo files currently use */
uint64_t CalculateCurrentUsage();
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp
index 0e1c2177fc..d7e6176be1 100644
--- a/src/node/chainstate.cpp
+++ b/src/node/chainstate.cpp
@@ -50,7 +50,7 @@ static ChainstateLoadResult CompleteChainstateInitialization(
if (options.wipe_block_tree_db) {
pblocktree->WriteReindexing(true);
- chainman.m_blockman.m_reindexing = true;
+ chainman.m_blockman.m_blockfiles_indexed = false;
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
if (options.prune) {
chainman.m_blockman.CleanupBlockRevFiles();
@@ -61,7 +61,7 @@ static ChainstateLoadResult CompleteChainstateInitialization(
// LoadBlockIndex will load m_have_pruned if we've ever removed a
// block file from disk.
- // Note that it also sets m_reindexing based on the disk flag!
+ // Note that it also sets m_blockfiles_indexed based on the disk flag!
if (!chainman.LoadBlockIndex()) {
if (chainman.m_interrupt) return {ChainstateLoadStatus::INTERRUPTED, {}};
return {ChainstateLoadStatus::FAILURE, _("Error loading block database")};
@@ -84,7 +84,7 @@ static ChainstateLoadResult CompleteChainstateInitialization(
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
// (otherwise we use the one already on disk).
// This is called again in ImportBlocks after the reindex completes.
- if (!chainman.m_blockman.m_reindexing && !chainman.ActiveChainstate().LoadGenesisBlock()) {
+ if (chainman.m_blockman.m_blockfiles_indexed && !chainman.ActiveChainstate().LoadGenesisBlock()) {
return {ChainstateLoadStatus::FAILURE, _("Error initializing block database")};
}