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

Don't sync with peer unless we already received Status message from it #5562

Merged
merged 2 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added: [#5537](https://github.com/ethereum/aleth/pull/5537) Creating Ethereum Node Record (ENR) at program start.
- Added: [#5557](https://github.com/ethereum/aleth/pull/5557) Improved debug logging of full sync.
- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages.
- Fixed: [#5562](https://github.com/ethereum/aleth/pull/5562) Don't send header request messages to peers that haven't sent us Status yet.

## [1.6.0] - Unreleased

Expand Down
12 changes: 9 additions & 3 deletions libethereum/BlockChainSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,16 @@ bool BlockChainSync::requestDaoForkBlockHeader(NodeID const& _peerID)

void BlockChainSync::syncPeer(NodeID const& _peerID, bool _force)
{
if (m_host.peer(_peerID).isConversing())
auto& peer = m_host.peer(_peerID);
if (!peer.statusReceived())
{
LOG(m_loggerDetail) << "Can't sync with this peer - outstanding asks.";
LOG(m_loggerDetail) << "Can't sync with peer " << _peerID << " - Status not received yet.";
return;
}

if (peer.isConversing())
{
LOG(m_loggerDetail) << "Can't sync with peer " << _peerID << " - outstanding asks.";
return;
}

Expand All @@ -238,7 +245,6 @@ void BlockChainSync::syncPeer(NodeID const& _peerID, bool _force)

u256 syncingDifficulty = std::max(m_syncingTotalDifficulty, td);

auto& peer = m_host.peer(_peerID);
u256 peerTotalDifficulty = peer.totalDifficulty();

if (_force || peerTotalDifficulty > syncingDifficulty)
Expand Down
2 changes: 2 additions & 0 deletions libethereum/EthereumPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class EthereumPeer
: m_host(std::move(_host)), m_id(_peerID)
{}

bool statusReceived() const { return m_protocolVersion != 0; }

void setStatus(unsigned _protocolVersion, u256 const& _networkId, u256 const& _totalDifficulty,
h256 const& _latestHash, h256 const& _genesisHash);

Expand Down