From a8a8fa5ced19a7f0f6f138e9af7508016c448500 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 8 Jul 2015 19:35:04 +0200 Subject: [PATCH 1/3] start pv60 sync after 10sec delay --- libethereum/BlockChainSync.cpp | 4 +++- libethereum/BlockChainSync.h | 6 +++--- libethereum/EthereumHost.cpp | 25 ++++++++++++++++++++++++- libethereum/EthereumHost.h | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index b3b168cb7..5249c41e0 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -298,10 +298,12 @@ void BlockChainSync::onPeerNewBlock(std::shared_ptr _peer, RLP con case ImportResult::UnknownParent: { logNewBlock(h); - clog(NetMessageDetail) << "Received block with no known parent. Resyncing..."; u256 totalDifficulty = _r[1].toInt(); if (totalDifficulty > _peer->m_totalDifficulty) + { + clog(NetMessageDetail) << "Received block with no known parent. Resyncing..."; resetSyncFor(_peer, h, totalDifficulty); + } break; } default:; diff --git a/libethereum/BlockChainSync.h b/libethereum/BlockChainSync.h index 4fb7bae2c..6be17bc74 100644 --- a/libethereum/BlockChainSync.h +++ b/libethereum/BlockChainSync.h @@ -58,6 +58,9 @@ public: /// @returns true is Sync is in progress virtual bool isSyncing() const = 0; + /// Restart sync + virtual void restartSync() = 0; + /// Called by peer to report status virtual void onPeerStatus(std::shared_ptr _peer); @@ -92,9 +95,6 @@ protected: /// Resume downloading after witing state virtual void continueSync() = 0; - /// Restart sync - virtual void restartSync() = 0; - /// Called after all blocks have been donloaded virtual void completeSync() = 0; diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index f00ec7dc7..1c9a491a8 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -88,6 +88,7 @@ void EthereumHost::reset() if (m_sync) m_sync->abortSync(); m_sync.reset(); + m_syncStart = 0; m_latestBlockSent = h256(); Guard tl(x_transactions); @@ -115,6 +116,21 @@ void EthereumHost::doWork() foreachPeer([](std::shared_ptr _p) { _p->tick(); return true; }); + if (m_syncStart) + { + Guard l(x_sync); + if (!m_sync) + { + time_t now = std::chrono::system_clock::to_time_t(chrono::system_clock::now()); + if ((now - m_syncStart) > 10) + { + m_sync.reset(new PV60Sync(*this)); + m_syncStart = 0; + m_sync->restartSync(); + } + } + } + // return netChange; // TODO: Figure out what to do with netChange. (void)netChange; @@ -259,7 +275,14 @@ BlockChainSync* EthereumHost::sync() pv61 = true; return !pv61; }); - m_sync.reset(pv61 ? new PV61Sync(*this) : new PV60Sync(*this)); + if (pv61) + { + m_syncStart = 0; + m_sync.reset(new PV61Sync(*this)); + } + else if (!m_syncStart) + m_syncStart = std::chrono::system_clock::to_time_t(chrono::system_clock::now()); + return m_sync.get(); } diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index 6cb82ebb4..9afaa8413 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -138,6 +138,7 @@ private: mutable Mutex x_transactions; DownloadMan m_man; std::unique_ptr m_sync; + std::atomic m_syncStart = { 0 }; }; } From fbe0d01ee761b9b792630c21baa3becb3861d14f Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 8 Jul 2015 21:01:32 +0200 Subject: [PATCH 2/3] style --- libethereum/EthereumHost.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 1c9a491a8..88f95f64f 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -118,17 +118,17 @@ void EthereumHost::doWork() if (m_syncStart) { - Guard l(x_sync); - if (!m_sync) - { - time_t now = std::chrono::system_clock::to_time_t(chrono::system_clock::now()); - if ((now - m_syncStart) > 10) + DEV_GUARDED(x_sync); + if (!m_sync) { - m_sync.reset(new PV60Sync(*this)); - m_syncStart = 0; - m_sync->restartSync(); + time_t now = std::chrono::system_clock::to_time_t(chrono::system_clock::now()); + if (now - m_syncStart > 10) + { + m_sync.reset(new PV60Sync(*this)); + m_syncStart = 0; + m_sync->restartSync(); + } } - } } // return netChange; From 5b4c6f86788b744b7171df61ec622a0a6ef61880 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 8 Jul 2015 21:21:32 +0200 Subject: [PATCH 3/3] fixed reported sync protocol version --- libethereum/BlockChainSync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index 5249c41e0..6aede0c16 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -1170,9 +1170,9 @@ SyncStatus PV61Sync::status() const { RecursiveGuard l(x_sync); SyncStatus res = PV60Sync::status(); + res.protocolVersion = 61; if (m_state == SyncState::Hashes && isPV61Syncing()) { - res.protocolVersion = 61; res.hashesReceived = 0; for (auto const& d : m_readyChainMap) res.hashesReceived += d.second.size();