Browse Source

Merge pull request #2428 from arkpar/bc

Start pv60 sync with 10sec delay
cl-refactor
Gav Wood 10 years ago
parent
commit
f0d26d6907
  1. 6
      libethereum/BlockChainSync.cpp
  2. 6
      libethereum/BlockChainSync.h
  3. 25
      libethereum/EthereumHost.cpp
  4. 1
      libethereum/EthereumHost.h

6
libethereum/BlockChainSync.cpp

@ -298,10 +298,12 @@ void BlockChainSync::onPeerNewBlock(std::shared_ptr<EthereumPeer> _peer, RLP con
case ImportResult::UnknownParent: case ImportResult::UnknownParent:
{ {
logNewBlock(h); logNewBlock(h);
clog(NetMessageDetail) << "Received block with no known parent. Resyncing...";
u256 totalDifficulty = _r[1].toInt<u256>(); u256 totalDifficulty = _r[1].toInt<u256>();
if (totalDifficulty > _peer->m_totalDifficulty) if (totalDifficulty > _peer->m_totalDifficulty)
{
clog(NetMessageDetail) << "Received block with no known parent. Resyncing...";
resetSyncFor(_peer, h, totalDifficulty); resetSyncFor(_peer, h, totalDifficulty);
}
break; break;
} }
default:; default:;
@ -1168,9 +1170,9 @@ SyncStatus PV61Sync::status() const
{ {
RecursiveGuard l(x_sync); RecursiveGuard l(x_sync);
SyncStatus res = PV60Sync::status(); SyncStatus res = PV60Sync::status();
res.protocolVersion = 61;
if (m_state == SyncState::Hashes && isPV61Syncing()) if (m_state == SyncState::Hashes && isPV61Syncing())
{ {
res.protocolVersion = 61;
res.hashesReceived = 0; res.hashesReceived = 0;
for (auto const& d : m_readyChainMap) for (auto const& d : m_readyChainMap)
res.hashesReceived += d.second.size(); res.hashesReceived += d.second.size();

6
libethereum/BlockChainSync.h

@ -58,6 +58,9 @@ public:
/// @returns true is Sync is in progress /// @returns true is Sync is in progress
virtual bool isSyncing() const = 0; virtual bool isSyncing() const = 0;
/// Restart sync
virtual void restartSync() = 0;
/// Called by peer to report status /// Called by peer to report status
virtual void onPeerStatus(std::shared_ptr<EthereumPeer> _peer); virtual void onPeerStatus(std::shared_ptr<EthereumPeer> _peer);
@ -92,9 +95,6 @@ protected:
/// Resume downloading after witing state /// Resume downloading after witing state
virtual void continueSync() = 0; virtual void continueSync() = 0;
/// Restart sync
virtual void restartSync() = 0;
/// Called after all blocks have been donloaded /// Called after all blocks have been donloaded
virtual void completeSync() = 0; virtual void completeSync() = 0;

25
libethereum/EthereumHost.cpp

@ -88,6 +88,7 @@ void EthereumHost::reset()
if (m_sync) if (m_sync)
m_sync->abortSync(); m_sync->abortSync();
m_sync.reset(); m_sync.reset();
m_syncStart = 0;
m_latestBlockSent = h256(); m_latestBlockSent = h256();
Guard tl(x_transactions); Guard tl(x_transactions);
@ -115,6 +116,21 @@ void EthereumHost::doWork()
foreachPeer([](std::shared_ptr<EthereumPeer> _p) { _p->tick(); return true; }); foreachPeer([](std::shared_ptr<EthereumPeer> _p) { _p->tick(); return true; });
if (m_syncStart)
{
DEV_GUARDED(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; // return netChange;
// TODO: Figure out what to do with netChange. // TODO: Figure out what to do with netChange.
(void)netChange; (void)netChange;
@ -259,7 +275,14 @@ BlockChainSync* EthereumHost::sync()
pv61 = true; pv61 = true;
return !pv61; 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(); return m_sync.get();
} }

1
libethereum/EthereumHost.h

@ -138,6 +138,7 @@ private:
mutable Mutex x_transactions; mutable Mutex x_transactions;
DownloadMan m_man; DownloadMan m_man;
std::unique_ptr<BlockChainSync> m_sync; std::unique_ptr<BlockChainSync> m_sync;
std::atomic<time_t> m_syncStart = { 0 };
}; };
} }

Loading…
Cancel
Save