PIVX Core  5.6.99
P2P Digital Currency
evodb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 The Dash Core developers
2 // Copyright (c) 2021 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "evodb.h"
7 #include "clientversion.h"
8 #include "netaddress.h"
9 
10 std::unique_ptr<CEvoDB> evoDb;
11 
13  evoDB(_evoDB)
14 {
15 }
16 
18 {
20  Rollback();
21 }
22 
24 {
25  assert(!didCommitOrRollback);
26  didCommitOrRollback = true;
28 }
29 
31 {
32  assert(!didCommitOrRollback);
33  didCommitOrRollback = true;
35 }
36 
37 CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(fMemory ? "" : (GetDataDir() / "evodb"), nCacheSize, fMemory, fWipe, CLIENT_VERSION | ADDRV2_FORMAT),
38  rootBatch(CLIENT_VERSION | ADDRV2_FORMAT),
39  rootDBTransaction(db, rootBatch, CLIENT_VERSION | ADDRV2_FORMAT),
40  curDBTransaction(rootDBTransaction, rootDBTransaction, CLIENT_VERSION | ADDRV2_FORMAT)
41 {
42 }
43 
45 {
46  LOCK(cs);
48 }
49 
51 {
52  LOCK(cs);
54 }
55 
57 {
58  LOCK(cs);
59  assert(curDBTransaction.IsClean());
61  bool ret = db.WriteBatch(rootBatch);
62  rootBatch.Clear();
63  return ret;
64 }
65 
67 {
68  uint256 hashBestBlock;
69  return Read(EVODB_BEST_BLOCK, hashBestBlock) && hashBestBlock == hash;
70 }
71 
73 {
74  Write(EVODB_BEST_BLOCK, hash);
75 }
void Clear()
Definition: dbwrapper.h:62
void Clear()
Definition: dbwrapper.h:675
void Commit()
Definition: dbwrapper.h:682
bool IsClean()
Definition: dbwrapper.h:693
bool WriteBatch(CDBBatch &batch, bool fSync=false)
Definition: dbwrapper.cpp:94
Definition: evodb.h:32
void RollbackCurTransaction()
Definition: evodb.cpp:50
CDBWrapper db
Definition: evodb.h:37
bool VerifyBestBlock(const uint256 &hash)
Definition: evodb.cpp:66
CDBBatch rootBatch
Definition: evodb.h:42
void WriteBestBlock(const uint256 &hash)
Definition: evodb.cpp:72
CEvoDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: evodb.cpp:37
bool CommitRootTransaction()
Definition: evodb.cpp:56
void Write(const K &key, const V &value)
Definition: evodb.h:69
bool Read(const K &key, V &value)
Definition: evodb.h:62
void CommitCurTransaction()
Definition: evodb.cpp:44
CurTransaction curDBTransaction
Definition: evodb.h:44
RecursiveMutex cs
Definition: evodb.h:34
RootTransaction rootDBTransaction
Definition: evodb.h:43
CEvoDB & evoDB
Definition: evodb.h:20
CEvoDBScopedCommitter(CEvoDB &_evoDB)
Definition: evodb.cpp:12
bool didCommitOrRollback
Definition: evodb.h:21
256-bit opaque blob.
Definition: uint256.h:138
std::unique_ptr< CEvoDB > evoDb
Definition: evodb.cpp:10
@ LOCK
Definition: lockunlock.h:16
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:724