Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit d2b72ae

Browse files
committed
Address PR feedback
Fix some bugs: * Only shuffle the peers list in randomPeers if a subset of them are being returned * Update the hash of the latest block sent in EthereumCapability if we're too far behind - otherwise we'll always be behind and therefore send any new blocks or new block hashes. Also, change the CHANGELOG entry from "added" to "changed" (since this isn't a new feature but modification of existing behavior)
1 parent c3f1b85 commit d2b72ae

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
- Added: [#5701](https://github.com/ethereum/aleth/issues/5701) Outputs ENR text representation in admin.nodeInfo RPC.
2020
- Added: [#5705](https://github.com/ethereum/aleth/pull/5705) Istanbul support: EIP 1108 Reduce alt_bn128 precompile gas costs.
2121
- Added: [#5707](https://github.com/ethereum/aleth/pull/5707) Aleth waits for 2 seconds after sending disconnect to peer before closing socket.
22-
- Added: [#5713](https://github.com/ethereum/aleth/pull/5713) Propagate new blocks after PoW check rather than after import into the blockchain.
2322
- Changed: [#5532](https://github.com/ethereum/aleth/pull/5532) The leveldb is upgraded to 1.22. This is breaking change on Windows and the old databases are not compatible.
2423
- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages.
2524
- Changed: [#5568](https://github.com/ethereum/aleth/pull/5568) Improve rlpx handshake log messages and create new rlpx log channel.
@@ -35,6 +34,7 @@
3534
- Changed: [#5675](https://github.com/ethereum/aleth/pull/5675) Disconnect from peer when syncing is disabled for peer.
3635
- Changed: [#5676](https://github.com/ethereum/aleth/pull/5676) When receiving large batches of new block hashes, process up to 1024 hashes instead of disabling the peer.
3736
- Changed: [#5719](https://github.com/ethereum/aleth/pull/5719) Enable support for Visual Studio 2017 on Windows.
37+
- Changed: [#5713](https://github.com/ethereum/aleth/pull/5713) Propagate new blocks after PoW check rather than after import into the blockchain.
3838
- Removed: [#5631](https://github.com/ethereum/aleth/pull/5631) Removed PARANOID build option.
3939
- Fixed: [#5562](https://github.com/ethereum/aleth/pull/5562) Don't send header request messages to peers that haven't sent us Status yet.
4040
- Fixed: [#5581](https://github.com/ethereum/aleth/pull/5581) Fixed finding neighbour nodes in Discovery.

libethereum/Client.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ void Client::syncBlockQueue()
390390
unsigned count;
391391
Timer t;
392392

393+
// The verified blocks list needs to be a shared_ptr since we propagate them on the network
394+
// thread and import them into our local chain on the client thread.
393395
std::shared_ptr<VerifiedBlocks> verifiedBlocks = std::make_shared<VerifiedBlocks>();
394396
m_bq.drain(*verifiedBlocks, m_syncAmount);
395397

libethereum/EthereumCapability.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,11 @@ std::vector<NodeID> EthereumCapability::randomPeers(
511511
std::vector<NodeID> const& _peers, size_t _count) const
512512
{
513513
std::vector<NodeID> peers{_peers};
514-
if (peers.empty())
514+
if (peers.empty() || _count >= _peers.size())
515515
return peers;
516516

517-
if (_count > peers.size())
518-
_count = peers.size();
519-
auto itEnd = peers.begin() + _count;
520-
std::shuffle(peers.begin(), itEnd, m_urng);
521-
return {peers.begin(), itEnd};
517+
std::shuffle(peers.begin(), peers.end(), m_urng);
518+
return {peers.begin(), peers.begin() + _count};
522519
}
523520

524521
void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
@@ -533,7 +530,10 @@ void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
533530
// don't be sending more than c_maxSendNewBlocksCount "new" block hashes. if there are any
534531
// more we were probably waaaay behind.
535532
if (diff(detailsFrom.number, detailsTo.number) > c_maxSendNewBlocksCount)
533+
{
534+
m_latestBlockHashSent = _currentHash;
536535
return;
536+
}
537537

538538
LOG(m_logger) << "Sending new block hashes (current is " << _currentHash << ", was "
539539
<< m_latestBlockHashSent << ")";
@@ -950,15 +950,18 @@ void EthereumCapability::propagateNewBlocks(std::shared_ptr<VerifiedBlocks const
950950
m_host->postWork([this, _newBlocks]() {
951951
// Verify that we're not too far behind - we perform this check on the network thread to
952952
// simplify the synchronization story (since otherwise we'd need to synchronize access to
953-
// m_latestBlockSent)
953+
// m_latestBlockSent).
954954
auto const latestHash = _newBlocks->back().verified.info.hash();
955955
auto const detailsFrom = m_chain.details(m_latestBlockSent);
956956
auto const detailsTo = m_chain.details(latestHash);
957957
if (detailsFrom.totalDifficulty >= detailsTo.totalDifficulty)
958958
return;
959959

960960
if (diff(detailsFrom.number, detailsTo.number) > c_maxSendNewBlocksCount)
961+
{
962+
m_latestBlockSent = latestHash;
961963
return;
964+
}
962965

963966
auto const peersWithoutBlock = selectPeers(
964967
[&](EthereumPeer const& _peer) { return !_peer.isBlockKnown(latestHash); });

0 commit comments

Comments
 (0)