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

Commit

Permalink
Merge branch 'thread' of github.com:ethcore/parity into thread
Browse files Browse the repository at this point in the history
Conflicts:
	Cargo.toml
	ethcore/src/block_queue.rs
	ethcore/src/blockchain.rs
  • Loading branch information
NikVolf committed Feb 23, 2016
2 parents a1372ff + 778fa92 commit 2389621
Show file tree
Hide file tree
Showing 20 changed files with 230 additions and 107 deletions.
18 changes: 16 additions & 2 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ethcore = { path = "ethcore" }
ethsync = { path = "sync" }
ethcore-rpc = { path = "rpc", optional = true }
fdlimit = { path = "util/fdlimit" }
target_info = "0.1"
daemonize = "0.2"
ethcore-devtools = { path = "devtools" }

Expand All @@ -33,4 +32,4 @@ path = "parity/main.rs"
name = "parity"

[profile.release]
debug = true
debug = false
2 changes: 1 addition & 1 deletion ethcore/src/block_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl QueueSignal {
}

struct Verification {
// All locks must be captured in the order declared here.
unverified: Mutex<VecDeque<UnVerifiedBlock>>,
verified: Mutex<VecDeque<PreVerifiedBlock>>,
verifying: Mutex<VecDeque<VerifyingBlock>>,
Expand Down Expand Up @@ -137,7 +138,6 @@ impl BlockQueue {
.name(format!("Verifier #{}", i))
.spawn(move || {
panic_handler.catch_panic(move || {
lower_thread_priority();
BlockQueue::verify(verification, engine, more_to_verify, ready_signal, deleting, empty)
}).unwrap()
})
Expand Down
4 changes: 4 additions & 0 deletions ethcore/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct CacheManager {
///
/// **Does not do input data verification.**
pub struct BlockChain {
// All locks must be captured in the order declared here.
pref_cache_size: AtomicUsize,
max_cache_size: AtomicUsize,

Expand All @@ -167,6 +168,7 @@ pub struct BlockChain {
blocks_db: DB,

cache_man: RwLock<CacheManager>,
insert_lock: Mutex<()>
}

impl BlockProvider for BlockChain {
Expand Down Expand Up @@ -274,6 +276,7 @@ impl BlockChain {
extras_db: extras_db,
blocks_db: blocks_db,
cache_man: RwLock::new(cache_man),
insert_lock: Mutex::new(()),
};

// load best block
Expand Down Expand Up @@ -436,6 +439,7 @@ impl BlockChain {
return;
}

let _lock = self.insert_lock.lock();
// store block in db
self.blocks_db.put(&hash, &bytes).unwrap();
let (batch, new_best, details) = self.block_to_extras_insert_batch(bytes);
Expand Down
2 changes: 1 addition & 1 deletion install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ function run_installer()
depFound=$((depFound+1))
check "multirust"
isMultirust=true
if [[ $(multirust show-default 2>/dev/null | grep beta | wc -l) == 4 ]]; then
if [[ $(multirust show-default 2>/dev/null | grep beta | wc -l) == 3 ]]; then
depFound=$((depFound+1))
check "rust beta"
isMultirustBeta=true
Expand Down
20 changes: 10 additions & 10 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern crate log as rlog;
extern crate env_logger;
extern crate ctrlc;
extern crate fdlimit;
extern crate target_info;
extern crate daemonize;

#[cfg(feature = "rpc")]
Expand All @@ -51,7 +50,6 @@ use ethcore::ethereum;
use ethcore::blockchain::CacheSize;
use ethsync::EthSync;
use docopt::Docopt;
use target_info::Target;
use daemonize::Daemonize;

const USAGE: &'static str = "
Expand All @@ -76,7 +74,7 @@ Options:
--peers NUM Try to manintain that many peers [default: 25].
--no-discovery Disable new peer discovery.
--upnp Use UPnP to try to figure out the correct network settings.
--node-key KEY Specify node secret key as hex string.
--node-key KEY Specify node secret key, either as 64-character hex string or input to SHA3 operation.
--cache-pref-size BYTES Specify the prefered size of the blockchain cache in bytes [default: 16384].
--cache-max-size BYTES Specify the maximum size of the blockchain cache in bytes [default: 262144].
Expand Down Expand Up @@ -146,14 +144,15 @@ fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>, _url: &str) {

fn print_version() {
println!("\
Parity version {} ({}-{}-{})
Parity
version {}
Copyright 2015, 2016 Ethcore (UK) Limited
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
By Wood/Paronyan/Kotewicz/Drwięga/Volf.\
", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os());
", version());
}

fn die_with_message(msg: &str) -> ! {
Expand Down Expand Up @@ -215,17 +214,17 @@ impl Configuration {
let mut public_address = None;

if let Some(ref a) = self.args.flag_address {
public_address = Some(SocketAddr::from_str(a.as_ref()).expect("Invalid listen/public address given with --address"));
public_address = Some(SocketAddr::from_str(a.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --address", a)));
listen_address = public_address;
}
if listen_address.is_none() {
listen_address = Some(SocketAddr::from_str(self.args.flag_listen_address.as_ref()).expect("Invalid listen address given with --listen-address"));
listen_address = Some(SocketAddr::from_str(self.args.flag_listen_address.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --listen-address", self.args.flag_listen_address)));
}
if let Some(ref a) = self.args.flag_public_address {
if public_address.is_some() {
panic!("Conflicting flags: --address and --public-address");
die!("Conflicting flags provided: --address and --public-address");
}
public_address = Some(SocketAddr::from_str(a.as_ref()).expect("Invalid listen address given with --public-address"));
public_address = Some(SocketAddr::from_str(a.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --public-address", a)));
}
(listen_address, public_address)
}
Expand All @@ -237,7 +236,7 @@ impl Configuration {
let (listen, public) = self.net_addresses();
ret.listen_address = listen;
ret.public_address = public;
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| Secret::from_str(&s).expect("Invalid key string"));
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| Secret::from_str(&s).unwrap_or_else(|_| s.sha3()));
ret.discovery_enabled = !self.args.flag_no_discovery;
ret.ideal_peers = self.args.flag_peers;
let mut net_path = PathBuf::from(&self.path());
Expand Down Expand Up @@ -280,6 +279,7 @@ impl Configuration {

// Setup rpc
if self.args.flag_jsonrpc {
SocketAddr::from_str(&self.args.flag_jsonrpc_url).unwrap_or_else(|_|die!("{}: Invalid JSONRPC listen address given with --jsonrpc-url. Should be of the form 'IP:port'.", self.args.flag_jsonrpc_url));
setup_rpc_server(service.client(), sync.clone(), &self.args.flag_jsonrpc_url);
}

Expand Down
1 change: 0 additions & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ethcore-util = { path = "../util" }
ethcore = { path = "../ethcore" }
ethsync = { path = "../sync" }
clippy = { version = "0.0.42", optional = true }
target_info = "0.1.0"
rustc-serialize = "0.3"
serde_macros = { version = "0.6.13", optional = true }

Expand Down
1 change: 0 additions & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![cfg_attr(nightly, plugin(serde_macros, clippy))]

extern crate rustc_serialize;
extern crate target_info;
extern crate serde;
extern crate serde_json;
extern crate jsonrpc_core;
Expand Down
6 changes: 4 additions & 2 deletions rpc/src/v1/impls/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! Web3 rpc implementation.
use target_info::Target;
use jsonrpc_core::*;
use util::version;
use v1::traits::Web3;

/// Web3 rpc implementation.
Expand All @@ -30,7 +30,9 @@ impl Web3Client {
impl Web3 for Web3Client {
fn client_version(&self, params: Params) -> Result<Value, Error> {
match params {
Params::None => Ok(Value::String(format!("Parity/-/{}/{}-{}-{}/rust1.8-nightly", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os()))),
Params::None => {
Ok(Value::String(version())),
}
_ => Err(Error::invalid_params())
}
}
Expand Down
8 changes: 7 additions & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ license = "GPL-3.0"
name = "ethcore-util"
version = "0.9.99"
authors = ["Ethcore <admin@ethcore.io>"]
build = "build.rs"

[dependencies]
log = "0.3"
Expand All @@ -28,11 +29,16 @@ sha3 = { path = "sha3" }
serde = "0.6.7"
clippy = { version = "0.0.42", optional = true }
json-tests = { path = "json-tests" }
target_info = "0.1.0"
rustc_version = "0.1.0"
igd = "0.4.2"
ethcore-devtools = { path = "../devtools" }
libc = "0.2.7"
vergen = "0.1"
target_info = "0.1"

[features]
default = []
dev = ["clippy"]

[build-dependencies]
vergen = "*"
6 changes: 6 additions & 0 deletions util/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern crate vergen;
use vergen::*;

fn main() {
vergen(OutputFns::all()).unwrap();
}
4 changes: 3 additions & 1 deletion util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
//! cargo build --release
//! ```

extern crate target_info;
extern crate slab;
extern crate rustc_serialize;
extern crate mio;
Expand All @@ -108,6 +107,9 @@ extern crate log as rlog;
extern crate igd;
extern crate ethcore_devtools as devtools;
extern crate libc;
extern crate rustc_version;
extern crate target_info;
extern crate vergen;

pub mod standard;
#[macro_use]
Expand Down
9 changes: 9 additions & 0 deletions util/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

use std::fs::File;
use common::*;
use target_info::Target;
use rustc_version;

include!(concat!(env!("OUT_DIR"), "/version.rs"));

#[derive(Debug,Clone,PartialEq,Eq)]
/// Diff type for specifying a change (or not).
Expand Down Expand Up @@ -62,3 +66,8 @@ pub fn contents(name: &str) -> Result<Bytes, UtilError> {
try!(file.read_to_end(&mut ret));
Ok(ret)
}

/// Get the standard version string for this software.
pub fn version() -> String {
format!("Parity//{}-{}-{}/{}-{}-{}/rustc{}", env!("CARGO_PKG_VERSION"), short_sha(), commit_date().replace("-", ""), Target::arch(), Target::os(), Target::env(), rustc_version::version())
}
36 changes: 28 additions & 8 deletions util/src/network/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,26 @@ impl Connection {
self.socket.peer_addr()
}

/// Clone this connection. Clears the receiving buffer of the returned connection.
pub fn try_clone(&self) -> io::Result<Self> {
Ok(Connection {
token: self.token,
socket: try!(self.socket.try_clone()),
rec_buf: Vec::new(),
rec_size: 0,
send_queue: self.send_queue.clone(),
interest: EventSet::hup() | EventSet::readable(),
stats: self.stats.clone(),
})
}

/// Register this connection with the IO event loop.
pub fn register_socket<Host: Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> io::Result<()> {
trace!(target: "net", "connection register; token={:?}", reg);
event_loop.register(&self.socket, reg, self.interest, PollOpt::edge() | PollOpt::oneshot()).or_else(|e| {
if let Err(e) = event_loop.register(&self.socket, reg, self.interest, PollOpt::edge() | PollOpt::oneshot()) {
debug!("Failed to register {:?}, {:?}", reg, e);
Ok(())
})
}
Ok(())
}

/// Update connection registration. Should be called at the end of the IO handler.
Expand Down Expand Up @@ -265,7 +278,7 @@ impl EncryptedConnection {
}

/// Create an encrypted connection out of the handshake. Consumes a handshake object.
pub fn new(mut handshake: Handshake) -> Result<EncryptedConnection, UtilError> {
pub fn new(handshake: &mut Handshake) -> Result<EncryptedConnection, UtilError> {
let shared = try!(crypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_public));
let mut nonce_material = H512::new();
if handshake.originated {
Expand Down Expand Up @@ -300,9 +313,8 @@ impl EncryptedConnection {
ingress_mac.update(&mac_material);
ingress_mac.update(if handshake.originated { &handshake.ack_cipher } else { &handshake.auth_cipher });

handshake.connection.expect(ENCRYPTED_HEADER_LEN);
Ok(EncryptedConnection {
connection: handshake.connection,
let mut enc = EncryptedConnection {
connection: try!(handshake.connection.try_clone()),
encoder: encoder,
decoder: decoder,
mac_encoder: mac_encoder,
Expand All @@ -311,7 +323,9 @@ impl EncryptedConnection {
read_state: EncryptedConnectionState::Header,
protocol_id: 0,
payload_len: 0
})
};
enc.connection.expect(ENCRYPTED_HEADER_LEN);
Ok(enc)
}

/// Send a packet
Expand Down Expand Up @@ -440,6 +454,12 @@ impl EncryptedConnection {
Ok(())
}

/// Register socket with the event lpop. This should be called at the end of the event loop.
pub fn register_socket<Host:Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> {
try!(self.connection.register_socket(reg, event_loop));
Ok(())
}

/// Update connection registration. This should be called at the end of the event loop.
pub fn update_socket<Host:Handler>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> {
try!(self.connection.update_socket(reg, event_loop));
Expand Down

0 comments on commit 2389621

Please sign in to comment.