Skip to content

Commit c3f1821

Browse files
committed
Make blockdir always net specific
The blocks directory is net specific by definition. Also this prevents the side effect of calling GetBlocksDir(false) in the non-mainnet environment.
1 parent 13d98ea commit c3f1821

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ bool AppInitParameterInteraction()
906906

907907
// also see: InitParameterInteraction()
908908

909-
if (!fs::is_directory(GetBlocksDir(false))) {
909+
if (!fs::is_directory(GetBlocksDir())) {
910910
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), gArgs.GetArg("-blocksdir", "").c_str()));
911911
}
912912

src/util/system.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -728,18 +728,17 @@ fs::path GetDefaultDataDir()
728728
#endif
729729
}
730730

731-
static fs::path g_blocks_path_cached;
732731
static fs::path g_blocks_path_cache_net_specific;
733732
static fs::path pathCached;
734733
static fs::path pathCachedNetSpecific;
735734
static CCriticalSection csPathCached;
736735

737-
const fs::path &GetBlocksDir(bool fNetSpecific)
736+
const fs::path &GetBlocksDir()
738737
{
739738

740739
LOCK(csPathCached);
741740

742-
fs::path &path = fNetSpecific ? g_blocks_path_cache_net_specific : g_blocks_path_cached;
741+
fs::path &path = g_blocks_path_cache_net_specific;
743742

744743
// This can be called during exceptions by LogPrintf(), so we cache the
745744
// value so we don't have to do memory allocations after that.
@@ -755,9 +754,8 @@ const fs::path &GetBlocksDir(bool fNetSpecific)
755754
} else {
756755
path = GetDataDir(false);
757756
}
758-
if (fNetSpecific)
759-
path /= BaseParams().DataDir();
760757

758+
path /= BaseParams().DataDir();
761759
path /= "blocks";
762760
fs::create_directories(path);
763761
return path;
@@ -801,7 +799,6 @@ void ClearDatadirCache()
801799

802800
pathCached = fs::path();
803801
pathCachedNetSpecific = fs::path();
804-
g_blocks_path_cached = fs::path();
805802
g_blocks_path_cache_net_specific = fs::path();
806803
}
807804

src/util/system.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ void ReleaseDirectoryLocks();
7878

7979
bool TryCreateDirectories(const fs::path& p);
8080
fs::path GetDefaultDataDir();
81-
const fs::path &GetBlocksDir(bool fNetSpecific = true);
81+
// The blocks directory is always net specific.
82+
const fs::path &GetBlocksDir();
8283
const fs::path &GetDataDir(bool fNetSpecific = true);
8384
void ClearDatadirCache();
8485
fs::path GetConfigFile(const std::string& confPath);

0 commit comments

Comments
 (0)