diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index c1016992a..2c6d326d1 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -747,7 +747,7 @@ void Main::refreshNetwork() ui->peerCount->setText(QString::fromStdString(toString(ps.size())) + " peer(s)"); ui->peers->clear(); for (PeerInfo const& i: ps) - ui->peers->addItem(QString("[%6] %3 ms - %1:%2 - %4 %5").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))).arg(i.socket)); + ui->peers->addItem(QString("[%7] %3 ms - %1:%2 - %4 %5 %6").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))).arg(QString::fromStdString(toString(i.notes))).arg(i.socket)); } void Main::refreshAll() diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index bc903b52d..551b7af87 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -27,7 +27,7 @@ using namespace dev; namespace dev { -char const* Version = "0.6.10"; +char const* Version = "0.6.11"; } diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index eed8b4bb9..44297e0ba 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -35,7 +35,7 @@ namespace eth { const unsigned c_protocolVersion = 33; -const unsigned c_databaseVersion = 1; +const unsigned c_databaseVersion = 2; static const vector> g_units = { diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index eea3fd5af..de0e991e6 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -102,7 +102,7 @@ void EthereumHost::noteHaveChain(EthereumPeer* _from) if (_from->m_neededBlocks.empty()) { - _from->m_grabbing = Grabbing::Nothing; + _from->setGrabbing(Grabbing::Nothing); updateGrabbing(Grabbing::Nothing); return; } @@ -112,7 +112,7 @@ void EthereumHost::noteHaveChain(EthereumPeer* _from) if (td < m_chain.details().totalDifficulty || (td == m_chain.details().totalDifficulty && m_chain.currentHash() == _from->m_latestHash)) { clog(NetNote) << "Difficulty of hashchain not HIGHER. Ignoring."; - _from->m_grabbing = Grabbing::Nothing; + _from->setGrabbing(Grabbing::Nothing); updateGrabbing(Grabbing::Nothing); return; } @@ -123,7 +123,7 @@ void EthereumHost::noteHaveChain(EthereumPeer* _from) m_man.resetToChain(_from->m_neededBlocks); m_latestBlockSent = _from->m_latestHash; - _from->m_grabbing = Grabbing::Chain; + _from->setGrabbing(Grabbing::Chain); updateGrabbing(Grabbing::Chain); } @@ -266,7 +266,11 @@ void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash) } clog(NetMessageSummary) << "Sending" << c << "new blocks (current is" << _currentHash << ", was" << m_latestBlockSent << ")"; if (c > 1000) - cwarn << "Gaa sending an awful lot of new blocks. Sure this is right?"; + { + cwarn << "Gaa this would be an awful lot of new blocks. Not bothering"; + return; + } + ts.appendList(1 + c).append(BlocksPacket).appendRaw(bs, c); bytes b; ts.swapOut(b); diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index 99ff41bad..d7d69187d 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -38,6 +38,7 @@ EthereumPeer::EthereumPeer(Session* _s, HostCapabilityFace* _h): Capability(_s, _h), m_sub(host()->m_man) { + setGrabbing(Grabbing::State); sendStatus(); } @@ -94,7 +95,7 @@ void EthereumPeer::tryGrabbingHashChain() if (td >= m_totalDifficulty) { clogS(NetAllDetail) << "No. Our chain is better."; - m_grabbing = Grabbing::Nothing; + setGrabbing(Grabbing::Nothing); return; // All good - we have the better chain. } @@ -103,7 +104,7 @@ void EthereumPeer::tryGrabbingHashChain() clogS(NetAllDetail) << "Yes. Their chain is better."; host()->updateGrabbing(Grabbing::Hashes); - m_grabbing = Grabbing::Hashes; + setGrabbing(Grabbing::Hashes); RLPStream s; prep(s).appendList(3); s << GetBlockHashesPacket << m_latestHash << c_maxHashesAsk; @@ -120,11 +121,11 @@ void EthereumPeer::giveUpOnFetch() if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper) { host()->noteDoneBlocks(this); - m_grabbing = Grabbing::Nothing; + setGrabbing(Grabbing::Nothing); } - m_sub.doneFetch(); // NOTE: need to notify of giving up on chain-hashes, too, altering state as necessary. + m_sub.doneFetch(); } bool EthereumPeer::interpret(RLP const& _r) @@ -143,12 +144,14 @@ bool EthereumPeer::interpret(RLP const& _r) if (genesisHash != host()->m_chain.genesisHash()) disable("Invalid genesis hash"); - if (m_protocolVersion != host()->protocolVersion()) + else if (m_protocolVersion != host()->protocolVersion()) disable("Invalid protocol version."); - if (m_networkId != host()->networkId()) + else if (m_networkId != host()->networkId()) disable("Invalid network identifier."); - - startInitialSync(); + else if (session()->info().clientVersion.find("/v0.6.9/") != string::npos) + disable("Blacklisted client version."); + else + startInitialSync(); break; } case GetTransactionsPacket: @@ -244,8 +247,8 @@ bool EthereumPeer::interpret(RLP const& _r) if (_r.itemCount() == 1) { // Couldn't get any from last batch - probably got to this peer's latest block - just give up. - m_sub.doneFetch(); - giveUpOnFetch(); + if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper) + giveUpOnFetch(); break; } @@ -283,7 +286,8 @@ bool EthereumPeer::interpret(RLP const& _r) } } clogS(NetMessageSummary) << dec << knownParents << "known parents," << unknownParents << "unknown," << used << "used."; - continueGettingChain(); + if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper) + continueGettingChain(); break; } default: @@ -297,13 +301,18 @@ void EthereumPeer::ensureGettingChain() if (m_grabbing == Grabbing::ChainHelper) return; // Already asked & waiting for some. + // Switch to ChainHelper otherwise, unless we're already the Chain grabber. + if (m_grabbing != Grabbing::Chain) + setGrabbing(Grabbing::ChainHelper); + continueGettingChain(); } void EthereumPeer::continueGettingChain() { - if (m_grabbing != Grabbing::Chain) - m_grabbing = Grabbing::ChainHelper; + // If we're getting the hashes already, then we shouldn't be asking for the chain. + if (m_grabbing == Grabbing::Hashes) + return; auto blocks = m_sub.nextFetch(c_maxBlocksAsk); @@ -319,3 +328,9 @@ void EthereumPeer::continueGettingChain() else giveUpOnFetch(); } + +void EthereumPeer::setGrabbing(Grabbing _g) +{ + m_grabbing = _g; + session()->addNote("grab", _g == Grabbing::Nothing ? "nothing" : _g == Grabbing::State ? "state" : _g == Grabbing::Hashes ? "hashes" : _g == Grabbing::Chain ? "chain" : _g == Grabbing::ChainHelper ? "chainhelper" : "?"); +} diff --git a/libethereum/EthereumPeer.h b/libethereum/EthereumPeer.h index f88a757d8..052af3c7e 100644 --- a/libethereum/EthereumPeer.h +++ b/libethereum/EthereumPeer.h @@ -71,11 +71,12 @@ private: void giveUpOnFetch(); void clearKnownTransactions() { std::lock_guard l(x_knownTransactions); m_knownTransactions.clear(); } + void setGrabbing(Grabbing _g); unsigned m_protocolVersion; u256 m_networkId; - Grabbing m_grabbing = Grabbing::State; + Grabbing m_grabbing; h256 m_latestHash; ///< Peer's latest block's hash. u256 m_totalDifficulty; ///< Peer's latest block's total difficulty. diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index d9d373bb2..84fba15d6 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -131,11 +131,9 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g // We can allow for the reverted state (i.e. that with which m_ext is constructed) to contain the m_newAddress, since // we delete it explicitly if we decide we need to revert. m_newAddress = right160(sha3(rlpList(_sender, m_s.transactionsFrom(_sender) - 1))); - while (m_s.addressInUse(m_newAddress)) - m_newAddress = (u160)m_newAddress + 1; // Set up new account... - m_s.m_cache[m_newAddress] = AddressState(0, _endowment, h256(), h256()); + m_s.m_cache[m_newAddress] = AddressState(0, m_s.balance(m_newAddress) + _endowment, h256(), h256()); // Execute _init. m_vm = new VM(_gas); diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 7c7a40754..6c0598b57 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -1142,7 +1142,7 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, newAddress = (u160)newAddress + 1; // Set up new account... - m_cache[newAddress] = AddressState(0, _endowment, h256(), h256()); + m_cache[newAddress] = AddressState(0, balance(newAddress) + _endowment, h256(), h256()); // Execute init code. VM vm(*_gas); diff --git a/libp2p/Common.h b/libp2p/Common.h index 3339df8bb..a5f7e5d84 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -96,6 +96,7 @@ struct PeerInfo std::chrono::steady_clock::duration lastPing; std::set caps; unsigned socket; + std::map notes; }; } diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index 9225a92f9..524e1e657 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -40,7 +40,7 @@ Session::Session(Host* _s, bi::tcp::socket _socket, bi::address _peerAddress, un { m_disconnect = std::chrono::steady_clock::time_point::max(); m_connect = std::chrono::steady_clock::now(); - m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0), set(), 0}); + m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0), set(), 0, map()}); } Session::~Session() @@ -102,7 +102,7 @@ bool Session::interpret(RLP const& _r) return false; } try - { m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration(), _r[3].toSet(), (unsigned)m_socket.native_handle()}); } + { m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration(), _r[3].toSet(), (unsigned)m_socket.native_handle(), map() }); } catch (...) { disconnect(BadProtocol); diff --git a/libp2p/Session.h b/libp2p/Session.h index 7c3fc3732..934e548d4 100644 --- a/libp2p/Session.h +++ b/libp2p/Session.h @@ -71,6 +71,10 @@ public: void addRating(unsigned _r) { m_rating += _r; } + void addNote(std::string const& _k, std::string const& _v) { m_info.notes[_k] = _v; } + + PeerInfo const& info() const { return m_info; } + private: void dropped(); void doRead(); diff --git a/merge.sh b/merge.sh new file mode 100755 index 000000000..7f7bb7536 --- /dev/null +++ b/merge.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +git checkout "$1+" && git merge --no-ff develop && git push && git tag -f $1 && git push --tags -f && git checkout develop +