Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 9255326

Browse files
halfaliciouschfast
authored andcommitted
Rename MemoryDB to StateCacheDB
Update associated source references, tests and documentation.
1 parent b0121c5 commit 9255326

File tree

10 files changed

+95
-96
lines changed

10 files changed

+95
-96
lines changed

doc/database_layout.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ implemenation is in
106106
For lower-level code accessing the database itself see
107107
`OverlayDB <https://github.com/ethereum/aleth/blob/master/libdevcore/OverlayDB.h>`__
108108
and
109-
`MemoryDB <https://github.com/ethereum/aleth/blob/master/libdevcore/MemoryDB.h>`__.
109+
`StateCacheDB` <https://github.com/ethereum/aleth/blob/master/libdevcore/StateCacheB.h>`__.

libdevcore/OverlayDB.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void OverlayDB::commit()
101101

102102
bytes OverlayDB::lookupAux(h256 const& _h) const
103103
{
104-
bytes ret = MemoryDB::lookupAux(_h);
104+
bytes ret = StateCacheDB::lookupAux(_h);
105105
if (!ret.empty() || !m_db)
106106
return ret;
107107

@@ -124,7 +124,7 @@ void OverlayDB::rollback()
124124

125125
std::string OverlayDB::lookup(h256 const& _h) const
126126
{
127-
std::string ret = MemoryDB::lookup(_h);
127+
std::string ret = StateCacheDB::lookup(_h);
128128
if (!ret.empty() || !m_db)
129129
return ret;
130130

@@ -133,15 +133,15 @@ std::string OverlayDB::lookup(h256 const& _h) const
133133

134134
bool OverlayDB::exists(h256 const& _h) const
135135
{
136-
if (MemoryDB::exists(_h))
136+
if (StateCacheDB::exists(_h))
137137
return true;
138138
return m_db && m_db->exists(toSlice(_h));
139139
}
140140

141141
void OverlayDB::kill(h256 const& _h)
142142
{
143143
#if ETH_PARANOIA || 1
144-
if (!MemoryDB::kill(_h))
144+
if (!StateCacheDB::kill(_h))
145145
{
146146
if (m_db)
147147
{
@@ -158,7 +158,7 @@ void OverlayDB::kill(h256 const& _h)
158158
}
159159
}
160160
#else
161-
MemoryDB::kill(_h);
161+
StateCacheDB::kill(_h);
162162
#endif
163163
}
164164

libdevcore/OverlayDB.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#include <libdevcore/db.h>
2626
#include <libdevcore/Common.h>
2727
#include <libdevcore/Log.h>
28-
#include <libdevcore/MemoryDB.h>
28+
#include <libdevcore/StateCacheDB.h>
2929

3030
namespace dev
3131
{
3232

33-
class OverlayDB: public MemoryDB
33+
class OverlayDB: public StateCacheDB
3434
{
3535
public:
3636
explicit OverlayDB(std::unique_ptr<db::DatabaseFace> _db = nullptr)
@@ -59,7 +59,7 @@ class OverlayDB: public MemoryDB
5959
bytes lookupAux(h256 const& _h) const;
6060

6161
private:
62-
using MemoryDB::clear;
62+
using StateCacheDB::clear;
6363

6464
std::shared_ptr<db::DatabaseFace> m_db;
6565
};
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
You should have received a copy of the GNU General Public License
1515
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
/** @file MemoryDB.cpp
17+
/** @file StateCacheDB.cpp
1818
* @author Gav Wood <i@gavwood.com>
1919
* @date 2014
2020
*/
2121

22-
#include "MemoryDB.h"
22+
#include "StateCacheDB.h"
2323
#include "Common.h"
2424
#include "CommonData.h"
2525
using namespace std;
@@ -28,7 +28,7 @@ using namespace dev;
2828
namespace dev
2929
{
3030

31-
std::unordered_map<h256, std::string> MemoryDB::get() const
31+
std::unordered_map<h256, std::string> StateCacheDB::get() const
3232
{
3333
#if DEV_GUARDED_DB
3434
ReadGuard l(x_this);
@@ -40,7 +40,7 @@ std::unordered_map<h256, std::string> MemoryDB::get() const
4040
return ret;
4141
}
4242

43-
MemoryDB& MemoryDB::operator=(MemoryDB const& _c)
43+
StateCacheDB& StateCacheDB::operator=(StateCacheDB const& _c)
4444
{
4545
if (this == &_c)
4646
return *this;
@@ -53,7 +53,7 @@ MemoryDB& MemoryDB::operator=(MemoryDB const& _c)
5353
return *this;
5454
}
5555

56-
std::string MemoryDB::lookup(h256 const& _h) const
56+
std::string StateCacheDB::lookup(h256 const& _h) const
5757
{
5858
#if DEV_GUARDED_DB
5959
ReadGuard l(x_this);
@@ -69,7 +69,7 @@ std::string MemoryDB::lookup(h256 const& _h) const
6969
return std::string();
7070
}
7171

72-
bool MemoryDB::exists(h256 const& _h) const
72+
bool StateCacheDB::exists(h256 const& _h) const
7373
{
7474
#if DEV_GUARDED_DB
7575
ReadGuard l(x_this);
@@ -80,7 +80,7 @@ bool MemoryDB::exists(h256 const& _h) const
8080
return false;
8181
}
8282

83-
void MemoryDB::insert(h256 const& _h, bytesConstRef _v)
83+
void StateCacheDB::insert(h256 const& _h, bytesConstRef _v)
8484
{
8585
#if DEV_GUARDED_DB
8686
WriteGuard l(x_this);
@@ -98,7 +98,7 @@ void MemoryDB::insert(h256 const& _h, bytesConstRef _v)
9898
#endif
9999
}
100100

101-
bool MemoryDB::kill(h256 const& _h)
101+
bool StateCacheDB::kill(h256 const& _h)
102102
{
103103
#if DEV_GUARDED_DB
104104
ReadGuard l(x_this);
@@ -114,7 +114,7 @@ bool MemoryDB::kill(h256 const& _h)
114114
else
115115
{
116116
// If we get to this point, then there was probably a node in the level DB which we need to remove and which we have previously
117-
// used as part of the memory-based MemoryDB. Nothing to be worried about *as long as the node exists in the DB*.
117+
// used as part of the memory-based StateCacheDB. Nothing to be worried about *as long as the node exists in the DB*.
118118
cdebug << "NOKILL-WAS" << _h;
119119
}
120120
cdebug << "KILL" << _h << "=>" << m_main[_h].second;
@@ -127,7 +127,7 @@ bool MemoryDB::kill(h256 const& _h)
127127
return false;
128128
}
129129

130-
bytes MemoryDB::lookupAux(h256 const& _h) const
130+
bytes StateCacheDB::lookupAux(h256 const& _h) const
131131
{
132132
#if DEV_GUARDED_DB
133133
ReadGuard l(x_this);
@@ -138,23 +138,23 @@ bytes MemoryDB::lookupAux(h256 const& _h) const
138138
return bytes();
139139
}
140140

141-
void MemoryDB::removeAux(h256 const& _h)
141+
void StateCacheDB::removeAux(h256 const& _h)
142142
{
143143
#if DEV_GUARDED_DB
144144
WriteGuard l(x_this);
145145
#endif
146146
m_aux[_h].second = false;
147147
}
148148

149-
void MemoryDB::insertAux(h256 const& _h, bytesConstRef _v)
149+
void StateCacheDB::insertAux(h256 const& _h, bytesConstRef _v)
150150
{
151151
#if DEV_GUARDED_DB
152152
WriteGuard l(x_this);
153153
#endif
154154
m_aux[_h] = make_pair(_v.toBytes(), true);
155155
}
156156

157-
void MemoryDB::purge()
157+
void StateCacheDB::purge()
158158
{
159159
#if DEV_GUARDED_DB
160160
WriteGuard l(x_this);
@@ -174,7 +174,7 @@ void MemoryDB::purge()
174174
it = m_aux.erase(it);
175175
}
176176

177-
h256Hash MemoryDB::keys() const
177+
h256Hash StateCacheDB::keys() const
178178
{
179179
#if DEV_GUARDED_DB
180180
ReadGuard l(x_this);
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,31 @@
1414
You should have received a copy of the GNU General Public License
1515
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
/** @file MemoryDB.h
17+
/** @file StateCacheDB.h
1818
* @author Gav Wood <i@gavwood.com>
1919
* @date 2014
2020
*/
2121

2222
#pragma once
2323

24-
#include <unordered_map>
2524
#include "Common.h"
2625
#include "Log.h"
2726
#include "RLP.h"
2827

2928
namespace dev
3029
{
3130

32-
class MemoryDB
31+
class StateCacheDB
3332
{
3433
friend class EnforceRefs;
3534

3635
public:
37-
MemoryDB() {}
38-
MemoryDB(MemoryDB const& _c) { operator=(_c); }
36+
StateCacheDB() {}
37+
StateCacheDB(StateCacheDB const& _c) { operator=(_c); }
3938

40-
MemoryDB& operator=(MemoryDB const& _c);
39+
StateCacheDB& operator=(StateCacheDB const& _c);
4140

42-
virtual ~MemoryDB() = default;
41+
virtual ~StateCacheDB() = default;
4342

4443
void clear() { m_main.clear(); m_aux.clear(); } // WARNING !!!! didn't originally clear m_refCount!!!
4544
std::unordered_map<h256, std::string> get() const;
@@ -69,15 +68,15 @@ class MemoryDB
6968
class EnforceRefs
7069
{
7170
public:
72-
EnforceRefs(MemoryDB const& _o, bool _r): m_o(_o), m_r(_o.m_enforceRefs) { _o.m_enforceRefs = _r; }
71+
EnforceRefs(StateCacheDB const& _o, bool _r): m_o(_o), m_r(_o.m_enforceRefs) { _o.m_enforceRefs = _r; }
7372
~EnforceRefs() { m_o.m_enforceRefs = m_r; }
7473

7574
private:
76-
MemoryDB const& m_o;
75+
StateCacheDB const& m_o;
7776
bool m_r;
7877
};
7978

80-
inline std::ostream& operator<<(std::ostream& _out, MemoryDB const& _m)
79+
inline std::ostream& operator<<(std::ostream& _out, StateCacheDB const& _m)
8180
{
8281
for (auto const& i: _m.get())
8382
{

libethcore/BlockHeader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <libdevcore/Log.h>
2424
#include <libdevcore/RLP.h>
2525
#include <libdevcore/TrieDB.h>
26-
#include <libdevcore/MemoryDB.h>
26+
#include <libdevcore/StateCacheDB.h>
2727
#include <libdevcore/TrieHash.h>
2828
#include <libethcore/Common.h>
2929
#include "Exceptions.h"
@@ -237,8 +237,8 @@ void BlockHeader::verify(Strictness _s, BlockHeader const& _parent, bytesConstRe
237237
LOG(m_logger) << "Expected trie root: " << toString(expectedRoot);
238238
if (m_transactionsRoot != expectedRoot)
239239
{
240-
MemoryDB tm;
241-
GenericTrieDB<MemoryDB> transactionsTrie(&tm);
240+
StateCacheDB tm;
241+
GenericTrieDB<StateCacheDB> transactionsTrie(&tm);
242242
transactionsTrie.init();
243243

244244
vector<bytesConstRef> txs;

libethereum/ChainParams.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ void ChainParams::populateFromGenesis(bytes const& _genesisRLP, AccountMap const
187187

188188
h256 ChainParams::calculateStateRoot(bool _force) const
189189
{
190-
MemoryDB db;
191-
SecureTrieDB<Address, MemoryDB> state(&db);
190+
StateCacheDB db;
191+
SecureTrieDB<Address, StateCacheDB> state(&db);
192192
state.init();
193193
if (!stateRoot || _force)
194194
{

libethereum/State.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,4 @@ AddressHash dev::eth::commit(AccountMap const& _cache, SecureTrieDB<Address, DB>
802802

803803

804804
template AddressHash dev::eth::commit<OverlayDB>(AccountMap const& _cache, SecureTrieDB<Address, OverlayDB>& _state);
805-
template AddressHash dev::eth::commit<MemoryDB>(AccountMap const& _cache, SecureTrieDB<Address, MemoryDB>& _state);
805+
template AddressHash dev::eth::commit<StateCacheDB>(AccountMap const& _cache, SecureTrieDB<Address, StateCacheDB>& _state);

0 commit comments

Comments
 (0)