|
|
@ -169,13 +169,18 @@ bool PeerSession::interpret(RLP const& _r) |
|
|
|
|
|
|
|
// Grab their block chain off them.
|
|
|
|
{ |
|
|
|
clogS(NetNote) << "Want chain. Latest:" << m_server->m_latestBlockSent << ", number:" << m_server->m_chain->details(m_server->m_latestBlockSent).number; |
|
|
|
unsigned count = std::min<unsigned>(c_maxHashes, m_server->m_chain->details(m_server->m_latestBlockSent).number + 1); |
|
|
|
RLPStream s; |
|
|
|
prep(s).appendList(2 + count); |
|
|
|
s << GetChainPacket; |
|
|
|
auto h = m_server->m_latestBlockSent; |
|
|
|
for (unsigned i = 0; i < count; ++i, h = m_server->m_chain->details(h).parent) |
|
|
|
{ |
|
|
|
clogS(NetNote) << " " << i << ":" << h; |
|
|
|
s << h; |
|
|
|
} |
|
|
|
|
|
|
|
s << c_maxBlocksAsk; |
|
|
|
sealAndSend(s); |
|
|
|
s.clear(); |
|
|
@ -781,7 +786,7 @@ void PeerServer::ensureAccepting() |
|
|
|
} |
|
|
|
|
|
|
|
m_accepting = false; |
|
|
|
if (m_mode == NodeMode::PeerServer || m_peers.size() < m_idealPeerCount) |
|
|
|
if (m_mode == NodeMode::PeerServer || m_peers.size() < m_idealPeerCount * 2) |
|
|
|
ensureAccepting(); |
|
|
|
}); |
|
|
|
} |
|
|
@ -832,6 +837,7 @@ void PeerServer::connect(bi::tcp::endpoint const& _ep) |
|
|
|
bool PeerServer::sync() |
|
|
|
{ |
|
|
|
bool ret = false; |
|
|
|
if (isInitialised()) |
|
|
|
for (auto i = m_peers.begin(); i != m_peers.end();) |
|
|
|
{ |
|
|
|
auto p = i->second.lock(); |
|
|
@ -847,10 +853,8 @@ bool PeerServer::sync() |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
bool PeerServer::sync(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o) |
|
|
|
bool PeerServer::ensureInitialised(BlockChain& _bc, TransactionQueue& _tq) |
|
|
|
{ |
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
if (m_latestBlockSent == h256()) |
|
|
|
{ |
|
|
|
// First time - just initialise.
|
|
|
@ -860,8 +864,14 @@ bool PeerServer::sync(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o) |
|
|
|
for (auto const& i: _tq.transactions()) |
|
|
|
m_transactionsSent.insert(i.first); |
|
|
|
m_lastPeersRequest = chrono::steady_clock::time_point::min(); |
|
|
|
ret = true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
bool PeerServer::sync(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o) |
|
|
|
{ |
|
|
|
bool ret = ensureInitialised(_bc, _tq); |
|
|
|
|
|
|
|
if (sync()) |
|
|
|
ret = true; |
|
|
|