@@ -93,7 +93,7 @@ class EthereumPeerObserver : public EthereumPeerObserverFace
9393 }
9494 catch (Exception&)
9595 {
96- cwarn << " Exception on peer destruciton : "
96+ cwarn << " Exception on peer destruction : "
9797 << boost::current_exception_diagnostic_information ();
9898 }
9999 }
@@ -388,7 +388,7 @@ class EthereumHostData : public EthereumHostDataFace
388388
389389std::vector<NodeID> randomPeers (std::vector<NodeID> const & _peers, size_t _count)
390390{
391- if (_peers.size () > = _count || _peers.empty ())
391+ if (_peers.size () < = _count || _peers.empty ())
392392 return _peers;
393393
394394 std::vector<NodeID> peers{_peers};
@@ -545,44 +545,43 @@ void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
545545 // Send any new block hashes
546546 auto const detailsFrom = m_chain.details (m_latestBlockHashSent);
547547 auto const detailsTo = m_chain.details (_currentHash);
548- if (detailsFrom.totalDifficulty < detailsTo.totalDifficulty )
549- {
550- if (diff (detailsFrom.number , detailsTo.number ) <= c_maxSendNewBlocksCount)
551- {
552- // don't be sending more than c_maxSendNewBlocksCount "new" block hashes. if there are any more we were probably
553- // waaaay behind.
554- LOG (m_logger) << " Sending new block hashes (current is " << _currentHash << " , was "
555- << m_latestBlockHashSent << " )" ;
548+ if (detailsFrom.totalDifficulty >= detailsTo.totalDifficulty ||
549+ // don't be sending more than c_maxSendNewBlocksCount "new" block hashes. if there are any
550+ // more we were probably waaaay behind.
551+ diff (detailsFrom.number , detailsTo.number ) > c_maxSendNewBlocksCount)
552+ return ;
556553
557- h256s blocks =
558- get< 0 >(m_chain. treeRoute (m_latestBlockHashSent, _currentHash, false , false , true )) ;
554+ LOG (m_logger) << " Sending new block hashes (current is " << _currentHash << " , was "
555+ << m_latestBlockHashSent << " ) " ;
559556
560- auto const peersWithoutBlock = selectPeers (
561- [&](EthereumPeer const & _peer) { return !_peer.isBlockKnown (_currentHash); });
562- for (NodeID const & peerID : peersWithoutBlock)
563- {
564- RLPStream ts;
565- m_host->prep (peerID, name (), ts, NewBlockHashesPacket, blocks.size ());
566- for (auto const & b : blocks)
567- {
568- ts.appendList (2 );
569- ts.append (b);
570- ts.append (m_chain.number (b));
571- }
557+ h256s const blockHashes =
558+ std::get<0 >(m_chain.treeRoute (m_latestBlockHashSent, _currentHash, false , false , true ));
572559
573- auto itPeer = m_peers.find (peerID);
574- if (itPeer != m_peers.end ())
575- {
576- m_host->sealAndSend (peerID, ts);
577- itPeer->second .clearKnownBlocks ();
578- }
579- }
580- if (!peersWithoutBlock.empty ())
581- LOG (m_logger) << " Announced " << blocks.size () << " block(s) to "
582- << peersWithoutBlock.size () << " peers" ;
560+ auto const peersWithoutBlock = selectPeers (
561+ [&](EthereumPeer const & _peer) { return !_peer.isBlockKnown (_currentHash); });
562+ for (NodeID const & peerID : peersWithoutBlock)
563+ {
564+ RLPStream ts;
565+ m_host->prep (peerID, name (), ts, NewBlockHashesPacket, blockHashes.size ());
566+ for (auto const & bh : blockHashes)
567+ {
568+ ts.appendList (2 );
569+ ts.append (bh);
570+ ts.append (m_chain.number (bh));
571+ }
572+
573+ auto itPeer = m_peers.find (peerID);
574+ if (itPeer != m_peers.end ())
575+ {
576+ m_host->sealAndSend (peerID, ts);
577+ itPeer->second .clearKnownBlocks ();
583578 }
584- m_latestBlockHashSent = _currentHash;
585579 }
580+ if (!peersWithoutBlock.empty ())
581+ LOG (m_logger) << " Announced " << blockHashes.size () << " block(s) to "
582+ << peersWithoutBlock.size () << " peers" ;
583+
584+ m_latestBlockHashSent = _currentHash;
586585}
587586
588587bool EthereumCapability::isSyncing () const
@@ -957,16 +956,17 @@ void EthereumCapability::removeSentTransactions(std::vector<h256> const& _txHash
957956 }
958957}
959958
960- void EthereumCapability::propagateNewBlocks (shared_ptr<VerifiedBlocks const > const & _newBlocks)
959+ void EthereumCapability::propagateNewBlocks (std:: shared_ptr<VerifiedBlocks const > const & _newBlocks)
961960{
962961 // Safe to call isSyncing() from a non-network thread since the underlying variable is
963962 // std::atomic
964963 if (_newBlocks->empty () || isSyncing ())
965964 return ;
966965
967966 m_host->postWork ([this , _newBlocks]() {
968- // Verify that we're not too far behind - we perform this check on the network thread rather
969- // than before posting the work to simplify the synchronization story
967+ // Verify that we're not too far behind - we perform this check on the network thread to
968+ // simplify the synchronization story (since otherwise we'd need to synchronize access to
969+ // m_latestBlockSent)
970970 auto const latestHash = _newBlocks->back ().verified .info .hash ();
971971 auto const detailsFrom = m_chain.details (m_latestBlockSent);
972972 auto const detailsTo = m_chain.details (latestHash);
0 commit comments