Skip to content

Commit ccdd90e

Browse files
committed
refactor: drop unique_ptr from EvoDb wrapper
1 parent 3c85563 commit ccdd90e

File tree

7 files changed

+26
-29
lines changed

7 files changed

+26
-29
lines changed

src/dbwrapper.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ namespace leveldb {
3838
class Env;
3939
}
4040

41+
namespace util {
42+
struct DbWrapperParams
43+
{
44+
const fs::path path{""};
45+
const bool memory{false};
46+
const bool wipe{false};
47+
const size_t cache_size{1 << 20};
48+
};
49+
} // namespace util
50+
4151
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
4252
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
4353

@@ -264,6 +274,9 @@ class CDBWrapper
264274

265275
CDBWrapper(const CDBWrapper&) = delete;
266276
CDBWrapper& operator=(const CDBWrapper&) = delete;
277+
CDBWrapper(const util::DbWrapperParams& params) :CDBWrapper(params.path, params.cache_size, params.memory, params.wipe)
278+
{
279+
}
267280

268281
template <typename K>
269282
bool ReadDataStream(const K& key, CDataStream& ssValue) const
@@ -709,19 +722,4 @@ class CDBTransaction {
709722
}
710723
};
711724

712-
namespace util {
713-
struct DbWrapperParams
714-
{
715-
const fs::path path{""};
716-
const bool memory{false};
717-
const bool wipe{false};
718-
const size_t cache_size{1 << 20};
719-
};
720-
721-
static inline std::unique_ptr<CDBWrapper> MakeDbWrapper(const DbWrapperParams& params)
722-
{
723-
return std::make_unique<CDBWrapper>(params.path, params.cache_size, params.memory, params.wipe);
724-
}
725-
} // namespace util
726-
727725
#endif // BITCOIN_DBWRAPPER_H

src/evo/evodb.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ void CEvoDBScopedCommitter::Rollback()
3232
}
3333

3434
CEvoDB::CEvoDB(const util::DbWrapperParams& db_params) :
35-
db{util::MakeDbWrapper({db_params.path / "evodb", db_params.memory, db_params.wipe, /*cache_size=*/64 << 20})},
36-
rootBatch{*db},
37-
rootDBTransaction{*db, rootBatch},
35+
db{util::DbWrapperParams({db_params.path / "evodb", db_params.memory, db_params.wipe, /*cache_size=*/64 << 20})},
36+
rootBatch{db},
37+
rootDBTransaction{db, rootBatch},
3838
curDBTransaction{rootDBTransaction, rootDBTransaction}
3939
{
4040
}
@@ -58,7 +58,7 @@ bool CEvoDB::CommitRootTransaction()
5858
LOCK(cs);
5959
assert(curDBTransaction.IsClean());
6060
rootDBTransaction.Commit();
61-
bool ret = db->WriteBatch(rootBatch);
61+
bool ret = db.WriteBatch(rootBatch);
6262
rootBatch.Clear();
6363
return ret;
6464
}

src/evo/evodb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CEvoDB
4040
public:
4141
Mutex cs;
4242
private:
43-
std::unique_ptr<CDBWrapper> db;
43+
CDBWrapper db;
4444

4545
using RootTransaction = CDBTransaction<CDBWrapper, CDBBatch>;
4646
using CurTransaction = CDBTransaction<RootTransaction, RootTransaction>;
@@ -98,7 +98,7 @@ class CEvoDB
9898

9999
CDBWrapper& GetRawDB()
100100
{
101-
return *db;
101+
return db;
102102
}
103103

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

109109
bool CommitRootTransaction() EXCLUSIVE_LOCKS_REQUIRED(!cs);
110110

111-
bool IsEmpty() { return db->IsEmpty(); }
111+
bool IsEmpty() { return db.IsEmpty(); }
112112

113113
bool VerifyBestBlock(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
114114
void WriteBestBlock(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs);

src/instantsend/db.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(std::st
2727
} // anonymous namespace
2828

2929
CInstantSendDb::CInstantSendDb(const util::DbWrapperParams& db_params) :
30-
db{util::MakeDbWrapper({db_params.path / "llmq" / "isdb", db_params.memory, db_params.wipe, /*cache_size=*/32 << 20})}
30+
db{std::make_unique<CDBWrapper>(util::DbWrapperParams{db_params.path / "llmq" / "isdb", db_params.memory, db_params.wipe, /*cache_size=*/32 << 20})}
3131
{
3232
Upgrade({db_params.path / "llmq" / "isdb", db_params.memory, /*wipe=*/true, /*cache_size=*/32 << 20});
3333
}
@@ -40,8 +40,7 @@ void CInstantSendDb::Upgrade(const util::DbWrapperParams& db_params)
4040
int v{0};
4141
if (!db->Read(DB_VERSION, v) || v < CInstantSendDb::CURRENT_VERSION) {
4242
// Wipe db
43-
db.reset();
44-
db = util::MakeDbWrapper(db_params);
43+
db = std::make_unique<CDBWrapper>(db_params);
4544
CDBBatch batch(*db);
4645
batch.Write(DB_VERSION, CInstantSendDb::CURRENT_VERSION);
4746
// Sync DB changes to disk

src/llmq/dkgsessionmgr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chai
3434
CQuorumBlockProcessor& _quorumBlockProcessor, CQuorumSnapshotManager& qsnapman,
3535
const CActiveMasternodeManager* const mn_activeman,
3636
const CSporkManager& sporkman, const util::DbWrapperParams& db_params) :
37-
db{util::MakeDbWrapper({db_params.path / "llmq" / "dkgdb", db_params.memory, db_params.wipe, /*cache_size=*/1 << 20})},
37+
db{std::make_unique<CDBWrapper>(util::DbWrapperParams{db_params.path / "llmq" / "dkgdb", db_params.memory, db_params.wipe, /*cache_size=*/1 << 20})},
3838
blsWorker{_blsWorker},
3939
m_chainstate{chainstate},
4040
m_dmnman{dmnman},

src/llmq/quorums.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate,
212212
CQuorumBlockProcessor& _quorumBlockProcessor, CQuorumSnapshotManager& qsnapman,
213213
const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
214214
const CSporkManager& sporkman, const util::DbWrapperParams& db_params) :
215-
db{util::MakeDbWrapper(
216-
{db_params.path / "llmq" / "quorumdb", db_params.memory, db_params.wipe, /*cache_size=*/1 << 20})},
215+
db{std::make_unique<CDBWrapper>(util::DbWrapperParams{
216+
db_params.path / "llmq" / "quorumdb", db_params.memory, db_params.wipe, /*cache_size=*/1 << 20})},
217217
blsWorker{_blsWorker},
218218
m_chainstate{chainstate},
219219
m_dmnman{dmnman},

src/llmq/signing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace llmq
2929
{
3030
CRecoveredSigsDb::CRecoveredSigsDb(const util::DbWrapperParams& db_params) :
31-
db{util::MakeDbWrapper({db_params.path / "llmq" / "recsigdb", db_params.memory, db_params.wipe, /*cache_size=*/8 << 20})}
31+
db{std::make_unique<CDBWrapper>(util::DbWrapperParams{db_params.path / "llmq" / "recsigdb", db_params.memory, db_params.wipe, /*cache_size=*/8 << 20})}
3232
{
3333
}
3434

0 commit comments

Comments
 (0)