Skip to content

Commit a7bec54

Browse files
committed
refactor: move EvoDb cache size to constructor, use std::unique_ptr
To harmonize with the rest of the `CDBWrapper` instantiations needed for the next commit.
1 parent 556d0b8 commit a7bec54

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/evo/evodb.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ void CEvoDBScopedCommitter::Rollback()
3232
evoDB.RollbackCurTransaction();
3333
}
3434

35-
CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) :
36-
db{fMemory ? "" : (gArgs.GetDataDirNet() / "evodb"), nCacheSize, fMemory, fWipe},
37-
rootBatch{db},
38-
rootDBTransaction{db, rootBatch},
35+
CEvoDB::CEvoDB(bool fMemory, bool fWipe) :
36+
db{std::make_unique<CDBWrapper>(fMemory ? "" : (gArgs.GetDataDirNet() / "evodb"), 64 << 20, fMemory, fWipe)},
37+
rootBatch{*db},
38+
rootDBTransaction{*db, rootBatch},
3939
curDBTransaction{rootDBTransaction, rootDBTransaction}
4040
{
4141
}
@@ -59,7 +59,7 @@ bool CEvoDB::CommitRootTransaction()
5959
LOCK(cs);
6060
assert(curDBTransaction.IsClean());
6161
rootDBTransaction.Commit();
62-
bool ret = db.WriteBatch(rootBatch);
62+
bool ret = db->WriteBatch(rootBatch);
6363
rootBatch.Clear();
6464
return ret;
6565
}

src/evo/evodb.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CEvoDB
3636
public:
3737
Mutex cs;
3838
private:
39-
CDBWrapper db;
39+
std::unique_ptr<CDBWrapper> db;
4040

4141
using RootTransaction = CDBTransaction<CDBWrapper, CDBBatch>;
4242
using CurTransaction = CDBTransaction<RootTransaction, RootTransaction>;
@@ -49,7 +49,7 @@ class CEvoDB
4949
CEvoDB() = delete;
5050
CEvoDB(const CEvoDB&) = delete;
5151
CEvoDB& operator=(const CEvoDB&) = delete;
52-
explicit CEvoDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
52+
explicit CEvoDB(bool fMemory, bool fWipe);
5353
~CEvoDB();
5454

5555
std::unique_ptr<CEvoDBScopedCommitter> BeginTransaction() EXCLUSIVE_LOCKS_REQUIRED(!cs)
@@ -94,7 +94,7 @@ class CEvoDB
9494

9595
CDBWrapper& GetRawDB()
9696
{
97-
return db;
97+
return *db;
9898
}
9999

100100
[[nodiscard]] size_t GetMemoryUsage() const
@@ -104,7 +104,7 @@ class CEvoDB
104104

105105
bool CommitRootTransaction() EXCLUSIVE_LOCKS_REQUIRED(!cs);
106106

107-
bool IsEmpty() { return db.IsEmpty(); }
107+
bool IsEmpty() { return db->IsEmpty(); }
108108

109109
bool VerifyBestBlock(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
110110
void WriteBestBlock(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs);

src/node/chainstate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
7171

7272
LOCK(cs_main);
7373

74-
int64_t nEvoDbCache{64 * 1024 * 1024}; // TODO
7574
evodb.reset();
76-
evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
75+
evodb = std::make_unique<CEvoDB>(/*fMemory=*/false, /*fWipe=*/fReset || fReindexChainState);
7776

7877
mnhf_manager.reset();
7978
mnhf_manager = std::make_unique<CMNHFManager>(*evodb);

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
214214
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); // Deterministic randomness for tests.
215215

216216
fCheckBlockIndex = true;
217-
m_node.evodb = std::make_unique<CEvoDB>(1 << 20, true, true);
217+
m_node.evodb = std::make_unique<CEvoDB>(/*fMemory=*/true, /*fWipe=*/true);
218218
m_node.mnhf_manager = std::make_unique<CMNHFManager>(*m_node.evodb);
219219
m_node.cpoolman = std::make_unique<CCreditPoolManager>(*m_node.evodb);
220220
static bool noui_connected = false;

0 commit comments

Comments
 (0)