Browse Source

FatDB integrated.

cl-refactor
Gav Wood 10 years ago
parent
commit
96dda9d47f
  1. 7
      CMakeLists.txt
  2. 35
      libdevcrypto/TrieDB.h
  3. 8
      libethcore/CommonEth.cpp
  4. 28
      libethereum/State.cpp

7
CMakeLists.txt

@ -19,6 +19,7 @@ function(createDefaultCacheConfig)
set(PARANOIA OFF CACHE BOOL "Additional run-time checks") set(PARANOIA OFF CACHE BOOL "Additional run-time checks")
set(JSONRPC ON CACHE BOOL "Build with jsonprc. default on") set(JSONRPC ON CACHE BOOL "Build with jsonprc. default on")
set(EVMJIT OFF CACHE BOOL "Build a just-in-time compiler for EVM code (requires LLVM)") set(EVMJIT OFF CACHE BOOL "Build a just-in-time compiler for EVM code (requires LLVM)")
set(FATDB OFF CACHE BOOL "Build with ability to list entries in the Trie. Doubles DB size, slows everything down, but good for looking at state diffs and trie contents.")
endfunction() endfunction()
@ -44,6 +45,10 @@ function(configureProject)
add_definitions(-DETH_EVMJIT) add_definitions(-DETH_EVMJIT)
endif() endif()
if (FATDB)
add_definitions(-DETH_FATDB)
endif()
if (HEADLESS) if (HEADLESS)
add_definitions(-DETH_HEADLESS) add_definitions(-DETH_HEADLESS)
endif() endif()
@ -110,7 +115,7 @@ cmake_policy(SET CMP0015 NEW)
createDefaultCacheConfig() createDefaultCacheConfig()
configureProject() configureProject()
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
message("-- VMTRACE: ${VMTRACE}; PARANOIA: ${PARANOIA}; HEADLESS: ${HEADLESS}; JSONRPC: ${JSONRPC}; EVMJIT: ${EVMJIT}") message("-- VMTRACE: ${VMTRACE}; PARANOIA: ${PARANOIA}; HEADLESS: ${HEADLESS}; JSONRPC: ${JSONRPC}; EVMJIT: ${EVMJIT}; FATDB: ${FATDB}")
# Default TARGET_PLATFORM to "linux". # Default TARGET_PLATFORM to "linux".

35
libdevcrypto/TrieDB.h

@ -68,7 +68,7 @@ class GenericTrieDB
public: public:
using DB = _DB; using DB = _DB;
GenericTrieDB(DB* _db): m_db(_db) {} GenericTrieDB(DB* _db = nullptr): m_db(_db) {}
GenericTrieDB(DB* _db, h256 _root) { open(_db, _root); } GenericTrieDB(DB* _db, h256 _root) { open(_db, _root); }
~GenericTrieDB() {} ~GenericTrieDB() {}
@ -294,7 +294,7 @@ public:
using DB = typename Generic::DB; using DB = typename Generic::DB;
using KeyType = _KeyType; using KeyType = _KeyType;
SpecificTrieDB(DB* _db): Generic(_db) {} SpecificTrieDB(DB* _db = nullptr): Generic(_db) {}
SpecificTrieDB(DB* _db, h256 _root): Generic(_db, _root) {} SpecificTrieDB(DB* _db, h256 _root): Generic(_db, _root) {}
std::string operator[](KeyType _k) const { return at(_k); } std::string operator[](KeyType _k) const { return at(_k); }
@ -342,7 +342,7 @@ class HashedGenericTrieDB: private SpecificTrieDB<GenericTrieDB<_DB>, h256>
public: public:
using DB = _DB; using DB = _DB;
HashedGenericTrieDB(DB* _db): Super(_db) {} HashedGenericTrieDB(DB* _db = nullptr): Super(_db) {}
HashedGenericTrieDB(DB* _db, h256 _root): Super(_db, _root) {} HashedGenericTrieDB(DB* _db, h256 _root): Super(_db, _root) {}
using Super::open; using Super::open;
@ -364,11 +364,28 @@ public:
void insert(bytesConstRef _key, bytesConstRef _value) { Super::insert(sha3(_key), _value); } void insert(bytesConstRef _key, bytesConstRef _value) { Super::insert(sha3(_key), _value); }
void remove(bytesConstRef _key) { Super::remove(sha3(_key)); } void remove(bytesConstRef _key) { Super::remove(sha3(_key)); }
// empty from the PoV of the iterator interface. // empty from the PoV of the iterator interface; still need a basic iterator impl though.
using iterator = void*; class iterator
iterator begin() const { return nullptr; } {
iterator end() const { return nullptr; } public:
iterator lower_bound(bytesConstRef) const { return end(); } using value_type = std::pair<bytesConstRef, bytesConstRef>;
iterator() {}
iterator(HashedGenericTrieDB const*) {}
iterator(HashedGenericTrieDB const*, bytesConstRef) {}
iterator& operator++() { return *this; }
value_type operator*() const { return value_type(); }
value_type operator->() const { return value_type(); }
bool operator==(iterator const&) const { return true; }
bool operator!=(iterator const&) const { return false; }
value_type at() const { return value_type(); }
};
iterator begin() const { return iterator(); }
iterator end() const { return iterator(); }
iterator lower_bound(bytesConstRef) const { return iterator(); }
}; };
// Hashed & Basic // Hashed & Basic
@ -411,7 +428,7 @@ private:
template <class KeyType, class DB> using TrieDB = SpecificTrieDB<GenericTrieDB<DB>, KeyType>; template <class KeyType, class DB> using TrieDB = SpecificTrieDB<GenericTrieDB<DB>, KeyType>;
#if ETH_FAT_DB #if ETH_FATDB
template <class KeyType, class DB> using SecureTrieDB = SpecificTrieDB<FatGenericTrieDB<DB>, KeyType>; template <class KeyType, class DB> using SecureTrieDB = SpecificTrieDB<FatGenericTrieDB<DB>, KeyType>;
#else #else
template <class KeyType, class DB> using SecureTrieDB = SpecificTrieDB<HashedGenericTrieDB<DB>, KeyType>; template <class KeyType, class DB> using SecureTrieDB = SpecificTrieDB<HashedGenericTrieDB<DB>, KeyType>;

8
libethcore/CommonEth.cpp

@ -33,7 +33,13 @@ namespace eth
{ {
const unsigned c_protocolVersion = 55; const unsigned c_protocolVersion = 55;
const unsigned c_databaseVersion = 5; const unsigned c_databaseVersion = 5 +
#if ETH_FATDB
1000
#else
0
#endif
;
vector<pair<u256, string>> const& units() vector<pair<u256, string>> const& units()
{ {

28
libethereum/State.cpp

@ -179,11 +179,10 @@ StateDiff State::diff(State const& _c) const
auto trie = SecureTrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&m_db), rootHash()); auto trie = SecureTrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&m_db), rootHash());
auto trieD = SecureTrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&_c.m_db), _c.rootHash()); auto trieD = SecureTrieDB<Address, OverlayDB>(const_cast<OverlayDB*>(&_c.m_db), _c.rootHash());
// TODO: fix for (auto i: trie)
// for (auto i: trie) ads.insert(i.first), trieAds.insert(i.first);
// ads.insert(i.first), trieAds.insert(i.first); for (auto i: trieD)
// for (auto i: trieD) ads.insert(i.first), trieAdsD.insert(i.first);
// ads.insert(i.first), trieAdsD.insert(i.first);
for (auto i: m_cache) for (auto i: m_cache)
ads.insert(i.first); ads.insert(i.first);
for (auto i: _c.m_cache) for (auto i: _c.m_cache)
@ -345,10 +344,9 @@ map<Address, u256> State::addresses() const
for (auto i: m_cache) for (auto i: m_cache)
if (i.second.isAlive()) if (i.second.isAlive())
ret[i.first] = i.second.balance(); ret[i.first] = i.second.balance();
// TODO: fix. for (auto const& i: m_state)
// for (auto const& i: m_state) if (m_cache.find(i.first) == m_cache.end())
// if (m_cache.find(i.first) == m_cache.end()) ret[i.first] = RLP(i.second)[1].toInt<u256>();
// ret[i.first] = RLP(i.second)[1].toInt<u256>();
return ret; return ret;
} }
@ -941,10 +939,9 @@ map<u256, u256> State::storage(Address _id) const
// Pull out all values from trie storage. // Pull out all values from trie storage.
if (it->second.baseRoot()) if (it->second.baseRoot())
{ {
// TODO: fix SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&m_db), it->second.baseRoot()); // promise we won't alter the overlay! :)
// SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&m_db), it->second.baseRoot()); // promise we won't alter the overlay! :) for (auto const& i: memdb)
// for (auto const& i: memdb) ret[i.first] = RLP(i.second).toInt<u256>();
// ret[i.first] = RLP(i.second).toInt<u256>();
} }
// Then merge cached storage over the top. // Then merge cached storage over the top.
@ -1180,9 +1177,8 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s)
if (r) if (r)
{ {
SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&_s.m_db), r[2].toHash<h256>()); // promise we won't alter the overlay! :) SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&_s.m_db), r[2].toHash<h256>()); // promise we won't alter the overlay! :)
// TODO: fix for (auto const& j: memdb)
// for (auto const& j: memdb) mem[j.first] = RLP(j.second).toInt<u256>(), back.insert(j.first);
// mem[j.first] = RLP(j.second).toInt<u256>(), back.insert(j.first);
} }
if (cache) if (cache)
for (auto const& j: cache->storageOverlay()) for (auto const& j: cache->storageOverlay())

Loading…
Cancel
Save