Browse Source

fixed syncing stalling issues

cl-refactor
arkpar 10 years ago
parent
commit
1c2a9cd088
  1. 34
      libethereum/EthereumHost.cpp
  2. 1
      libethereum/EthereumPeer.cpp

34
libethereum/EthereumHost.cpp

@ -292,8 +292,8 @@ void EthereumHost::onPeerStatus(EthereumPeer* _peer)
else else
_peer->m_expectedHashes = estimatedHashes; _peer->m_expectedHashes = estimatedHashes;
continueSync(_peer); continueSync(_peer);
}
DEV_INVARIANT_CHECK; DEV_INVARIANT_CHECK;
}
} }
unsigned EthereumHost::estimateHashes() unsigned EthereumHost::estimateHashes()
@ -313,6 +313,7 @@ unsigned EthereumHost::estimateHashes()
void EthereumHost::onPeerHashes(EthereumPeer* _peer, h256s const& _hashes) void EthereumHost::onPeerHashes(EthereumPeer* _peer, h256s const& _hashes)
{ {
RecursiveGuard l(x_sync); RecursiveGuard l(x_sync);
DEV_INVARIANT_CHECK;
if (_peer->m_syncHashNumber > 0) if (_peer->m_syncHashNumber > 0)
_peer->m_syncHashNumber += _hashes.size(); _peer->m_syncHashNumber += _hashes.size();
@ -322,7 +323,6 @@ void EthereumHost::onPeerHashes(EthereumPeer* _peer, h256s const& _hashes)
void EthereumHost::onPeerHashes(EthereumPeer* _peer, h256s const& _hashes, bool _complete) void EthereumHost::onPeerHashes(EthereumPeer* _peer, h256s const& _hashes, bool _complete)
{ {
DEV_INVARIANT_CHECK;
if (_hashes.empty()) if (_hashes.empty())
{ {
_peer->m_hashSub.doneFetch(); _peer->m_hashSub.doneFetch();
@ -454,7 +454,8 @@ void EthereumHost::onPeerBlocks(EthereumPeer* _peer, RLP const& _r)
unsigned unknown = 0; unsigned unknown = 0;
unsigned got = 0; unsigned got = 0;
unsigned repeated = 0; unsigned repeated = 0;
h256 lastUnknown; u256 maxDifficulty = 0;
h256 maxUnknown;
for (unsigned i = 0; i < itemCount; ++i) for (unsigned i = 0; i < itemCount; ++i)
{ {
@ -483,9 +484,17 @@ void EthereumHost::onPeerBlocks(EthereumPeer* _peer, RLP const& _r)
break; break;
case ImportResult::UnknownParent: case ImportResult::UnknownParent:
lastUnknown = h; {
unknown++; unknown++;
BlockInfo bi;
bi.populateFromHeader(_r[i][0]);
if (bi.difficulty > maxDifficulty)
{
maxDifficulty = bi.difficulty;
maxUnknown = h;
}
break; break;
}
default:; default:;
} }
@ -501,8 +510,10 @@ void EthereumHost::onPeerBlocks(EthereumPeer* _peer, RLP const& _r)
if (m_state == SyncState::NewBlocks && unknown > 0) if (m_state == SyncState::NewBlocks && unknown > 0)
{ {
_peer->m_latestHash = lastUnknown; _peer->m_latestHash = maxUnknown;
resetSyncTo(lastUnknown); _peer->m_totalDifficulty = maxDifficulty;
if (peerShouldGrabChain(_peer))
resetSyncTo(maxUnknown);
} }
continueSync(_peer); continueSync(_peer);
@ -528,7 +539,7 @@ void EthereumHost::onPeerNewBlock(EthereumPeer* _peer, RLP const& _r)
{ {
RecursiveGuard l(x_sync); RecursiveGuard l(x_sync);
DEV_INVARIANT_CHECK; DEV_INVARIANT_CHECK;
if ((isSyncing() || _peer->isConversing()) && m_state != SyncState::NewBlocks) if ((isSyncing() || _peer->isConversing()))
{ {
clog(NetMessageSummary) << "Ignoring new blocks since we're already downloading."; clog(NetMessageSummary) << "Ignoring new blocks since we're already downloading.";
return; return;
@ -565,13 +576,16 @@ void EthereumHost::onPeerNewBlock(EthereumPeer* _peer, RLP const& _r)
u256 difficulty = _r[1].toInt<u256>(); u256 difficulty = _r[1].toInt<u256>();
if (m_syncingTotalDifficulty < difficulty) if (m_syncingTotalDifficulty < difficulty)
{ {
clog(NetMessageSummary) << "Received block with no known parent. Resyncing...";
_peer->m_latestHash = h; _peer->m_latestHash = h;
_peer->m_totalDifficulty = difficulty; _peer->m_totalDifficulty = difficulty;
if (peerShouldGrabChain(_peer))
{
clog(NetMessageSummary) << "Received block with no known parent. Resyncing...";
resetSyncTo(h);; resetSyncTo(h);;
sync = true; sync = true;
} }
} }
}
break; break;
default:; default:;
} }
@ -580,7 +594,7 @@ void EthereumHost::onPeerNewBlock(EthereumPeer* _peer, RLP const& _r)
_peer->m_knownBlocks.insert(h); _peer->m_knownBlocks.insert(h);
if (sync) if (sync)
continueSync(); continueSync(_peer);
} }
DEV_INVARIANT_CHECK; DEV_INVARIANT_CHECK;
} }
@ -623,6 +637,7 @@ void EthereumHost::onPeerAborting(EthereumPeer* _peer)
_peer->setRude(); _peer->setRude();
continueSync(); continueSync();
} }
DEV_INVARIANT_CHECK;
} }
void EthereumHost::continueSync() void EthereumHost::continueSync()
@ -811,6 +826,5 @@ bool EthereumHost::invariants() const
return false; return false;
if (needBlocks() && (m_syncingLatestHash || !m_hashes.empty())) if (needBlocks() && (m_syncingLatestHash || !m_hashes.empty()))
return false; return false;
return true; return true;
} }

1
libethereum/EthereumPeer.cpp

@ -100,6 +100,7 @@ void EthereumPeer::requestStatus()
{ {
assert(m_asking == Asking::Nothing); assert(m_asking == Asking::Nothing);
setAsking(Asking::State); setAsking(Asking::State);
m_requireTransactions = true;
RLPStream s; RLPStream s;
bool latest = m_peerCapabilityVersion == host()->protocolVersion(); bool latest = m_peerCapabilityVersion == host()->protocolVersion();
prep(s, StatusPacket, latest ? 6 : 5) prep(s, StatusPacket, latest ? 6 : 5)

Loading…
Cancel
Save