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

Commit c78037c

Browse files
committed
Merge branch 'master' into refactor/hashdb-generic
* 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)
2 parents 4e2e81b + 3d76417 commit c78037c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+419
-279
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ android-armv7:
190190
- triggers
191191
script:
192192
- cargo build --target=armv7-linux-androideabi
193-
- if [ $(arm-linux-androideabi-objdump -x ./target/armv7-linux-androideabi/debug/parity | grep -i 'c++_shared' | wc -l) -ne 0]; then echo "FAIL!!" fi
194193
tags:
195194
- rust-arm
195+
allow_failure: true
196196
artifacts:
197197
paths:
198198
- parity.zip

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore/light/src/net/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use transaction::UnverifiedTransaction;
2222

2323
use io::TimerToken;
24-
use network::{HostInfo, NetworkProtocolHandler, NetworkContext, PeerId};
24+
use network::{NetworkProtocolHandler, NetworkContext, PeerId};
2525
use rlp::{RlpStream, Rlp};
2626
use ethereum_types::{H256, U256};
2727
use kvdb::DBValue;
@@ -1082,7 +1082,7 @@ fn punish(peer: PeerId, io: &IoContext, e: Error) {
10821082
}
10831083

10841084
impl NetworkProtocolHandler for LightProtocol {
1085-
fn initialize(&self, io: &NetworkContext, _host_info: &HostInfo) {
1085+
fn initialize(&self, io: &NetworkContext) {
10861086
io.register_timer(TIMEOUT, TIMEOUT_INTERVAL)
10871087
.expect("Error registering sync timer.");
10881088
io.register_timer(TICK_TIMEOUT, TICK_TIMEOUT_INTERVAL)

ethcore/src/miner/miner.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,12 @@ impl Miner {
290290
{
291291
self.sealing.lock().queue
292292
.peek_last_ref()
293-
.and_then(|b| if b.block().header().number() > latest_block_number {
294-
Some(f(b))
295-
} else {
296-
None
293+
.and_then(|b| {
294+
if b.block().header().number() > latest_block_number {
295+
Some(f(b))
296+
} else {
297+
None
298+
}
297299
})
298300
}
299301

ethcore/sync/src/api.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
use std::sync::Arc;
1818
use std::collections::{HashMap, BTreeMap};
1919
use std::io;
20+
use std::ops::Range;
2021
use std::time::Duration;
2122
use bytes::Bytes;
2223
use devp2p::NetworkService;
23-
use network::{NetworkProtocolHandler, NetworkContext, HostInfo, PeerId, ProtocolId,
24+
use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
2425
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error, ErrorKind,
2526
ConnectionFilter};
2627
use ethereum_types::{H256, H512, U256};
@@ -370,7 +371,7 @@ struct SyncProtocolHandler {
370371
}
371372

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

454455
fn start(&self) {
455-
match self.network.start().map_err(Into::into) {
456-
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.")),
457-
Err(err) => warn!("Error starting network: {}", err),
456+
match self.network.start() {
457+
Err((err, listen_address)) => {
458+
match err.into() {
459+
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
460+
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."))
461+
},
462+
err => warn!("Error starting network: {}", err),
463+
}
464+
},
458465
_ => {},
459466
}
467+
460468
self.network.register_protocol(self.eth_handler.clone(), self.subprotocol_name, &[ETH_PROTOCOL_VERSION_62, ETH_PROTOCOL_VERSION_63])
461469
.unwrap_or_else(|e| warn!("Error registering ethereum protocol: {:?}", e));
462470
// register the warp sync subprotocol
@@ -520,8 +528,10 @@ pub trait ManageNetwork : Send + Sync {
520528
fn start_network(&self);
521529
/// Stop network
522530
fn stop_network(&self);
523-
/// Query the current configuration of the network
524-
fn network_config(&self) -> NetworkConfiguration;
531+
/// Returns the minimum and maximum peers.
532+
/// Note that `range.end` is *exclusive*.
533+
// TODO: Range should be changed to RangeInclusive once stable (https://github.com/rust-lang/rust/pull/50758)
534+
fn num_peers_range(&self) -> Range<u32>;
525535
/// Get network context for protocol.
526536
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext));
527537
}
@@ -561,8 +571,8 @@ impl ManageNetwork for EthSync {
561571
self.stop();
562572
}
563573

564-
fn network_config(&self) -> NetworkConfiguration {
565-
NetworkConfiguration::from(self.network.config().clone())
574+
fn num_peers_range(&self) -> Range<u32> {
575+
self.network.num_peers_range()
566576
}
567577

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

817827
fn start_network(&self) {
818-
match self.network.start().map_err(Into::into) {
819-
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => {
820-
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."))
821-
}
822-
Err(err) => warn!("Error starting network: {}", err),
828+
match self.network.start() {
829+
Err((err, listen_address)) => {
830+
match err.into() {
831+
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
832+
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."))
833+
},
834+
err => warn!("Error starting network: {}", err),
835+
}
836+
},
823837
_ => {},
824838
}
825839

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

839-
fn network_config(&self) -> NetworkConfiguration {
840-
NetworkConfiguration::from(self.network.config().clone())
853+
fn num_peers_range(&self) -> Range<u32> {
854+
self.network.num_peers_range()
841855
}
842856

843857
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext)) {
@@ -848,12 +862,13 @@ impl ManageNetwork for LightSync {
848862
impl LightSyncProvider for LightSync {
849863
fn peer_numbers(&self) -> PeerNumbers {
850864
let (connected, active) = self.proto.peer_count();
851-
let config = self.network_config();
865+
let peers_range = self.num_peers_range();
866+
debug_assert!(peers_range.end > peers_range.start);
852867
PeerNumbers {
853868
connected: connected,
854869
active: active,
855-
max: config.max_peers as usize,
856-
min: config.min_peers as usize,
870+
max: peers_range.end as usize - 1,
871+
min: peers_range.start as usize,
857872
}
858873
}
859874

ethcore/sync/src/chain/handler.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,6 @@ impl SyncHandler {
332332
Ok(())
333333
}
334334

335-
fn on_peer_confirmed(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId) {
336-
{
337-
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
338-
peer.confirmation = ForkConfirmation::Confirmed;
339-
}
340-
sync.sync_peer(io, peer_id, false);
341-
}
342-
343335
fn on_peer_fork_header(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId, r: &Rlp) -> Result<(), PacketDecodeError> {
344336
{
345337
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
@@ -349,24 +341,27 @@ impl SyncHandler {
349341

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

356-
let header = r.at(0)?.as_raw();
357-
if keccak(&header) != fork_hash {
358-
trace!(target: "sync", "{}: Fork mismatch", peer_id);
359-
io.disable_peer(peer_id);
360-
return Ok(());
361-
}
346+
} else {
347+
let header = r.at(0)?.as_raw();
348+
if keccak(&header) != fork_hash {
349+
trace!(target: "sync", "{}: Fork mismatch", peer_id);
350+
io.disable_peer(peer_id);
351+
return Ok(());
352+
}
353+
354+
trace!(target: "sync", "{}: Confirmed peer", peer_id);
355+
peer.confirmation = ForkConfirmation::Confirmed;
362356

363-
trace!(target: "sync", "{}: Confirmed peer", peer_id);
364-
if !io.chain_overlay().read().contains_key(&fork_number) {
365-
trace!(target: "sync", "Inserting (fork) block {} header", fork_number);
366-
io.chain_overlay().write().insert(fork_number, header.to_vec());
357+
if !io.chain_overlay().read().contains_key(&fork_number) {
358+
trace!(target: "sync", "Inserting (fork) block {} header", fork_number);
359+
io.chain_overlay().write().insert(fork_number, header.to_vec());
360+
}
367361
}
368362
}
369-
SyncHandler::on_peer_confirmed(sync, io, peer_id);
363+
364+
sync.sync_peer(io, peer_id, false);
370365
return Ok(());
371366
}
372367

@@ -686,7 +681,9 @@ impl SyncHandler {
686681
SyncRequester::request_fork_header(sync, io, peer_id, fork_block);
687682
},
688683
_ => {
689-
SyncHandler::on_peer_confirmed(sync, io, peer_id);
684+
// when there's no `fork_block` defined we initialize the peer with
685+
// `confirmation: ForkConfirmation::Confirmed`.
686+
sync.sync_peer(io, peer_id, false);
690687
}
691688
}
692689

ethcore/sync/src/chain/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ pub enum BlockSet {
294294
pub enum ForkConfirmation {
295295
/// Fork block confirmation pending.
296296
Unconfirmed,
297+
/// Peer's chain is too short to confirm the fork.
298+
TooShort,
297299
/// Fork is confirmed.
298300
Confirmed,
299301
}

parity/cli/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ usage! {
240240
{
241241
// Global flags and arguments
242242
["Operating Options"]
243-
FLAG flag_public_node: (bool) = false, or |c: &Config| c.parity.as_ref()?.public_node.clone(),
244-
"--public-node",
245-
"Start Parity as a public web server. Account storage and transaction signing will be delegated to the UI.",
246-
247243
FLAG flag_no_download: (bool) = false, or |c: &Config| c.parity.as_ref()?.no_download.clone(),
248244
"--no-download",
249245
"Normally new releases will be downloaded ready for updating. This disables it. Not recommended.",
@@ -948,6 +944,10 @@ usage! {
948944
"--rpc",
949945
"Does nothing; JSON-RPC is on by default now.",
950946

947+
FLAG flag_public_node: (bool) = false, or |_| None,
948+
"--public-node",
949+
"Does nothing; Public node is removed from Parity.",
950+
951951
ARG arg_dapps_port: (Option<u16>) = None, or |c: &Config| c.dapps.as_ref()?.port.clone(),
952952
"--dapps-port=[PORT]",
953953
"Dapps server is merged with RPC server. Use --jsonrpc-port.",
@@ -1070,7 +1070,6 @@ struct Operating {
10701070
auto_update_delay: Option<u16>,
10711071
auto_update_check_frequency: Option<u16>,
10721072
release_track: Option<String>,
1073-
public_node: Option<bool>,
10741073
no_download: Option<bool>,
10751074
no_consensus: Option<bool>,
10761075
chain: Option<String>,
@@ -1081,6 +1080,9 @@ struct Operating {
10811080
light: Option<bool>,
10821081
no_persistent_txqueue: Option<bool>,
10831082
no_hardcoded_sync: Option<bool>,
1083+
1084+
#[serde(rename="public_node")]
1085+
_legacy_public_node: Option<bool>,
10841086
}
10851087

10861088
#[derive(Default, Debug, PartialEq, Deserialize)]
@@ -1797,7 +1799,6 @@ mod tests {
17971799
auto_update_delay: None,
17981800
auto_update_check_frequency: None,
17991801
release_track: None,
1800-
public_node: None,
18011802
no_download: None,
18021803
no_consensus: None,
18031804
chain: Some("./chain.json".into()),
@@ -1808,6 +1809,7 @@ mod tests {
18081809
light: None,
18091810
no_hardcoded_sync: None,
18101811
no_persistent_txqueue: None,
1812+
_legacy_public_node: None,
18111813
}),
18121814
account: Some(Account {
18131815
unlock: Some(vec!["0x1".into(), "0x2".into(), "0x3".into()]),

parity/configuration.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use ethcore::verification::queue::VerifierSettings;
3535
use miner::pool;
3636

3737
use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration, UiConfiguration};
38-
use rpc_apis::ApiSet;
3938
use parity_rpc::NetworkSettings;
4039
use cache::CacheConfig;
4140
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};
@@ -138,7 +137,6 @@ impl Configuration {
138137
let fat_db = self.args.arg_fat_db.parse()?;
139138
let compaction = self.args.arg_db_compaction.parse()?;
140139
let wal = !self.args.flag_fast_and_loose;
141-
let public_node = self.args.flag_public_node;
142140
let warp_sync = !self.args.flag_no_warp;
143141
let geth_compatibility = self.args.flag_geth;
144142
let dapps_conf = self.dapps_config();
@@ -379,7 +377,6 @@ impl Configuration {
379377
vm_type: vm_type,
380378
warp_sync: warp_sync,
381379
warp_barrier: self.args.arg_warp_barrier,
382-
public_node: public_node,
383380
geth_compatibility: geth_compatibility,
384381
net_settings: self.network_settings()?,
385382
dapps_conf: dapps_conf,
@@ -914,10 +911,7 @@ impl Configuration {
914911
enabled: self.rpc_enabled(),
915912
interface: self.rpc_interface(),
916913
port: self.args.arg_ports_shift + self.args.arg_rpcport.unwrap_or(self.args.arg_jsonrpc_port),
917-
apis: match self.args.flag_public_node {
918-
false => self.rpc_apis().parse()?,
919-
true => self.rpc_apis().parse::<ApiSet>()?.retain(ApiSet::PublicContext),
920-
},
914+
apis: self.rpc_apis().parse()?,
921915
hosts: self.rpc_hosts(),
922916
cors: self.rpc_cors(),
923917
server_threads: match self.args.arg_jsonrpc_server_threads {
@@ -935,10 +929,8 @@ impl Configuration {
935929
let http = self.http_config()?;
936930

937931
let support_token_api =
938-
// never enabled for public node
939-
!self.args.flag_public_node
940-
// enabled when not unlocking unless the ui is forced
941-
&& (self.args.arg_unlock.is_none() || ui.enabled);
932+
// enabled when not unlocking
933+
self.args.arg_unlock.is_none();
942934

943935
let conf = WsConfiguration {
944936
enabled: self.ws_enabled(),
@@ -1263,6 +1255,7 @@ mod tests {
12631255
use params::SpecType;
12641256
use presale::ImportWallet;
12651257
use rpc::{WsConfiguration, UiConfiguration};
1258+
use rpc_apis::ApiSet;
12661259
use run::RunCmd;
12671260

12681261
use network::{AllowIP, IpFilter};
@@ -1499,7 +1492,6 @@ mod tests {
14991492
ipc_conf: Default::default(),
15001493
net_conf: default_network_config(),
15011494
network_id: None,
1502-
public_node: false,
15031495
warp_sync: true,
15041496
warp_barrier: None,
15051497
acc_conf: Default::default(),

parity/informant.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ impl InformantData for FullNodeInformantData {
145145
let (importing, sync_info) = match (self.sync.as_ref(), self.net.as_ref()) {
146146
(Some(sync), Some(net)) => {
147147
let status = sync.status();
148-
let net_config = net.network_config();
148+
let num_peers_range = net.num_peers_range();
149+
debug_assert!(num_peers_range.end > num_peers_range.start);
149150

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

@@ -154,7 +155,7 @@ impl InformantData for FullNodeInformantData {
154155
last_imported_block_number: status.last_imported_block_number.unwrap_or(chain_info.best_block_number),
155156
last_imported_old_block_number: status.last_imported_old_block_number,
156157
num_peers: status.num_peers,
157-
max_peers: status.current_max_peers(net_config.min_peers, net_config.max_peers),
158+
max_peers: status.current_max_peers(num_peers_range.start, num_peers_range.end - 1),
158159
snapshot_sync: status.is_snapshot_syncing(),
159160
}))
160161
}

0 commit comments

Comments
 (0)