diff --git a/libethereum/DownloadMan.cpp b/libethereum/DownloadMan.cpp index 3e33f3eb5..5e68e3c49 100644 --- a/libethereum/DownloadMan.cpp +++ b/libethereum/DownloadMan.cpp @@ -80,7 +80,6 @@ HashDownloadSub::HashDownloadSub(HashDownloadMan& _man): m_man(&_man) { WriteGuard l(m_man->x_subs); m_asked = RangeMask(m_man->m_chainStart, m_man->m_chainStart + m_man->m_chainCount); - m_attempted = RangeMask(m_man->m_chainStart, m_man->m_chainStart + m_man->m_chainCount); m_man->m_subs.insert(this); } @@ -98,7 +97,6 @@ void HashDownloadSub::resetFetch() Guard l(m_fetch); m_remaining = 0; m_asked = RangeMask(m_man->m_chainStart, m_man->m_chainStart + m_man->m_chainCount); - m_attempted = RangeMask(m_man->m_chainStart, m_man->m_chainStart + m_man->m_chainCount); } unsigned HashDownloadSub::nextFetch(unsigned _n) @@ -110,10 +108,9 @@ unsigned HashDownloadSub::nextFetch(unsigned _n) if (!m_man || m_man->chainEmpty()) return 0; - m_asked = (~(m_man->taken() + m_attempted)).lowest(_n); + m_asked = (~(m_man->taken())).lowest(_n); if (m_asked.empty()) - m_asked = (~(m_man->taken(true) + m_attempted)).lowest(_n); - m_attempted += m_asked; + m_asked = (~(m_man->taken(true))).lowest(_n); return *m_asked.begin(); } diff --git a/libethereum/DownloadMan.h b/libethereum/DownloadMan.h index 0ffa6fdb0..0c27e84ea 100644 --- a/libethereum/DownloadMan.h +++ b/libethereum/DownloadMan.h @@ -187,7 +187,6 @@ public: bool askedContains(unsigned _i) const { Guard l(m_fetch); return m_asked.contains(_i); } RangeMask const& asked() const { return m_asked; } - RangeMask const& attemped() const { return m_attempted; } private: void resetFetch(); // Called by DownloadMan when we need to reset the download. @@ -196,7 +195,6 @@ private: mutable Mutex m_fetch; unsigned m_remaining; RangeMask m_asked; - RangeMask m_attempted; }; class HashDownloadMan @@ -279,3 +277,4 @@ private: } } + diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index c76fcf82c..abeac0af9 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -254,7 +254,8 @@ void EthereumHost::onPeerStatus(EthereumPeer* _peer) estimatePeerHashes(_peer); else { - _peer->m_expectedHashes = (unsigned)_peer->m_latestBlockNumber - m_chain.number(); + if (_peer->m_latestBlockNumber > m_chain.number()) + _peer->m_expectedHashes = (unsigned)_peer->m_latestBlockNumber - m_chain.number(); if (m_hashMan.chainSize() < _peer->m_expectedHashes) m_hashMan.resetToRange(m_chain.number() + 1, _peer->m_expectedHashes); } @@ -287,6 +288,7 @@ void EthereumHost::onPeerHashes(EthereumPeer* _peer, h256s const& _hashes, bool { if (_hashes.empty()) { + _peer->m_hashSub.doneFetch(); continueSync(); return; } @@ -399,6 +401,7 @@ void EthereumHost::onPeerBlocks(EthereumPeer* _peer, RLP const& _r) // Got to this peer's latest block - just give up. clog(NetNote) << "Finishing blocks fetch..."; // NOTE: need to notify of giving up on chain-hashes, too, altering state as necessary. + _peer->m_sub.doneFetch(); _peer->setIdle(); return; } @@ -693,3 +696,4 @@ HashChainStatus EthereumHost::status() return HashChainStatus { static_cast(m_hashMan.chainSize()), static_cast(m_hashMan.gotCount()), false }; return HashChainStatus { m_estimatedHashes, static_cast(m_hashes.size()), true }; } +