Browse Source

Fix unordered sync issue.

cl-refactor
Gav Wood 10 years ago
parent
commit
5a9a59a91b
  1. 14
      libethereum/EthereumPeer.cpp
  2. 1
      libethereum/EthereumPeer.h

14
libethereum/EthereumPeer.cpp

@ -121,7 +121,7 @@ void EthereumPeer::transition(Asking _a, bool _force)
clog(NetWarn) << "Bad state: asking for Hashes yet not syncing!"; clog(NetWarn) << "Bad state: asking for Hashes yet not syncing!";
setAsking(_a, true); setAsking(_a, true);
prep(s, GetBlockHashesPacket, 2) << m_syncingNeededBlocks.back() << c_maxHashesAsk; prep(s, GetBlockHashesPacket, 2) << m_syncingLastReceivedHash << c_maxHashesAsk;
sealAndSend(s); sealAndSend(s);
return; return;
} }
@ -385,6 +385,8 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
transition(Asking::Blocks); transition(Asking::Blocks);
return true; return true;
} }
unsigned knowns = 0;
unsigned unknowns = 0;
for (unsigned i = 0; i < _r.itemCount(); ++i) for (unsigned i = 0; i < _r.itemCount(); ++i)
{ {
addRating(1); addRating(1);
@ -392,18 +394,26 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
auto status = host()->m_bq.blockStatus(h); auto status = host()->m_bq.blockStatus(h);
if (status == QueueStatus::Importing || status == QueueStatus::Ready || host()->m_chain.isKnown(h)) if (status == QueueStatus::Importing || status == QueueStatus::Ready || host()->m_chain.isKnown(h))
{ {
clog(NetMessageSummary) << "block hash ready:" << h << ". Start blocks download...";
transition(Asking::Blocks); transition(Asking::Blocks);
return true; return true;
} }
else if (status == QueueStatus::Bad) else if (status == QueueStatus::Bad)
{ {
cwarn << "BAD hash chain discovered. Ignoring."; cwarn << "block hash bad!" << h << ". Bailing...";
transition(Asking::Nothing); transition(Asking::Nothing);
return true; return true;
} }
else if (status == QueueStatus::Unknown) else if (status == QueueStatus::Unknown)
{
unknowns++;
m_syncingNeededBlocks.push_back(h); m_syncingNeededBlocks.push_back(h);
}
else
knowns++;
m_syncingLastReceivedHash = h;
} }
clog(NetMessageSummary) << knowns << "knowns," << unknowns << "unknowns; now at" << m_syncingLastReceivedHash.abridged();
// run through - ask for more. // run through - ask for more.
transition(Asking::Hashes); transition(Asking::Hashes);
break; break;

1
libethereum/EthereumPeer.h

@ -129,6 +129,7 @@ private:
/// This is built as we ask for hashes. Once no more hashes are given, we present this to the /// This is built as we ask for hashes. Once no more hashes are given, we present this to the
/// host who initialises the DownloadMan and m_sub becomes active for us to begin asking for blocks. /// host who initialises the DownloadMan and m_sub becomes active for us to begin asking for blocks.
h256s m_syncingNeededBlocks; ///< The blocks that we should download from this peer. h256s m_syncingNeededBlocks; ///< The blocks that we should download from this peer.
h256 m_syncingLastReceivedHash; ///< Hash more recently received from peer.
h256 m_syncingLatestHash; ///< Peer's latest block's hash, as of the current sync. h256 m_syncingLatestHash; ///< Peer's latest block's hash, as of the current sync.
u256 m_syncingTotalDifficulty; ///< Peer's latest block's total difficulty, as of the current sync. u256 m_syncingTotalDifficulty; ///< Peer's latest block's total difficulty, as of the current sync.

Loading…
Cancel
Save