From 49d753b3027ddccb29358fa6bb280f6e8ad56c20 Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 2 Jun 2015 12:37:45 +0200 Subject: [PATCH] fixed isSyncing usage --- libethereum/EthereumHost.cpp | 12 +++++------- libethereum/EthereumHost.h | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 899960c23..d90bf57e2 100644 --- a/libethereum/EthereumHost.cpp +++ b/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) diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index f8fa79a15..ad18bccc7 100644 --- a/libethereum/EthereumHost.h +++ b/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>> randomSelection(unsigned _percent = 25, std::function const& _allow = [](EthereumPeer const*){ return true; }); void forEachPeerPtr(std::function)> const& _f) const; void forEachPeer(std::function 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();