Skip to content

Commit 64ee943

Browse files
committed
Merge #14409: utils and libraries: Make 'blocksdir' always net specific
e4a0c35 Improve blocksdir functional test. (Hennadii Stepanov) c3f1821 Make blockdir always net specific (Hennadii Stepanov) Pull request description: The blocks directory is net specific by definition. Also this prevents the side effect of calling `GetBlocksDir(false)` in the non-mainnet environment. Currently a new node creates an unused `blocks\` directory in the root of the data directory when `-testnet` or `-regtest` is specified. Refs: - #12653 - bitcoin/bitcoin#12653 (comment) by @laanwj - bitcoin/bitcoin#14595 (comment) Tree-SHA512: c9957a68a4a200ebd2010823a56db7e61563afedcb7c9828e86b13f3af2990e07854b622c1f3374756f94574acb3ea32de7d2a399eef6c0623f0e11265155627
2 parents 3ae3748 + e4a0c35 commit 64ee943

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/init.cpp

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

931931
// also see: InitParameterInteraction()
932932

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

src/util/system.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,18 +749,17 @@ fs::path GetDefaultDataDir()
749749
#endif
750750
}
751751

752-
static fs::path g_blocks_path_cached;
753752
static fs::path g_blocks_path_cache_net_specific;
754753
static fs::path pathCached;
755754
static fs::path pathCachedNetSpecific;
756755
static CCriticalSection csPathCached;
757756

758-
const fs::path &GetBlocksDir(bool fNetSpecific)
757+
const fs::path &GetBlocksDir()
759758
{
760759

761760
LOCK(csPathCached);
762761

763-
fs::path &path = fNetSpecific ? g_blocks_path_cache_net_specific : g_blocks_path_cached;
762+
fs::path &path = g_blocks_path_cache_net_specific;
764763

765764
// This can be called during exceptions by LogPrintf(), so we cache the
766765
// value so we don't have to do memory allocations after that.
@@ -776,9 +775,8 @@ const fs::path &GetBlocksDir(bool fNetSpecific)
776775
} else {
777776
path = GetDataDir(false);
778777
}
779-
if (fNetSpecific)
780-
path /= BaseParams().DataDir();
781778

779+
path /= BaseParams().DataDir();
782780
path /= "blocks";
783781
fs::create_directories(path);
784782
return path;
@@ -822,7 +820,6 @@ void ClearDatadirCache()
822820

823821
pathCached = fs::path();
824822
pathCachedNetSpecific = fs::path();
825-
g_blocks_path_cached = fs::path();
826823
g_blocks_path_cache_net_specific = fs::path();
827824
}
828825

src/util/system.h

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

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

test/functional/feature_blocksdir.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def set_test_params(self):
1818

1919
def run_test(self):
2020
self.stop_node(0)
21+
assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks"))
22+
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks"))
2123
shutil.rmtree(self.nodes[0].datadir)
2224
initialize_datadir(self.options.tmpdir, 0)
2325
self.log.info("Starting with nonexistent blocksdir ...")

0 commit comments

Comments
 (0)