diff --git a/alethzero/Debugger.h b/alethzero/Debugger.h index 76ef6a0d3..38ed973df 100644 --- a/alethzero/Debugger.h +++ b/alethzero/Debugger.h @@ -45,7 +45,7 @@ struct WorldState dev::u256s stack; dev::bytes memory; dev::bigint gasCost; - std::map storage; + std::unordered_map storage; std::vector levels; }; diff --git a/alethzero/ExportState.cpp b/alethzero/ExportState.cpp index a8e47ad6a..c11132768 100644 --- a/alethzero/ExportState.cpp +++ b/alethzero/ExportState.cpp @@ -91,7 +91,7 @@ void ExportStateDialog::fillBlocks() while (i > 0 && i >= m_recentBlocks) ui->block->removeItem(i--); - h256Set blocks; + h256Hash blocks; for (QString f: filters) { if (f.startsWith("#")) @@ -153,13 +153,17 @@ void ExportStateDialog::generateJSON() auto address = Address((byte const*)hba.data(), Address::ConstructFromPointer); json << prefix << "\t\"" << toHex(address.ref()) << "\":\n\t{\n\t\t\"wei\": \"" << ethereum()->balanceAt(address, m_block) << "\",\n"; json << "\t\t\"code\": \"" << toHex(ethereum()->codeAt(address, m_block)) << "\",\n"; - std::map storage = ethereum()->storageAt(address, m_block); + std::unordered_map storage = ethereum()->storageAt(address, m_block); if (!storage.empty()) { json << "\t\t\"storage\":\n\t\t{\n"; + std::string storagePrefix; for (auto s: storage) - json << "\t\t\t\"" << toHex(s.first) << "\": \"" << toHex(s.second) << "\"" << (s.first == storage.rbegin()->first ? "" : ",") <<"\n"; - json << "\t\t}\n"; + { + json << storagePrefix << "\t\t\t\"" << toHex(s.first) << "\": \"" << toHex(s.second) << "\""; + storagePrefix = ",\n"; + } + json << "\n\t\t}\n"; } json << "\t}"; prefix = ",\n"; diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index e5504cab2..437e75576 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1092,7 +1092,7 @@ void Main::refreshBlockChain() auto const& bc = ethereum()->blockChain(); QStringList filters = ui->blockChainFilter->text().toLower().split(QRegExp("\\s+"), QString::SkipEmptyParts); - h256Set blocks; + h256Hash blocks; for (QString f: filters) if (f.size() == 64) { diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index 9e9ae687e..0d6fd7907 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -55,6 +55,7 @@ endif () if (PROFILING AND (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}") add_definitions(-DETH_PROFILING_GPERF) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lprofiler") # set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -lprofiler") diff --git a/libdevcore/Common.h b/libdevcore/Common.h index e0872b5d4..36e57c44f 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -34,10 +34,13 @@ #endif #include +#include #include #include +#include #include #include +#include #pragma warning(push) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -84,6 +87,10 @@ using StringMap = std::map; using u256Map = std::map; using HexMap = std::map; +// Hash types. +using StringHashMap = std::unordered_map; +using u256HashMap = std::unordered_map; + // String types. using strings = std::vector; @@ -215,4 +222,14 @@ inline dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b) return static_cast(max(static_cast(_a), static_cast(_b))); } +template <> struct hash +{ + size_t operator()(dev::u256 const& _a) const + { + unsigned size = _a.backend().size(); + auto limbs = _a.backend().limbs(); + return boost::hash_range(limbs, limbs + size); + } +}; + } diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index a0ea01a1b..6c1f34667 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -258,6 +258,14 @@ template std::set& operator+=(std::set& _a, U const& _b return _a; } +/// Insert the contents of a container into an unordered_st +template std::unordered_set& operator+=(std::unordered_set& _a, U const& _b) +{ + for (auto const& i: _b) + _a.insert(i); + return _a; +} + /// Concatenate the contents of a container onto a vector template std::vector& operator+=(std::vector& _a, U const& _b) { diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 2cf81cb77..5ba96b9a8 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -147,17 +147,10 @@ public: /// @returns a random valued object. static FixedHash random() { return random(s_fixedHashEngine); } - /// A generic std::hash compatible function object. struct hash { /// Make a hash of the object's data. - size_t operator()(FixedHash const& value) const - { - size_t h = 0; - for (auto i: value.m_data) - h = (h << (5 - h)) + i; - return h; - } + size_t operator()(FixedHash const& value) const; }; template inline FixedHash& shiftBloom(FixedHash const& _h) @@ -215,6 +208,23 @@ template<> inline bool FixedHash<32>::operator==(FixedHash<32> const& _other) co return (hash1[0] == hash2[0]) && (hash1[1] == hash2[1]) && (hash1[2] == hash2[2]) && (hash1[3] == hash2[3]); } +/// Fast std::hash compatible hash function object for h64. +template<> inline size_t FixedHash<8>::hash::operator()(FixedHash<8> const& value) const +{ + const uint64_t*data = (const uint64_t*)value.data(); + return (size_t)(*data); +} + +/// Fast std::hash compatible hash function object for h160. +template<> inline size_t FixedHash<20>::hash::operator()(FixedHash<20> const& value) const +{ + const uint64_t*data = (const uint64_t*)value.data(); + uint64_t hash = data[0]; + hash ^= data[1]; + hash ^= ((const uint32_t*)value.data())[4]; + return (size_t)hash; +} + /// Fast std::hash compatible hash function object for h256. template<> inline size_t FixedHash<32>::hash::operator()(FixedHash<32> const& value) const { @@ -226,6 +236,21 @@ template<> inline size_t FixedHash<32>::hash::operator()(FixedHash<32> const& va return (size_t)hash; } +/// Fast std::hash compatible hash function object for h512. +template<> inline size_t FixedHash<64>::hash::operator()(FixedHash<64> const& value) const +{ + const uint64_t*data = (const uint64_t*)value.data(); + uint64_t hash = data[0]; + hash ^= data[1]; + hash ^= data[2]; + hash ^= data[3]; + hash ^= data[4]; + hash ^= data[5]; + hash ^= data[6]; + hash ^= data[7]; + return (size_t)hash; +} + /// Stream I/O for the FixedHash class. template inline std::ostream& operator<<(std::ostream& _out, FixedHash const& _h) @@ -251,6 +276,8 @@ using h256s = std::vector; using h160s = std::vector; using h256Set = std::set; using h160Set = std::set; +using h256Hash = std::unordered_set; +using h160Hash = std::unordered_set; /// Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes. inline h160 right160(h256 const& _t) @@ -282,6 +309,9 @@ inline std::string toString(h256s const& _bs) namespace std { - /// Forward std::hash to dev::h256::hash. + /// Forward std::hash to dev::FixedHash::hash. + template<> struct hash: dev::h64::hash {}; + template<> struct hash: dev::h160::hash {}; template<> struct hash: dev::h256::hash {}; + template<> struct hash: dev::h512::hash {}; } diff --git a/libdevcore/Log.h b/libdevcore/Log.h index f42e9cbdd..20ad9fd20 100644 --- a/libdevcore/Log.h +++ b/libdevcore/Log.h @@ -164,6 +164,30 @@ public: } m_sstr << EthLime "}" EthReset; } + template void append(std::unordered_set const& _t) + { + m_sstr << EthYellow "{" EthReset; + int n = 0; + for (auto const& i: _t) + { + m_sstr << (n++ ? EthYellow ", " EthReset : ""); + append(i); + } + m_sstr << EthYellow "}" EthReset; + } + template void append(std::unordered_map const& _t) + { + m_sstr << EthLime "{" EthReset; + int n = 0; + for (auto const& i: _t) + { + m_sstr << (n++ ? EthLime ", " EthReset : ""); + append(i.first); + m_sstr << (n++ ? EthLime ": " EthReset : ""); + append(i.second); + } + m_sstr << EthLime "}" EthReset; + } template void append(std::pair const& _t) { m_sstr << EthPurple "(" EthReset; diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index ac5e2ef1e..6e46807ab 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -362,6 +362,7 @@ public: template RLPStream& appendVector(std::vector<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } template RLPStream& append(std::array<_T, S> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } template RLPStream& append(std::set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } + template RLPStream& append(std::unordered_set<_T> const& _s) { appendList(_s.size()); for (auto const& i: _s) append(i); return *this; } template RLPStream& append(std::pair const& _s) { appendList(2); append(_s.first); append(_s.second); return *this; } /// Appends a list. diff --git a/libdevcrypto/Common.h b/libdevcrypto/Common.h index 50072c1bf..b854e76a3 100644 --- a/libdevcrypto/Common.h +++ b/libdevcrypto/Common.h @@ -68,8 +68,8 @@ extern Address ZeroAddress; /// A vector of Ethereum addresses. using Addresses = h160s; -/// A set of Ethereum addresses. -using AddressSet = std::set; +/// A hash table of Ethereum addresses. +using AddressHash = std::unordered_set; /// A vector of secrets. using Secrets = h256s; diff --git a/libdevcrypto/MemoryDB.cpp b/libdevcrypto/MemoryDB.cpp index 907e6abe6..4b08db083 100644 --- a/libdevcrypto/MemoryDB.cpp +++ b/libdevcrypto/MemoryDB.cpp @@ -30,9 +30,9 @@ namespace dev const char* DBChannel::name() { return "TDB"; } const char* DBWarn::name() { return "TDB"; } -std::map MemoryDB::get() const +std::unordered_map MemoryDB::get() const { - std::map ret; + std::unordered_map ret; for (auto const& i: m_main) if (!m_enforceRefs || i.second.second > 0) ret.insert(make_pair(i.first, i.second.first)); @@ -112,9 +112,9 @@ void MemoryDB::purge() it = m_main.erase(it); } -set MemoryDB::keys() const +h256Hash MemoryDB::keys() const { - set ret; + h256Hash ret; for (auto const& i: m_main) if (i.second.second) ret.insert(i.first); diff --git a/libdevcrypto/MemoryDB.h b/libdevcrypto/MemoryDB.h index 71428ecdb..3169d8fbc 100644 --- a/libdevcrypto/MemoryDB.h +++ b/libdevcrypto/MemoryDB.h @@ -21,7 +21,7 @@ #pragma once -#include +#include #include #include #include @@ -45,7 +45,7 @@ public: MemoryDB() {} void clear() { m_main.clear(); } // WARNING !!!! didn't originally clear m_refCount!!! - std::map get() const; + std::unordered_map get() const; std::string lookup(h256 const& _h) const; bool exists(h256 const& _h) const; @@ -57,11 +57,11 @@ public: void removeAux(h256 const& _h) { m_aux[_h].second = false; } void insertAux(h256 const& _h, bytesConstRef _v) { m_aux[_h] = make_pair(_v.toBytes(), true); } - std::set keys() const; + h256Hash keys() const; protected: - std::map> m_main; - std::map> m_aux; + std::unordered_map> m_main; + std::unordered_map> m_aux; mutable bool m_enforceRefs = false; }; diff --git a/libdevcrypto/TrieDB.h b/libdevcrypto/TrieDB.h index ef628d20b..ff2bcc589 100644 --- a/libdevcrypto/TrieDB.h +++ b/libdevcrypto/TrieDB.h @@ -26,7 +26,6 @@ #include #pragma warning(pop) -#include #include #include #include @@ -105,7 +104,7 @@ public: void debugPrint() {} - void descendKey(h256 _k, std::set& _keyMask, bool _wasExt, std::ostream* _out, int _indent = 0) const + void descendKey(h256 _k, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent = 0) const { _keyMask.erase(_k); if (_k == m_root && _k == c_shaNull) // root allowed to be empty @@ -113,7 +112,7 @@ public: descendList(RLP(node(_k)), _keyMask, _wasExt, _out, _indent); // if not, it must be a list } - void descendEntry(RLP const& _r, std::set& _keyMask, bool _wasExt, std::ostream* _out, int _indent) const + void descendEntry(RLP const& _r, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent) const { if (_r.isData() && _r.size() == 32) descendKey(_r.toHash(), _keyMask, _wasExt, _out, _indent); @@ -123,7 +122,7 @@ public: BOOST_THROW_EXCEPTION(InvalidTrie()); } - void descendList(RLP const& _r, std::set& _keyMask, bool _wasExt, std::ostream* _out, int _indent) const + void descendList(RLP const& _r, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent) const { if (_r.isList() && _r.itemCount() == 2 && (!_wasExt || _out)) { @@ -144,9 +143,9 @@ public: BOOST_THROW_EXCEPTION(InvalidTrie()); } - std::set leftOvers(std::ostream* _out = nullptr) const + h256Hash leftOvers(std::ostream* _out = nullptr) const { - std::set k = m_db->keys(); + h256Hash k = m_db->keys(); descendKey(m_root, k, false, _out); return k; } @@ -431,7 +430,7 @@ public: void insert(bytesConstRef _key, bytesConstRef _value) { Super::insert(_key, _value); m_secure.insert(_key, _value); syncRoot(); } void remove(bytesConstRef _key) { Super::remove(_key); m_secure.remove(_key); syncRoot(); } - std::set leftOvers(std::ostream* = nullptr) const { return std::set{}; } + h256Hash leftOvers(std::ostream* = nullptr) const { return h256Hash{}; } bool check(bool) const { return m_secure.check(false) && Super::check(false); } private: diff --git a/libethcore/EthashAux.h b/libethcore/EthashAux.h index 0389697f5..c90ee048e 100644 --- a/libethcore/EthashAux.h +++ b/libethcore/EthashAux.h @@ -75,12 +75,12 @@ private: static EthashAux* s_this; RecursiveMutex x_this; - std::map> m_lights; - std::map> m_fulls; + std::unordered_map> m_lights; + std::unordered_map> m_fulls; FullType m_lastUsedFull; Mutex x_epochs; - std::map m_epochs; + std::unordered_map m_epochs; h256s m_seedHashes; }; diff --git a/libethereum/Account.h b/libethereum/Account.h index 2cc962baa..660dc0a4c 100644 --- a/libethereum/Account.h +++ b/libethereum/Account.h @@ -134,8 +134,8 @@ public: /// which encodes the base-state of the account's storage (upon which the storage is overlaid). h256 baseRoot() const { assert(m_storageRoot); return m_storageRoot; } - /// @returns the storage overlay as a simple map. - std::map const& storageOverlay() const { return m_storageOverlay; } + /// @returns the storage overlay as a simple hash map. + std::unordered_map const& storageOverlay() const { return m_storageOverlay; } /// Set a key/value pair in the account's storage. This actually goes into the overlay, for committing /// to the trie later. @@ -194,7 +194,7 @@ private: h256 m_codeHash = EmptySHA3; /// The map with is overlaid onto whatever storage is implied by the m_storageRoot in the trie. - std::map m_storageOverlay; + std::unordered_map m_storageOverlay; /// The associated code for this account. The SHA3 of this should be equal to m_codeHash unless m_codeHash /// equals c_contractConceptionCodeHash. diff --git a/libethereum/AccountDiff.h b/libethereum/AccountDiff.h index dd494c0a5..22107b958 100644 --- a/libethereum/AccountDiff.h +++ b/libethereum/AccountDiff.h @@ -62,7 +62,7 @@ struct AccountDiff Diff exist; ///< The account's existance; was it created/deleted or not? Diff balance; ///< The account's balance; did it alter? Diff nonce; ///< The account's nonce; did it alter? - std::map> storage; ///< The account's storage addresses; each has its own Diff. + std::unordered_map> storage; ///< The account's storage addresses; each has its own Diff. Diff code; ///< The account's code; in general this should only have changed if exist also changed. }; diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 192cff34c..607fc586c 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -961,10 +961,10 @@ vector BlockChain::withBlockBloom(LogBloom const& _b, unsigned _earlie return ret; } -h256Set BlockChain::allUnclesFrom(h256 const& _parent) const +h256Hash BlockChain::allUnclesFrom(h256 const& _parent) const { // Get all uncles cited given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + 5). - h256Set ret; + h256Hash ret; h256 p = _parent; for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent) { diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 12e1fc785..e77369534 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -72,7 +72,7 @@ struct BlockChainWarn: public LogChannel { static const char* name(); static con struct BlockChainDebug: public LogChannel { static const char* name(); static const int verbosity = 0; }; // TODO: Move all this Genesis stuff into Genesis.h/.cpp -std::map const& genesisState(); +std::unordered_map const& genesisState(); ldb::Slice toSlice(h256 const& _h, unsigned _sub = 0); @@ -206,7 +206,7 @@ public: /// Get all blocks not allowed as uncles given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + 5). /// @returns set including the header-hash of every parent (including @a _parent) up to and including generation +5 /// togther with all their quoted uncles. - h256Set allUnclesFrom(h256 const& _parent) const; + h256Hash allUnclesFrom(h256 const& _parent) const; /// Run through database and verify all blocks by reevaluating. /// Will call _progress with the progress in this operation first param done, second total. diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index d9cb0ed53..a4e44b390 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -106,15 +106,15 @@ private: bool invariants() const override; - mutable boost::shared_mutex m_lock; ///< General lock. - std::set m_drainingSet; ///< All blocks being imported. - std::set m_readySet; ///< All blocks ready for chain-import. - std::vector> m_ready; ///< List of blocks, in correct order, ready for chain-import. - std::set m_unknownSet; ///< Set of all blocks whose parents are not ready/in-chain. - std::multimap> m_unknown; ///< For blocks that have an unknown parent; we map their parent hash to the block stuff, and insert once the block appears. - std::set m_knownBad; ///< Set of blocks that we know will never be valid. - std::multimap> m_future;///< Set of blocks that are not yet valid. - Signal m_onReady; ///< Called when a subsequent call to import blocks will return a non-empty container. Be nice and exit fast. + mutable boost::shared_mutex m_lock; ///< General lock. + h256Hash m_drainingSet; ///< All blocks being imported. + h256Hash m_readySet; ///< All blocks ready for chain-import. + std::vector> m_ready; ///< List of blocks, in correct order, ready for chain-import. + h256Hash m_unknownSet; ///< Set of all blocks whose parents are not ready/in-chain. + std::unordered_multimap> m_unknown; ///< For blocks that have an unknown parent; we map their parent hash to the block stuff, and insert once the block appears. + h256Hash m_knownBad; ///< Set of blocks that we know will never be valid. + std::multimap> m_future; ///< Set of blocks that are not yet valid. Ordered by timestamp + Signal m_onReady; ///< Called when a subsequent call to import blocks will return a non-empty container. Be nice and exit fast. }; } diff --git a/libethereum/CachedAddressState.cpp b/libethereum/CachedAddressState.cpp index e2fadc8b5..a25017793 100644 --- a/libethereum/CachedAddressState.cpp +++ b/libethereum/CachedAddressState.cpp @@ -51,9 +51,9 @@ bytes CachedAddressState::code() const return h == EmptySHA3 ? bytes() : asBytes(m_o->lookup(h)); } -std::map CachedAddressState::storage() const +std::unordered_map CachedAddressState::storage() const { - std::map ret; + std::unordered_map ret; if (m_r) { SecureTrieDB memdb(const_cast(m_o), m_r[2].toHash()); // promise we won't alter the overlay! :) diff --git a/libethereum/CachedAddressState.h b/libethereum/CachedAddressState.h index 8a3c3a607..2a34c1b34 100644 --- a/libethereum/CachedAddressState.h +++ b/libethereum/CachedAddressState.h @@ -47,7 +47,7 @@ public: bytes code() const; // TODO: DEPRECATE. - std::map storage() const; + std::unordered_map storage() const; AccountDiff diff(CachedAddressState const& _c); diff --git a/libethereum/CanonBlockChain.cpp b/libethereum/CanonBlockChain.cpp index 2cc1d24dc..f1de7292b 100644 --- a/libethereum/CanonBlockChain.cpp +++ b/libethereum/CanonBlockChain.cpp @@ -41,9 +41,9 @@ namespace js = json_spirit; #define ETH_CATCH 1 -std::map const& dev::eth::genesisState() +std::unordered_map const& dev::eth::genesisState() { - static std::map s_ret; + static std::unordered_map s_ret; if (s_ret.empty()) { diff --git a/libethereum/CanonBlockChain.h b/libethereum/CanonBlockChain.h index 619af87eb..df4ac2d88 100644 --- a/libethereum/CanonBlockChain.h +++ b/libethereum/CanonBlockChain.h @@ -45,7 +45,7 @@ namespace eth { // TODO: Move all this Genesis stuff into Genesis.h/.cpp -std::map const& genesisState(); +std::unordered_map const& genesisState(); /** * @brief Implements the blockchain database. All data this gives is disk-backed. diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 01426527f..a43c98aa2 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -308,7 +308,7 @@ void Client::killChain() void Client::clearPending() { - h256Set changeds; + h256Hash changeds; DEV_WRITE_GUARDED(x_postMine) { if (!m_postMine.pending().size()) @@ -345,7 +345,7 @@ static S& filtersStreamOut(S& _out, T const& _fs) return _out; } -void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _transactionHash) +void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed, h256 _transactionHash) { Guard l(x_filtersWatches); for (pair& i: m_filters) @@ -363,7 +363,7 @@ void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& i } } -void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed) +void Client::appendFromNewBlock(h256 const& _block, h256Hash& io_changed) { // TODO: more precise check on whether the txs match. auto d = m_bc.info(_block); @@ -496,7 +496,7 @@ void Client::syncTransactionQueue() // returns TransactionReceipts, once for each transaction. cwork << "postSTATE <== TQ"; - h256Set changeds; + h256Hash changeds; TransactionReceipts newPendingReceipts; DEV_TIMED(working) DEV_WRITE_GUARDED(x_working) @@ -552,7 +552,7 @@ void Client::onChainChanged(ImportRoute const& _ir) if (auto h = m_host.lock()) h->noteNewBlocks(); - h256Set changeds; + h256Hash changeds; for (auto const& h: _ir.first) appendFromNewBlock(h, changeds); changeds.insert(ChainChangedFilter); @@ -631,7 +631,7 @@ void Client::startMining() onPostStateChanged(); } -void Client::noteChanged(h256Set const& _filters) +void Client::noteChanged(h256Hash const& _filters) { Guard l(x_filtersWatches); if (_filters.size()) diff --git a/libethereum/Client.h b/libethereum/Client.h index 946825828..e40356f86 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -228,15 +228,15 @@ protected: /// Collate the changed filters for the bloom filter of the given pending transaction. /// Insert any filters that are activated into @a o_changed. - void appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _sha3); + void appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed, h256 _sha3); /// Collate the changed filters for the hash of the given block. /// Insert any filters that are activated into @a o_changed. - void appendFromNewBlock(h256 const& _blockHash, h256Set& io_changed); + void appendFromNewBlock(h256 const& _blockHash, h256Hash& io_changed); /// Record that the set of filters @a _filters have changed. /// This doesn't actually make any callbacks, but incrememnts some counters in m_watches. - void noteChanged(h256Set const& _filters); + void noteChanged(h256Hash const& _filters); private: /// Called when Worker is starting. diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 136239cf3..8b3cd416f 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -147,7 +147,7 @@ h256 ClientBase::codeHashAt(Address _a, BlockNumber _block) const return asOf(_block).codeHash(_a); } -map ClientBase::storageAt(Address _a, BlockNumber _block) const +unordered_map ClientBase::storageAt(Address _a, BlockNumber _block) const { return asOf(_block).storage(_a); } diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index fc0b301ad..87888affe 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -100,7 +100,7 @@ public: virtual u256 stateAt(Address _a, u256 _l, BlockNumber _block) const override; virtual bytes codeAt(Address _a, BlockNumber _block) const override; virtual h256 codeHashAt(Address _a, BlockNumber _block) const override; - virtual std::map storageAt(Address _a, BlockNumber _block) const override; + virtual std::unordered_map storageAt(Address _a, BlockNumber _block) const override; virtual LocalisedLogEntries logs(unsigned _watchId) const override; virtual LocalisedLogEntries logs(LogFilter const& _filter) const override; @@ -172,9 +172,9 @@ protected: TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain. // filters - mutable Mutex x_filtersWatches; ///< Our lock. - std::map m_filters; ///< The dictionary of filters that are active. - std::map m_watches; ///< Each and every watch - these reference a filter. + mutable Mutex x_filtersWatches; ///< Our lock. + std::unordered_map m_filters; ///< The dictionary of filters that are active. + std::map m_watches; ///< Each and every watch - these reference a filter. }; }} diff --git a/libethereum/DownloadMan.cpp b/libethereum/DownloadMan.cpp index 1b73dca5b..05d0a533e 100644 --- a/libethereum/DownloadMan.cpp +++ b/libethereum/DownloadMan.cpp @@ -39,7 +39,7 @@ DownloadSub::~DownloadSub() } } -h256Set DownloadSub::nextFetch(unsigned _n) +h256Hash DownloadSub::nextFetch(unsigned _n) { Guard l(m_fetch); @@ -51,7 +51,7 @@ h256Set DownloadSub::nextFetch(unsigned _n) m_remaining.clear(); if (!m_man || m_man->chainEmpty()) - return h256Set(); + return h256Hash(); m_asked = (~(m_man->taken() + m_attempted)).lowest(_n); if (m_asked.empty()) diff --git a/libethereum/DownloadMan.h b/libethereum/DownloadMan.h index 82e0f09e2..2b41e660b 100644 --- a/libethereum/DownloadMan.h +++ b/libethereum/DownloadMan.h @@ -21,9 +21,9 @@ #pragma once -#include #include -#include +#include +#include #include #include #include @@ -46,7 +46,7 @@ public: ~DownloadSub(); /// Finished last fetch - grab the next bunch of block hashes to download. - h256Set nextFetch(unsigned _n); + h256Hash nextFetch(unsigned _n); /// Note that we've received a particular block. @returns true if we had asked for it but haven't received it yet. bool noteBlock(h256 _hash); @@ -71,8 +71,8 @@ private: DownloadMan* m_man = nullptr; mutable Mutex m_fetch; - h256Set m_remaining; - std::map m_indices; + h256Hash m_remaining; + std::unordered_map m_indices; RangeMask m_asked; RangeMask m_attempted; }; @@ -155,7 +155,7 @@ private: RangeMask m_blocksGot; mutable SharedMutex x_subs; - std::set m_subs; + std::unordered_set m_subs; }; } diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 299984a16..72ee1854d 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -21,7 +21,6 @@ #include "EthereumHost.h" -#include #include #include #include @@ -184,7 +183,7 @@ void EthereumHost::doWork() void EthereumHost::maintainTransactions() { // Send any new transactions. - map, h256s> peerTransactions; + unordered_map, h256s> peerTransactions; auto ts = m_tq.transactions(); for (auto const& i: ts) { diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index baa850b5c..d53c3cc79 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -22,9 +22,9 @@ #pragma once #include -#include +#include #include -#include +#include #include #include #include @@ -97,7 +97,7 @@ private: /// Get a bunch of needed blocks. /// Removes them from our list of needed blocks. /// @returns empty if there's no more blocks left to fetch, otherwise the blocks to fetch. - h256Set neededBlocks(h256Set const& _exclude); + h256Hash neededBlocks(h256Hash const& _exclude); /// Check to see if the network peer-state initialisation has happened. bool isInitialised() const { return (bool)m_latestBlockSent; } @@ -121,9 +121,9 @@ private: DownloadMan m_man; h256 m_latestBlockSent; - h256Set m_transactionsSent; + h256Hash m_transactionsSent; - std::set m_banned; + std::unordered_set m_banned; bool m_newTransactions = false; bool m_newBlocks = false; diff --git a/libethereum/EthereumPeer.h b/libethereum/EthereumPeer.h index 75ebab02f..54f7ad829 100644 --- a/libethereum/EthereumPeer.h +++ b/libethereum/EthereumPeer.h @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -140,9 +139,9 @@ private: bool m_requireTransactions = false; Mutex x_knownBlocks; - h256Set m_knownBlocks; ///< Blocks that the peer already knows about (that don't need to be sent to them). + h256Hash m_knownBlocks; ///< Blocks that the peer already knows about (that don't need to be sent to them). Mutex x_knownTransactions; - h256Set m_knownTransactions; ///< Transactions that the peer already knows of. + h256Hash m_knownTransactions; ///< Transactions that the peer already knows of. }; diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index 8807bcd58..1a2d180dd 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -91,8 +91,8 @@ public: State& state() const { return m_s; } private: - State& m_s; ///< A reference to the base state. - std::map m_origCache; ///< The cache of the address states (i.e. the externalities) as-was prior to the execution. + State& m_s; ///< A reference to the base state. + std::unordered_map m_origCache; ///< The cache of the address states (i.e. the externalities) as-was prior to the execution. }; } diff --git a/libethereum/Interface.h b/libethereum/Interface.h index ba68e976e..f36d0f2c1 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -100,14 +100,14 @@ public: u256 stateAt(Address _a, u256 _l) const { return stateAt(_a, _l, m_default); } bytes codeAt(Address _a) const { return codeAt(_a, m_default); } h256 codeHashAt(Address _a) const { return codeHashAt(_a, m_default); } - std::map storageAt(Address _a) const { return storageAt(_a, m_default); } + std::unordered_map storageAt(Address _a) const { return storageAt(_a, m_default); } virtual u256 balanceAt(Address _a, BlockNumber _block) const = 0; virtual u256 countAt(Address _a, BlockNumber _block) const = 0; virtual u256 stateAt(Address _a, u256 _l, BlockNumber _block) const = 0; virtual bytes codeAt(Address _a, BlockNumber _block) const = 0; virtual h256 codeHashAt(Address _a, BlockNumber _block) const = 0; - virtual std::map storageAt(Address _a, BlockNumber _block) const = 0; + virtual std::unordered_map storageAt(Address _a, BlockNumber _block) const = 0; // [LOGS API] diff --git a/libethereum/LogFilter.h b/libethereum/LogFilter.h index 304fab317..97ff5a3b1 100644 --- a/libethereum/LogFilter.h +++ b/libethereum/LogFilter.h @@ -67,8 +67,8 @@ public: friend std::ostream& dev::eth::operator<<(std::ostream& _out, dev::eth::LogFilter const& _s); private: - AddressSet m_addresses; - std::array m_topics; + AddressHash m_addresses; + std::array m_topics; unsigned m_earliest = 0; unsigned m_latest = LatestBlock; }; diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 0fd5cb45b..cdcb4a46a 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -81,7 +81,7 @@ static bytes identityCode(bytesConstRef _in) return _in.toBytes(); } -static const std::map c_precompiled = +static const std::unordered_map c_precompiled = { { 1, { [](bytesConstRef) -> bigint { return c_ecrecoverGas; }, ecrecoverCode }}, { 2, { [](bytesConstRef i) -> bigint { return c_sha256Gas + (i.size() + 31) / 32 * c_sha256WordGas; }, sha256Code }}, @@ -89,7 +89,7 @@ static const std::map c_precompiled = { 4, { [](bytesConstRef i) -> bigint { return c_identityGas + (i.size() + 31) / 32 * c_identityWordGas; }, identityCode }} }; -std::map const& dev::eth::precompiled() +std::unordered_map const& dev::eth::precompiled() { return c_precompiled; } diff --git a/libethereum/Precompiled.h b/libethereum/Precompiled.h index c65cd9a63..bded27386 100644 --- a/libethereum/Precompiled.h +++ b/libethereum/Precompiled.h @@ -21,7 +21,7 @@ #pragma once -#include +#include #include #include @@ -38,7 +38,7 @@ struct PrecompiledAddress }; /// Info on precompiled contract accounts baked into the protocol. -std::map const& precompiled(); +std::unordered_map const& precompiled(); } } diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 83a78e1e8..9156820b9 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -208,9 +208,9 @@ StateDiff State::diff(State const& _c) const { StateDiff ret; - std::set
ads; - std::set
trieAds; - std::set
trieAdsD; + std::unordered_set
ads; + std::unordered_set
trieAds; + std::unordered_set
trieAdsD; auto trie = SecureTrieDB(const_cast(&m_db), rootHash()); auto trieD = SecureTrieDB(const_cast(&_c.m_db), _c.rootHash()); @@ -246,7 +246,7 @@ void State::ensureCached(Address _a, bool _requireCode, bool _forceCreate) const ensureCached(m_cache, _a, _requireCode, _forceCreate); } -void State::ensureCached(std::map& _cache, Address _a, bool _requireCode, bool _forceCreate) const +void State::ensureCached(std::unordered_map& _cache, Address _a, bool _requireCode, bool _forceCreate) const { auto it = _cache.find(_a); if (it == _cache.end()) @@ -426,10 +426,10 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const return ret; } -map State::addresses() const +unordered_map State::addresses() const { #if ETH_FATDB - map ret; + unordered_map ret; for (auto i: m_cache) if (i.second.isAlive()) ret[i.first] = i.second.balance(); @@ -649,9 +649,9 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement if (rlp[2].itemCount() > 2) BOOST_THROW_EXCEPTION(TooManyUncles()); - set nonces = { m_currentBlock.nonce }; + unordered_set nonces = { m_currentBlock.nonce }; vector rewarded; - set knownUncles = _bc.allUnclesFrom(m_currentBlock.parentHash); + h256Hash knownUncles = _bc.allUnclesFrom(m_currentBlock.parentHash); for (auto const& i: rlp[2]) { @@ -805,7 +805,7 @@ void State::commitToMine(BlockChain const& _bc) { // Find great-uncles (or second-cousins or whatever they are) - children of great-grandparents, great-great-grandparents... that were not already uncles in previous generations. // cout << "Checking " << m_previousBlock.hash << ", parent=" << m_previousBlock.parentHash << endl; - set knownUncles = _bc.allUnclesFrom(m_currentBlock.parentHash); + h256Hash knownUncles = _bc.allUnclesFrom(m_currentBlock.parentHash); auto p = m_previousBlock.parentHash; for (unsigned gen = 0; gen < 6 && p != _bc.genesisHash() && unclesCount < 2; ++gen, p = _bc.details(p).parent) { @@ -1016,9 +1016,9 @@ u256 State::storage(Address _id, u256 _memory) const return ret; } -map State::storage(Address _id) const +unordered_map State::storage(Address _id) const { - map ret; + unordered_map ret; ensureCached(_id, false, false); auto it = m_cache.find(_id); diff --git a/libethereum/State.h b/libethereum/State.h index e3468c24c..74d75685c 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -22,7 +22,6 @@ #pragma once #include -#include #include #include #include @@ -142,7 +141,7 @@ public: /// @returns the set containing all addresses currently in use in Ethereum. /// @throws InterfaceNotSupported if compiled without ETH_FATDB. - std::map addresses() const; + std::unordered_map addresses() const; /// Get the header information on the present block. BlockInfo const& info() const { return m_currentBlock; } @@ -238,8 +237,8 @@ public: /// Get the storage of an account. /// @note This is expensive. Don't use it unless you need to. - /// @returns std::map if no account exists at that address. - std::map storage(Address _contract) const; + /// @returns std::unordered_map if no account exists at that address. + std::unordered_map storage(Address _contract) const; /// Get the code of an account. /// @returns bytes() if no account exists at that address. @@ -263,7 +262,7 @@ public: Transactions const& pending() const { return m_transactions; } /// Get the list of hashes of pending transactions. - h256Set const& pendingHashes() const { return m_transactionSet; } + h256Hash const& pendingHashes() const { return m_transactionSet; } /// Get the transaction receipt for the transaction of the given index. TransactionReceipt const& receipt(unsigned _i) const { return m_receipts[_i]; } @@ -334,7 +333,7 @@ private: void ensureCached(Address _a, bool _requireCode, bool _forceCreate) const; /// Retrieve all information about a given address into a cache. - void ensureCached(std::map& _cache, Address _a, bool _requireCode, bool _forceCreate) const; + void ensureCached(std::unordered_map& _cache, Address _a, bool _requireCode, bool _forceCreate) const; /// Execute the given block, assuming it corresponds to m_currentBlock. /// Throws on failure. @@ -355,10 +354,10 @@ private: SecureTrieDB m_state; ///< Our state tree, as an OverlayDB DB. Transactions m_transactions; ///< The current list of transactions that we've included in the state. TransactionReceipts m_receipts; ///< The corresponding list of transaction receipts. - std::set m_transactionSet; ///< The set of transaction hashes that we've included in the state. + h256Hash m_transactionSet; ///< The set of transaction hashes that we've included in the state. OverlayDB m_lastTx; - mutable std::map m_cache; ///< Our address cache. This stores the states of each address that has (or at least might have) been changed. + mutable std::unordered_map m_cache; ///< Our address cache. This stores the states of each address that has (or at least might have) been changed. BlockInfo m_previousBlock; ///< The previous block's information. BlockInfo m_currentBlock; ///< The current block's information. @@ -380,7 +379,7 @@ private: std::ostream& operator<<(std::ostream& _out, State const& _s); template -void commit(std::map const& _cache, DB& _db, SecureTrieDB& _state) +void commit(std::unordered_map const& _cache, DB& _db, SecureTrieDB& _state) { for (auto const& i: _cache) if (i.second.isDirty()) diff --git a/libethereum/TransactionQueue.h b/libethereum/TransactionQueue.h index 69e1c935f..50fcea574 100644 --- a/libethereum/TransactionQueue.h +++ b/libethereum/TransactionQueue.h @@ -55,7 +55,7 @@ public: void drop(h256 const& _txHash); - std::map transactions() const { ReadGuard l(m_lock); return m_current; } + std::unordered_map transactions() const { ReadGuard l(m_lock); return m_current; } std::pair items() const { ReadGuard l(m_lock); return std::make_pair(m_current.size(), m_unknown.size()); } u256 maxNonce(Address const& _a) const; @@ -72,14 +72,14 @@ private: void insertCurrent_WITH_LOCK(std::pair const& _p); bool removeCurrent_WITH_LOCK(h256 const& _txHash); - mutable SharedMutex m_lock; ///< General lock. - std::set m_known; ///< Hashes of transactions in both sets. - std::map m_current; ///< Map of SHA3(tx) to tx. - std::multimap> m_unknown; ///< For transactions that have a future nonce; we map their sender address to the tx stuff, and insert once the sender has a valid TX. - std::map> m_callbacks; ///< Called once. - std::set m_dropped; ///< Transactions that have previously been dropped. - std::multimap m_senders; ///< Mapping from the sender address to the transaction hash; useful for determining the nonce of a given sender. - Signal m_onReady; ///< Called when a subsequent call to import transactions will return a non-empty container. Be nice and exit fast. + mutable SharedMutex m_lock; ///< General lock. + h256Hash m_known; ///< Hashes of transactions in both sets. + std::unordered_map m_current; ///< Map of SHA3(tx) to tx. + std::unordered_multimap> m_unknown; ///< For transactions that have a future nonce; we map their sender address to the tx stuff, and insert once the sender has a valid TX. + std::unordered_map> m_callbacks; ///< Called once. + h256Hash m_dropped; ///< Transactions that have previously been dropped. + std::multimap m_senders; ///< Mapping from the sender address to the transaction hash; useful for determining the nonce of a given sender. + Signal m_onReady; ///< Called when a subsequent call to import transactions will return a non-empty container. Be nice and exit fast. }; } diff --git a/libethereum/TransactionReceipt.h b/libethereum/TransactionReceipt.h index 1e0663054..0a0b154f4 100644 --- a/libethereum/TransactionReceipt.h +++ b/libethereum/TransactionReceipt.h @@ -22,7 +22,6 @@ #pragma once #include -#include #include #include #include diff --git a/libp2p/Common.h b/libp2p/Common.h index 378064e7d..96b8b9683 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -203,3 +203,26 @@ struct Node /// Simple stream output for a NodeIPEndpoint. std::ostream& operator<<(std::ostream& _out, dev::p2p::NodeIPEndpoint const& _ep); } + +/// std::hash for asio::adress +namespace std +{ + +template <> struct hash +{ + size_t operator()(bi::address const& _a) const + { + if (_a.is_v4()) + return _a.to_v4().to_ulong(); + if (_a.is_v6()) + { + auto const& range = _a.to_v6().to_bytes(); + return boost::hash_range(range.begin(), range.end()); + } + if (_a.is_unspecified()) + return static_cast(0x3487194039229152ul); // Some random value + return std::hash()(_a.to_string()); + } +}; + +} diff --git a/libp2p/Host.h b/libp2p/Host.h index 41f4d1e72..b9af0e8b0 100644 --- a/libp2p/Host.h +++ b/libp2p/Host.h @@ -227,7 +227,7 @@ private: std::shared_ptr m_nodeTable; ///< Node table (uses kademlia-like discovery). /// Shared storage of Peer objects. Peers are created or destroyed on demand by the Host. Active sessions maintain a shared_ptr to a Peer; - std::map> m_peers; + std::unordered_map> m_peers; /// Peers we try to connect regardless of p2p network. std::set m_requiredPeers; @@ -235,7 +235,7 @@ private: /// The nodes to which we are currently connected. Used by host to service peer requests and keepAlivePeers and for shutdown. (see run()) /// Mutable because we flush zombie entries (null-weakptrs) as regular maintenance from a const method. - mutable std::map> m_sessions; + mutable std::unordered_map> m_sessions; mutable RecursiveMutex x_sessions; std::list> m_connecting; ///< Pending connections. diff --git a/libp2p/Network.cpp b/libp2p/Network.cpp index 847e6a42d..d8ab90a20 100644 --- a/libp2p/Network.cpp +++ b/libp2p/Network.cpp @@ -154,12 +154,12 @@ int Network::tcp4Listen(bi::tcp::acceptor& _acceptor, NetworkPreferences const& _acceptor.bind(endpoint); _acceptor.listen(); retport = _acceptor.local_endpoint().port(); + assert(retport == _netPrefs.listenPort); } catch (...) { clog(NetWarn) << "Couldn't start accepting connections on host. Failed to accept socket.\n" << boost::current_exception_diagnostic_information(); } - assert(retport == _netPrefs.listenPort); return retport; } return retport; diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 42f1cad02..7a68cae10 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -232,7 +232,7 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) unsigned head = distance(m_node.id, _target); unsigned tail = head == 0 ? lastBin : (head - 1) % s_bins; - map>> found; + unordered_multimap> found; unsigned count = 0; // if d is 0, then we roll look forward, if last, we reverse, else, spread from d @@ -244,7 +244,7 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) if (auto p = n.lock()) { if (count < s_bucketSize) - found[distance(_target, p->id)].push_back(p); + found.insert(make_pair(distance(_target, p->id), p)); else break; } @@ -254,7 +254,7 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) if (auto p = n.lock()) { if (count < s_bucketSize) - found[distance(_target, p->id)].push_back(p); + found.insert(make_pair(distance(_target, p->id), p)); else break; } @@ -271,7 +271,7 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) if (auto p = n.lock()) { if (count < s_bucketSize) - found[distance(_target, p->id)].push_back(p); + found.insert(make_pair(distance(_target, p->id), p)); else break; } @@ -285,7 +285,7 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) if (auto p = n.lock()) { if (count < s_bucketSize) - found[distance(_target, p->id)].push_back(p); + found.insert(make_pair(distance(_target, p->id), p)); else break; } @@ -293,10 +293,9 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) } vector> ret; - for (auto& nodes: found) - for (auto n: nodes.second) - if (n->endpoint.isAllowed()) - ret.push_back(n); + for (auto n: found) + if (n.second->endpoint.isAllowed()) + ret.push_back(n.second); return move(ret); } diff --git a/libp2p/NodeTable.h b/libp2p/NodeTable.h index 95028db2b..f09e27857 100644 --- a/libp2p/NodeTable.h +++ b/libp2p/NodeTable.h @@ -80,7 +80,7 @@ protected: Mutex x_events; std::list m_nodeEventHandler; - std::map m_events; + std::unordered_map m_events; }; class NodeTable; @@ -254,32 +254,32 @@ private: /// Purges and pings nodes for any buckets which haven't been touched for c_bucketRefresh seconds. void doRefreshBuckets(boost::system::error_code const& _ec); - std::unique_ptr m_nodeEventHandler; ///< Event handler for node events. + std::unique_ptr m_nodeEventHandler; ///< Event handler for node events. - Node m_node; ///< This node. - Secret m_secret; ///< This nodes secret key. + Node m_node; ///< This node. + Secret m_secret; ///< This nodes secret key. - mutable Mutex x_nodes; ///< LOCK x_state first if both locks are required. Mutable for thread-safe copy in nodes() const. - std::map> m_nodes; ///< Nodes + mutable Mutex x_nodes; ///< LOCK x_state first if both locks are required. Mutable for thread-safe copy in nodes() const. + std::unordered_map> m_nodes; ///< Nodes - mutable Mutex x_state; ///< LOCK x_state first if both x_nodes and x_state locks are required. - std::array m_state; ///< State of p2p node network. + mutable Mutex x_state; ///< LOCK x_state first if both x_nodes and x_state locks are required. + std::array m_state; ///< State of p2p node network. - Mutex x_evictions; ///< LOCK x_nodes first if both x_nodes and x_evictions locks are required. - std::deque m_evictions; ///< Eviction timeouts. + Mutex x_evictions; ///< LOCK x_nodes first if both x_nodes and x_evictions locks are required. + std::deque m_evictions; ///< Eviction timeouts. - Mutex x_pubkDiscoverPings; ///< LOCK x_nodes first if both x_nodes and x_pubkDiscoverPings locks are required. - std::map m_pubkDiscoverPings; ///< List of pending pings where node entry wasn't created due to unkown pubk. + Mutex x_pubkDiscoverPings; ///< LOCK x_nodes first if both x_nodes and x_pubkDiscoverPings locks are required. + std::unordered_map m_pubkDiscoverPings; ///< List of pending pings where node entry wasn't created due to unkown pubk. Mutex x_findNodeTimeout; - std::list m_findNodeTimeout; ///< Timeouts for pending Ping and FindNode requests. + std::list m_findNodeTimeout; ///< Timeouts for pending Ping and FindNode requests. - ba::io_service& m_io; ///< Used by bucket refresh timer. - std::shared_ptr m_socket; ///< Shared pointer for our UDPSocket; ASIO requires shared_ptr. - NodeSocket* m_socketPointer; ///< Set to m_socket.get(). Socket is created in constructor and disconnected in destructor to ensure access to pointer is safe. + ba::io_service& m_io; ///< Used by bucket refresh timer. + std::shared_ptr m_socket; ///< Shared pointer for our UDPSocket; ASIO requires shared_ptr. + NodeSocket* m_socketPointer; ///< Set to m_socket.get(). Socket is created in constructor and disconnected in destructor to ensure access to pointer is safe. - boost::asio::deadline_timer m_bucketRefreshTimer; ///< Timer which schedules and enacts bucket refresh. - boost::asio::deadline_timer m_evictionCheckTimer; ///< Timer for handling node evictions. + boost::asio::deadline_timer m_bucketRefreshTimer; ///< Timer which schedules and enacts bucket refresh. + boost::asio::deadline_timer m_evictionCheckTimer; ///< Timer for handling node evictions. }; inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index fa5ec1c27..c558c71f3 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -211,7 +211,7 @@ void ClientModel::setupState(QVariantMap _state) QVariantList stateContracts = _state.value("contracts").toList(); QVariantList transactions = _state.value("transactions").toList(); - map accounts; + unordered_map accounts; std::vector userAccounts; for (auto const& b: stateAccounts) @@ -284,7 +284,7 @@ void ClientModel::setupState(QVariantMap _state) executeSequence(transactionSequence, accounts, Secret(_state.value("miner").toMap().value("secret").toString().toStdString())); } -void ClientModel::executeSequence(vector const& _sequence, std::map const& _accounts, Secret const& _miner) +void ClientModel::executeSequence(vector const& _sequence, std::unordered_map const& _accounts, Secret const& _miner) { if (m_running) { @@ -551,7 +551,7 @@ QVariant ClientModel::formatValue(SolidityType const& _type, u256 const& _value) return res; } -QVariant ClientModel::formatStorageValue(SolidityType const& _type, map const& _storage, unsigned _offset, u256 const& _slot) +QVariant ClientModel::formatStorageValue(SolidityType const& _type, unordered_map const& _storage, unsigned _offset, u256 const& _slot) { u256 slot = _slot; QVariantList values; diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 91b66c76c..b88ae8511 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -220,14 +220,14 @@ private: RecordLogEntry* lastBlock() const; QVariantMap contractAddresses() const; QVariantList gasCosts() const; - void executeSequence(std::vector const& _sequence, std::map const& _accounts, Secret const& _miner); + void executeSequence(std::vector const& _sequence, std::unordered_map const& _accounts, Secret const& _miner); dev::Address deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); void callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); void onNewTransaction(); void onStateReset(); void showDebuggerForTransaction(ExecutionResult const& _t); QVariant formatValue(SolidityType const& _type, dev::u256 const& _value); - QVariant formatStorageValue(SolidityType const& _type, std::map const& _storage, unsigned _offset, dev::u256 const& _slot); + QVariant formatStorageValue(SolidityType const& _type, std::unordered_map const& _storage, unsigned _offset, dev::u256 const& _slot); std::atomic m_running; std::atomic m_mining; diff --git a/mix/MachineStates.h b/mix/MachineStates.h index afd2b990a..2a88d83bf 100644 --- a/mix/MachineStates.h +++ b/mix/MachineStates.h @@ -50,7 +50,7 @@ namespace mix dev::u256s stack; dev::bytes memory; dev::bigint gasCost; - std::map storage; + std::unordered_map storage; std::vector levels; unsigned codeIndex; unsigned dataIndex; diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index b1d8f889e..1f309c5af 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -69,14 +69,14 @@ bytes MixBlockChain::createGenesisBlock(h256 _stateRoot) MixClient::MixClient(std::string const& _dbPath): m_dbPath(_dbPath) { - resetState(std::map()); + resetState(std::unordered_map()); } MixClient::~MixClient() { } -void MixClient::resetState(std::map const& _accounts, Secret const& _miner) +void MixClient::resetState(std::unordered_map const& _accounts, Secret const& _miner) { WriteGuard l(x_state); Guard fl(x_filtersWatches); diff --git a/mix/MixClient.h b/mix/MixClient.h index 182e333c2..99637720a 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -48,7 +48,7 @@ public: MixClient(std::string const& _dbPath); virtual ~MixClient(); /// Reset state to the empty state with given balance. - void resetState(std::map const& _accounts, Secret const& _miner = Secret()); + void resetState(std::unordered_map const& _accounts, Secret const& _miner = Secret()); void mine(); ExecutionResult lastExecution() const; ExecutionResult execution(unsigned _index) const; diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index 144a1a286..96e11e02c 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -305,7 +305,7 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta if (addressOptions.m_bHasStorage) { - map stateStorage = _statePost.storage(a.first); + unordered_map stateStorage = _statePost.storage(a.first); for (auto const& s: _stateExpect.storage(a.first)) CHECK(stateStorage[s.first] == s.second, "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second)); diff --git a/test/fuzzTesting/checkRandomStateTest.cpp b/test/fuzzTesting/checkRandomStateTest.cpp index 719798620..01366cd4d 100644 --- a/test/fuzzTesting/checkRandomStateTest.cpp +++ b/test/fuzzTesting/checkRandomStateTest.cpp @@ -173,7 +173,7 @@ bool doStateTest(mValue& _v) } //checkStorage(importer.m_statePost.storage(expectedAddr), theState.storage(expectedAddr), expectedAddr); - map _resultStore = theState.storage(expectedAddr); + unordered_map _resultStore = theState.storage(expectedAddr); for (auto&& expectedStorePair : importer.m_statePost.storage(expectedAddr)) { diff --git a/test/libethereum/state.cpp b/test/libethereum/state.cpp index 93f7498b8..b682056ee 100644 --- a/test/libethereum/state.cpp +++ b/test/libethereum/state.cpp @@ -99,7 +99,7 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) ImportTest::checkExpectedState(importer.m_statePost, theState); auto expectedAddrs = importer.m_statePost.addresses(); auto resultAddrs = theState.addresses(); - checkAddresses >(expectedAddrs, resultAddrs); + checkAddresses(expectedAddrs, resultAddrs); #endif BOOST_CHECK_MESSAGE(theState.rootHash() == h256(o["postStateRoot"].get_str()), "wrong post state root"); }