Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

evodb.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2020 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 #ifndef DASH_EVODB_H
6 #define DASH_EVODB_H
7 
8 #include <dbwrapper.h>
9 #include <sync.h>
10 #include <uint256.h>
11 
12 // "b_b" was used in the initial version of deterministic MN storage
13 // "b_b2" was used after compact diffs were introduced
14 static const std::string EVODB_BEST_BLOCK = "b_b2";
15 
16 class CEvoDB;
17 
19 {
20 private:
22  bool didCommitOrRollback{false};
23 
24 public:
25  explicit CEvoDBScopedCommitter(CEvoDB& _evoDB);
27 
28  void Commit();
29  void Rollback();
30 };
31 
32 class CEvoDB
33 {
34 public:
36 private:
38 
41 
45 
46 public:
47  explicit CEvoDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
48 
49  std::unique_ptr<CEvoDBScopedCommitter> BeginTransaction()
50  {
51  LOCK(cs);
52  return std::make_unique<CEvoDBScopedCommitter>(*this);
53  }
54 
56  {
57  AssertLockHeld(cs); // lock must be held from outside as long as the DB transaction is used
58  return curDBTransaction;
59  }
60 
61  template <typename K, typename V>
62  bool Read(const K& key, V& value)
63  {
64  LOCK(cs);
65  return curDBTransaction.Read(key, value);
66  }
67 
68  template <typename K, typename V>
69  void Write(const K& key, const V& value)
70  {
71  LOCK(cs);
72  curDBTransaction.Write(key, value);
73  }
74 
75  template <typename K>
76  bool Exists(const K& key)
77  {
78  LOCK(cs);
79  return curDBTransaction.Exists(key);
80  }
81 
82  template <typename K>
83  void Erase(const K& key)
84  {
85  LOCK(cs);
87  }
88 
90  {
91  return db;
92  }
93 
94  size_t GetMemoryUsage()
95  {
97  }
98 
99  bool CommitRootTransaction();
100 
101  bool VerifyBestBlock(const uint256& hash);
102  void WriteBestBlock(const uint256& hash);
103 
104 private:
105  // only CEvoDBScopedCommitter is allowed to invoke these
106  friend class CEvoDBScopedCommitter;
107  void CommitCurTransaction();
108  void RollbackCurTransaction();
109 };
110 
111 extern std::unique_ptr<CEvoDB> evoDb;
112 
113 #endif //DASH_EVODB_H
void CommitCurTransaction()
Definition: evodb.cpp:42
void Erase(const K &key)
Definition: evodb.h:83
bool Exists(const K &key)
Definition: dbwrapper.h:654
bool Exists(const K &key)
Definition: evodb.h:76
Definition: evodb.h:32
CEvoDB & evoDB
Definition: evodb.h:21
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:49
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: dbwrapper.h:630
bool Read(const K &key, V &value)
Definition: evodb.h:62
CEvoDBScopedCommitter(CEvoDB &_evoDB)
Definition: evodb.cpp:9
CDBWrapper & GetRawDB()
Definition: evodb.h:89
void WriteBestBlock(const uint256 &hash)
Definition: evodb.cpp:75
bool VerifyBestBlock(const uint256 &hash)
Definition: evodb.cpp:63
CDBTransaction< CDBWrapper, CDBBatch > RootTransaction
Definition: evodb.h:39
CEvoDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: evodb.cpp:34
size_t GetMemoryUsage()
Definition: evodb.h:94
#define LOCK(cs)
Definition: sync.h:178
void Erase(const K &key)
Definition: dbwrapper.h:671
size_t GetMemoryUsage() const
Definition: dbwrapper.h:706
CurTransaction & GetCurTransaction()
Definition: evodb.h:55
CDBTransaction< RootTransaction, RootTransaction > CurTransaction
Definition: evodb.h:40
std::unique_ptr< CEvoDBScopedCommitter > BeginTransaction()
Definition: evodb.h:49
bool CommitRootTransaction()
Definition: evodb.cpp:54
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
void Write(const K &key, const V &v)
Definition: dbwrapper.h:609
bool didCommitOrRollback
Definition: evodb.h:22
std::unique_ptr< CEvoDB > evoDb
Definition: evodb.cpp:7
AssertLockHeld(g_cs_orphans)
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
CDBWrapper db
Definition: evodb.h:37
CurTransaction curDBTransaction
Definition: evodb.h:44
Released under the MIT license