Browse Source

start pv60 sync after 10sec delay

cl-refactor
arkpar 10 years ago
parent
commit
a8a8fa5ced
  1. 4
      libethereum/BlockChainSync.cpp
  2. 6
      libethereum/BlockChainSync.h
  3. 25
      libethereum/EthereumHost.cpp
  4. 1
      libethereum/EthereumHost.h

4
libethereum/BlockChainSync.cpp

@ -298,10 +298,12 @@ void BlockChainSync::onPeerNewBlock(std::shared_ptr<EthereumPeer> _peer, RLP con
case ImportResult::UnknownParent:
{
logNewBlock(h);
clog(NetMessageDetail) << "Received block with no known parent. Resyncing...";
u256 totalDifficulty = _r[1].toInt<u256>();
if (totalDifficulty > _peer->m_totalDifficulty)
{
clog(NetMessageDetail) << "Received block with no known parent. Resyncing...";
resetSyncFor(_peer, h, totalDifficulty);
}
break;
}
default:;

6
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<EthereumPeer> _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;

25
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<EthereumPeer> _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();
}

1
libethereum/EthereumHost.h

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

Loading…
Cancel
Save