Browse Source

fixed isSyncing usage

cl-refactor
arkpar 10 years ago
parent
commit
49d753b302
  1. 12
      libethereum/EthereumHost.cpp
  2. 4
      libethereum/EthereumHost.h

12
libethereum/EthereumHost.cpp

@ -91,10 +91,7 @@ void EthereumHost::doWork()
bool netChange = ensureInitialised();
auto h = m_chain.currentHash();
// If we've finished our initial sync (including getting all the blocks into the chain so as to reduce invalid transactions), start trading transactions & blocks
bool syncing = false;
DEV_GUARDED(x_sync)
syncing = isSyncing();
if (syncing && m_chain.isKnown(m_latestBlockSent))
if (isSyncing() && m_chain.isKnown(m_latestBlockSent))
{
if (m_newTransactions)
{
@ -444,7 +441,8 @@ void EthereumHost::onPeerBlocks(EthereumPeer* _peer, RLP const& _r)
void EthereumHost::onPeerNewHashes(EthereumPeer* _peer, h256s const& _hashes)
{
if (isSyncing())
Guard l(x_sync);
if (isSyncingInternal())
{
clog(NetMessageSummary) << "Ignoring new hashes since we're already downloading.";
return;
@ -456,7 +454,7 @@ void EthereumHost::onPeerNewHashes(EthereumPeer* _peer, h256s const& _hashes)
void EthereumHost::onPeerNewBlock(EthereumPeer* _peer, RLP const& _r)
{
Guard l(x_sync);
if (isSyncing())
if (isSyncingInternal())
{
clog(NetMessageSummary) << "Ignoring new blocks since we're already downloading.";
return;
@ -619,7 +617,7 @@ bool EthereumHost::peerShouldGrabChain(EthereumPeer* _peer) const
}
}
bool EthereumHost::isSyncing() const
bool EthereumHost::isSyncingInternal() const
{
bool syncing = false;
forEachPeer([&](EthereumPeer* _p)

4
libethereum/EthereumHost.h

@ -70,8 +70,7 @@ public:
void reset();
DownloadMan const& downloadMan() const { return m_man; }
bool isSyncing() const;
bool isSyncing() const { Guard l(x_sync); return isSyncingInternal(); }
bool isBanned(p2p::NodeId _id) const { return !!m_banned.count(_id); }
void noteNewTransactions() { m_newTransactions = true; }
@ -93,6 +92,7 @@ private:
std::pair<std::vector<std::shared_ptr<EthereumPeer>>, std::vector<std::shared_ptr<EthereumPeer>>> randomSelection(unsigned _percent = 25, std::function<bool(EthereumPeer*)> const& _allow = [](EthereumPeer const*){ return true; });
void forEachPeerPtr(std::function<void(std::shared_ptr<EthereumPeer>)> const& _f) const;
void forEachPeer(std::function<void(EthereumPeer*)> const& _f) const;
bool isSyncingInternal() const;
/// Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network.
void doWork();

Loading…
Cancel
Save