Skip to content

Commit 1469952

Browse files
committed
allow for custom block index path
useful for when you have a blocks dir and you want to benchmark rebuilding the block index / chainstate with different db implementations. can specify -blocksdir=<blocks directory> -blockindexdir=<my custom index dir> and reuse the same blocksdir to test multiple chainstate / block index implementations
1 parent fc642c3 commit 1469952

6 files changed

+18
-1
lines changed

src/common/args.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ fs::path ArgsManager::GetBlocksDirPath() const
304304
return path;
305305
}
306306

307+
fs::path ArgsManager::GetIndexDir() const
308+
{
309+
LOCK(cs_args);
310+
const fs::path indexdir{GetPathArg("-blockindexdir")};
311+
if (!indexdir.empty()) {
312+
return fs::absolute(indexdir);
313+
} else {
314+
return GetDataDirNet() / "blocks" / "index";
315+
}
316+
}
307317
fs::path ArgsManager::GetDataDir(bool net_specific) const
308318
{
309319
LOCK(cs_args);

src/common/args.h

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class ArgsManager
232232
* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned
233233
*/
234234
fs::path GetDataDirNet() const { return GetDataDir(true); }
235+
fs::path GetIndexDir() const;
235236

236237
/**
237238
* Clear cached directory paths

src/init.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
461461
#endif
462462
argsman.AddArg("-assumevalid=<hex>", strprintf("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet3: %s, testnet4: %s, signet: %s)", defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnet4ChainParams->GetConsensus().defaultAssumeValid.GetHex(), signetChainParams->GetConsensus().defaultAssumeValid.GetHex()), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
463463
argsman.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
464+
argsman.AddArg("-blockindexdir=<dir>", "Specify directory to hold blocks index subdirectory (default: <datadir>/blocks/)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
464465
argsman.AddArg("-blocksxor",
465466
strprintf("Whether an XOR-key applies to blocksdir *.dat files. "
466467
"The created XOR-key will be zeros for an existing blocksdir or when `-blocksxor=0` is "
@@ -1055,6 +1056,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10551056
ChainstateManager::Options chainman_opts_dummy{
10561057
.chainparams = chainparams,
10571058
.datadir = args.GetDataDirNet(),
1059+
.indexdir = args.GetIndexDir(),
10581060
.notifications = notifications,
10591061
};
10601062
auto chainman_result{ApplyArgsManOptions(args, chainman_opts_dummy)};
@@ -1205,6 +1207,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
12051207
ChainstateManager::Options chainman_opts{
12061208
.chainparams = chainparams,
12071209
.datadir = args.GetDataDirNet(),
1210+
.indexdir = args.GetIndexDir(),
12081211
.notifications = *node.notifications,
12091212
.signals = node.validation_signals.get(),
12101213
};

src/kernel/chainstatemanager_opts.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace kernel {
3434
struct ChainstateManagerOpts {
3535
const CChainParams& chainparams;
3636
fs::path datadir;
37+
fs::path indexdir;
3738
std::optional<int32_t> check_block_index{};
3839
bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED};
3940
//! If set, it will override the minimum work we will assume exists on some valid chain.

src/node/chainstate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static ChainstateLoadResult CompleteChainstateInitialization(
4242
// fails if it's still open from the previous loop. Close it first:
4343
pblocktree.reset();
4444
pblocktree = std::make_unique<BlockTreeDB>(DBParams{
45-
.path = chainman.m_options.datadir / "blocks" / "index",
45+
.path = chainman.m_options.indexdir,
4646
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
4747
.memory_only = options.block_tree_db_in_memory,
4848
.wipe_data = options.wipe_block_tree_db,

src/test/validation_chainstatemanager_tests.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ struct SnapshotTestSetup : TestChain100Setup {
386386
const ChainstateManager::Options chainman_opts{
387387
.chainparams = ::Params(),
388388
.datadir = chainman.m_options.datadir,
389+
.indexdir = chainman.m_options.indexdir,
389390
.notifications = *m_node.notifications,
390391
.signals = m_node.validation_signals.get(),
391392
};
@@ -795,6 +796,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_args, BasicTestingSetup)
795796
static const ChainstateManager::Options options{
796797
.chainparams = ::Params(),
797798
.datadir = {},
799+
.indexdir = {},
798800
.notifications = notifications};
799801
return SetOptsFromArgs(*this->m_node.args, options, args);
800802
};

0 commit comments

Comments
 (0)