Skip to content

Commit 0352258

Browse files
committed
refactor, txdb: Use DBParams struct in CBlockTreeDB
Use DBParams struct to remove ArgsManager uses from txdb. To reduce size of this commit, this moves references to gArgs variable out of txdb.cpp to calling code in chainstate.cpp. But these moves are temporary. The gArgs references in chainstate.cpp are moved out to calling code in init.cpp in later commits. This commit does not change behavior.
1 parent c00fa1a commit 0352258

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/node/chainstate.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#include <consensus/params.h>
1111
#include <logging.h>
1212
#include <node/blockstorage.h>
13+
#include <node/database_args.h>
1314
#include <node/caches.h>
1415
#include <sync.h>
1516
#include <threadsafety.h>
1617
#include <tinyformat.h>
1718
#include <txdb.h>
1819
#include <uint256.h>
20+
#include <util/system.h>
1921
#include <util/time.h>
2022
#include <util/translation.h>
2123
#include <validation.h>
@@ -64,7 +66,12 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
6466
// new CBlockTreeDB tries to delete the existing file, which
6567
// fails if it's still open from the previous loop. Close it first:
6668
pblocktree.reset();
67-
pblocktree.reset(new CBlockTreeDB(cache_sizes.block_tree_db, options.block_tree_db_in_memory, options.reindex));
69+
pblocktree = std::make_unique<CBlockTreeDB>(DBParams{
70+
.path = gArgs.GetDataDirNet() / "blocks" / "index",
71+
.cache_bytes = static_cast<size_t>(cache_sizes.block_tree_db),
72+
.memory_only = options.block_tree_db_in_memory,
73+
.wipe_data = options.reindex,
74+
.options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()});
6875

6976
if (options.reindex) {
7077
pblocktree->WriteReindexing(true);

src/test/util/setup_common.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
184184
.check_block_index = true,
185185
};
186186
m_node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
187-
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
187+
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(DBParams{
188+
.path = m_args.GetDataDirNet() / "blocks" / "index",
189+
.cache_bytes = static_cast<size_t>(m_cache_sizes.block_tree_db),
190+
.memory_only = true});
188191

189192
constexpr int script_check_threads = 2;
190193
StartScriptCheckWorkerThreads(script_check_threads);

src/txdb.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <txdb.h>
77

88
#include <chain.h>
9-
#include <node/database_args.h>
109
#include <pow.h>
1110
#include <random.h>
1211
#include <shutdown.h>
@@ -176,14 +175,6 @@ size_t CCoinsViewDB::EstimateSize() const
176175
return m_db->EstimateSize(DB_COIN, uint8_t(DB_COIN + 1));
177176
}
178177

179-
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper{DBParams{
180-
.path = gArgs.GetDataDirNet() / "blocks" / "index",
181-
.cache_bytes = nCacheSize,
182-
.memory_only = fMemory,
183-
.wipe_data = fWipe,
184-
.options = [] { DBOptions options; node::ReadDatabaseArgs(gArgs, options); return options; }()}} {
185-
}
186-
187178
bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {
188179
return Read(std::make_pair(DB_BLOCK_FILES, nFile), info);
189180
}

src/txdb.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ class CCoinsViewDB final : public CCoinsView
8686
class CBlockTreeDB : public CDBWrapper
8787
{
8888
public:
89-
explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
90-
89+
using CDBWrapper::CDBWrapper;
9190
bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
9291
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info);
9392
bool ReadLastBlockFile(int &nFile);

0 commit comments

Comments
 (0)