Browse Source

Minor sync bug.

cl-refactor
Gav Wood 10 years ago
parent
commit
022695af48
  1. 6
      libethereum/BlockChain.cpp
  2. 2
      libethereum/BlockChain.h
  3. 12
      libethereum/PeerServer.cpp

6
libethereum/BlockChain.cpp

@ -329,7 +329,7 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
return ret; return ret;
} }
h256s BlockChain::treeRoute(h256 _from, h256 _to, h256* o_common) const h256s BlockChain::treeRoute(h256 _from, h256 _to, h256* o_common, bool _pre, bool _post) const
{ {
h256s ret; h256s ret;
h256s back; h256s back;
@ -337,19 +337,23 @@ h256s BlockChain::treeRoute(h256 _from, h256 _to, h256* o_common) const
unsigned tn = details(_to).number; unsigned tn = details(_to).number;
while (fn > tn) while (fn > tn)
{ {
if (_pre)
ret.push_back(_from); ret.push_back(_from);
_from = details(_from).parent; _from = details(_from).parent;
fn--; fn--;
} }
while (fn < tn) while (fn < tn)
{ {
if (_post)
back.push_back(_to); back.push_back(_to);
_to = details(_to).parent; _to = details(_to).parent;
tn--; tn--;
} }
while (_from != _to) while (_from != _to)
{ {
if (_pre)
_from = details(_from).parent; _from = details(_from).parent;
if (_post)
_to = details(_to).parent; _to = details(_to).parent;
ret.push_back(_from); ret.push_back(_from);
back.push_back(_to); back.push_back(_to);

2
libethereum/BlockChain.h

@ -128,7 +128,7 @@ public:
* treeRoute(1b, 2a) == { 1b, 1a, 2a }; // *o_common == g * treeRoute(1b, 2a) == { 1b, 1a, 2a }; // *o_common == g
* @endcode * @endcode
*/ */
h256s treeRoute(h256 _from, h256 _to, h256* o_common = nullptr) const; h256s treeRoute(h256 _from, h256 _to, h256* o_common = nullptr, bool _pre = true, bool _post = true) const;
private: private:
template<class T, unsigned N> T queryExtras(h256 _h, std::map<h256, T>& _m, boost::shared_mutex& _x, T const& _n) const template<class T, unsigned N> T queryExtras(h256 _h, std::map<h256, T>& _m, boost::shared_mutex& _x, T const& _n) const

12
libethereum/PeerServer.cpp

@ -507,12 +507,18 @@ void PeerServer::maintainBlocks(BlockQueue& _bq, h256 _currentHash)
// Send any new blocks. // Send any new blocks.
if (_currentHash != m_latestBlockSent) if (_currentHash != m_latestBlockSent)
{ {
// TODO: find where they diverge and send complete new branch.
RLPStream ts; RLPStream ts;
PeerSession::prep(ts); PeerSession::prep(ts);
ts.appendList(2) << BlocksPacket; bytes bs;
unsigned c = 0;
for (auto h: m_chain->treeRoute(m_latestBlockSent, _currentHash, nullptr, false, true))
{
bs += m_chain->block(h);
++c;
}
ts.appendList(1 + c).append(BlocksPacket).appendRaw(bs, c);
bytes b; bytes b;
ts.appendRaw(m_chain->block()).swapOut(b); ts.swapOut(b);
seal(b); seal(b);
Guard l(x_peers); Guard l(x_peers);

Loading…
Cancel
Save