Browse Source

Minor blockchain sync fixes

cl-refactor
arkpar 10 years ago
parent
commit
6dbb2ed27b
  1. 33
      libethereum/BlockChainSync.cpp
  2. 1
      libethereum/BlockChainSync.h
  3. 4
      libethereum/EthereumPeer.cpp

33
libethereum/BlockChainSync.cpp

@ -300,7 +300,7 @@ void BlockChainSync::onPeerNewBlock(std::shared_ptr<EthereumPeer> _peer, RLP con
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..."; clog(NetMessageDetail) << "Received block with no known parent. Peer needs syncing...";
resetSyncFor(_peer, h, totalDifficulty); resetSyncFor(_peer, h, totalDifficulty);
} }
break; break;
@ -649,11 +649,8 @@ void PV60Sync::noteDoneBlocks(std::shared_ptr<EthereumPeer> _peer, bool _clemenc
else else
{ {
// Done our chain-get. // Done our chain-get.
clog(NetWarn) << "Chain download failed. Peer with blocks didn't have them all. This peer is bad and should be punished."; clog(NetNote) << "Peer does not have required blocks";
clog(NetWarn) << downloadMan().remaining(); resetNeedsSyncing(_peer);
clog(NetWarn) << "WOULD BAN.";
// m_banned.insert(_peer->session()->id()); // We know who you are!
// _peer->disable("Peer sent hashes but was unable to provide the blocks.");
} }
resetSync(); resetSync();
downloadMan().reset(); downloadMan().reset();
@ -747,7 +744,7 @@ void PV60Sync::onPeerNewHashes(std::shared_ptr<EthereumPeer> _peer, h256s const&
RecursiveGuard l(x_sync); RecursiveGuard l(x_sync);
if (isSyncing() && (m_state != SyncState::NewBlocks || isSyncing(_peer))) if (isSyncing() && (m_state != SyncState::NewBlocks || isSyncing(_peer)))
{ {
clog(NetMessageSummary) << "Ignoring since we're already downloading."; clog(NetMessageDetail) << "Ignoring new hashes since we're already downloading.";
return; return;
} }
clog(NetMessageDetail) << "Not syncing and new block hash discovered: syncing without help."; clog(NetMessageDetail) << "Not syncing and new block hash discovered: syncing without help.";
@ -838,7 +835,7 @@ void PV60Sync::onPeerAborting()
// Can't check invariants here since the peers is already removed from the list and the state is not updated yet. // Can't check invariants here since the peers is already removed from the list and the state is not updated yet.
if (m_syncer.expired() && m_state != SyncState::Idle) if (m_syncer.expired() && m_state != SyncState::Idle)
{ {
clog(NetWarn) << "Syncing peer disconnected, restarting sync"; clog(NetNote) << "Syncing peer disconnected";
m_syncer.reset(); m_syncer.reset();
abortSync(); abortSync();
} }
@ -971,9 +968,6 @@ void PV61Sync::completeSubchain(std::shared_ptr<EthereumPeer> _peer, unsigned _n
m_syncingNeededBlocks.clear(); m_syncingNeededBlocks.clear();
for (auto h = m_completeChainMap.rbegin(); h != m_completeChainMap.rend(); ++h) for (auto h = m_completeChainMap.rbegin(); h != m_completeChainMap.rend(); ++h)
m_syncingNeededBlocks.insert(m_syncingNeededBlocks.end(), h->second.hashes.begin(), h->second.hashes.end()); m_syncingNeededBlocks.insert(m_syncingNeededBlocks.end(), h->second.hashes.begin(), h->second.hashes.end());
m_completeChainMap.clear();
m_knownHashes.clear();
m_syncingBlockNumber = 0;
transition(syncer, SyncState::Blocks); transition(syncer, SyncState::Blocks);
} }
else else
@ -1007,6 +1001,7 @@ void PV61Sync::onPeerHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _h
{ {
// End of hash chain, add last chunk to download // End of hash chain, add last chunk to download
m_readyChainMap.insert(make_pair(m_syncingBlockNumber, SubChain{ h256s{ _peer->m_latestHash }, _peer->m_latestHash })); m_readyChainMap.insert(make_pair(m_syncingBlockNumber, SubChain{ h256s{ _peer->m_latestHash }, _peer->m_latestHash }));
m_knownHashes.insert(_peer->m_latestHash);
m_hashScanComplete = true; m_hashScanComplete = true;
_peer->m_syncHashNumber = 0; _peer->m_syncHashNumber = 0;
requestSubchain(_peer); requestSubchain(_peer);
@ -1032,7 +1027,13 @@ void PV61Sync::onPeerHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _h
if (isSyncing(_peer) && _peer->m_syncHashNumber == m_syncingBlockNumber) if (isSyncing(_peer) && _peer->m_syncHashNumber == m_syncingBlockNumber)
{ {
// Got new subchain marker // Got new subchain marker
assert(_hashes.size() == 1); if(_hashes.size() != 1)
{
clog(NetWarn) << "Peers gives to much hashes";
_peer->disable("Too many hashes");
restartSync();
return;
}
m_knownHashes.insert(_hashes[0]); m_knownHashes.insert(_hashes[0]);
m_readyChainMap.insert(make_pair(m_syncingBlockNumber, SubChain{ h256s{ _hashes[0] }, _hashes[0] })); m_readyChainMap.insert(make_pair(m_syncingBlockNumber, SubChain{ h256s{ _hashes[0] }, _hashes[0] }));
if ((m_readyChainMap.size() + m_downloadingChainMap.size() + m_completeChainMap.size()) * c_hashSubchainSize > _peer->m_expectedHashes) if ((m_readyChainMap.size() + m_downloadingChainMap.size() + m_completeChainMap.size()) * c_hashSubchainSize > _peer->m_expectedHashes)
@ -1186,6 +1187,14 @@ bool PV61Sync::isPV61Syncing() const
return m_syncingBlockNumber != 0; return m_syncingBlockNumber != 0;
} }
void PV61Sync::completeSync()
{
m_completeChainMap.clear();
m_knownHashes.clear();
m_syncingBlockNumber = 0;
PV60Sync::completeSync();
}
bool PV61Sync::invariants() const bool PV61Sync::invariants() const
{ {
if (m_state == SyncState::Hashes) if (m_state == SyncState::Hashes)

1
libethereum/BlockChainSync.h

@ -292,6 +292,7 @@ public:
protected: protected:
void restartSync() override; void restartSync() override;
void completeSync() override;
void requestSubchain(std::shared_ptr<EthereumPeer> _peer) override; void requestSubchain(std::shared_ptr<EthereumPeer> _peer) override;
void syncHashes(std::shared_ptr<EthereumPeer> _peer) override; void syncHashes(std::shared_ptr<EthereumPeer> _peer) override;
void onPeerHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _hashes) override; void onPeerHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _hashes) override;

4
libethereum/EthereumPeer.cpp

@ -145,7 +145,7 @@ void EthereumPeer::requestHashes(u256 _number, unsigned _count)
setAsking(Asking::Hashes); setAsking(Asking::Hashes);
RLPStream s; RLPStream s;
prep(s, GetBlockHashesByNumberPacket, 2) << m_syncHashNumber << _count; prep(s, GetBlockHashesByNumberPacket, 2) << m_syncHashNumber << _count;
clog(NetMessageDetail) << "Requesting block hashes for numbers " << m_syncHashNumber << "-" << m_syncHashNumber + c_maxHashesAsk - 1; clog(NetMessageDetail) << "Requesting block hashes for numbers " << m_syncHashNumber << "-" << m_syncHashNumber + _count - 1;
sealAndSend(s); sealAndSend(s);
} }
@ -298,7 +298,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
if (m_asking != Asking::Hashes) if (m_asking != Asking::Hashes)
{ {
clog(NetWarn) << "Peer giving us hashes when we didn't ask for them."; clog(NetAllDetail) << "Peer giving us hashes when we didn't ask for them.";
break; break;
} }
setIdle(); setIdle();

Loading…
Cancel
Save