Skip to content

Commit 8789b11

Browse files
committed
refactor: Add path argument to FindSnapshotChainstateDir
Remove access to the global gArgs for getting the directory in utxo_snapshot. This is done in the context of the libbitcoinkernel project, wherein reliance of libbitcoinkernel code on the global gArgs is incrementally removed.
1 parent ef95be3 commit 8789b11

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/node/utxo_snapshot.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <node/utxo_snapshot.h>
66

7-
#include <common/args.h>
87
#include <logging.h>
98
#include <streams.h>
109
#include <sync.h>
@@ -82,10 +81,10 @@ std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
8281
return base_blockhash;
8382
}
8483

85-
std::optional<fs::path> FindSnapshotChainstateDir()
84+
std::optional<fs::path> FindSnapshotChainstateDir(const fs::path& data_dir)
8685
{
8786
fs::path possible_dir =
88-
gArgs.GetDataDirNet() / fs::u8path(strprintf("chainstate%s", SNAPSHOT_CHAINSTATE_SUFFIX));
87+
data_dir / fs::u8path(strprintf("chainstate%s", SNAPSHOT_CHAINSTATE_SUFFIX));
8988

9089
if (fs::exists(possible_dir)) {
9190
return possible_dir;

src/node/utxo_snapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot";
6767

6868

6969
//! Return a path to the snapshot-based chainstate dir, if one exists.
70-
std::optional<fs::path> FindSnapshotChainstateDir();
70+
std::optional<fs::path> FindSnapshotChainstateDir(const fs::path& data_dir);
7171

7272
} // namespace node
7373

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct SnapshotTestSetup : TestChain100Setup {
184184
{
185185
LOCK(::cs_main);
186186
BOOST_CHECK(!chainman.IsSnapshotValidated());
187-
BOOST_CHECK(!node::FindSnapshotChainstateDir());
187+
BOOST_CHECK(!node::FindSnapshotChainstateDir(m_args.GetDataDirNet()));
188188
}
189189

190190
size_t initial_size;
@@ -234,7 +234,7 @@ struct SnapshotTestSetup : TestChain100Setup {
234234
auto_infile >> coin;
235235
}));
236236

237-
BOOST_CHECK(!node::FindSnapshotChainstateDir());
237+
BOOST_CHECK(!node::FindSnapshotChainstateDir(m_args.GetDataDirNet()));
238238

239239
BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(
240240
this, [](AutoFile& auto_infile, SnapshotMetadata& metadata) {
@@ -258,7 +258,7 @@ struct SnapshotTestSetup : TestChain100Setup {
258258
}));
259259

260260
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(this));
261-
BOOST_CHECK(fs::exists(*node::FindSnapshotChainstateDir()));
261+
BOOST_CHECK(fs::exists(*node::FindSnapshotChainstateDir(m_args.GetDataDirNet())));
262262

263263
// Ensure our active chain is the snapshot chainstate.
264264
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash->IsNull());
@@ -271,7 +271,7 @@ struct SnapshotTestSetup : TestChain100Setup {
271271
{
272272
LOCK(::cs_main);
273273

274-
fs::path found = *node::FindSnapshotChainstateDir();
274+
fs::path found = *node::FindSnapshotChainstateDir(m_args.GetDataDirNet());
275275

276276
// Note: WriteSnapshotBaseBlockhash() is implicitly tested above.
277277
BOOST_CHECK_EQUAL(
@@ -491,7 +491,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_init, SnapshotTestSetup)
491491

492492
this->SetupSnapshot();
493493

494-
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir();
494+
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir(m_args.GetDataDirNet());
495495
BOOST_CHECK(fs::exists(snapshot_chainstate_dir));
496496
BOOST_CHECK_EQUAL(snapshot_chainstate_dir, gArgs.GetDataDirNet() / "chainstate_snapshot");
497497

@@ -565,7 +565,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_completion, SnapshotTestSetup
565565
SnapshotCompletionResult res;
566566
auto mock_shutdown = [](bilingual_str msg) {};
567567

568-
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir();
568+
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir(m_args.GetDataDirNet());
569569
BOOST_CHECK(fs::exists(snapshot_chainstate_dir));
570570
BOOST_CHECK_EQUAL(snapshot_chainstate_dir, gArgs.GetDataDirNet() / "chainstate_snapshot");
571571

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5107,7 +5107,7 @@ bool ChainstateManager::ActivateSnapshot(
51075107

51085108
// PopulateAndValidateSnapshot can return (in error) before the leveldb datadir
51095109
// has been created, so only attempt removal if we got that far.
5110-
if (auto snapshot_datadir = node::FindSnapshotChainstateDir()) {
5110+
if (auto snapshot_datadir = node::FindSnapshotChainstateDir(m_options.datadir)) {
51115111
// We have to destruct leveldb::DB in order to release the db lock, otherwise
51125112
// DestroyDB() (in DeleteCoinsDBFromDisk()) will fail. See `leveldb::~DBImpl()`.
51135113
// Destructing the chainstate (and so resetting the coinsviews object) does this.
@@ -5597,7 +5597,7 @@ ChainstateManager::~ChainstateManager()
55975597
bool ChainstateManager::DetectSnapshotChainstate(CTxMemPool* mempool)
55985598
{
55995599
assert(!m_snapshot_chainstate);
5600-
std::optional<fs::path> path = node::FindSnapshotChainstateDir();
5600+
std::optional<fs::path> path = node::FindSnapshotChainstateDir(m_options.datadir);
56015601
if (!path) {
56025602
return false;
56035603
}

0 commit comments

Comments
 (0)