From dfd18f714b12eb9c88c09144bb945dea66254d05 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 1 Mar 2015 18:15:05 +0100 Subject: [PATCH] FatDB integrated. --- CMakeLists.txt | 8 +------- libdevcrypto/TrieDB.h | 35 ++++++++++++++++++++++++++--------- libethcore/CommonEth.cpp | 8 +++++++- libethereum/State.cpp | 28 ++++++++++++---------------- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43ee58eaa..e86ded470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,6 @@ function(createDefaultCacheConfig) 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(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.") - set(JUSTTESTS OFF CACHE BOOL "Build only for tests.") - set(SOLIDITY ON CACHE BOOL "Build the Solidity language components (requried unless HEADLESS)") endfunction() @@ -51,11 +49,7 @@ function(configureProject) add_definitions(-DETH_FATDB) endif() - if (SOLIDITY) - add_definitions(-DETH_SOLIDITY) - endif() - - if (HEADLESS OR JUSTTESTS) + if (HEADLESS) add_definitions(-DETH_HEADLESS) endif() endfunction() diff --git a/libdevcrypto/TrieDB.h b/libdevcrypto/TrieDB.h index 91a39b3cc..e00e03f44 100644 --- a/libdevcrypto/TrieDB.h +++ b/libdevcrypto/TrieDB.h @@ -68,7 +68,7 @@ class GenericTrieDB public: 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() {} @@ -294,7 +294,7 @@ public: using DB = typename Generic::DB; using KeyType = _KeyType; - SpecificTrieDB(DB* _db): Generic(_db) {} + SpecificTrieDB(DB* _db = nullptr): Generic(_db) {} SpecificTrieDB(DB* _db, h256 _root): Generic(_db, _root) {} std::string operator[](KeyType _k) const { return at(_k); } @@ -342,7 +342,7 @@ class HashedGenericTrieDB: private SpecificTrieDB, h256> public: using DB = _DB; - HashedGenericTrieDB(DB* _db): Super(_db) {} + HashedGenericTrieDB(DB* _db = nullptr): Super(_db) {} HashedGenericTrieDB(DB* _db, h256 _root): Super(_db, _root) {} using Super::open; @@ -364,11 +364,28 @@ public: void insert(bytesConstRef _key, bytesConstRef _value) { Super::insert(sha3(_key), _value); } void remove(bytesConstRef _key) { Super::remove(sha3(_key)); } - // empty from the PoV of the iterator interface. - using iterator = void*; - iterator begin() const { return nullptr; } - iterator end() const { return nullptr; } - iterator lower_bound(bytesConstRef) const { return end(); } + // empty from the PoV of the iterator interface; still need a basic iterator impl though. + class iterator + { + public: + using value_type = std::pair; + + 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 @@ -411,7 +428,7 @@ private: template using TrieDB = SpecificTrieDB, KeyType>; -#if ETH_FAT_DB +#if ETH_FATDB template using SecureTrieDB = SpecificTrieDB, KeyType>; #else template using SecureTrieDB = SpecificTrieDB, KeyType>; diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 8facdf0f1..eba10e321 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -33,7 +33,13 @@ namespace eth { const unsigned c_protocolVersion = 55; -const unsigned c_databaseVersion = 5; +const unsigned c_databaseVersion = 5 + +#if ETH_FATDB + 1000 +#else + 0 +#endif +; vector> const& units() { diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 676ad104f..a9837d118 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -179,11 +179,10 @@ StateDiff State::diff(State const& _c) const auto trie = SecureTrieDB(const_cast(&m_db), rootHash()); auto trieD = SecureTrieDB(const_cast(&_c.m_db), _c.rootHash()); - // TODO: fix -// for (auto i: trie) -// ads.insert(i.first), trieAds.insert(i.first); -// for (auto i: trieD) -// ads.insert(i.first), trieAdsD.insert(i.first); + for (auto i: trie) + ads.insert(i.first), trieAds.insert(i.first); + for (auto i: trieD) + ads.insert(i.first), trieAdsD.insert(i.first); for (auto i: m_cache) ads.insert(i.first); for (auto i: _c.m_cache) @@ -345,10 +344,9 @@ map State::addresses() const for (auto i: m_cache) if (i.second.isAlive()) ret[i.first] = i.second.balance(); - // TODO: fix. -// for (auto const& i: m_state) -// if (m_cache.find(i.first) == m_cache.end()) -// ret[i.first] = RLP(i.second)[1].toInt(); + for (auto const& i: m_state) + if (m_cache.find(i.first) == m_cache.end()) + ret[i.first] = RLP(i.second)[1].toInt(); return ret; } @@ -942,10 +940,9 @@ map State::storage(Address _id) const // Pull out all values from trie storage. if (it->second.baseRoot()) { - // TODO: fix -// SecureTrieDB memdb(const_cast(&m_db), it->second.baseRoot()); // promise we won't alter the overlay! :) -// for (auto const& i: memdb) -// ret[i.first] = RLP(i.second).toInt(); + SecureTrieDB memdb(const_cast(&m_db), it->second.baseRoot()); // promise we won't alter the overlay! :) + for (auto const& i: memdb) + ret[i.first] = RLP(i.second).toInt(); } // Then merge cached storage over the top. @@ -1181,9 +1178,8 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s) if (r) { SecureTrieDB memdb(const_cast(&_s.m_db), r[2].toHash()); // promise we won't alter the overlay! :) - // TODO: fix -// for (auto const& j: memdb) -// mem[j.first] = RLP(j.second).toInt(), back.insert(j.first); + for (auto const& j: memdb) + mem[j.first] = RLP(j.second).toInt(), back.insert(j.first); } if (cache) for (auto const& j: cache->storageOverlay())