diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index c6adcfbbf..5df652568 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -743,7 +743,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/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 317ad3909..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); } diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index 99ff41bad..d6390bdfd 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(); } @@ -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) @@ -244,8 +245,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 +284,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 +299,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 +326,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/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.h b/libp2p/Session.h index 7c3fc3732..64dbd9dac 100644 --- a/libp2p/Session.h +++ b/libp2p/Session.h @@ -71,6 +71,8 @@ public: void addRating(unsigned _r) { m_rating += _r; } + void addNote(std::string const& _k, std::string const& _v) { m_info.notes[_k] = _v; } + 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 +