Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

evodb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Dash Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <evo/evodb.h>
6 
7 std::unique_ptr<CEvoDB> evoDb;
8 
10  evoDB(_evoDB)
11 {
12 }
13 
15 {
17  Rollback();
18 }
19 
21 {
22  assert(!didCommitOrRollback);
23  didCommitOrRollback = true;
25 }
26 
28 {
29  assert(!didCommitOrRollback);
30  didCommitOrRollback = true;
32 }
33 
34 CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) :
35  db(fMemory ? "" : (GetDataDir() / "evodb"), nCacheSize, fMemory, fWipe),
36  rootBatch(db),
37  rootDBTransaction(db, rootBatch),
38  curDBTransaction(rootDBTransaction, rootDBTransaction)
39 {
40 }
41 
43 {
44  LOCK(cs);
46 }
47 
49 {
50  LOCK(cs);
52 }
53 
55 {
56  assert(curDBTransaction.IsClean());
58  bool ret = db.WriteBatch(rootBatch);
59  rootBatch.Clear();
60  return ret;
61 }
62 
64 {
65  // Make sure evodb is consistent.
66  // If we already have best block hash saved, the previous block should match it.
67  uint256 hashBestBlock;
68  bool fHasBestBlock = Read(EVODB_BEST_BLOCK, hashBestBlock);
69  uint256 hashBlockIndex = fHasBestBlock ? hash : uint256();
70  assert(hashBestBlock == hashBlockIndex);
71 
72  return fHasBestBlock;
73 }
74 
76 {
77  Write(EVODB_BEST_BLOCK, hash);
78 }
void CommitCurTransaction()
Definition: evodb.cpp:42
void Clear()
Definition: dbwrapper.h:68
Definition: evodb.h:32
CEvoDB & evoDB
Definition: evodb.h:21
static const std::string EVODB_BEST_BLOCK
Definition: evodb.h:14
CCriticalSection cs
Definition: evodb.h:35
void Write(const K &key, const V &value)
Definition: evodb.h:69
bool Read(const K &key, V &value)
Definition: evodb.h:62
std::unique_ptr< CEvoDB > evoDb
Definition: evodb.cpp:7
CEvoDBScopedCommitter(CEvoDB &_evoDB)
Definition: evodb.cpp:9
bool IsClean()
Definition: dbwrapper.h:702
void WriteBestBlock(const uint256 &hash)
Definition: evodb.cpp:75
bool VerifyBestBlock(const uint256 &hash)
Definition: evodb.cpp:63
CEvoDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: evodb.cpp:34
void Clear()
Definition: dbwrapper.h:686
#define LOCK(cs)
Definition: sync.h:178
bool CommitRootTransaction()
Definition: evodb.cpp:54
void Commit()
Definition: dbwrapper.h:692
CDBBatch rootBatch
Definition: evodb.h:42
256-bit opaque blob.
Definition: uint256.h:123
void RollbackCurTransaction()
Definition: evodb.cpp:48
RootTransaction rootDBTransaction
Definition: evodb.h:43
bool didCommitOrRollback
Definition: evodb.h:22
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:928
bool WriteBatch(CDBBatch &batch, bool fSync=false)
Definition: dbwrapper.cpp:157
CDBWrapper db
Definition: evodb.h:37
CurTransaction curDBTransaction
Definition: evodb.h:44
Released under the MIT license