From 7624bcf49ec4eb0e3dccdef8daa51989546b2e4b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 22 Mar 2016 18:43:06 +0100 Subject: [PATCH 1/2] Increase threads to 4. --- parity/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parity/main.rs b/parity/main.rs index e029124c4..946e409bb 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -269,7 +269,9 @@ fn setup_rpc_server( } } } - Some(server.start_http(url, cors_domain, 1)) + // 4 is the number of threads which also happens to be the maximum number of concurrent + // connections our jsonrpc can manage. + Some(server.start_http(url, cors_domain, 4)) } #[cfg(not(feature = "rpc"))] From 0e026ed11ff7e3330c84965c6228d43aeffd298c Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 22 Mar 2016 19:12:17 +0100 Subject: [PATCH 2/2] Fix author reporting. num_cpus for JSONRPC threads. --- Cargo.lock | 1 + Cargo.toml | 1 + miner/src/lib.rs | 8 +++++++- miner/src/miner.rs | 8 ++++++++ parity/main.rs | 5 ++--- rpc/src/v1/impls/eth.rs | 4 ++-- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56bd823c1..14ebabb6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,7 @@ dependencies = [ "ethsync 1.1.0", "fdlimit 0.1.0", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index e468799ea..f281cb854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ time = "0.1" ctrlc = { git = "https://github.com/tomusdrw/rust-ctrlc.git" } fdlimit = { path = "util/fdlimit" } daemonize = "0.2" +num_cpus = "0.2" number_prefix = "0.2" rpassword = "0.1" clippy = { version = "0.0.54", optional = true } diff --git a/miner/src/lib.rs b/miner/src/lib.rs index ca25e3993..06faf057e 100644 --- a/miner/src/lib.rs +++ b/miner/src/lib.rs @@ -65,7 +65,7 @@ pub use transaction_queue::{TransactionQueue, AccountDetails}; pub use miner::{Miner}; use std::sync::Mutex; -use util::{H256, Address, Bytes}; +use util::{H256, Address, FixedHash, Bytes}; use ethcore::client::{BlockChainClient}; use ethcore::block::{ClosedBlock}; use ethcore::error::{Error}; @@ -77,6 +77,12 @@ pub trait MinerService : Send + Sync { /// Returns miner's status. fn status(&self) -> MinerStatus; + /// Get the author that we will seal blocks as. + fn author(&self) -> Address { Address::zero() } + + /// Get the extra_data that we will seal blocks wuth. + fn extra_data(&self) -> Bytes { vec![] } + /// Imports transactions to transaction queue. fn import_transactions(&self, transactions: Vec, fetch_account: T) -> Vec> where T: Fn(&Address) -> AccountDetails; diff --git a/miner/src/miner.rs b/miner/src/miner.rs index e1b314d57..d4f6c8a00 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -146,6 +146,14 @@ impl MinerService for Miner { } } + fn author(&self) -> Address { + *self.author.read().unwrap() + } + + fn extra_data(&self) -> Bytes { + self.extra_data.read().unwrap().clone() + } + fn import_transactions(&self, transactions: Vec, fetch_account: T) -> Vec> where T: Fn(&Address) -> AccountDetails { let mut transaction_queue = self.transaction_queue.lock().unwrap(); diff --git a/parity/main.rs b/parity/main.rs index 946e409bb..731bba9a1 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -20,6 +20,7 @@ #![cfg_attr(feature="dev", feature(plugin))] #![cfg_attr(feature="dev", plugin(clippy))] extern crate docopt; +extern crate num_cpus; extern crate rustc_serialize; extern crate ethcore_util as util; extern crate ethcore; @@ -269,9 +270,7 @@ fn setup_rpc_server( } } } - // 4 is the number of threads which also happens to be the maximum number of concurrent - // connections our jsonrpc can manage. - Some(server.start_http(url, cors_domain, 4)) + Some(server.start_http(url, cors_domain, ::num_cpus::get())) } #[cfg(not(feature = "rpc"))] diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index d7ee478bf..df21623fd 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -168,8 +168,8 @@ impl Eth for EthClient // TODO: do not hardcode author. fn author(&self, params: Params) -> Result { match params { - Params::None => to_value(&Address::new()), - _ => Err(Error::invalid_params()) + Params::None => to_value(&take_weak!(self.miner).author()), + _ => Err(Error::invalid_params()), } }