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

Commit 8739dd0

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 8739dd0

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
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: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ void EthereumCapability::reset()
436436
m_sync->abortSync();
437437

438438
// reset() can be called from RPC handling thread,
439-
// but we access m_latestBlockHashSent and m_transactionsSent only from the network thread
439+
// but we access m_latestBlockHashSent, m_latestBlockSent, and m_transactionsSent only from the
440+
// network thread
440441
m_host->postWork([this]() {
441442
m_latestBlockHashSent = {};
442443
m_latestBlockSent = {};
@@ -511,14 +512,11 @@ std::vector<NodeID> EthereumCapability::randomPeers(
511512
std::vector<NodeID> const& _peers, size_t _count) const
512513
{
513514
std::vector<NodeID> peers{_peers};
514-
if (peers.empty())
515+
if (peers.empty() || _count >= _peers.size())
515516
return peers;
516517

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};
518+
std::shuffle(peers.begin(), peers.end(), m_urng);
519+
return {peers.begin(), peers.begin() + _count};
522520
}
523521

524522
void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
@@ -533,7 +531,10 @@ void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
533531
// don't be sending more than c_maxSendNewBlocksCount "new" block hashes. if there are any
534532
// more we were probably waaaay behind.
535533
if (diff(detailsFrom.number, detailsTo.number) > c_maxSendNewBlocksCount)
534+
{
535+
m_latestBlockHashSent = _currentHash;
536536
return;
537+
}
537538

538539
LOG(m_logger) << "Sending new block hashes (current is " << _currentHash << ", was "
539540
<< m_latestBlockHashSent << ")";
@@ -950,15 +951,18 @@ void EthereumCapability::propagateNewBlocks(std::shared_ptr<VerifiedBlocks const
950951
m_host->postWork([this, _newBlocks]() {
951952
// Verify that we're not too far behind - we perform this check on the network thread to
952953
// simplify the synchronization story (since otherwise we'd need to synchronize access to
953-
// m_latestBlockSent)
954+
// m_latestBlockSent).
954955
auto const latestHash = _newBlocks->back().verified.info.hash();
955956
auto const detailsFrom = m_chain.details(m_latestBlockSent);
956957
auto const detailsTo = m_chain.details(latestHash);
957958
if (detailsFrom.totalDifficulty >= detailsTo.totalDifficulty)
958959
return;
959960

960961
if (diff(detailsFrom.number, detailsTo.number) > c_maxSendNewBlocksCount)
962+
{
963+
m_latestBlockSent = latestHash;
961964
return;
965+
}
962966

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

0 commit comments

Comments
 (0)