Skip to content

Commit

Permalink
Use CDBWrapper::Options ctor for non-test callers
Browse files Browse the repository at this point in the history
  • Loading branch information
dongcarl committed Jul 20, 2022
1 parent d29f09a commit c5566d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/index/base.cpp
Expand Up @@ -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
{
Expand Down
37 changes: 30 additions & 7 deletions src/txdb.cpp
Expand Up @@ -6,6 +6,7 @@
#include <txdb.h>

#include <chain.h>
#include <dbwrapper.h>
#include <pow.h>
#include <random.h>
#include <shutdown.h>
Expand Down Expand Up @@ -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<CDBWrapper>(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)
{
Expand All @@ -84,7 +92,15 @@ void CCoinsViewDB::ResizeCache(size_t new_cache_size)
// filesystem lock.
m_db.reset();
m_db = std::make_unique<CDBWrapper>(
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),
}
);
}
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c5566d4

Please sign in to comment.