Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14362713
D12032.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
D12032.diff
View Options
diff --git a/arcanist/linter/LocaleDependenceLinter.php b/arcanist/linter/LocaleDependenceLinter.php
--- a/arcanist/linter/LocaleDependenceLinter.php
+++ b/arcanist/linter/LocaleDependenceLinter.php
@@ -49,7 +49,7 @@
"vsnprintf"
],
"src/httprpc.cpp" => ["trim"],
- "src/init.cpp" => ["atoi"],
+ "src/node/blockstorage.cpp" => ["atoi"],
"src/netbase.cpp" => ["to_lower"],
"src/qt/rpcconsole.cpp" => [
"atoi",
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1460,47 +1460,6 @@
}
}
-// If we're using -prune with -reindex, then delete block files that will be
-// ignored by the reindex. Since reindexing works by starting at block file 0
-// and looping until a blockfile is missing, do the same here to delete any
-// later block files after a gap. Also delete all rev files since they'll be
-// rewritten by the reindex anyway. This ensures that vinfoBlockFile is in sync
-// with what's actually on disk by the time we start downloading, so that
-// pruning works correctly.
-static void CleanupBlockRevFiles() {
- std::map<std::string, fs::path> mapBlockFiles;
-
- // Glob all blk?????.dat and rev?????.dat files from the blocks directory.
- // Remove the rev files immediately and insert the blk file paths into an
- // ordered map keyed by block file index.
- LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for "
- "-reindex with -prune\n");
- for (const auto &file : fs::directory_iterator{gArgs.GetBlocksDirPath()}) {
- const std::string path = fs::PathToString(file.path().filename());
- if (fs::is_regular_file(file) && path.length() == 12 &&
- path.substr(8, 4) == ".dat") {
- if (path.substr(0, 3) == "blk") {
- mapBlockFiles[path.substr(3, 5)] = file.path();
- } else if (path.substr(0, 3) == "rev") {
- remove(file.path());
- }
- }
- }
-
- // Remove all block files that aren't part of a contiguous set starting at
- // zero by walking the ordered map (keys are block file indices) by keeping
- // a separate counter. Once we hit a gap (or if 0 doesn't exist) start
- // removing block files.
- int contiguousCounter = 0;
- for (const auto &item : mapBlockFiles) {
- if (atoi(item.first) == contiguousCounter) {
- contiguousCounter++;
- continue;
- }
- remove(item.second);
- }
-}
-
#if HAVE_SYSTEM
static void StartupNotify(const ArgsManager &args) {
std::string cmd = args.GetArg("-startupnotify", "");
diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp
--- a/src/interfaces/node.cpp
+++ b/src/interfaces/node.cpp
@@ -17,6 +17,7 @@
#include <net_processing.h>
#include <netaddress.h>
#include <netbase.h>
+#include <node/blockstorage.h>
#include <node/context.h>
#include <node/ui_interface.h>
#include <policy/fees.h>
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -26,6 +26,21 @@
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
+extern std::atomic_bool fImporting;
+extern std::atomic_bool fReindex;
+/** Pruning-related variables and constants */
+/** True if any block files have ever been pruned. */
+extern bool fHavePruned;
+/** True if we're running in -prune mode. */
+extern bool fPruneMode;
+/** Number of MiB of block files that we're trying to stay below. */
+extern uint64_t nPruneTarget;
+
+//! Check whether the block associated with this index entry is pruned or not.
+bool IsBlockPruned(const CBlockIndex *pblockindex);
+
+void CleanupBlockRevFiles();
+
/** Functions for disk access for blocks */
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos,
const Consensus::Params &consensusParams);
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -17,6 +17,58 @@
#include <util/system.h>
#include <validation.h>
+std::atomic_bool fImporting(false);
+std::atomic_bool fReindex(false);
+bool fHavePruned = false;
+bool fPruneMode = false;
+uint64_t nPruneTarget = 0;
+
+bool IsBlockPruned(const CBlockIndex *pblockindex) {
+ return (fHavePruned && !pblockindex->nStatus.hasData() &&
+ pblockindex->nTx > 0);
+}
+
+// If we're using -prune with -reindex, then delete block files that will be
+// ignored by the reindex. Since reindexing works by starting at block file 0
+// and looping until a blockfile is missing, do the same here to delete any
+// later block files after a gap. Also delete all rev files since they'll be
+// rewritten by the reindex anyway. This ensures that vinfoBlockFile is in sync
+// with what's actually on disk by the time we start downloading, so that
+// pruning works correctly.
+void CleanupBlockRevFiles() {
+ std::map<std::string, fs::path> mapBlockFiles;
+
+ // Glob all blk?????.dat and rev?????.dat files from the blocks directory.
+ // Remove the rev files immediately and insert the blk file paths into an
+ // ordered map keyed by block file index.
+ LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for "
+ "-reindex with -prune\n");
+ for (const auto &file : fs::directory_iterator{gArgs.GetBlocksDirPath()}) {
+ const std::string path = fs::PathToString(file.path().filename());
+ if (fs::is_regular_file(file) && path.length() == 12 &&
+ path.substr(8, 4) == ".dat") {
+ if (path.substr(0, 3) == "blk") {
+ mapBlockFiles[path.substr(3, 5)] = file.path();
+ } else if (path.substr(0, 3) == "rev") {
+ remove(file.path());
+ }
+ }
+ }
+
+ // Remove all block files that aren't part of a contiguous set starting at
+ // zero by walking the ordered map (keys are block file indices) by keeping
+ // a separate counter. Once we hit a gap (or if 0 doesn't exist) start
+ // removing block files.
+ int contiguousCounter = 0;
+ for (const auto &item : mapBlockFiles) {
+ if (atoi(item.first) == contiguousCounter) {
+ contiguousCounter++;
+ continue;
+ }
+ remove(item.second);
+ }
+}
+
// From validation. TODO move here
bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight,
CChain &active_chain, uint64_t nTime, bool fKnown = false);
diff --git a/src/validation.h b/src/validation.h
--- a/src/validation.h
+++ b/src/validation.h
@@ -141,8 +141,6 @@
extern Mutex g_best_block_mutex;
extern std::condition_variable g_best_block_cv;
extern uint256 g_best_block;
-extern std::atomic_bool fImporting;
-extern std::atomic_bool fReindex;
extern bool fRequireStandard;
extern bool fCheckBlockIndex;
extern bool fCheckpointsEnabled;
@@ -174,13 +172,6 @@
*/
extern CBlockIndex *pindexBestHeader;
-/** Pruning-related variables and constants */
-/** True if any block files have ever been pruned. */
-extern bool fHavePruned;
-/** True if we're running in -prune mode. */
-extern bool fPruneMode;
-/** Number of MiB of block files that we're trying to stay below. */
-extern uint64_t nPruneTarget;
/** Documentation for argument 'checklevel'. */
extern const std::vector<std::string> CHECKLEVEL_DOC;
@@ -1370,9 +1361,6 @@
bool LoadMempool(const Config &config, CTxMemPool &pool,
CChainState &active_chainstate);
-//! Check whether the block associated with this index entry is pruned or not.
-bool IsBlockPruned(const CBlockIndex *pblockindex);
-
/**
* Return the expected assumeutxo value for a given height, if one exists.
*
diff --git a/src/validation.cpp b/src/validation.cpp
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -95,14 +95,9 @@
Mutex g_best_block_mutex;
std::condition_variable g_best_block_cv;
uint256 g_best_block;
-std::atomic_bool fImporting(false);
-std::atomic_bool fReindex(false);
-bool fHavePruned = false;
-bool fPruneMode = false;
bool fRequireStandard = true;
bool fCheckBlockIndex = false;
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
-uint64_t nPruneTarget = 0;
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
BlockHash hashAssumeValid;
@@ -5913,11 +5908,6 @@
return true;
}
-bool IsBlockPruned(const CBlockIndex *pblockindex) {
- return (fHavePruned && !pblockindex->nStatus.hasData() &&
- pblockindex->nTx > 0);
-}
-
//! Guess how far we are in the verification process at the given block index
//! require cs_main if pindex has not been validated yet (because the chain's
//! transaction count might be unset) This conditional lock requirement might be
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, May 12, 01:42 (20 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5777044
Default Alt Text
D12032.diff (8 KB)
Attached To
D12032: refactor: Move pruning/reindex/importing globals to blockstorage
Event Timeline
Log In to Comment