Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/paritytech/parity into wa…
Browse files Browse the repository at this point in the history
…rp_sync_on_light_client

* 'master' of https://github.com/paritytech/parity:
  CI: Fixes for Android Pipeline (openethereum#8745)
  Remove NetworkService::config() (openethereum#8653)
  Fix XOR distance calculation in discovery Kademlia impl (openethereum#8589)
  Print warnings when fetching pending blocks (openethereum#8711)
  Fix PoW blockchains sealing notifications in chain_new_blocks (openethereum#8656)
  Remove -k/--insecure option from curl installer (openethereum#8719)
  ease tiny-keccak version requirements (1.4.1 -> 1.4) (openethereum#8726)
  bump tinykeccak to 1.4 (openethereum#8728)
  Remove a couple of unnecessary `transmute()` (openethereum#8736)
  Fix some nits using clippy (openethereum#8731)
  Add 'interface' option to cli (openethereum#8699)
  • Loading branch information
ordian committed Jun 1, 2018
2 parents 402b5ac + 27f3f42 commit bee1e5c
Show file tree
Hide file tree
Showing 30 changed files with 368 additions and 197 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ first.
## Simple one-line installer for Mac and Ubuntu
```bash
bash <(curl https://get.parity.io -Lk)
bash <(curl https://get.parity.io -L)
```
The one-line installer always defaults to the latest beta release. To install a stable release, run:
```bash
bash <(curl https://get.parity.io -Lk) -r stable
bash <(curl https://get.parity.io -L) -r stable
```
## Start Parity
Expand Down
5 changes: 2 additions & 3 deletions ethash/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ use seed_compute::SeedHashCompute;
use shared::*;
use std::io;

use std::mem;
use std::{mem, ptr};
use std::path::Path;
use std::ptr;

const MIX_WORDS: usize = ETHASH_MIX_BYTES / 4;
const MIX_NODES: usize = MIX_WORDS / NODE_WORDS;
Expand Down Expand Up @@ -111,7 +110,7 @@ pub fn quick_get_difficulty(header_hash: &H256, nonce: u64, mix_hash: &H256) ->
let mut buf: [u8; 64 + 32] = mem::uninitialized();

ptr::copy_nonoverlapping(header_hash.as_ptr(), buf.as_mut_ptr(), 32);
ptr::copy_nonoverlapping(mem::transmute(&nonce), buf[32..].as_mut_ptr(), 8);
ptr::copy_nonoverlapping(&nonce as *const u64 as *const u8, buf[32..].as_mut_ptr(), 8);

keccak_512::unchecked(buf.as_mut_ptr(), 64, buf.as_ptr(), 40);
ptr::copy_nonoverlapping(mix_hash.as_ptr(), buf[64..].as_mut_ptr(), 32);
Expand Down
2 changes: 1 addition & 1 deletion ethcore/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ ethereum-types = "0.3"
quick-error = "1.2"
ring = "0.12"
rust-crypto = "0.2.36"
tiny-keccak = "1.3"
tiny-keccak = "1.4"

2 changes: 1 addition & 1 deletion ethcore/private-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tiny-keccak = "1.3"
tiny-keccak = "1.4"
url = "1"
2 changes: 1 addition & 1 deletion ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ impl ImportSealedBlock for Client {
route
};
let route = ChainRoute::from([route].as_ref());
self.importer.miner.chain_new_blocks(self, &[h.clone()], &[], route.enacted(), route.retracted(), true);
self.importer.miner.chain_new_blocks(self, &[h.clone()], &[], route.enacted(), route.retracted(), self.engine.seals_internally().is_some());
self.notify(|notify| {
notify.new_blocks(
vec![h.clone()],
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
49 changes: 32 additions & 17 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -453,11 +454,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 @@ -521,8 +529,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 @@ -562,8 +572,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 @@ -821,11 +831,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 @@ -844,8 +858,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 @@ -861,12 +875,13 @@ impl LightSyncProvider for LightSync {
} else {
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
2 changes: 1 addition & 1 deletion ethkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ parity-wordlist = "1.2"
quick-error = "1.2"
rand = "0.4"
rustc-hex = "1.0"
tiny-keccak = "1.3"
tiny-keccak = "1.4"
2 changes: 1 addition & 1 deletion ethstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
rustc-hex = "1.0"
tiny-keccak = "1.3"
tiny-keccak = "1.4"
time = "0.1.34"
itertools = "0.5"
parking_lot = "0.5"
Expand Down
7 changes: 7 additions & 0 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ usage! {
"--port=[PORT]",
"Override the port on which the node should listen.",

ARG arg_interface: (String) = "all", or |c: &Config| c.network.as_ref()?.interface.clone(),
"--interface=[IP]",
"Network interfaces. Valid values are 'all', 'local' or the ip of the interface you want parity to listen to.",

ARG arg_min_peers: (Option<u16>) = None, or |c: &Config| c.network.as_ref()?.min_peers.clone(),
"--min-peers=[NUM]",
"Try to maintain at least NUM peers.",
Expand Down Expand Up @@ -1119,6 +1123,7 @@ struct Network {
warp: Option<bool>,
warp_barrier: Option<u64>,
port: Option<u16>,
interface: Option<String>,
min_peers: Option<u16>,
max_peers: Option<u16>,
snapshot_peers: Option<u16>,
Expand Down Expand Up @@ -1567,6 +1572,7 @@ mod tests {
// -- Networking Options
flag_no_warp: false,
arg_port: 30303u16,
arg_interface: "all".into(),
arg_min_peers: Some(25u16),
arg_max_peers: Some(50u16),
arg_max_pending_peers: 64u16,
Expand Down Expand Up @@ -1823,6 +1829,7 @@ mod tests {
warp: Some(false),
warp_barrier: None,
port: None,
interface: None,
min_peers: Some(10),
max_peers: Some(20),
max_pending_peers: Some(30),
Expand Down
2 changes: 1 addition & 1 deletion parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl Configuration {

fn net_addresses(&self) -> Result<(SocketAddr, Option<SocketAddr>), String> {
let port = self.args.arg_ports_shift + self.args.arg_port;
let listen_address = SocketAddr::new("0.0.0.0".parse().unwrap(), port);
let listen_address = SocketAddr::new(self.interface(&self.args.arg_interface).parse().unwrap(), port);
let public_address = if self.args.arg_nat.starts_with("extip:") {
let host = &self.args.arg_nat[6..];
let host = host.parse().map_err(|_| format!("Invalid host given with `--nat extip:{}`", host))?;
Expand Down
5 changes: 3 additions & 2 deletions parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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 @@ -153,7 +154,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
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tempdir = "0.3"
tiny-keccak = "1.3"
tiny-keccak = "1.4"
tokio-timer = "0.1"
transient-hashmap = "0.4"
itertools = "0.5"
Expand Down
36 changes: 23 additions & 13 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub struct EthClient<C, SN: ?Sized, S: ?Sized, M, EM> where
eip86_transition: u64,
}

#[derive(Debug)]
enum BlockNumberOrId {
Number(BlockNumber),
Id(BlockId),
Expand Down Expand Up @@ -184,29 +185,38 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
let (block, difficulty, extra, is_pending) = match id {
BlockNumberOrId::Number(BlockNumber::Pending) => {
let info = self.client.chain_info();
let pending_block = self.miner.pending_block(info.best_block_number);
let difficulty = {
let latest_difficulty = self.client.block_total_difficulty(BlockId::Latest).expect("blocks in chain have details; qed");
let pending_difficulty = self.miner.pending_block_header(info.best_block_number).map(|header| *header.difficulty());
match self.miner.pending_block(info.best_block_number) {
Some(pending_block) => {
warn!("`Pending` is deprecated and may be removed in future versions.");

if let Some(difficulty) = pending_difficulty {
difficulty + latest_difficulty
} else {
latest_difficulty
}
};
let difficulty = {
let latest_difficulty = self.client.block_total_difficulty(BlockId::Latest).expect("blocks in chain have details; qed");
let pending_difficulty = self.miner.pending_block_header(info.best_block_number).map(|header| *header.difficulty());

if let Some(difficulty) = pending_difficulty {
difficulty + latest_difficulty
} else {
latest_difficulty
}
};

let extra = pending_block.as_ref().map(|b| self.client.engine().extra_info(&b.header));
let extra = self.client.engine().extra_info(&pending_block.header);

(pending_block.map(|b| encoded::Block::new(b.rlp_bytes())), Some(difficulty), extra, true)
(Some(encoded::Block::new(pending_block.rlp_bytes())), Some(difficulty), Some(extra), true)
},
None => {
warn!("`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`");
client_query(BlockId::Latest)
}
}
},

BlockNumberOrId::Number(num) => {
let id = match num {
BlockNumber::Latest => BlockId::Latest,
BlockNumber::Earliest => BlockId::Earliest,
BlockNumber::Num(n) => BlockId::Number(n),
BlockNumber::Pending => unreachable!(), // Already covered
BlockNumber::Pending => unreachable!() // Already covered
};

client_query(id)
Expand Down
5 changes: 3 additions & 2 deletions rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,14 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where

fn net_peers(&self) -> Result<Peers> {
let sync_status = self.sync.status();
let net_config = self.net.network_config();
let num_peers_range = self.net.num_peers_range();
debug_assert!(num_peers_range.end > num_peers_range.start);
let peers = self.sync.peers().into_iter().map(Into::into).collect();

Ok(Peers {
active: sync_status.num_active_peers,
connected: sync_status.num_peers,
max: sync_status.current_max_peers(net_config.min_peers, net_config.max_peers),
max: sync_status.current_max_peers(num_peers_range.start, num_peers_range.end - 1),
peers: peers
})
}
Expand Down
5 changes: 3 additions & 2 deletions rpc/src/v1/tests/mocked/manage_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use sync::{ManageNetwork, NetworkConfiguration};
use std::ops::Range;
use sync::ManageNetwork;
use self::ethcore_network::{ProtocolId, NetworkContext};

extern crate ethcore_network;
Expand All @@ -29,6 +30,6 @@ impl ManageNetwork for TestManageNetwork {
fn add_reserved_peer(&self, _peer: String) -> Result<(), String> { Ok(()) }
fn start_network(&self) {}
fn stop_network(&self) {}
fn network_config(&self) -> NetworkConfiguration { NetworkConfiguration::new_local() }
fn num_peers_range(&self) -> Range<u32> { 25 .. 51 }
fn with_proto_context(&self, _: ProtocolId, _: &mut FnMut(&NetworkContext)) { }
}
2 changes: 1 addition & 1 deletion secret_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde_derive = "1.0"
futures = "0.1"
futures-cpupool = "0.1"
rustc-hex = "1.0"
tiny-keccak = "1.3"
tiny-keccak = "1.4"
tokio = "0.1"
tokio-core = "0.1"
tokio-io = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion util/hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
ethereum-types = "0.3"
tiny-keccak = "1.4.1"
tiny-keccak = "1.4"

[dev-dependencies]
tempdir = "0.3"
2 changes: 1 addition & 1 deletion util/network-devp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ log = "0.3"
mio = "0.6.8"
bytes = "0.4"
rand = "0.4"
tiny-keccak = "1.3"
tiny-keccak = "1.4"
rust-crypto = "0.2.34"
slab = "0.2"
igd = "0.7"
Expand Down
Loading

0 comments on commit bee1e5c

Please sign in to comment.