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

Commit 60fbc2f

Browse files
authored
Merge pull request #5559 from ethereum/sync-status-checks
Rephrase error messages in EthereumPeer::validate and re-order validation conditions
2 parents a185162 + 649d26d commit 60fbc2f

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [1.7.0] - Unreleased
44

55
- Added: [#5537](https://github.com/ethereum/aleth/pull/5537) Creating Ethereum Node Record (ENR) at program start.
6+
- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages.
67

78
[1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...master
89

@@ -24,4 +25,4 @@
2425
- Fixed: [#5547](https://github.com/ethereum/aleth/pull/5547) Fix unnecessary slow-down of eth_flush RPC method.
2526

2627
[1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...release/1.6
27-
[1.7.0]: https://github.com/ethereum/aleth/compare/release/1.6...master
28+
[1.7.0]: https://github.com/ethereum/aleth/compare/release/1.6...master

libethereum/EthereumPeer.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
/*
2-
This file is part of cpp-ethereum.
3-
4-
cpp-ethereum is free software: you can redistribute it and/or modify
5-
it under the terms of the GNU General Public License as published by
6-
the Free Software Foundation, either version 3 of the License, or
7-
(at your option) any later version.
8-
9-
cpp-ethereum is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
GNU General Public License for more details.
13-
14-
You should have received a copy of the GNU General Public License
15-
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16-
*/
1+
// Aleth: Ethereum C++ client, tools and libraries.
2+
// Copyright 2019 Aleth Authors.
3+
// Licensed under the GNU General Public License, Version 3.
174

185
#include "EthereumPeer.h"
196
#include <libethcore/Common.h>
@@ -24,10 +11,10 @@ using namespace std;
2411
using namespace dev;
2512
using namespace dev::eth;
2613

27-
static std::string const c_ethCapability = "eth";
28-
2914
namespace
3015
{
16+
std::string const c_ethCapability = "eth";
17+
3118
string toString(Asking _a)
3219
{
3320
switch (_a)
@@ -67,17 +54,20 @@ void EthereumPeer::setStatus(unsigned _protocolVersion, u256 const& _networkId,
6754
std::string EthereumPeer::validate(
6855
h256 const& _hostGenesisHash, unsigned _hostProtocolVersion, u256 const& _hostNetworkId) const
6956
{
70-
std::string error;
71-
if (m_genesisHash != _hostGenesisHash)
72-
error = "Invalid genesis hash.";
57+
std::stringstream error;
58+
if (m_networkId != _hostNetworkId)
59+
error << "Network identifier mismatch. Host network id: " << _hostNetworkId
60+
<< ", peer network id: " << m_networkId;
7361
else if (m_protocolVersion != _hostProtocolVersion)
74-
error = "Invalid protocol version.";
75-
else if (m_networkId != _hostNetworkId)
76-
error = "Invalid network identifier.";
62+
error << "Protocol version mismatch. Host protocol version: " << _hostProtocolVersion
63+
<< ", peer protocol version: " << m_protocolVersion;
64+
else if (m_genesisHash != _hostGenesisHash)
65+
error << "Genesis hash mismatch. Host genesis hash: " << _hostGenesisHash
66+
<< ", peer genesis hash: " << m_genesisHash;
7767
else if (m_asking != Asking::State && m_asking != Asking::Nothing)
78-
error = "Peer banned for unexpected status message.";
68+
error << "Peer banned for unexpected status message.";
7969

80-
return error;
70+
return error.str();
8171
}
8272

8373
void EthereumPeer::requestStatus(

0 commit comments

Comments
 (0)