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 3d7a830e6..a5d64f77f 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -150,17 +150,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 { return boost::hash_range(_value.m_data.cbegin(), _value.m_data.cend()); } }; template inline FixedHash& shiftBloom(FixedHash const& _h) @@ -221,12 +214,8 @@ template<> inline bool FixedHash<32>::operator==(FixedHash<32> const& _other) co /// Fast std::hash compatible hash function object for h256. template<> inline size_t FixedHash<32>::hash::operator()(FixedHash<32> 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]; - return (size_t)hash; + uint64_t const* data = reinterpret_cast(value.data()); + return boost::hash_range(data, data + 4); } /// Stream I/O for the FixedHash class. @@ -254,6 +243,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) @@ -285,6 +276,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 48660bb96..6464c7ede 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 set 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/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 24fc1cb65..431f98bf8 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -212,9 +212,10 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const if (transactionsRoot != t.root())*/ auto txList = root[1]; auto expectedRoot = trieRootOver(txList.itemCount(), [&](unsigned i){ return rlp(i); }, [&](unsigned i){ return txList[i].data(); }); + cnote << "expect trroot " << toString(expectedRoot); if (transactionsRoot != expectedRoot) BOOST_THROW_EXCEPTION(InvalidTransactionsHash() << HashMismatchError(expectedRoot, transactionsRoot)); - + cnote << "expect uncleh " << toString(sha3(root[2].data())); if (sha3Uncles != sha3(root[2].data())) BOOST_THROW_EXCEPTION(InvalidUnclesHash()); } 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..2e4fe5749 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(); @@ -610,6 +610,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement if (receiptsTrie.root() != m_currentBlock.receiptsRoot) { cwarn << "Bad receipts state root."; + cwarn << "Expected: " << toString(receiptsTrie.root()) << " received: " << toString(m_currentBlock.receiptsRoot); cwarn << "Block:" << toHex(_block); cwarn << "Block RLP:" << rlp; cwarn << "Calculated: " << receiptsTrie.root(); @@ -649,9 +650,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 +806,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 +1017,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 15ee981bc..da7558ecb 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -214,3 +214,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 std::hash()(_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); // Chosen by fair dice roll, guaranteed to be random + 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.h b/libp2p/NodeTable.h index 458044997..92bf17f79 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; @@ -243,32 +243,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_evictions first if both x_nodes and x_evictions locks are required. - std::deque m_evictions; ///< Eviction timeouts. + Mutex x_evictions; ///< LOCK x_evictions 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/BlockTestsFiller/bcTotalDifficultyTestFiller.json b/test/libethereum/BlockTestsFiller/bcTotalDifficultyTestFiller.json new file mode 100644 index 000000000..1acaa23e9 --- /dev/null +++ b/test/libethereum/BlockTestsFiller/bcTotalDifficultyTestFiller.json @@ -0,0 +1,1596 @@ +{ + "sideChainWithMoreTransactions" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "40" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "4" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31059", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x3453454", + "gasLimit" : "31509", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + }, + { + "data" : "", + "gasLimit" : "31509", + "gasPrice" : "1", + "nonce" : "4", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "195e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + } + ] + }, + + "lotsOfBranchesOverrideAtTheEnd" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "820" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "4" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314134359", + "gasPrice" : "1343", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x34235435346", + "gasLimit" : "314143359", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "3331", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x44634634", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31059", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x3453454", + "gasLimit" : "31509", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "795e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1000" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31400", + "gasPrice" : "100000000", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "10", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "5", + "transactions" : [ + { + "data" : "0x44634634", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + } + ] + }, + + "lotsOfBranchesOverrideAtTheMiddle" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "420" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "4" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314134359", + "gasPrice" : "1343", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x34235435346", + "gasLimit" : "314143359", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "3331", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x44634634", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "5", + "transactions" : [ + { + "data" : "0x44634634", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31059", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x3453454", + "gasLimit" : "31509", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "795e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1000" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31400", + "gasPrice" : "100000000", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "10", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + } + ] + }, + + "lotsOfBranches" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "40" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "4" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314134359", + "gasPrice" : "1343", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x34235435346", + "gasLimit" : "314143359", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "100" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "3331", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x44634634", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "200" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31059", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "0x3453454", + "gasLimit" : "31509", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "300" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "795e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1000" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31400", + "gasPrice" : "100000000", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "10", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "400" + } + ], + "uncleHeaders" : [ + ] + } + ] + }, + + "lotsOfLeafs" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "1" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "3" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "0" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "0" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314134359", + "gasPrice" : "1343", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "2" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "0x34235435346", + "gasLimit" : "314143359", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "3" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "3331", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "4" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "0x44634634", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31059", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "6" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "0x3453454", + "gasLimit" : "31509", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "7" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "795e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "9" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "31400", + "gasPrice" : "100000000000", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "10", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "11" + } + ], + "uncleHeaders" : [ + ] + } + ] + }, + + "sideChainWithNewMaxDifficultyStartingFromBlock3AfterBlock4" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "45" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "5" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "3" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "7" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "11" + } + ], + "uncleHeaders" : [ + { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "0x020040", + "extraData" : "0x", + "gasLimit" : "0x2fefd8", + "gasUsed" : "0x5208", + "hash" : "9168fbfb2e3fbedfdb9eac6f73b6d7c9323c957fc3406f27a2f44983f0e5dd43", + "mixHash" : "d56ea25bfefc68484759c3dd934030624308b7ab02bb20aee17852aff72f1397", + "nonce" : "6e7970f59660cbd7", + "number" : "0x02", + "parentHash" : "b7afc3043361f44fd15c0f8df8ebab8284d01c8f79fb47b6fc75eec98b4b4683", + "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fe", + "timestamp" : "0x553e25de", + "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + } + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "13" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "5", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "4", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "17" + } + ], + "uncleHeaders" : [ + ] + } + ] + }, + + "uncleBlockAtBlock3afterBlock4" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "16" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "4" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "3" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "4", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "3", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "7" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "11" + } + ], + "uncleHeaders" : [ + { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "0x020040", + "extraData" : "0x", + "gasLimit" : "0x2fefd8", + "gasUsed" : "0x5208", + "hash" : "9168fbfb2e3fbedfdb9eac6f73b6d7c9323c957fc3406f27a2f44983f0e5dd43", + "mixHash" : "d56ea25bfefc68484759c3dd934030624308b7ab02bb20aee17852aff72f1397", + "nonce" : "6e7970f59660cbd7", + "number" : "0x02", + "parentHash" : "b7afc3043361f44fd15c0f8df8ebab8284d01c8f79fb47b6fc75eec98b4b4683", + "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fe", + "timestamp" : "0x553e25de", + "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + } + ] + } + ] + }, + + "uncleBlockAtBlock3AfterBlock3" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "131072", + "extraData" : "0x42", + "gasLimit" : "3141592", + "gasUsed" : "0", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "nonce" : "0x0102030405060708", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "expect" : { + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "9" + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "nonce" : "3" + } + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "blocks" : [ + { + "blocknumber" : "1", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "1" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "2", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "1", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "3" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5" + } + ], + "uncleHeaders" : [ + ] + }, + { + "blocknumber" : "3", + "transactions" : [ + { + "data" : "", + "gasLimit" : "314159", + "gasPrice" : "1", + "nonce" : "2", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "7" + } + ], + "uncleHeaders" : [ + { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "0x020040", + "extraData" : "0x", + "gasLimit" : "0x2fefd8", + "gasUsed" : "0x5208", + "hash" : "9168fbfb2e3fbedfdb9eac6f73b6d7c9323c957fc3406f27a2f44983f0e5dd43", + "mixHash" : "d56ea25bfefc68484759c3dd934030624308b7ab02bb20aee17852aff72f1397", + "nonce" : "6e7970f59660cbd7", + "number" : "0x02", + "parentHash" : "b7afc3043361f44fd15c0f8df8ebab8284d01c8f79fb47b6fc75eec98b4b4683", + "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fe", + "timestamp" : "0x553e25de", + "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + } + ] + } + ] + } +} diff --git a/test/libethereum/blockchain.cpp b/test/libethereum/blockchain.cpp index 954e65c8a..c5ac936fe 100644 --- a/test/libethereum/blockchain.cpp +++ b/test/libethereum/blockchain.cpp @@ -48,26 +48,35 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) { for (auto& i: _v.get_obj()) { - cerr << i.first << endl; mObject& o = i.second.get_obj(); + if (test::Options::get().singleTest && test::Options::get().singleTestName != i.first) + { + o.clear(); + continue; + } + cerr << i.first << endl; BOOST_REQUIRE(o.count("genesisBlockHeader")); BlockInfo biGenesisBlock = constructBlock(o["genesisBlockHeader"].get_obj()); BOOST_REQUIRE(o.count("pre")); ImportTest importer(o["pre"].get_obj()); - TransientDirectory td_stateDB; TransientDirectory td_stateDB_tmp; - State state(State::openDB(td_stateDB.path()), BaseState::Empty, biGenesisBlock.coinbaseAddress); - State stateTemp(State::openDB(td_stateDB_tmp.path()), BaseState::Empty, biGenesisBlock.coinbaseAddress); - importer.importState(o["pre"].get_obj(), state); - o["pre"] = fillJsonWithState(state); - state.commit(); + State trueState(OverlayDB(State::openDB(td_stateDB_tmp.path())), BaseState::Empty, biGenesisBlock.coinbaseAddress); + + //Imported blocks from the start + typedef std::vector uncleList; + typedef std::pair blockSet; + std::vector blockSets; + + importer.importState(o["pre"].get_obj(), trueState); + o["pre"] = fillJsonWithState(trueState); + trueState.commit(); if (_fillin) - biGenesisBlock.stateRoot = state.rootHash(); + biGenesisBlock.stateRoot = trueState.rootHash(); else - BOOST_CHECK_MESSAGE(biGenesisBlock.stateRoot == state.rootHash(), "root hash does not match"); + BOOST_CHECK_MESSAGE(biGenesisBlock.stateRoot == trueState.rootHash(), "root hash does not match"); if (_fillin) { @@ -83,20 +92,55 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) biGenesisBlock.verifyInternals(&rlpGenesisBlock.out()); o["genesisRLP"] = toHex(rlpGenesisBlock.out(), 2, HexPrefix::Add); - // construct blockchain + // construct true blockchain TransientDirectory td; - BlockChain bc(rlpGenesisBlock.out(), td.path(), WithExisting::Kill); + BlockChain trueBc(rlpGenesisBlock.out(), td.path(), WithExisting::Kill); if (_fillin) { BOOST_REQUIRE(o.count("blocks")); mArray blArray; + + blockSet genesis; + genesis.first = rlpGenesisBlock.out(); + genesis.second = uncleList(); + blockSets.push_back(genesis); vector vBiBlocks; vBiBlocks.push_back(biGenesisBlock); + + size_t importBlockNumber = 0; for (auto const& bl: o["blocks"].get_array()) { - stateTemp = state; mObject blObj = bl.get_obj(); + if (blObj.count("blocknumber") > 0) + importBlockNumber = std::max((int)toInt(blObj["blocknumber"]), 1); + else + importBlockNumber++; + + //each time construct a new blockchain up to importBlockNumber (to generate next block header) + vBiBlocks.clear(); + vBiBlocks.push_back(biGenesisBlock); + + TransientDirectory td_stateDB, td_bc; + BlockChain bc(rlpGenesisBlock.out(), td_bc.path(), WithExisting::Kill); + State state(OverlayDB(State::openDB(td_stateDB.path())), BaseState::Empty, biGenesisBlock.coinbaseAddress); + importer.importState(o["pre"].get_obj(), state); + state.commit(); + + for (size_t i = 1; i < importBlockNumber; i++) //0 block is genesis + { + BlockQueue uncleQueue; + uncleList uncles = blockSets.at(i).second; + for (size_t j = 0; j < uncles.size(); j++) + uncleQueue.import(&uncles.at(j), bc); + + const bytes block = blockSets.at(i).first; + bc.sync(uncleQueue, state.db(), 4); + bc.attemptImport(block, state.db()); + vBiBlocks.push_back(BlockInfo(block)); + + state.sync(bc); + } // get txs TransactionQueue txs; @@ -115,6 +159,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) blObj["uncleHeaders"] = importUncles(blObj, vBiUncles, vBiBlocks); BlockQueue uncleBlockQueue; + uncleList uncleBlockQueueList; cnote << "import uncle in blockQueue"; for (size_t i = 0; i < vBiUncles.size(); i++) { @@ -122,6 +167,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) try { uncleBlockQueue.import(&uncle.out(), bc); + uncleBlockQueueList.push_back(uncle.out()); } catch(...) { @@ -205,6 +251,25 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) bc.import(block2.out(), state.db()); state.sync(bc); state.commit(); + + //there we get new blockchain status in state which could have more difficulty than we have in trueState + //attempt to import new block to the true blockchain + trueBc.sync(uncleBlockQueue, trueState.db(), 4); + trueBc.attemptImport(block2.out(), trueState.db()); + trueState.sync(trueBc); + + blockSet newBlock; + newBlock.first = block2.out(); + newBlock.second = uncleBlockQueueList; + if (importBlockNumber < blockSets.size()) + { + //make new correct history of imported blocks + blockSets[importBlockNumber] = newBlock; + for (size_t i = importBlockNumber + 1; i < blockSets.size(); i++) + blockSets.pop_back(); + } + else + blockSets.push_back(newBlock); } // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given catch (...) @@ -213,7 +278,6 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) blObj.erase(blObj.find("blockHeader")); blObj.erase(blObj.find("uncleHeaders")); blObj.erase(blObj.find("transactions")); - state = stateTemp; //revert state as if it was before executing this block } blArray.push_back(blObj); this_thread::sleep_for(chrono::seconds(1)); @@ -224,14 +288,15 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) stateOptionsMap expectStateMap; State stateExpect(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); importer.importState(o["expect"].get_obj(), stateExpect, expectStateMap); - ImportTest::checkExpectedState(stateExpect, state, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); + ImportTest::checkExpectedState(stateExpect, trueState, expectStateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); o.erase(o.find("expect")); } o["blocks"] = blArray; - o["postState"] = fillJsonWithState(state); + o["postState"] = fillJsonWithState(trueState); + o["lastblockhash"] = toString(trueBc.info().hash()); - //make all values hex + //make all values hex in pre section State prestate(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); importer.importState(o["pre"].get_obj(), prestate); o["pre"] = fillJsonWithState(prestate); @@ -241,14 +306,17 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) { for (auto const& bl: o["blocks"].get_array()) { + bool importedAndBest = true; mObject blObj = bl.get_obj(); bytes blockRLP; try { - state.sync(bc); blockRLP = importByteArray(blObj["rlp"].get_str()); - bc.import(blockRLP, state.db()); - state.sync(bc); + trueState.sync(trueBc); + trueBc.import(blockRLP, trueState.db()); + if (trueBc.info() != BlockInfo(blockRLP)) + importedAndBest = false; + trueState.sync(trueBc); } // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given catch (Exception const& _e) @@ -284,124 +352,131 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) const RLP c_blockHeaderRLP(c_rlpBytesBlockHeader); blockHeaderFromFields.populateFromHeader(c_blockHeaderRLP, IgnoreNonce); - BlockInfo blockFromRlp = bc.info(); - - //Check the fields restored from RLP to original fields - BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce), "hash in given RLP not matching the block hash!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot, "receiptsRoot in given RLP not matching the block receiptsRoot!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.mixHash == blockFromRlp.mixHash, "mixHash in given RLP not matching the block mixHash!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); - - BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); - - //Check transaction list + BlockInfo blockFromRlp = trueBc.info(); - Transactions txsFromField; - - for (auto const& txObj: blObj["transactions"].get_array()) + if (importedAndBest) { - mObject tx = txObj.get_obj(); - - BOOST_REQUIRE(tx.count("nonce")); - BOOST_REQUIRE(tx.count("gasPrice")); - BOOST_REQUIRE(tx.count("gasLimit")); - BOOST_REQUIRE(tx.count("to")); - BOOST_REQUIRE(tx.count("value")); - BOOST_REQUIRE(tx.count("v")); - BOOST_REQUIRE(tx.count("r")); - BOOST_REQUIRE(tx.count("s")); - BOOST_REQUIRE(tx.count("data")); - - try - { - Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckTransaction::Everything); - txsFromField.push_back(t); - } - catch (Exception const& _e) + //Check the fields restored from RLP to original fields + BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce), "hash in given RLP not matching the block hash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot, "receiptsRoot in given RLP not matching the block receiptsRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.mixHash == blockFromRlp.mixHash, "mixHash in given RLP not matching the block mixHash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); + + BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); + + //Check transaction list + + Transactions txsFromField; + + for (auto const& txObj: blObj["transactions"].get_array()) { - BOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e)); + mObject tx = txObj.get_obj(); + + BOOST_REQUIRE(tx.count("nonce")); + BOOST_REQUIRE(tx.count("gasPrice")); + BOOST_REQUIRE(tx.count("gasLimit")); + BOOST_REQUIRE(tx.count("to")); + BOOST_REQUIRE(tx.count("value")); + BOOST_REQUIRE(tx.count("v")); + BOOST_REQUIRE(tx.count("r")); + BOOST_REQUIRE(tx.count("s")); + BOOST_REQUIRE(tx.count("data")); + + try + { + Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckTransaction::Everything); + txsFromField.push_back(t); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e)); + } + catch (exception const& _e) + { + cnote << _e.what(); + } } - catch (exception const& _e) + + Transactions txsFromRlp; + RLP root(blockRLP); + for (auto const& tr: root[1]) { - cnote << _e.what(); + Transaction tx(tr.data(), CheckTransaction::Everything); + txsFromRlp.push_back(tx); } - } - Transactions txsFromRlp; - RLP root(blockRLP); - for (auto const& tr: root[1]) - { - Transaction tx(tr.data(), CheckTransaction::Everything); - txsFromRlp.push_back(tx); - } - - BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match"); + BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match"); - for (size_t i = 0; i < txsFromField.size(); ++i) - { - BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), "transaction data in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), "transaction gasLimit in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), "transaction gasPrice in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), "transaction nonce in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, "transaction r in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, "transaction s in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, "transaction v in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match"); - - BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "transactions from rlp and transaction from field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].rlp() == txsFromRlp[i].rlp(), "transactions rlp do not match"); - } + for (size_t i = 0; i < txsFromField.size(); ++i) + { + BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), "transaction data in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), "transaction gasLimit in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), "transaction gasPrice in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), "transaction nonce in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, "transaction r in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, "transaction s in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, "transaction v in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match"); + + BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "transactions from rlp and transaction from field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].rlp() == txsFromRlp[i].rlp(), "transactions rlp do not match"); + } - // check uncle list + // check uncle list - // uncles from uncle list field - vector uBlHsFromField; - if (blObj["uncleHeaders"].type() != json_spirit::null_type) - for (auto const& uBlHeaderObj: blObj["uncleHeaders"].get_array()) - { - mObject uBlH = uBlHeaderObj.get_obj(); - BOOST_REQUIRE(uBlH.size() == 16); - bytes uncleRLP = createBlockRLPFromFields(uBlH); - const RLP c_uRLP(uncleRLP); - BlockInfo uncleBlockHeader; - try - { - uncleBlockHeader.populateFromHeader(c_uRLP); - } - catch(...) + // uncles from uncle list field + vector uBlHsFromField; + if (blObj["uncleHeaders"].type() != json_spirit::null_type) + for (auto const& uBlHeaderObj: blObj["uncleHeaders"].get_array()) { - BOOST_ERROR("invalid uncle header"); + mObject uBlH = uBlHeaderObj.get_obj(); + BOOST_REQUIRE(uBlH.size() == 16); + bytes uncleRLP = createBlockRLPFromFields(uBlH); + const RLP c_uRLP(uncleRLP); + BlockInfo uncleBlockHeader; + try + { + uncleBlockHeader.populateFromHeader(c_uRLP); + } + catch(...) + { + BOOST_ERROR("invalid uncle header"); + } + uBlHsFromField.push_back(uncleBlockHeader); } - uBlHsFromField.push_back(uncleBlockHeader); + + // uncles from block RLP + vector uBlHsFromRlp; + for (auto const& uRLP: root[2]) + { + BlockInfo uBl; + uBl.populateFromHeader(uRLP); + uBlHsFromRlp.push_back(uBl); } - // uncles from block RLP - vector uBlHsFromRlp; - for (auto const& uRLP: root[2]) - { - BlockInfo uBl; - uBl.populateFromHeader(uRLP); - uBlHsFromRlp.push_back(uBl); - } + BOOST_REQUIRE_EQUAL(uBlHsFromField.size(), uBlHsFromRlp.size()); - BOOST_REQUIRE_EQUAL(uBlHsFromField.size(), uBlHsFromRlp.size()); + for (size_t i = 0; i < uBlHsFromField.size(); ++i) + BOOST_CHECK_MESSAGE(uBlHsFromField[i] == uBlHsFromRlp[i], "block header in rlp and in field do not match"); + }//importedAndBest + }//all blocks - for (size_t i = 0; i < uBlHsFromField.size(); ++i) - BOOST_CHECK_MESSAGE(uBlHsFromField[i] == uBlHsFromRlp[i], "block header in rlp and in field do not match"); - } + BOOST_REQUIRE(o.count("lastblockhash") > 0); + BOOST_CHECK_MESSAGE(toString(trueBc.info().hash()) == o["lastblockhash"].get_str(), + "Boost check: " + i.first + " lastblockhash does not match " + toString(trueBc.info().hash()) + " expected: " + o["lastblockhash"].get_str()); } } } @@ -443,6 +518,7 @@ mArray importUncles(mObject const& blObj, vector& vBiUncles, vector >(expectedAddrs, resultAddrs); + checkAddresses(expectedAddrs, resultAddrs); #endif BOOST_CHECK_MESSAGE(theState.rootHash() == h256(o["postStateRoot"].get_str()), "wrong post state root"); }