From 7b2cfd1cfb3a9f5e77cfa4a24ae2c9825cc58d06 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 18 Jan 2017 19:10:07 +0100 Subject: [PATCH 1/7] JsonRPC bump for IPC fix --- Cargo.lock | 48 +++++++++++++++++++++---------------------- dapps/Cargo.toml | 4 ++-- rpc/Cargo.toml | 8 ++++---- rpc_client/Cargo.toml | 2 +- signer/Cargo.toml | 2 +- stratum/Cargo.toml | 4 ++-- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02dc3e1e4..e8cd338e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,8 +414,8 @@ dependencies = [ "fetch 0.1.0", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.0-a.0 (git+https://github.com/ethcore/hyper)", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", - "jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", + "jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -583,10 +583,10 @@ dependencies = [ "ethsync 1.5.0", "fetch 0.1.0", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", - "jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git)", - "jsonrpc-ipc-server 0.2.4 (git+https://github.com/ethcore/jsonrpc.git)", - "jsonrpc-macros 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", + "jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", + "jsonrpc-ipc-server 0.2.4 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", + "jsonrpc-macros 0.1.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-reactor 0.1.0", "parity-updater 1.5.0", @@ -611,7 +611,7 @@ dependencies = [ "ethcore-io 1.5.0", "ethcore-rpc 1.5.0", "ethcore-util 1.5.0", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-ui 1.5.0", @@ -630,8 +630,8 @@ dependencies = [ "ethcore-ipc-codegen 1.5.0", "ethcore-ipc-nano 1.5.0", "ethcore-util 1.5.0", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", - "jsonrpc-tcp-server 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", + "jsonrpc-tcp-server 0.1.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (git+https://github.com/ethcore/mio?branch=v0.5.x)", @@ -952,7 +952,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "jsonrpc-core" version = "4.0.0" -source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" +source = "git+https://github.com/ethcore/jsonrpc.git?branch=mio-old#057cc58a849d18933a9cce60a33559c7505bd7ce" dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -964,10 +964,10 @@ dependencies = [ [[package]] name = "jsonrpc-http-server" version = "6.1.1" -source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" +source = "git+https://github.com/ethcore/jsonrpc.git?branch=mio-old#057cc58a849d18933a9cce60a33559c7505bd7ce" dependencies = [ "hyper 0.10.0-a.0 (git+https://github.com/ethcore/hyper)", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -975,11 +975,11 @@ dependencies = [ [[package]] name = "jsonrpc-ipc-server" version = "0.2.4" -source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" +source = "git+https://github.com/ethcore/jsonrpc.git?branch=mio-old#057cc58a849d18933a9cce60a33559c7505bd7ce" dependencies = [ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -990,20 +990,20 @@ dependencies = [ [[package]] name = "jsonrpc-macros" version = "0.1.0" -source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" +source = "git+https://github.com/ethcore/jsonrpc.git?branch=mio-old#057cc58a849d18933a9cce60a33559c7505bd7ce" dependencies = [ - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "serde 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-tcp-server" version = "0.1.0" -source = "git+https://github.com/ethcore/jsonrpc.git#33262d626a294a00c20435dec331058ba65e224a" +source = "git+https://github.com/ethcore/jsonrpc.git?branch=mio-old#057cc58a849d18933a9cce60a33559c7505bd7ce" dependencies = [ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1471,7 +1471,7 @@ dependencies = [ "ethcore-signer 1.5.0", "ethcore-util 1.5.0", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)", + "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2415,11 +2415,11 @@ dependencies = [ "checksum isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7408a548dc0e406b7912d9f84c261cc533c1866e047644a811c133c56041ac0c" "checksum itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "086e1fa5fe48840b1cfdef3a20c7e3115599f8d5c4c87ef32a794a7cdd184d76" "checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" -"checksum jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git)" = "" -"checksum jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git)" = "" -"checksum jsonrpc-ipc-server 0.2.4 (git+https://github.com/ethcore/jsonrpc.git)" = "" -"checksum jsonrpc-macros 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)" = "" -"checksum jsonrpc-tcp-server 0.1.0 (git+https://github.com/ethcore/jsonrpc.git)" = "" +"checksum jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)" = "" +"checksum jsonrpc-http-server 6.1.1 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)" = "" +"checksum jsonrpc-ipc-server 0.2.4 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)" = "" +"checksum jsonrpc-macros 0.1.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)" = "" +"checksum jsonrpc-tcp-server 0.1.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)" = "" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index 5b044fb89..8df25b2d3 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -13,8 +13,8 @@ rand = "0.3" log = "0.3" env_logger = "0.3" futures = "0.1" -jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git" } -jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc.git" } +jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } +jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } hyper = { default-features = false, git = "https://github.com/ethcore/hyper" } unicase = "1.3" url = "1.0" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 9031f6adf..6a0d23e9d 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -18,10 +18,10 @@ time = "0.1" rand = "0.3" semver = "0.5" transient-hashmap = "0.1" -jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git" } -jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc.git" } -jsonrpc-ipc-server = { git = "https://github.com/ethcore/jsonrpc.git" } -jsonrpc-macros = { git = "https://github.com/ethcore/jsonrpc.git" } +jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } +jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } +jsonrpc-ipc-server = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } +jsonrpc-macros = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } ethcore-io = { path = "../util/io" } ethcore-util = { path = "../util" } ethcore = { path = "../ethcore" } diff --git a/rpc_client/Cargo.toml b/rpc_client/Cargo.toml index e5c8e9b12..75034870d 100644 --- a/rpc_client/Cargo.toml +++ b/rpc_client/Cargo.toml @@ -16,7 +16,7 @@ serde = "0.8" serde_json = "0.8" tempdir = "0.3.5" url = "1.2.0" -jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git" } +jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } ws = { git = "https://github.com/ethcore/ws-rs.git", branch = "mio-upstream-stable" } ethcore-rpc = { path = "../rpc" } ethcore-signer = { path = "../signer" } diff --git a/signer/Cargo.toml b/signer/Cargo.toml index abf5d7755..ef7759580 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -12,7 +12,7 @@ rustc_version = "0.1" [dependencies] rand = "0.3.14" -jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git" } +jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } log = "0.3" env_logger = "0.3" parity-dapps-glue = { version = "1.4", optional = true } diff --git a/stratum/Cargo.toml b/stratum/Cargo.toml index daf7aa15c..1b23134fb 100644 --- a/stratum/Cargo.toml +++ b/stratum/Cargo.toml @@ -11,8 +11,8 @@ ethcore-ipc-codegen = { path = "../ipc/codegen" } [dependencies] log = "0.3" -jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git" } -jsonrpc-tcp-server = { git = "https://github.com/ethcore/jsonrpc.git" } +jsonrpc-core = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } +jsonrpc-tcp-server = { git = "https://github.com/ethcore/jsonrpc.git", branch="mio-old" } mio = { git = "https://github.com/ethcore/mio", branch = "v0.5.x" } ethcore-util = { path = "../util" } ethcore-devtools = { path = "../devtools" } From e01636fc341d7d06545ac5945cbba649649f3a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 18 Jan 2017 17:56:21 +0100 Subject: [PATCH 2/7] Fixing etherscan price parsing (#4202) * Fixing etherscan price parsing * Handling all errors --- ethcore/src/miner/miner.rs | 9 ++-- ethcore/src/miner/price_info.rs | 74 ++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 59237ed6a..d5b3b00b6 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -149,7 +149,8 @@ impl GasPriceCalibrator { if Instant::now() >= self.next_calibration { let usd_per_tx = self.options.usd_per_tx; trace!(target: "miner", "Getting price info"); - let price_info = PriceInfo::get(move |price: PriceInfo| { + + PriceInfo::get(move |price: PriceInfo| { trace!(target: "miner", "Price info arrived: {:?}", price); let usd_per_eth = price.ethusd; let wei_per_usd: f32 = 1.0e18 / usd_per_eth; @@ -159,11 +160,7 @@ impl GasPriceCalibrator { set_price(U256::from(wei_per_gas as u64)); }); - if price_info.is_ok() { - self.next_calibration = Instant::now() + self.options.recalibration_period; - } else { - warn!(target: "miner", "Unable to update Ether price."); - } + self.next_calibration = Instant::now() + self.options.recalibration_period; } } } diff --git a/ethcore/src/miner/price_info.rs b/ethcore/src/miner/price_info.rs index 9cd97e287..3f38ffbb2 100644 --- a/ethcore/src/miner/price_info.rs +++ b/ethcore/src/miner/price_info.rs @@ -21,7 +21,7 @@ use std::time::Duration; use std::str::FromStr; use std::sync::mpsc; use hyper::client::{Handler, Request, Response, Client}; -use hyper::{Next, Encoder, Decoder}; +use hyper::{Url, Next, Encoder, Decoder}; use hyper::net::HttpStream; #[derive(Debug)] @@ -29,12 +29,12 @@ pub struct PriceInfo { pub ethusd: f32, } -pub struct SetPriceHandler { +pub struct SetPriceHandler { set_price: F, channel: mpsc::Sender<()>, } -impl Drop for SetPriceHandler { +impl Drop for SetPriceHandler { fn drop(&mut self) { let _ = self.channel.send(()); } @@ -47,37 +47,61 @@ impl Handler for SetPriceH fn on_response_readable(&mut self, r: &mut Decoder) -> Next { let mut body = String::new(); - let _ = r.read_to_string(&mut body).ok() - .and_then(|_| Json::from_str(&body).ok()) - .and_then(|json| json.find_path(&["result", "ethusd"]) - .and_then(|obj| match *obj { - Json::String(ref s) => Some((self.set_price)(PriceInfo { - ethusd: FromStr::from_str(s) - .expect("Etherscan API will always return properly formatted price; qed") - })), - _ => None, - })); + let info = r.read_to_string(&mut body) + .map_err(|e| format!("Unable to read response: {:?}", e)) + .and_then(|_| self.process_response(&body)); + + if let Err(e) = info { + warn!("Failed to auto-update latest ETH price: {:?}", e); + } Next::end() } +} +impl SetPriceHandler { + fn process_response(&self, body: &str) -> Result<(), String> { + let json = Json::from_str(body).map_err(|e| format!("Invalid JSON returned: {:?}", e))?; + let obj = json.find_path(&["result", "ethusd"]).ok_or("USD price not found".to_owned())?; + let ethusd = match *obj { + Json::String(ref s) => FromStr::from_str(s).ok(), + _ => None, + }.ok_or("Unexpected price format.".to_owned())?; + + (self.set_price)(PriceInfo { + ethusd: ethusd, + }); + Ok(()) + } } impl PriceInfo { - pub fn get(set_price: F) -> Result<(), ()> { - // TODO: Handle each error type properly - let client = Client::new().map_err(|_| ())?; + pub fn get(set_price: F) { thread::spawn(move || { - let (tx, rx) = mpsc::channel(); let url = FromStr::from_str("http://api.etherscan.io/api?module=stats&action=ethprice") .expect("string known to be a valid URL; qed"); - let _ = client.request( - url, - SetPriceHandler { - set_price: set_price, - channel: tx, - }).ok().and_then(|_| rx.recv().ok()); - client.close(); + + if let Err(e) = Self::request(url, set_price) { + warn!("Failed to auto-update latest ETH price: {:?}", e); + } }); + } + + fn request(url: Url, set_price: F) -> Result<(), String> { + let (tx, rx) = mpsc::channel(); + let client = Client::new().map_err(|e| format!("Unable to start client: {:?}", e))?; + + client.request( + url, + SetPriceHandler { + set_price: set_price, + channel: tx, + }, + ).map_err(|_| "Request failed.".to_owned())?; + + // Wait for exit + let _ = rx.recv().map_err(|e| format!("Request interrupted: {:?}", e))?; + client.close(); + Ok(()) } } @@ -93,7 +117,7 @@ fn should_get_price_info() { let done = Arc::new((Mutex::new(PriceInfo { ethusd: 0f32 }), Condvar::new())); let rdone = done.clone(); - PriceInfo::get(move |price| { let mut p = rdone.0.lock(); *p = price; rdone.1.notify_one(); }).unwrap(); + PriceInfo::get(move |price| { let mut p = rdone.0.lock(); *p = price; rdone.1.notify_one(); }); let mut p = done.0.lock(); let t = done.1.wait_for(&mut p, Duration::from_millis(10000)); assert!(!t.timed_out()); From 77b14b2736d39e73a517bdd23614dd1fb21e4079 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Wed, 18 Jan 2017 18:45:30 +0100 Subject: [PATCH 3/7] Fixed --base-path on windows (#4193) * Fixed --base-path on windows * Add support for optional args with default text --- parity/cli/mod.rs | 11 +++++++---- parity/cli/usage.rs | 22 ++++++++++++++++++++++ parity/configuration.rs | 15 +++++++++------ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 2c008623a..0802cb67f 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -91,8 +91,6 @@ usage! { flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(), flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(), flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(), - flag_base_path: String = dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(), - flag_db_path: String = dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone(), flag_keys_path: String = "$BASE/keys", or |c: &Config| otry!(c.parity).keys_path.clone(), flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(), @@ -289,6 +287,11 @@ usage! { flag_no_color: bool = false, or |c: &Config| otry!(c.misc).color.map(|c| !c).clone(), } + { + // Values with optional default value. + flag_base_path: Option, display dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone().map(Some), + flag_db_path: Option, display dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone().map(Some), + } } @@ -547,8 +550,8 @@ mod tests { flag_no_download: false, flag_no_consensus: false, flag_chain: "xyz".into(), - flag_base_path: "$HOME/.parity".into(), - flag_db_path: "$HOME/.parity/chains".into(), + flag_base_path: Some("$HOME/.parity".into()), + flag_db_path: Some("$HOME/.parity/chains".into()), flag_keys_path: "$HOME/.parity/keys".into(), flag_identity: "".into(), diff --git a/parity/cli/usage.rs b/parity/cli/usage.rs index 235087168..1f9de6f17 100644 --- a/parity/cli/usage.rs +++ b/parity/cli/usage.rs @@ -43,6 +43,11 @@ macro_rules! usage { $field:ident : $typ:ty = $default:expr, or $from_config:expr, )* } + { + $( + $field_s:ident : $typ_s:ty, display $default_s:expr, or $from_config_s:expr, + )* + } ) => { use toml; use std::{fs, io, process}; @@ -108,6 +113,10 @@ macro_rules! usage { $( pub $field: $typ, )* + + $( + pub $field_s: $typ_s, + )* } impl Default for Args { @@ -120,6 +129,10 @@ macro_rules! usage { $( $field: $default.into(), )* + + $( + $field_s: Default::default(), + )* } } } @@ -132,6 +145,9 @@ macro_rules! usage { $( $field: Option<$typ>, )* + $( + $field_s: Option<$typ_s>, + )* } impl Args { @@ -206,6 +222,9 @@ macro_rules! usage { $( args.$field = self.$field.or_else(|| $from_config(&config)).unwrap_or_else(|| $default.into()); )* + $( + args.$field_s = self.$field_s.or_else(|| $from_config_s(&config)).unwrap_or(None); + )* args } @@ -222,6 +241,9 @@ macro_rules! usage { // "named argument never used" error // $field = $default, )* + $( + $field_s = $default_s, + )* ) } } diff --git a/parity/configuration.rs b/parity/configuration.rs index 42816a823..9a0b8d831 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -35,7 +35,7 @@ use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_pri geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy}; use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras}; use ethcore_logger::Config as LogConfig; -use dir::{Directories, default_hypervisor_path, default_local_path}; +use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path}; use dapps::Configuration as DappsConfiguration; use signer::{Configuration as SignerConfiguration}; use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack}; @@ -734,13 +734,16 @@ impl Configuration { use util::path; let local_path = default_local_path(); - let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_base_path)); - - let db_path = if self.args.flag_datadir.is_some() { - replace_home(&data_path, &self.args.flag_db_path) + let base_path = self.args.flag_base_path.as_ref().map_or_else(|| default_data_path(), |s| s.clone()); + let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&base_path)); + let base_db_path = if self.args.flag_base_path.is_some() && self.args.flag_db_path.is_none() { + // If base_path is set and db_path is not we default to base path subdir instead of LOCAL. + "$BASE/chains" } else { - replace_home_for_db(&data_path, &local_path, &self.args.flag_db_path) + self.args.flag_db_path.as_ref().map_or(dir::CHAINS_PATH, |s| &s) }; + + let db_path = replace_home_for_db(&data_path, &local_path, &base_db_path); let keys_path = replace_home(&data_path, &self.args.flag_keys_path); let dapps_path = replace_home(&data_path, &self.args.flag_dapps_path); let ui_path = replace_home(&data_path, &self.args.flag_ui_path); From 516e16a36bead0f8bc9c03f7eff5dc5bfe9f288b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 18 Jan 2017 19:44:24 +0100 Subject: [PATCH 4/7] Fixing minimal transaction queue price (#4204) * Fixing minimal transaction queue price * Fixing tests --- ethcore/src/client/test_client.rs | 6 +++--- ethcore/src/miner/miner.rs | 23 +++++++++++++---------- parity/configuration.rs | 18 ++++++++++++++---- parity/params.rs | 13 ++++++++++++- parity/run.rs | 3 +++ sync/src/chain.rs | 2 +- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 22e61ab09..06c3054a9 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -242,7 +242,7 @@ impl TestBlockChainClient { value: U256::from(100), data: "3331600055".from_hex().unwrap(), gas: U256::from(100_000), - gas_price: U256::one(), + gas_price: U256::from(200_000_000_000u64), nonce: U256::zero() }; let signed_tx = tx.sign(keypair.secret(), None); @@ -308,11 +308,11 @@ impl TestBlockChainClient { value: U256::from(100), data: "3331600055".from_hex().unwrap(), gas: U256::from(100_000), - gas_price: U256::one(), + gas_price: U256::from(20_000_000_000u64), nonce: U256::zero() }; let signed_tx = tx.sign(keypair.secret(), None); - self.set_balance(signed_tx.sender().unwrap(), 10_000_000.into()); + self.set_balance(signed_tx.sender().unwrap(), 10_000_000_000_000_000_000u64.into()); let res = self.miner.import_external_transactions(self, vec![signed_tx]); let res = res.into_iter().next().unwrap().expect("Successful import"); assert_eq!(res, TransactionImportResult::Current); diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index d5b3b00b6..2f1e80058 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -304,16 +304,6 @@ impl Miner { #[cfg_attr(feature="dev", allow(match_same_arms))] /// Prepares new block for sealing including top transactions from queue. fn prepare_block(&self, chain: &MiningBlockChainClient) -> (ClosedBlock, Option) { - { - trace!(target: "miner", "prepare_block: recalibrating..."); - let txq = self.transaction_queue.clone(); - self.gas_pricer.lock().recalibrate(move |price| { - trace!(target: "miner", "prepare_block: Got gas price! {}", price); - txq.lock().set_minimal_gas_price(price); - }); - trace!(target: "miner", "prepare_block: done recalibration."); - } - let _timer = PerfTimer::new("prepare_block"); let chain_info = chain.chain_info(); let (transactions, mut open_block, original_work_hash) = { @@ -428,6 +418,16 @@ impl Miner { (block, original_work_hash) } + /// Asynchronously updates minimal gas price for transaction queue + pub fn recalibrate_minimal_gas_price(&self) { + debug!(target: "miner", "minimal_gas_price: recalibrating..."); + let txq = self.transaction_queue.clone(); + self.gas_pricer.lock().recalibrate(move |price| { + debug!(target: "miner", "minimal_gas_price: Got gas price! {}", price); + txq.lock().set_minimal_gas_price(price); + }); + } + /// Check is reseal is allowed and necessary. fn requires_reseal(&self, best_block: BlockNumber) -> bool { let has_local_transactions = self.transaction_queue.lock().has_local_pending_transactions(); @@ -1121,6 +1121,9 @@ impl MinerService for Miner { // First update gas limit in transaction queue self.update_gas_limit(chain); + // Update minimal gas price + self.recalibrate_minimal_gas_price(); + // Then import all transactions... { retracted.par_iter() diff --git a/parity/configuration.rs b/parity/configuration.rs index 9a0b8d831..6d23579c1 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -532,22 +532,32 @@ impl Configuration { } fn gas_pricer_config(&self) -> Result { + fn wei_per_gas(usd_per_tx: f32, usd_per_eth: f32) -> U256 { + let wei_per_usd: f32 = 1.0e18 / usd_per_eth; + let gas_per_tx: f32 = 21000.0; + let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx; + U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap() + } + if let Some(d) = self.args.flag_gasprice.as_ref() { return Ok(GasPricerConfig::Fixed(to_u256(d)?)); } let usd_per_tx = to_price(&self.args.flag_usd_per_tx)?; if "auto" == self.args.flag_usd_per_eth.as_str() { + // Just a very rough estimate to avoid accepting + // ZGP transactions before the price is fetched + // if user does not want it. + let last_known_usd_per_eth = 10.0; return Ok(GasPricerConfig::Calibrated { + initial_minimum: wei_per_gas(usd_per_tx, last_known_usd_per_eth), usd_per_tx: usd_per_tx, recalibration_period: to_duration(self.args.flag_price_update_period.as_str())?, }); } let usd_per_eth = to_price(&self.args.flag_usd_per_eth)?; - let wei_per_usd: f32 = 1.0e18 / usd_per_eth; - let gas_per_tx: f32 = 21000.0; - let wei_per_gas: f32 = wei_per_usd * usd_per_tx / gas_per_tx; + let wei_per_gas = wei_per_gas(usd_per_tx, usd_per_eth); info!( "Using a fixed conversion rate of Ξ1 = {} ({} wei/gas)", @@ -555,7 +565,7 @@ impl Configuration { Colour::Yellow.bold().paint(format!("{}", wei_per_gas)) ); - Ok(GasPricerConfig::Fixed(U256::from_dec_str(&format!("{:.0}", wei_per_gas)).unwrap())) + Ok(GasPricerConfig::Fixed(wei_per_gas)) } fn extra_data(&self) -> Result { diff --git a/parity/params.rs b/parity/params.rs index 93d109979..7ef806fb8 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -192,14 +192,25 @@ impl Default for AccountsConfig { pub enum GasPricerConfig { Fixed(U256), Calibrated { + initial_minimum: U256, usd_per_tx: f32, recalibration_period: Duration, } } +impl GasPricerConfig { + pub fn initial_min(&self) -> U256 { + match *self { + GasPricerConfig::Fixed(ref min) => min.clone(), + GasPricerConfig::Calibrated { ref initial_minimum, .. } => initial_minimum.clone(), + } + } +} + impl Default for GasPricerConfig { fn default() -> Self { GasPricerConfig::Calibrated { + initial_minimum: 11904761856u64.into(), usd_per_tx: 0.0025f32, recalibration_period: Duration::from_secs(3600), } @@ -210,7 +221,7 @@ impl Into for GasPricerConfig { fn into(self) -> GasPricer { match self { GasPricerConfig::Fixed(u) => GasPricer::Fixed(u), - GasPricerConfig::Calibrated { usd_per_tx, recalibration_period } => { + GasPricerConfig::Calibrated { usd_per_tx, recalibration_period, .. } => { GasPricer::new_calibrated(GasPriceCalibratorOptions { usd_per_tx: usd_per_tx, recalibration_period: recalibration_period, diff --git a/parity/run.rs b/parity/run.rs index e4c5fca6f..b04118c75 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -236,12 +236,15 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc) -> R spec.engine.register_account_provider(account_provider.clone()); // create miner + let initial_min_gas_price = cmd.gas_pricer.initial_min(); let miner = Miner::new(cmd.miner_options, cmd.gas_pricer.into(), &spec, Some(account_provider.clone())); miner.set_author(cmd.miner_extras.author); miner.set_gas_floor_target(cmd.miner_extras.gas_floor_target); miner.set_gas_ceil_target(cmd.miner_extras.gas_ceil_target); miner.set_extra_data(cmd.miner_extras.extra_data); miner.set_transactions_limit(cmd.miner_extras.transactions_limit); + miner.set_minimal_gas_price(initial_min_gas_price); + miner.recalibrate_minimal_gas_price(); let engine_signer = cmd.miner_extras.engine_signer; if engine_signer != Default::default() { diff --git a/sync/src/chain.rs b/sync/src/chain.rs index d36cc26c9..f3ab5f3b3 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -2775,7 +2775,7 @@ mod tests { // Add some balance to clients and reset nonces for h in &[good_blocks[0], retracted_blocks[0]] { let block = client.block(BlockId::Hash(*h)).unwrap(); - client.set_balance(block.transactions()[0].sender().unwrap(), U256::from(1_000_000_000)); + client.set_balance(block.transactions()[0].sender().unwrap(), U256::from(10_000_000_000_000_000_000u64)); client.set_nonce(block.transactions()[0].sender().unwrap(), U256::from(0)); } From ff3ae33d9959c80205ec6707a95cf4531eaa8178 Mon Sep 17 00:00:00 2001 From: Jannis Redmann Date: Thu, 19 Jan 2017 08:45:32 +0100 Subject: [PATCH 5/7] verification: add mainnet BadgeReg ids (#4190) * verification: mainnet BadgeReg ids * verification: fetch contracts by name * verification: better wording * typo * reregistered badges --- js/src/contracts/badgereg.js | 20 +++++++++++++++++++ .../Verification/GatherData/gatherData.js | 15 +++++++++++++- js/src/modals/Verification/email-store.js | 3 ++- js/src/modals/Verification/sms-store.js | 3 ++- js/src/modals/Verification/store.js | 4 ++-- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/js/src/contracts/badgereg.js b/js/src/contracts/badgereg.js index 0813caa47..b9b10c19f 100644 --- a/js/src/contracts/badgereg.js +++ b/js/src/contracts/badgereg.js @@ -73,6 +73,26 @@ export default class BadgeReg { }); } + fetchCertifierByName (name) { + return this + .getContract() + .then((badgeReg) => { + return badgeReg.instance.fromName.call({}, [ name ]); + }) + .then(([ id, address, owner ]) => { + if (address === ZERO20) { + throw new Error(`Certifier ${name} does not exist.`); + } + + return this.fetchMeta(id) + .then(({ title, icon }) => { + const data = { address, id, name, title, icon }; + this.certifiers[id] = data; + return data; + }); + }); + } + fetchMeta (id) { return this .getContract() diff --git a/js/src/modals/Verification/GatherData/gatherData.js b/js/src/modals/Verification/GatherData/gatherData.js index 888585fcc..2afab1344 100644 --- a/js/src/modals/Verification/GatherData/gatherData.js +++ b/js/src/modals/Verification/GatherData/gatherData.js @@ -115,13 +115,26 @@ export default class GatherData extends Component { if (!fee) { return (

Fetching the fee…

); } + if (fee.eq(0)) { + return ( +
+ +

+ +

+
+ ); + } return (

{ this.contract = new Contract(api, abi).at(address); this.load(); From 096a44d9bfcebf01eaa1c8cf66d74270c2b18235 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 19 Jan 2017 10:24:34 +0100 Subject: [PATCH 6/7] Console now has admin (#4220) Fixes #4210 --- js/src/dapps/static/console.js | 1 + js/src/views/Dapps/builtin.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/js/src/dapps/static/console.js b/js/src/dapps/static/console.js index 41f00aef6..01d60e77a 100755 --- a/js/src/dapps/static/console.js +++ b/js/src/dapps/static/console.js @@ -18,6 +18,7 @@ // TODO: Fix linting issues if (typeof(window.parity) == 'object') + window.api = window.parent.secureApi; window.parity.api.subscribe('eth_blockNumber', function (error, blockNumber) { if (error) { console.log('error', error); diff --git a/js/src/views/Dapps/builtin.json b/js/src/views/Dapps/builtin.json index 477678156..a25ac4f69 100644 --- a/js/src/views/Dapps/builtin.json +++ b/js/src/views/Dapps/builtin.json @@ -81,6 +81,7 @@ "description": "A Javascript development console complete with web3 and parity objects.", "version": "0.3", "author": "Gav Wood ", - "visible": true + "visible": true, + "secure": true } ] From f15a3ca977a4ec5ab07f8f5d8ee45e92fa6b4526 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 19 Jan 2017 10:59:49 +0100 Subject: [PATCH 7/7] Non-secure for DappReg (#4216) --- js/src/dapps/index.js | 2 +- js/src/views/Dapps/builtin.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/js/src/dapps/index.js b/js/src/dapps/index.js index 32e2ececd..584fbb319 100644 --- a/js/src/dapps/index.js +++ b/js/src/dapps/index.js @@ -16,7 +16,7 @@ module.exports = [ { name: 'basiccoin', entry: 'basiccoin.js', title: 'Basic Token Deployment' }, - { name: 'dappreg', entry: 'dappreg.js', title: 'Dapp Registry', secure: true }, + { name: 'dappreg', entry: 'dappreg.js', title: 'Dapp Registry' }, { name: 'githubhint', entry: 'githubhint.js', title: 'GitHub Hint', secure: true }, { name: 'localtx', entry: 'localtx.js', title: 'Local transactions Viewer', secure: true }, { name: 'registry', entry: 'registry.js', title: 'Registry' }, diff --git a/js/src/views/Dapps/builtin.json b/js/src/views/Dapps/builtin.json index a25ac4f69..91c89d08a 100644 --- a/js/src/views/Dapps/builtin.json +++ b/js/src/views/Dapps/builtin.json @@ -62,8 +62,7 @@ "description": "Enables the registration and content management of dapps on the network", "author": "Parity Team ", "version": "1.0.0", - "visible": false, - "secure": true + "visible": false }, { "id": "0x9042323cd85c6576992d211de34b3ecc183f15e4f639aa87859882f839c374e5",