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