diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index a5a03297f..4025b1450 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -48,6 +48,7 @@ EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQu m_bq (_bq), m_networkId (_networkId) { + m_bq.onReady([=](){ if (readyForMore()) m_continueSync = true; }); m_latestBlockSent = _ch.currentHash(); m_hashMan.reset(m_chain.number() + 1); } @@ -105,6 +106,12 @@ void EthereumHost::doWork() } } + if (m_continueSync) + { + m_continueSync = false; + continueSync(); + } + foreachPeer([](EthereumPeer* _p) { _p->tick(); }); // return netChange; @@ -589,6 +596,11 @@ void EthereumHost::continueSync() }); } +bool EthereumHost::readyForMore() const +{ + return m_bq.status().verified + m_bq.status().verifying + m_bq.status().unverified < 1024; +} + void EthereumHost::continueSync(EthereumPeer* _peer) { assert(_peer->m_asking == Asking::Nothing); @@ -642,7 +654,10 @@ void EthereumHost::continueSync(EthereumPeer* _peer) } } else if (m_needSyncBlocks && peerCanHelp(_peer)) // Check if this peer can help with downloading blocks - _peer->requestBlocks(); + { + if (readyForMore()) + _peer->requestBlocks(); + } else _peer->setIdle(); } diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index df17b1e4e..e4a46bab2 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -126,6 +126,7 @@ private: bool peerShouldGrabChain(EthereumPeer* _peer) const; bool peerCanHelp(EthereumPeer* _peer) const; void estimatePeerHashes(EthereumPeer* _peer); + bool readyForMore() const; BlockChain const& m_chain; TransactionQueue& m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain. @@ -152,6 +153,7 @@ private: h256s m_hashes; ///< List of hashes with unknown block numbers. Used for PV60 chain downloading and catching up to a particular unknown unsigned m_estimatedHashes = 0; ///< Number of estimated hashes for the last peer over PV60. Used for status reporting only. bool m_syncingV61 = false; ///< True if recent activity was over pv61+. Used for status reporting only. + bool m_continueSync = false; ///< True when the block queue has processed a block; we should restart grabbing blocks. }; }