Browse Source

Avoid sending chain back to peer once initial sync complete.

cl-refactor
Gav Wood 10 years ago
parent
commit
2a18aa2d8e
  1. 24
      libethereum/EthereumHost.cpp
  2. 2
      libethereum/EthereumHost.h
  3. 3
      libethereum/EthereumSession.cpp

24
libethereum/EthereumHost.cpp

@ -421,6 +421,17 @@ bool EthereumHost::ensureInitialised(TransactionQueue& _tq)
return false;
}
void EthereumHost::noteDoneBlocks()
{
clog(NetNote) << "Peer given up on blocks fetch.";
if (m_blocksOnWay.empty())
{
// Done our chain-get.
clog(NetNote) << "No more blocks coming. Missing" << m_blocksNeeded.size() << "blocks.";
m_latestBlockSent = m_chain->currentHash();
}
}
bool EthereumHost::noteBlock(h256 _hash, bytesConstRef _data)
{
Guard l(x_blocksNeeded);
@ -509,8 +520,14 @@ void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash)
m_incomingBlocks.clear();
}
// Send any new blocks.
if (_currentHash != m_latestBlockSent)
// If we've finished our initial sync...
{
Guard l(x_blocksNeeded);
if (m_blocksOnWay.size())
return;
}
// ...send any new blocks.
if (m_latestBlockSent != _currentHash)
{
RLPStream ts;
EthereumSession::prep(ts);
@ -521,6 +538,7 @@ void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash)
bs += m_chain->block(h);
++c;
}
clog(NetNote) << "Sending" << c << "new blocks (current is" << _currentHash << ", was" << m_latestBlockSent << ")";
ts.appendList(1 + c).append(BlocksPacket).appendRaw(bs, c);
bytes b;
ts.swapOut(b);
@ -534,9 +552,9 @@ void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash)
p->send(&b);
p->m_knownBlocks.clear();
}
}
m_latestBlockSent = _currentHash;
}
}
void EthereumHost::growPeers()
{

2
libethereum/EthereumHost.h

@ -113,6 +113,8 @@ private:
bool noteBlock(h256 _hash, bytesConstRef _data);
/// Session has finished getting the chain of hashes.
void noteHaveChain(std::shared_ptr<EthereumSession> const& _who);
/// Called when the peer can no longer provide us with any needed blocks.
void noteDoneBlocks();
/// Called when the session has provided us with a new peer we can connect to.
void noteNewPeers() {}

3
libethereum/EthereumSession.cpp

@ -398,7 +398,10 @@ void EthereumSession::continueGettingChain()
sealAndSend(s);
}
else
{
clogS(NetMessageSummary) << "No blocks left to get. Peer doesn't seem to have " << m_failedBlocks.size() << "of our needed blocks.";
m_server->noteDoneBlocks();
}
}
void EthereumSession::ping()

Loading…
Cancel
Save