From c5566d4899d75d9030901092ecf82c97e277d6c2 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Fri, 15 Jul 2022 16:37:41 -0400 Subject: [PATCH] Use CDBWrapper::Options ctor for non-test callers --- src/index/base.cpp | 12 +++++++++--- src/txdb.cpp | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/index/base.cpp b/src/index/base.cpp index 2368189da285c..a9e484660dab5 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -44,9 +44,15 @@ CBlockLocator GetLocator(interfaces::Chain& chain, const uint256& block_hash) return locator; } -BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool f_memory, bool f_wipe, bool f_obfuscate) : - CDBWrapper(path, n_cache_size, f_memory, f_wipe, f_obfuscate) -{} +BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool f_memory, bool f_wipe, bool f_obfuscate) + : CDBWrapper{{ + .db_path = path, + .cache_size = n_cache_size, + .in_memory = f_memory, + .wipe_existing = f_wipe, + .obfuscate_data = f_obfuscate, + .do_compact = gArgs.GetBoolArg("-forcecompactdb", false), + }} {} bool BaseIndex::DB::ReadBestBlock(CBlockLocator& locator) const { diff --git a/src/txdb.cpp b/src/txdb.cpp index c048c2d92ac3d..7e0ed4f43f3e7 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -70,10 +71,17 @@ struct CoinEntry { } // namespace -CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, bool fWipe) : - m_db(std::make_unique(ldb_path, nCacheSize, fMemory, fWipe, true)), - m_ldb_path(ldb_path), - m_is_memory(fMemory) { } +CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, bool fWipe) + : m_db{new CDBWrapper{{ + .db_path = ldb_path, + .cache_size = nCacheSize, + .in_memory = fMemory, + .wipe_existing = fWipe, + .obfuscate_data = true, + .do_compact = gArgs.GetBoolArg("-forcecompactdb", false), + }}}, + m_ldb_path{ldb_path}, + m_is_memory{fMemory} {} void CCoinsViewDB::ResizeCache(size_t new_cache_size) { @@ -84,7 +92,15 @@ void CCoinsViewDB::ResizeCache(size_t new_cache_size) // filesystem lock. m_db.reset(); m_db = std::make_unique( - m_ldb_path, new_cache_size, m_is_memory, /*fWipe=*/false, /*obfuscate=*/true); + CDBWrapper::Options{ + .db_path = m_ldb_path, + .cache_size = new_cache_size, + .in_memory = m_is_memory, + .wipe_existing = false, + .obfuscate_data = true, + .do_compact = gArgs.GetBoolArg("-forcecompactdb", false), + } + ); } } @@ -177,8 +193,15 @@ size_t CCoinsViewDB::EstimateSize() const return m_db->EstimateSize(DB_COIN, uint8_t(DB_COIN + 1)); } -CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(gArgs.GetDataDirNet() / "blocks" / "index", nCacheSize, fMemory, fWipe) { -} +CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) + : CDBWrapper{{ + .db_path = gArgs.GetDataDirNet() / "blocks" / "index", + .cache_size = nCacheSize, + .in_memory = fMemory, + .wipe_existing = fWipe, + .obfuscate_data = false, + .do_compact = gArgs.GetBoolArg("-forcecompactdb", false), + }} {} bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) { return Read(std::make_pair(DB_BLOCK_FILES, nFile), info);