aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2019-01-16 13:28:54 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2019-01-16 13:40:27 +0100
commit64ee94356fb4b3ceda57c68d40ce192fc62c209e (patch)
tree2072f96277c29eea16936b3d4e83cc64f21f0b02
parent3ae3748ce1bd6f681896b4dbe40964310cf857fe (diff)
parente4a0c3547ed886871f8b3d51c6b4ffdb181a8b9c (diff)
downloadbitcoin-64ee94356fb4b3ceda57c68d40ce192fc62c209e.tar.xz
Merge #14409: utils and libraries: Make 'blocksdir' always net specific
e4a0c3547ed886871f8b3d51c6b4ffdb181a8b9c Improve blocksdir functional test. (Hennadii Stepanov) c3f1821ac788e522e7558e3575150433450dcb8c 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 - https://github.com/bitcoin/bitcoin/pull/12653#discussion_r174784834 by @laanwj - https://github.com/bitcoin/bitcoin/issues/14595#issuecomment-436011186 Tree-SHA512: c9957a68a4a200ebd2010823a56db7e61563afedcb7c9828e86b13f3af2990e07854b622c1f3374756f94574acb3ea32de7d2a399eef6c0623f0e11265155627
-rw-r--r--src/init.cpp2
-rw-r--r--src/util/system.cpp9
-rw-r--r--src/util/system.h3
-rwxr-xr-xtest/functional/feature_blocksdir.py2
4 files changed, 8 insertions, 8 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 679bf80047..e495a68d55 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -930,7 +930,7 @@ bool AppInitParameterInteraction()
// also see: InitParameterInteraction()
- if (!fs::is_directory(GetBlocksDir(false))) {
+ if (!fs::is_directory(GetBlocksDir())) {
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), gArgs.GetArg("-blocksdir", "").c_str()));
}
diff --git a/src/util/system.cpp b/src/util/system.cpp
index a4bf126900..7f2e9a3114 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -749,18 +749,17 @@ fs::path GetDefaultDataDir()
#endif
}
-static fs::path g_blocks_path_cached;
static fs::path g_blocks_path_cache_net_specific;
static fs::path pathCached;
static fs::path pathCachedNetSpecific;
static CCriticalSection csPathCached;
-const fs::path &GetBlocksDir(bool fNetSpecific)
+const fs::path &GetBlocksDir()
{
LOCK(csPathCached);
- fs::path &path = fNetSpecific ? g_blocks_path_cache_net_specific : g_blocks_path_cached;
+ fs::path &path = g_blocks_path_cache_net_specific;
// This can be called during exceptions by LogPrintf(), so we cache the
// value so we don't have to do memory allocations after that.
@@ -776,9 +775,8 @@ const fs::path &GetBlocksDir(bool fNetSpecific)
} else {
path = GetDataDir(false);
}
- if (fNetSpecific)
- path /= BaseParams().DataDir();
+ path /= BaseParams().DataDir();
path /= "blocks";
fs::create_directories(path);
return path;
@@ -822,7 +820,6 @@ void ClearDatadirCache()
pathCached = fs::path();
pathCachedNetSpecific = fs::path();
- g_blocks_path_cached = fs::path();
g_blocks_path_cache_net_specific = fs::path();
}
diff --git a/src/util/system.h b/src/util/system.h
index dca32cc6fc..5932e55793 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -79,7 +79,8 @@ void ReleaseDirectoryLocks();
bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir();
-const fs::path &GetBlocksDir(bool fNetSpecific = true);
+// The blocks directory is always net specific.
+const fs::path &GetBlocksDir();
const fs::path &GetDataDir(bool fNetSpecific = true);
void ClearDatadirCache();
fs::path GetConfigFile(const std::string& confPath);
diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py
index c170f510c8..3a4889bbe9 100755
--- a/test/functional/feature_blocksdir.py
+++ b/test/functional/feature_blocksdir.py
@@ -18,6 +18,8 @@ class BlocksdirTest(BitcoinTestFramework):
def run_test(self):
self.stop_node(0)
+ assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks"))
+ assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks"))
shutil.rmtree(self.nodes[0].datadir)
initialize_datadir(self.options.tmpdir, 0)
self.log.info("Starting with nonexistent blocksdir ...")