From 64d566ff523da2c913138bd4805567dc2682f83a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 22 Feb 2016 13:58:41 +0100 Subject: [PATCH 1/7] Manage final user-input errors. --- parity/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/parity/main.rs b/parity/main.rs index f4b7880ab..07741ee2a 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -214,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) } @@ -236,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()); @@ -279,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); } From 5917290562511487e95a1504ae7e087447d9c9e8 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 22 Feb 2016 13:59:25 +0100 Subject: [PATCH 2/7] Remove unneeded code, fix minor potential issue with length. --- util/src/network/discovery.rs | 3 --- util/src/network/node_table.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/util/src/network/discovery.rs b/util/src/network/discovery.rs index 01d2da52c..e2fd1c269 100644 --- a/util/src/network/discovery.rs +++ b/util/src/network/discovery.rs @@ -276,9 +276,6 @@ impl Discovery { } pub fn writable(&mut self) { - if self.send_queue.is_empty() { - return; - } while !self.send_queue.is_empty() { let data = self.send_queue.pop_front().unwrap(); match self.udp_socket.send_to(&data.payload, &data.address) { diff --git a/util/src/network/node_table.rs b/util/src/network/node_table.rs index ec6bad2aa..868863e8c 100644 --- a/util/src/network/node_table.rs +++ b/util/src/network/node_table.rs @@ -163,7 +163,7 @@ impl Display for Node { impl FromStr for Node { type Err = UtilError; fn from_str(s: &str) -> Result { - let (id, endpoint) = if &s[0..8] == "enode://" && s.len() > 136 && &s[136..137] == "@" { + let (id, endpoint) = if s.len() > 136 && &s[0..8] == "enode://" && &s[136..137] == "@" { (try!(NodeId::from_str(&s[8..136])), try!(NodeEndpoint::from_str(&s[137..]))) } else { From 72d071922341bec2e2ae7ca2c3dc01f3d327b4c2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 22 Feb 2016 18:11:53 +0100 Subject: [PATCH 3/7] Update docs. --- parity/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/main.rs b/parity/main.rs index 07741ee2a..328bfc0e2 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -74,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]. From 60a8b92e107ecad563dfea5d004abd6d2af7f681 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Tue, 23 Feb 2016 10:14:56 +0100 Subject: [PATCH 4/7] Bumping versions. Fixes #496 --- Cargo.lock | 65 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf747f3cc..f87496221 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,7 +3,7 @@ name = "parity" version = "0.9.99" dependencies = [ "clippy 0.0.42 (registry+https://github.com/rust-lang/crates.io-index)", - "ctrlc 1.0.1 (git+https://github.com/tomusdrw/rust-ctrlc.git)", + "ctrlc 1.1.1 (git+https://github.com/tomusdrw/rust-ctrlc.git)", "daemonize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.78 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -72,7 +72,7 @@ name = "clippy" version = "0.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "regex-syntax 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -107,11 +107,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ctrlc" -version = "1.0.1" -source = "git+https://github.com/tomusdrw/rust-ctrlc.git#d8751b66b31d9698cbb11f8ef37155a8211a0683" +version = "1.1.1" +source = "git+https://github.com/tomusdrw/rust-ctrlc.git#f4927770f89eca80ec250911eea3adcbf579ac48" dependencies = [ "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -129,7 +128,7 @@ name = "docopt" version = "0.6.78" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "regex 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -145,7 +144,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -158,7 +157,7 @@ dependencies = [ "libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -180,10 +179,10 @@ dependencies = [ "ethash 0.9.99", "ethcore-devtools 0.9.99", "ethcore-util 0.9.99", - "heapsize 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -208,7 +207,7 @@ dependencies = [ "jsonrpc-core 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "syntex 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -225,9 +224,9 @@ dependencies = [ "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.4 (git+https://github.com/arkpar/rust-secp256k1.git)", "ethcore-devtools 0.9.99", - "heapsize 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "igd 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "json-tests 0.1.0", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -238,7 +237,7 @@ dependencies = [ "rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "sha3 0.1.0", "slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -279,8 +278,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "heapsize" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "hpack" @@ -305,13 +308,13 @@ dependencies = [ "language-tags 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -325,13 +328,13 @@ dependencies = [ "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -342,14 +345,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hyper 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "xmltree 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "itertools" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -365,7 +368,7 @@ name = "jsonrpc-core" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "syntex 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -441,7 +444,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -516,12 +519,10 @@ dependencies = [ [[package]] name = "num_cpus" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -557,18 +558,18 @@ dependencies = [ [[package]] name = "regex" -version = "0.1.51" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -619,7 +620,7 @@ dependencies = [ [[package]] name = "serde" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", @@ -643,7 +644,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -734,7 +735,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicase" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", From c2952b49b429f0c0b4a1cda9cce588fa411ff078 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Tue, 23 Feb 2016 10:47:57 +0100 Subject: [PATCH 5/7] Bumping clippy version Fixes #496 --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- ethcore/Cargo.toml | 2 +- rpc/Cargo.toml | 2 +- sync/Cargo.toml | 4 ++-- util/Cargo.toml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f87496221..779220fb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ name = "parity" version = "0.9.99" dependencies = [ - "clippy 0.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "ctrlc 1.1.1 (git+https://github.com/tomusdrw/rust-ctrlc.git)", "daemonize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -69,7 +69,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clippy" -version = "0.0.42" +version = "0.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "regex-syntax 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -173,7 +173,7 @@ dependencies = [ name = "ethcore" version = "0.9.99" dependencies = [ - "clippy 0.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 0.9.99", @@ -200,7 +200,7 @@ dependencies = [ name = "ethcore-rpc" version = "0.9.99" dependencies = [ - "clippy 0.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 0.9.99", "ethcore-util 0.9.99", "ethsync 0.9.99", @@ -218,7 +218,7 @@ name = "ethcore-util" version = "0.9.99" dependencies = [ "arrayvec 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -250,7 +250,7 @@ dependencies = [ name = "ethsync" version = "0.9.99" dependencies = [ - "clippy 0.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 0.9.99", "ethcore-util 0.9.99", diff --git a/Cargo.toml b/Cargo.toml index 7fdfc2bee..fbf4b4ca6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ env_logger = "0.3" rustc-serialize = "0.3" docopt = "0.6" ctrlc = { git = "https://github.com/tomusdrw/rust-ctrlc.git" } -clippy = { version = "0.0.42", optional = true } +clippy = { version = "0.0.44", optional = true } ethcore-util = { path = "util" } ethcore = { path = "ethcore" } ethsync = { path = "sync" } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index d34a5478b..660fdb1b2 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -18,7 +18,7 @@ ethcore-util = { path = "../util" } evmjit = { path = "../evmjit", optional = true } ethash = { path = "../ethash" } num_cpus = "0.2" -clippy = { version = "0.0.42", optional = true } +clippy = { version = "0.0.44", optional = true } crossbeam = "0.1.5" lazy_static = "0.1" ethcore-devtools = { path = "../devtools" } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index be06316a4..e36048690 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -16,7 +16,7 @@ jsonrpc-http-server = "1.1" ethcore-util = { path = "../util" } ethcore = { path = "../ethcore" } ethsync = { path = "../sync" } -clippy = { version = "0.0.42", optional = true } +clippy = { version = "0.0.44", optional = true } rustc-serialize = "0.3" serde_macros = { version = "0.6.13", optional = true } diff --git a/sync/Cargo.toml b/sync/Cargo.toml index a99717150..7a81c7d97 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Ethcore Date: Tue, 23 Feb 2016 11:40:23 +0100 Subject: [PATCH 6/7] Fixing clippy warnings. Implementing PartialEq for Uints --- ethcore/src/block.rs | 10 +++++----- ethcore/src/ethereum/ethash.rs | 21 +++++++++------------ ethcore/src/evm/interpreter.rs | 7 ++++--- ethcore/src/lib.rs | 2 +- ethcore/src/transaction.rs | 12 +++++++----- hook.sh | 2 +- parity/main.rs | 10 ++++++---- util/src/keys/directory.rs | 2 +- util/src/nibbleslice.rs | 6 +++--- util/src/uint.rs | 29 ++++++++++++++++++++--------- 10 files changed, 57 insertions(+), 44 deletions(-) diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index b7590143e..a1194c665 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -48,7 +48,7 @@ impl Block { if urlp.at(1).unwrap().iter().find(|i| i.as_val::().is_err()).is_some() { return false; } - + if !urlp.at(2).unwrap().is_list() { return false; } if urlp.at(2).unwrap().iter().find(|i| i.as_val::
().is_err()).is_some() { return false; @@ -61,7 +61,7 @@ impl Block { impl Decodable for Block { fn decode(decoder: &D) -> Result where D: Decoder { if decoder.as_raw().len() != try!(decoder.as_rlp().payload_info()).total() { - return Err(DecoderError::RlpIsTooBig); + return Err(DecoderError::RlpIsTooBig); } let d = decoder.as_rlp(); if d.item_count() != 3 { @@ -87,7 +87,7 @@ pub struct ExecutedBlock { state: State, } -/// A set of references to `ExecutedBlock` fields that are publicly accessible. +/// A set of references to `ExecutedBlock` fields that are publicly accessible. pub struct BlockRefMut<'a> { /// Block header. pub header: &'a Header, @@ -171,7 +171,7 @@ pub struct SealedBlock { impl<'x, 'y> OpenBlock<'x, 'y> { /// Create a new OpenBlock ready for transaction pushing. - pub fn new<'a, 'b>(engine: &'a Engine, db: JournalDB, parent: &Header, last_hashes: &'b LastHashes, author: Address, extra_data: Bytes) -> OpenBlock<'a, 'b> { + pub fn new(engine: &'x Engine, db: JournalDB, parent: &Header, last_hashes: &'y LastHashes, author: Address, extra_data: Bytes) -> Self { let mut r = OpenBlock { block: ExecutedBlock::new(State::from_existing(db, parent.state_root().clone(), engine.account_start_nonce())), engine: engine, @@ -284,7 +284,7 @@ impl<'x, 'y> IsBlock for ClosedBlock<'x, 'y> { } impl<'x, 'y> ClosedBlock<'x, 'y> { - fn new<'a, 'b>(open_block: OpenBlock<'a, 'b>, uncle_bytes: Bytes) -> ClosedBlock<'a, 'b> { + fn new(open_block: OpenBlock<'x, 'y>, uncle_bytes: Bytes) -> Self { ClosedBlock { open_block: open_block, uncle_bytes: uncle_bytes, diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index ff6c6ba72..8c411e7f0 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -87,13 +87,10 @@ impl Engine for Ethash { fn schedule(&self, env_info: &EnvInfo) -> Schedule { trace!(target: "client", "Creating schedule. param={:?}, fCML={}", self.spec().engine_params.get("frontierCompatibilityModeLimit"), self.u64_param("frontierCompatibilityModeLimit")); - match env_info.number < self.u64_param("frontierCompatibilityModeLimit") { - true => { - Schedule::new_frontier() - }, - _ => { - Schedule::new_homestead() - }, + if env_info.number < self.u64_param("frontierCompatibilityModeLimit") { + Schedule::new_frontier() + } else { + Schedule::new_homestead() } } @@ -147,7 +144,7 @@ impl Engine for Ethash { } let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty( - &Ethash::to_ethash(header.bare_hash()), + &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64(), &Ethash::to_ethash(header.mix_hash())))); if difficulty < header.difficulty { @@ -189,7 +186,7 @@ impl Engine for Ethash { let min_gas = parent.gas_limit - parent.gas_limit / gas_limit_divisor; let max_gas = parent.gas_limit + parent.gas_limit / gas_limit_divisor; if header.gas_limit <= min_gas || header.gas_limit >= max_gas { - return Err(From::from(BlockError::InvalidGasLimit(OutOfBounds { min: Some(min_gas), max: Some(max_gas), found: header.gas_limit }))); + return Err(From::from(BlockError::InvalidGasLimit(OutOfBounds { min: Some(min_gas), max: Some(max_gas), found: header.gas_limit }))); } Ok(()) } @@ -220,8 +217,8 @@ impl Ethash { let frontier_limit = self.u64_param("frontierCompatibilityModeLimit"); let mut target = if header.number < frontier_limit { if header.timestamp >= parent.timestamp + duration_limit { - parent.difficulty - (parent.difficulty / difficulty_bound_divisor) - } + parent.difficulty - (parent.difficulty / difficulty_bound_divisor) + } else { parent.difficulty + (parent.difficulty / difficulty_bound_divisor) } @@ -243,7 +240,7 @@ impl Ethash { } target } - + fn boundary_to_difficulty(boundary: &H256) -> U256 { U256::from((U512::one() << 256) / x!(U256::from(boundary.as_slice()))) } diff --git a/ethcore/src/evm/interpreter.rs b/ethcore/src/evm/interpreter.rs index e09c37319..7491321cb 100644 --- a/ethcore/src/evm/interpreter.rs +++ b/ethcore/src/evm/interpreter.rs @@ -581,9 +581,10 @@ impl Interpreter { let code_address = stack.pop_back(); let code_address = u256_to_address(&code_address); - let value = match instruction == instructions::DELEGATECALL { - true => None, - false => Some(stack.pop_back()) + let value = if instruction == instructions::DELEGATECALL { + None + } else { + Some(stack.pop_back()) }; let in_off = stack.pop_back(); diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 9deb3a691..3d43fd725 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -22,7 +22,7 @@ // TODO [todr] not really sure #![cfg_attr(feature="dev", allow(needless_range_loop))] // Shorter than if-else -#![cfg_attr(feautre="dev", allow(match_bool))] +#![cfg_attr(feature="dev", allow(match_bool))] // Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref. #![cfg_attr(feature="dev", allow(clone_on_copy))] diff --git a/ethcore/src/transaction.rs b/ethcore/src/transaction.rs index b43c271d3..fc9886a4d 100644 --- a/ethcore/src/transaction.rs +++ b/ethcore/src/transaction.rs @@ -37,10 +37,11 @@ impl Default for Action { impl Decodable for Action { fn decode(decoder: &D) -> Result where D: Decoder { let rlp = decoder.as_rlp(); - match rlp.is_empty() { - true => Ok(Action::Create), - false => Ok(Action::Call(try!(rlp.as_val()))) - } + if rlp.is_empty() { + Ok(Action::Create) + } else { + Ok(Action::Call(try!(rlp.as_val()))) + } } } @@ -79,6 +80,7 @@ impl Transaction { } impl FromJson for SignedTransaction { + #[cfg_attr(feature="dev", allow(single_char_pattern))] fn from_json(json: &Json) -> SignedTransaction { let t = Transaction { nonce: xjson!(&json["nonce"]), @@ -110,7 +112,7 @@ impl FromJson for SignedTransaction { impl Transaction { /// The message hash of the transaction. - pub fn hash(&self) -> H256 { + pub fn hash(&self) -> H256 { let mut stream = RlpStream::new(); self.rlp_append_unsigned_transaction(&mut stream); stream.out().sha3() diff --git a/hook.sh b/hook.sh index bb17f4e4f..106ffe4f0 100755 --- a/hook.sh +++ b/hook.sh @@ -1,3 +1,3 @@ #!/bin/sh -echo "#!/bin/sh\ncargo test -p ethcore" >> ./.git/hooks/pre-push +echo "#!/bin/sh\ncargo test -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity --features dev" > ./.git/hooks/pre-push chmod +x ./.git/hooks/pre-push diff --git a/parity/main.rs b/parity/main.rs index 328bfc0e2..e25933f2d 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -181,7 +181,7 @@ impl Configuration { } fn _keys_path(&self) -> String { - self.args.flag_keys_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()) + self.args.flag_keys_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()) } fn spec(&self) -> Spec { @@ -194,9 +194,10 @@ impl Configuration { } fn normalize_enode(e: &str) -> Option { - match is_valid_node_url(e) { - true => Some(e.to_owned()), - false => None, + if is_valid_node_url(e) { + Some(e.to_owned()) + } else { + None } } @@ -209,6 +210,7 @@ impl Configuration { } } + #[cfg_attr(feature="dev", allow(useless_format))] fn net_addresses(&self) -> (Option, Option) { let mut listen_address = None; let mut public_address = None; diff --git a/util/src/keys/directory.rs b/util/src/keys/directory.rs index bc875db3f..d7db8ac11 100644 --- a/util/src/keys/directory.rs +++ b/util/src/keys/directory.rs @@ -305,7 +305,7 @@ fn uuid_to_string(uuid: &Uuid) -> String { } fn uuid_from_string(s: &str) -> Result { - let parts: Vec<&str> = s.split("-").collect(); + let parts: Vec<&str> = s.split('-').collect(); if parts.len() != 5 { return Err(UtilError::BadSize); } let mut uuid = H128::zero(); diff --git a/util/src/nibbleslice.rs b/util/src/nibbleslice.rs index 047990368..e10def40a 100644 --- a/util/src/nibbleslice.rs +++ b/util/src/nibbleslice.rs @@ -69,13 +69,13 @@ impl<'a> Iterator for NibbleSliceIterator<'a> { impl<'a, 'view> NibbleSlice<'a> where 'a: 'view { /// Create a new nibble slice with the given byte-slice. - pub fn new(data: &[u8]) -> NibbleSlice { NibbleSlice::new_offset(data, 0) } + pub fn new(data: &'a [u8]) -> Self { NibbleSlice::new_offset(data, 0) } /// Create a new nibble slice with the given byte-slice with a nibble offset. - pub fn new_offset(data: &'a [u8], offset: usize) -> NibbleSlice { NibbleSlice{data: data, offset: offset, data_encode_suffix: &b""[..], offset_encode_suffix: 0} } + pub fn new_offset(data: &'a [u8], offset: usize) -> Self { NibbleSlice{data: data, offset: offset, data_encode_suffix: &b""[..], offset_encode_suffix: 0} } /// Create a composed nibble slice; one followed by the other. - pub fn new_composed(a: &'a NibbleSlice, b: &'a NibbleSlice) -> NibbleSlice<'a> { NibbleSlice{data: a.data, offset: a.offset, data_encode_suffix: b.data, offset_encode_suffix: b.offset} } + pub fn new_composed(a: &'a NibbleSlice, b: &'a NibbleSlice) -> Self { NibbleSlice{data: a.data, offset: a.offset, data_encode_suffix: b.data, offset_encode_suffix: b.offset} } /*pub fn new_composed_bytes_offset(a: &NibbleSlice, b: &NibbleSlice) -> (Bytes, usize) { let r: Vec::with_capacity((a.len() + b.len() + 1) / 2); diff --git a/util/src/uint.rs b/util/src/uint.rs index 7206a521e..906bd91d0 100644 --- a/util/src/uint.rs +++ b/util/src/uint.rs @@ -31,7 +31,7 @@ // //! Big unsigned integer types -//! +//! //! Implementation of a various large-but-fixed sized unsigned integer types. //! The functions here are designed to be fast. //! @@ -99,7 +99,7 @@ pub trait Uint: Sized + Default + FromStr + From + FromJson + fmt::Debug + /// Conversion to u64 with overflow checking fn as_u64(&self) -> u64; - + /// Return the least number of bits needed to represent the number fn bits(&self) -> usize; /// Return if specific bit is set @@ -124,7 +124,7 @@ pub trait Uint: Sized + Default + FromStr + From + FromJson + fmt::Debug + /// Multiple this `Uint` with other returning result and possible overflow fn overflowing_mul(self, other: Self) -> (Self, bool); - + /// Divide this `Uint` by other returning result and possible overflow fn overflowing_div(self, other: Self) -> (Self, bool); @@ -133,7 +133,7 @@ pub trait Uint: Sized + Default + FromStr + From + FromJson + fmt::Debug + /// Returns negation of this `Uint` and overflow (always true) fn overflowing_neg(self) -> (Self, bool); - + /// Shifts this `Uint` and returns overflow fn overflowing_shl(self, shift: u32) -> (Self, bool); } @@ -141,7 +141,7 @@ pub trait Uint: Sized + Default + FromStr + From + FromJson + fmt::Debug + macro_rules! construct_uint { ($name:ident, $n_words:expr) => ( /// Little-endian large integer type - #[derive(Copy, Clone, Eq, PartialEq)] + #[derive(Copy, Clone, Eq)] pub struct $name(pub [u64; $n_words]); impl Uint for $name { @@ -175,7 +175,7 @@ macro_rules! construct_uint { fn as_u32(&self) -> u32 { let &$name(ref arr) = self; if (arr[0] & (0xffffffffu64 << 32)) != 0 { - panic!("Integer overflow when casting U256") + panic!("Integer overflow when casting U256") } self.as_u64() as u32 } @@ -186,7 +186,7 @@ macro_rules! construct_uint { let &$name(ref arr) = self; for i in 1..$n_words { if arr[i] != 0 { - panic!("Integer overflow when casting U256") + panic!("Integer overflow when casting U256") } } arr[0] @@ -320,7 +320,7 @@ macro_rules! construct_uint { if b_carry { let ret = overflowing!($name(ret).overflowing_add($name(carry)), overflow); (ret, overflow) - } else { + } else { ($name(ret), overflow) } } @@ -448,7 +448,7 @@ macro_rules! construct_uint { } impl serde::Serialize for $name { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer { let mut hex = "0x".to_owned(); let mut bytes = [0u8; 8 * $n_words]; @@ -791,6 +791,17 @@ macro_rules! construct_uint { } } + impl PartialEq for $name { + fn eq(&self, other: &$name) -> bool { + let &$name(ref me) = self; + let &$name(ref you) = other; + for i in 0..$n_words { + if me[$n_words - 1 - i] != you[$n_words - 1 - i] { return false; } + } + true + } + } + impl Hash for $name { fn hash(&self, state: &mut H) where H: Hasher { unsafe { state.write(::std::slice::from_raw_parts(self.0.as_ptr() as *mut u8, self.0.len() * 8)); } From 3734959f55fbc9967286511aa48af1aa6dece2fa Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Tue, 23 Feb 2016 11:54:10 +0100 Subject: [PATCH 7/7] Deriving PartialEq and disabling clippy warning --- util/src/uint.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/util/src/uint.rs b/util/src/uint.rs index 906bd91d0..6490cbd9b 100644 --- a/util/src/uint.rs +++ b/util/src/uint.rs @@ -141,7 +141,7 @@ pub trait Uint: Sized + Default + FromStr + From + FromJson + fmt::Debug + macro_rules! construct_uint { ($name:ident, $n_words:expr) => ( /// Little-endian large integer type - #[derive(Copy, Clone, Eq)] + #[derive(Copy, Clone, Eq, PartialEq)] pub struct $name(pub [u64; $n_words]); impl Uint for $name { @@ -791,17 +791,7 @@ macro_rules! construct_uint { } } - impl PartialEq for $name { - fn eq(&self, other: &$name) -> bool { - let &$name(ref me) = self; - let &$name(ref you) = other; - for i in 0..$n_words { - if me[$n_words - 1 - i] != you[$n_words - 1 - i] { return false; } - } - true - } - } - + #[cfg_attr(feature="dev", allow(derive_hash_xor_eq))] // We are pretty sure it's ok. impl Hash for $name { fn hash(&self, state: &mut H) where H: Hasher { unsafe { state.write(::std::slice::from_raw_parts(self.0.as_ptr() as *mut u8, self.0.len() * 8)); }