Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into refactor/hashdb-generic
Browse files Browse the repository at this point in the history
* master:
  Remove HostTrait altogether (#8681)
  ethcore-sync: fix connection to peers behind chain fork block (#8710)
  Remove public node settings from cli (#8758)
  Custom Error Messages on ENFILE and EMFILE IO Errors (#8744)
  CI: Fixes for Android Pipeline (#8745)
  Remove NetworkService::config() (#8653)
  Fix XOR distance calculation in discovery Kademlia impl (#8589)
  Print warnings when fetching pending blocks (#8711)
  • Loading branch information
dvdplm committed Jun 4, 2018
2 parents 4e2e81b + 3d76417 commit c78037c
Show file tree
Hide file tree
Showing 45 changed files with 419 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ android-armv7:
- triggers
script:
- cargo build --target=armv7-linux-androideabi
- if [ $(arm-linux-androideabi-objdump -x ./target/armv7-linux-androideabi/debug/parity | grep -i 'c++_shared' | wc -l) -ne 0]; then echo "FAIL!!" fi
tags:
- rust-arm
allow_failure: true
artifacts:
paths:
- parity.zip
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ethcore/light/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use transaction::UnverifiedTransaction;

use io::TimerToken;
use network::{HostInfo, NetworkProtocolHandler, NetworkContext, PeerId};
use network::{NetworkProtocolHandler, NetworkContext, PeerId};
use rlp::{RlpStream, Rlp};
use ethereum_types::{H256, U256};
use kvdb::DBValue;
Expand Down Expand Up @@ -1082,7 +1082,7 @@ fn punish(peer: PeerId, io: &IoContext, e: Error) {
}

impl NetworkProtocolHandler for LightProtocol {
fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
fn initialize(&self, io: &NetworkContext) {
io.register_timer(TIMEOUT, TIMEOUT_INTERVAL)
.expect("Error registering sync timer.");
io.register_timer(TICK_TIMEOUT, TICK_TIMEOUT_INTERVAL)
Expand Down
10 changes: 6 additions & 4 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,12 @@ impl Miner {
{
self.sealing.lock().queue
.peek_last_ref()
.and_then(|b| if b.block().header().number() > latest_block_number {
Some(f(b))
} else {
None
.and_then(|b| {
if b.block().header().number() > latest_block_number {
Some(f(b))
} else {
None
}
})
}

Expand Down
53 changes: 34 additions & 19 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
use std::sync::Arc;
use std::collections::{HashMap, BTreeMap};
use std::io;
use std::ops::Range;
use std::time::Duration;
use bytes::Bytes;
use devp2p::NetworkService;
use network::{NetworkProtocolHandler, NetworkContext, HostInfo, PeerId, ProtocolId,
use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error, ErrorKind,
ConnectionFilter};
use ethereum_types::{H256, H512, U256};
Expand Down Expand Up @@ -370,7 +371,7 @@ struct SyncProtocolHandler {
}

impl NetworkProtocolHandler for SyncProtocolHandler {
fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
fn initialize(&self, io: &NetworkContext) {
if io.subprotocol_name() != WARP_SYNC_PROTOCOL_ID {
io.register_timer(0, Duration::from_secs(1)).expect("Error registering sync timer");
}
Expand Down Expand Up @@ -452,11 +453,18 @@ impl ChainNotify for EthSync {
}

fn start(&self) {
match self.network.start().map_err(Into::into) {
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")),
Err(err) => warn!("Error starting network: {}", err),
match self.network.start() {
Err((err, listen_address)) => {
match err.into() {
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set."))
},
err => warn!("Error starting network: {}", err),
}
},
_ => {},
}

self.network.register_protocol(self.eth_handler.clone(), self.subprotocol_name, &[ETH_PROTOCOL_VERSION_62, ETH_PROTOCOL_VERSION_63])
.unwrap_or_else(|e| warn!("Error registering ethereum protocol: {:?}", e));
// register the warp sync subprotocol
Expand Down Expand Up @@ -520,8 +528,10 @@ pub trait ManageNetwork : Send + Sync {
fn start_network(&self);
/// Stop network
fn stop_network(&self);
/// Query the current configuration of the network
fn network_config(&self) -> NetworkConfiguration;
/// Returns the minimum and maximum peers.
/// Note that `range.end` is *exclusive*.
// TODO: Range should be changed to RangeInclusive once stable (https://github.com/rust-lang/rust/pull/50758)
fn num_peers_range(&self) -> Range<u32>;
/// Get network context for protocol.
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext));
}
Expand Down Expand Up @@ -561,8 +571,8 @@ impl ManageNetwork for EthSync {
self.stop();
}

fn network_config(&self) -> NetworkConfiguration {
NetworkConfiguration::from(self.network.config().clone())
fn num_peers_range(&self) -> Range<u32> {
self.network.num_peers_range()
}

fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext)) {
Expand Down Expand Up @@ -815,11 +825,15 @@ impl ManageNetwork for LightSync {
}

fn start_network(&self) {
match self.network.start().map_err(Into::into) {
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => {
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set."))
}
Err(err) => warn!("Error starting network: {}", err),
match self.network.start() {
Err((err, listen_address)) => {
match err.into() {
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set."))
},
err => warn!("Error starting network: {}", err),
}
},
_ => {},
}

Expand All @@ -836,8 +850,8 @@ impl ManageNetwork for LightSync {
self.network.stop();
}

fn network_config(&self) -> NetworkConfiguration {
NetworkConfiguration::from(self.network.config().clone())
fn num_peers_range(&self) -> Range<u32> {
self.network.num_peers_range()
}

fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext)) {
Expand All @@ -848,12 +862,13 @@ impl ManageNetwork for LightSync {
impl LightSyncProvider for LightSync {
fn peer_numbers(&self) -> PeerNumbers {
let (connected, active) = self.proto.peer_count();
let config = self.network_config();
let peers_range = self.num_peers_range();
debug_assert!(peers_range.end > peers_range.start);
PeerNumbers {
connected: connected,
active: active,
max: config.max_peers as usize,
min: config.min_peers as usize,
max: peers_range.end as usize - 1,
min: peers_range.start as usize,
}
}

Expand Down
43 changes: 20 additions & 23 deletions ethcore/sync/src/chain/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,6 @@ impl SyncHandler {
Ok(())
}

fn on_peer_confirmed(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId) {
{
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
peer.confirmation = ForkConfirmation::Confirmed;
}
sync.sync_peer(io, peer_id, false);
}

fn on_peer_fork_header(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId, r: &Rlp) -> Result<(), PacketDecodeError> {
{
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
Expand All @@ -349,24 +341,27 @@ impl SyncHandler {

if item_count == 0 || item_count != 1 {
trace!(target: "sync", "{}: Chain is too short to confirm the block", peer_id);
io.disable_peer(peer_id);
return Ok(());
}
peer.confirmation = ForkConfirmation::TooShort;

let header = r.at(0)?.as_raw();
if keccak(&header) != fork_hash {
trace!(target: "sync", "{}: Fork mismatch", peer_id);
io.disable_peer(peer_id);
return Ok(());
}
} else {
let header = r.at(0)?.as_raw();
if keccak(&header) != fork_hash {
trace!(target: "sync", "{}: Fork mismatch", peer_id);
io.disable_peer(peer_id);
return Ok(());
}

trace!(target: "sync", "{}: Confirmed peer", peer_id);
peer.confirmation = ForkConfirmation::Confirmed;

trace!(target: "sync", "{}: Confirmed peer", peer_id);
if !io.chain_overlay().read().contains_key(&fork_number) {
trace!(target: "sync", "Inserting (fork) block {} header", fork_number);
io.chain_overlay().write().insert(fork_number, header.to_vec());
if !io.chain_overlay().read().contains_key(&fork_number) {
trace!(target: "sync", "Inserting (fork) block {} header", fork_number);
io.chain_overlay().write().insert(fork_number, header.to_vec());
}
}
}
SyncHandler::on_peer_confirmed(sync, io, peer_id);

sync.sync_peer(io, peer_id, false);
return Ok(());
}

Expand Down Expand Up @@ -686,7 +681,9 @@ impl SyncHandler {
SyncRequester::request_fork_header(sync, io, peer_id, fork_block);
},
_ => {
SyncHandler::on_peer_confirmed(sync, io, peer_id);
// when there's no `fork_block` defined we initialize the peer with
// `confirmation: ForkConfirmation::Confirmed`.
sync.sync_peer(io, peer_id, false);
}
}

Expand Down
2 changes: 2 additions & 0 deletions ethcore/sync/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ pub enum BlockSet {
pub enum ForkConfirmation {
/// Fork block confirmation pending.
Unconfirmed,
/// Peer's chain is too short to confirm the fork.
TooShort,
/// Fork is confirmed.
Confirmed,
}
Expand Down
14 changes: 8 additions & 6 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ usage! {
{
// Global flags and arguments
["Operating Options"]
FLAG flag_public_node: (bool) = false, or |c: &Config| c.parity.as_ref()?.public_node.clone(),
"--public-node",
"Start Parity as a public web server. Account storage and transaction signing will be delegated to the UI.",

FLAG flag_no_download: (bool) = false, or |c: &Config| c.parity.as_ref()?.no_download.clone(),
"--no-download",
"Normally new releases will be downloaded ready for updating. This disables it. Not recommended.",
Expand Down Expand Up @@ -948,6 +944,10 @@ usage! {
"--rpc",
"Does nothing; JSON-RPC is on by default now.",

FLAG flag_public_node: (bool) = false, or |_| None,
"--public-node",
"Does nothing; Public node is removed from Parity.",

ARG arg_dapps_port: (Option<u16>) = None, or |c: &Config| c.dapps.as_ref()?.port.clone(),
"--dapps-port=[PORT]",
"Dapps server is merged with RPC server. Use --jsonrpc-port.",
Expand Down Expand Up @@ -1070,7 +1070,6 @@ struct Operating {
auto_update_delay: Option<u16>,
auto_update_check_frequency: Option<u16>,
release_track: Option<String>,
public_node: Option<bool>,
no_download: Option<bool>,
no_consensus: Option<bool>,
chain: Option<String>,
Expand All @@ -1081,6 +1080,9 @@ struct Operating {
light: Option<bool>,
no_persistent_txqueue: Option<bool>,
no_hardcoded_sync: Option<bool>,

#[serde(rename="public_node")]
_legacy_public_node: Option<bool>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
Expand Down Expand Up @@ -1797,7 +1799,6 @@ mod tests {
auto_update_delay: None,
auto_update_check_frequency: None,
release_track: None,
public_node: None,
no_download: None,
no_consensus: None,
chain: Some("./chain.json".into()),
Expand All @@ -1808,6 +1809,7 @@ mod tests {
light: None,
no_hardcoded_sync: None,
no_persistent_txqueue: None,
_legacy_public_node: None,
}),
account: Some(Account {
unlock: Some(vec!["0x1".into(), "0x2".into(), "0x3".into()]),
Expand Down
16 changes: 4 additions & 12 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use ethcore::verification::queue::VerifierSettings;
use miner::pool;

use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration, UiConfiguration};
use rpc_apis::ApiSet;
use parity_rpc::NetworkSettings;
use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_queue_strategy, to_queue_penalization, passwords_from_files};
Expand Down Expand Up @@ -138,7 +137,6 @@ impl Configuration {
let fat_db = self.args.arg_fat_db.parse()?;
let compaction = self.args.arg_db_compaction.parse()?;
let wal = !self.args.flag_fast_and_loose;
let public_node = self.args.flag_public_node;
let warp_sync = !self.args.flag_no_warp;
let geth_compatibility = self.args.flag_geth;
let dapps_conf = self.dapps_config();
Expand Down Expand Up @@ -379,7 +377,6 @@ impl Configuration {
vm_type: vm_type,
warp_sync: warp_sync,
warp_barrier: self.args.arg_warp_barrier,
public_node: public_node,
geth_compatibility: geth_compatibility,
net_settings: self.network_settings()?,
dapps_conf: dapps_conf,
Expand Down Expand Up @@ -914,10 +911,7 @@ impl Configuration {
enabled: self.rpc_enabled(),
interface: self.rpc_interface(),
port: self.args.arg_ports_shift + self.args.arg_rpcport.unwrap_or(self.args.arg_jsonrpc_port),
apis: match self.args.flag_public_node {
false => self.rpc_apis().parse()?,
true => self.rpc_apis().parse::<ApiSet>()?.retain(ApiSet::PublicContext),
},
apis: self.rpc_apis().parse()?,
hosts: self.rpc_hosts(),
cors: self.rpc_cors(),
server_threads: match self.args.arg_jsonrpc_server_threads {
Expand All @@ -935,10 +929,8 @@ impl Configuration {
let http = self.http_config()?;

let support_token_api =
// never enabled for public node
!self.args.flag_public_node
// enabled when not unlocking unless the ui is forced
&& (self.args.arg_unlock.is_none() || ui.enabled);
// enabled when not unlocking
self.args.arg_unlock.is_none();

let conf = WsConfiguration {
enabled: self.ws_enabled(),
Expand Down Expand Up @@ -1263,6 +1255,7 @@ mod tests {
use params::SpecType;
use presale::ImportWallet;
use rpc::{WsConfiguration, UiConfiguration};
use rpc_apis::ApiSet;
use run::RunCmd;

use network::{AllowIP, IpFilter};
Expand Down Expand Up @@ -1499,7 +1492,6 @@ mod tests {
ipc_conf: Default::default(),
net_conf: default_network_config(),
network_id: None,
public_node: false,
warp_sync: true,
warp_barrier: None,
acc_conf: Default::default(),
Expand Down
5 changes: 3 additions & 2 deletions parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ impl InformantData for FullNodeInformantData {
let (importing, sync_info) = match (self.sync.as_ref(), self.net.as_ref()) {
(Some(sync), Some(net)) => {
let status = sync.status();
let net_config = net.network_config();
let num_peers_range = net.num_peers_range();
debug_assert!(num_peers_range.end > num_peers_range.start);

cache_sizes.insert("sync", status.mem_used);

Expand All @@ -154,7 +155,7 @@ impl InformantData for FullNodeInformantData {
last_imported_block_number: status.last_imported_block_number.unwrap_or(chain_info.best_block_number),
last_imported_old_block_number: status.last_imported_old_block_number,
num_peers: status.num_peers,
max_peers: status.current_max_peers(net_config.min_peers, net_config.max_peers),
max_peers: status.current_max_peers(num_peers_range.start, num_peers_range.end - 1),
snapshot_sync: status.is_snapshot_syncing(),
}))
}
Expand Down
Loading

0 comments on commit c78037c

Please sign in to comment.