From c382fa7eaba8359838a5a854479362254e749f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 17 Mar 2016 12:17:20 +0100 Subject: [PATCH 01/11] Removing invalid transactions from queue --- ethcore/src/client/client.rs | 31 ++++++++++++++++++++++++++----- ethcore/src/client/mod.rs | 4 +++- ethcore/src/client/test_client.rs | 2 +- ethcore/src/tests/client.rs | 2 +- miner/src/miner.rs | 15 ++++++++++++++- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index caa92db97..7818fcdc8 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -391,7 +391,8 @@ impl BlockChainClient for Client where V: Verifier { } // TODO [todr] Should be moved to miner crate eventually. - fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec) -> Option { + fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec) + -> Option<(ClosedBlock, HashSet)> { let engine = self.engine.deref().deref(); let h = self.chain.best_block_hash(); @@ -417,21 +418,41 @@ impl BlockChainClient for Client where V: Verifier { // Add transactions let block_number = b.block().header().number(); + let gas_limit = *b.block().header().gas_limit(); + let mut gas_left = gas_limit; + let mut invalid_transactions = HashSet::new(); + for tx in transactions { + let hash = tx.hash(); + let gas = tx.gas; + // TODO [todr] It seems that calculating gas_left here doesn't really look nice. After moving this function + // to miner crate we should consider rewriting this logic in some better way. + if gas > gas_left { + trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", hash); + continue; + } + let import = b.push_transaction(tx, None); - if let Err(e) = import { - trace!("Error adding transaction to block: number={}. Error: {:?}", block_number, e); + match import { + Err(e) => { + trace!(target: "miner", "Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}", + block_number, hash, e); + invalid_transactions.insert(hash); + }, + Ok(receipt) => { + gas_left = gas_limit - receipt.gas_used; + } } } // And close let b = b.close(); - trace!("Sealing: number={}, hash={}, diff={}", + trace!(target: "miner", "Sealing: number={}, hash={}, diff={}", b.block().header().number(), b.hash(), b.block().header().difficulty() ); - Some(b) + Some((b, invalid_transactions)) } fn block_header(&self, id: BlockId) -> Option { diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 88e07d0b1..198e918f7 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -26,6 +26,7 @@ pub use self::config::{ClientConfig, BlockQueueConfig, BlockChainConfig}; pub use self::ids::{BlockId, TransactionId}; pub use self::test_client::{TestBlockChainClient, EachBlockWith}; +use std::collections::HashSet; use util::bytes::Bytes; use util::hash::{Address, H256, H2048}; use util::numbers::U256; @@ -110,7 +111,8 @@ pub trait BlockChainClient : Sync + Send { // TODO [todr] Should be moved to miner crate eventually. /// Returns ClosedBlock prepared for sealing. - fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec) -> Option; + fn prepare_sealing(&self, author: Address, gas_floor_target: U256, extra_data: Bytes, transactions: Vec) + -> Option<(ClosedBlock, HashSet)>; // TODO [todr] Should be moved to miner crate eventually. /// Attempts to seal given block. Returns `SealedBlock` on success and the same block in case of error. diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 83511b1cc..e351011f2 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -217,7 +217,7 @@ impl BlockChainClient for TestBlockChainClient { unimplemented!(); } - fn prepare_sealing(&self, _author: Address, _gas_floor_target: U256, _extra_data: Bytes, _transactions: Vec) -> Option { + fn prepare_sealing(&self, _author: Address, _gas_floor_target: U256, _extra_data: Bytes, _transactions: Vec) -> Option<(ClosedBlock, HashSet)> { unimplemented!() } diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index d9fae0527..64a2222b1 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -144,7 +144,7 @@ fn can_mine() { let client_result = get_test_client_with_blocks(vec![dummy_blocks[0].clone()]); let client = client_result.reference(); - let b = client.prepare_sealing(Address::default(), x!(31415926), vec![], vec![]).unwrap(); + let b = client.prepare_sealing(Address::default(), x!(31415926), vec![], vec![]).unwrap().0; assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().sha3()); assert!(client.try_seal(b, vec![]).is_ok()); diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 6d5b3086e..776cf7c83 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -132,7 +132,20 @@ impl MinerService for Miner { self.extra_data(), transactions, ); - *self.sealing_block.lock().unwrap() = b; + + match b { + None => { + *self.sealing_block.lock().unwrap() = None + }, + Some((block, invalid_transactions)) => { + let mut queue = self.transaction_queue.lock().unwrap(); + queue.remove_all( + &invalid_transactions.into_iter().collect::>(), + |a: &Address| chain.nonce(a) + ); + *self.sealing_block.lock().unwrap() = Some(block) + } + } } fn sealing_block(&self, chain: &BlockChainClient) -> &Mutex> { From dec69651fddee226bce347893ad4724183ebacbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 17 Mar 2016 13:41:08 +0100 Subject: [PATCH 02/11] Attempting to add all transactions to mined block --- miner/src/miner.rs | 5 +---- miner/src/transaction_queue.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 832dc5d02..7bbde6294 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -125,10 +125,7 @@ impl MinerService for Miner { } fn prepare_sealing(&self, chain: &BlockChainClient) { - let no_of_transactions = 128; - // TODO: should select transactions orm queue according to gas limit of block. - let transactions = self.transaction_queue.lock().unwrap().top_transactions(no_of_transactions); - + let transactions = self.transaction_queue.lock().unwrap().top_transactions(); let b = chain.prepare_sealing( self.author(), self.gas_floor_target(), diff --git a/miner/src/transaction_queue.rs b/miner/src/transaction_queue.rs index a1fc20b0f..71d845e38 100644 --- a/miner/src/transaction_queue.rs +++ b/miner/src/transaction_queue.rs @@ -59,7 +59,7 @@ //! // Check status //! assert_eq!(txq.status().pending, 2); //! // Check top transactions -//! let top = txq.top_transactions(3); +//! let top = txq.top_transactions(); //! assert_eq!(top.len(), 2); //! assert_eq!(top[0], st1); //! assert_eq!(top[1], st2); @@ -69,7 +69,7 @@ //! txq.remove(&st1.hash(), &default_nonce); //! assert_eq!(txq.status().pending, 0); //! assert_eq!(txq.status().future, 1); -//! assert_eq!(txq.top_transactions(3).len(), 0); +//! assert_eq!(txq.top_transactions().len(), 0); //! } //! ``` //! @@ -459,10 +459,9 @@ impl TransactionQueue { // Will be used when mining merged #[allow(dead_code)] /// Returns top transactions from the queue ordered by priority. - pub fn top_transactions(&self, size: usize) -> Vec { + pub fn top_transactions(&self) -> Vec { self.current.by_priority .iter() - .take(size) .map(|t| self.by_hash.get(&t.hash).expect("Transaction Queue Inconsistency")) .map(|t| t.transaction.clone()) .collect() @@ -754,7 +753,7 @@ mod test { txq.add(tx2.clone(), &default_nonce).unwrap(); // then - let top = txq.top_transactions(5); + let top = txq.top_transactions(); assert_eq!(top[0], tx); assert_eq!(top[1], tx2); assert_eq!(top.len(), 2); @@ -793,7 +792,7 @@ mod test { let stats = txq.status(); assert_eq!(stats.pending, 1); assert_eq!(stats.future, 1); - let top = txq.top_transactions(5); + let top = txq.top_transactions(); assert_eq!(top.len(), 1); assert_eq!(top[0], tx); } @@ -920,7 +919,7 @@ mod test { txq.add(tx2.clone(), &default_nonce).unwrap(); // then - let t = txq.top_transactions(2); + let t = txq.top_transactions(); assert_eq!(txq.status().pending, 1); assert_eq!(t.len(), 1); assert_eq!(t[0], tx); @@ -1044,7 +1043,7 @@ mod test { let stats = txq.status(); assert_eq!(stats.pending, 1); assert_eq!(stats.future, 0); - assert_eq!(txq.top_transactions(1)[0].gas_price, U256::from(200)); + assert_eq!(txq.top_transactions()[0].gas_price, U256::from(200)); } #[test] @@ -1074,7 +1073,7 @@ mod test { let stats = txq.status(); assert_eq!(stats.future, 0); assert_eq!(stats.pending, 2); - assert_eq!(txq.top_transactions(2)[1].gas_price, U256::from(200)); + assert_eq!(txq.top_transactions()[1].gas_price, U256::from(200)); } #[test] From c4021a77ca2afee506b1fcb1ff4ab796c33f6a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 17 Mar 2016 14:39:24 +0100 Subject: [PATCH 03/11] Stop adding transactions right after we know that no other will make it to block. --- ethcore/src/client/client.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 7818fcdc8..2c011047d 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -418,26 +418,33 @@ impl BlockChainClient for Client where V: Verifier { // Add transactions let block_number = b.block().header().number(); + let min_tx_gas = U256::from(self.engine.schedule(&b.env_info()).tx_gas); let gas_limit = *b.block().header().gas_limit(); let mut gas_left = gas_limit; let mut invalid_transactions = HashSet::new(); for tx in transactions { - let hash = tx.hash(); - let gas = tx.gas; - // TODO [todr] It seems that calculating gas_left here doesn't really look nice. After moving this function + // Stop early if we are sure that no other transaction will be included + if gas_left < min_tx_gas { + break; + } + + // TODO [todr] It seems that calculating gas_left here doesn't look nice. After moving this function // to miner crate we should consider rewriting this logic in some better way. - if gas > gas_left { - trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", hash); + if tx.gas > gas_left { + trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", tx.hash()); continue; } + // Push transaction to block + let hash = tx.hash(); let import = b.push_transaction(tx, None); match import { Err(e) => { - trace!(target: "miner", "Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}", - block_number, hash, e); invalid_transactions.insert(hash); + trace!(target: "miner", + "Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}", + block_number, hash, e); }, Ok(receipt) => { gas_left = gas_limit - receipt.gas_used; From fece330ca4e2cc31a9a22ea7705033b9e967fb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 17 Mar 2016 15:30:03 +0100 Subject: [PATCH 04/11] Refactoring removing invalid transactions from queue --- miner/src/miner.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 776cf7c83..6be2da512 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -133,19 +133,14 @@ impl MinerService for Miner { transactions, ); - match b { - None => { - *self.sealing_block.lock().unwrap() = None - }, - Some((block, invalid_transactions)) => { - let mut queue = self.transaction_queue.lock().unwrap(); - queue.remove_all( - &invalid_transactions.into_iter().collect::>(), - |a: &Address| chain.nonce(a) - ); - *self.sealing_block.lock().unwrap() = Some(block) - } - } + *self.sealing_block.lock().unwrap() = b.map(|(block, invalid_transactions)| { + let mut queue = self.transaction_queue.lock().unwrap(); + queue.remove_all( + &invalid_transactions.into_iter().collect::>(), + |a: &Address| chain.nonce(a) + ); + block + }); } fn sealing_block(&self, chain: &BlockChainClient) -> &Mutex> { From b1793fcb166ff8f8e49329a37fc621276b4795b3 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 17 Mar 2016 18:41:55 +0100 Subject: [PATCH 05/11] Prettier version wo git dir; Use rustc compile time version --- util/Cargo.toml | 2 +- util/build.rs | 14 ++++++++++++++ util/src/lib.rs | 2 -- util/src/misc.rs | 12 +++++++++--- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/util/Cargo.toml b/util/Cargo.toml index 641036191..ae99ef20b 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -29,7 +29,6 @@ sha3 = { path = "sha3" } serde = "0.7.0" clippy = { version = "0.0.50", optional = true } json-tests = { path = "json-tests" } -rustc_version = "0.1.0" igd = "0.4.2" ethcore-devtools = { path = "../devtools" } libc = "0.2.7" @@ -44,3 +43,4 @@ dev = ["clippy"] [build-dependencies] vergen = "*" +rustc_version = "0.1.0" diff --git a/util/build.rs b/util/build.rs index b0b64a380..f033e52e0 100644 --- a/util/build.rs +++ b/util/build.rs @@ -15,9 +15,23 @@ // along with Parity. If not, see . extern crate vergen; +extern crate rustc_version; use vergen::*; +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::Path; fn main() { vergen(OutputFns::all()).unwrap(); + let out_dir = env::var("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("rustc_version.rs"); + let mut f = File::create(&dest_path).unwrap(); + f.write_all(format!(" + /// Returns compiler version. + pub fn rustc_version() -> &'static str {{ + \"{}\" + }} + ", rustc_version::version()).as_bytes()).unwrap(); } diff --git a/util/src/lib.rs b/util/src/lib.rs index cdc3a3f19..6abf6485d 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -109,9 +109,7 @@ 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; extern crate bigint; extern crate chrono; diff --git a/util/src/misc.rs b/util/src/misc.rs index 8dcd25988..76accf93b 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -20,9 +20,9 @@ use std::fs::File; use common::*; use rlp::{Stream, RlpStream}; use target_info::Target; -use rustc_version; include!(concat!(env!("OUT_DIR"), "/version.rs")); +include!(concat!(env!("OUT_DIR"), "/rustc_version.rs")); #[derive(Debug,Clone,PartialEq,Eq)] /// Diff type for specifying a change (or not). @@ -70,7 +70,13 @@ pub fn contents(name: &str) -> Result { /// Get the standard version string for this software. pub fn version() -> String { - format!("Parity/v{}-unstable-{}-{}/{}-{}-{}/rustc{}", env!("CARGO_PKG_VERSION"), short_sha(), commit_date().replace("-", ""), Target::arch(), Target::os(), Target::env(), rustc_version::version()) + let sha3 = short_sha(); + let sha3_dash = if sha3.is_empty() { "" } else { "-" }; + let commit_date = commit_date().replace("-", ""); + let date_dash = if commit_date.is_empty() { "" } else { "-" }; + let env = Target::env(); + let env_dash = if env.is_empty() { "" } else { "-" }; + format!("Parity/v{}-unstable{}{}{}{}/{}-{}{}{}/rustc{}", env!("CARGO_PKG_VERSION"), sha3_dash, sha3, date_dash, commit_date, Target::arch(), Target::os(), env_dash, env, rustc_version()) } /// Get the standard version data for this software. @@ -82,7 +88,7 @@ pub fn version_data() -> Bytes { u32::from_str(env!("CARGO_PKG_VERSION_PATCH")).unwrap(); s.append(&v); s.append(&"Parity"); - s.append(&format!("{}", rustc_version::version())); + s.append(&format!("{}", rustc_version())); s.append(&&Target::os()[0..2]); s.out() } From a61d1d8d51c9fd3c17c792f3bf4c268e7c8c44a6 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 17 Mar 2016 18:43:01 +0100 Subject: [PATCH 06/11] Indent --- util/build.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/build.rs b/util/build.rs index f033e52e0..1ec89f704 100644 --- a/util/build.rs +++ b/util/build.rs @@ -26,12 +26,12 @@ use std::path::Path; fn main() { vergen(OutputFns::all()).unwrap(); let out_dir = env::var("OUT_DIR").unwrap(); - let dest_path = Path::new(&out_dir).join("rustc_version.rs"); - let mut f = File::create(&dest_path).unwrap(); + let dest_path = Path::new(&out_dir).join("rustc_version.rs"); + let mut f = File::create(&dest_path).unwrap(); f.write_all(format!(" /// Returns compiler version. - pub fn rustc_version() -> &'static str {{ + pub fn rustc_version() -> &'static str {{ \"{}\" - }} - ", rustc_version::version()).as_bytes()).unwrap(); + }} + ", rustc_version::version()).as_bytes()).unwrap(); } From a6bd15d333c25f3ac28ee95c3287f7849f34733d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 18 Mar 2016 09:46:13 +0100 Subject: [PATCH 07/11] Fixing compilation --- miner/src/miner.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 660fc55f9..4448b721b 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -137,7 +137,10 @@ impl MinerService for Miner { let mut queue = self.transaction_queue.lock().unwrap(); queue.remove_all( &invalid_transactions.into_iter().collect::>(), - |a: &Address| chain.nonce(a) + |a: &Address| AccountDetails { + nonce: chain.nonce(a), + balance: chain.balance(a), + } ); block }); From 338e5fadb9c87dac08548996fc364196030c4c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 18 Mar 2016 09:54:05 +0100 Subject: [PATCH 08/11] Bumping clippy --- Cargo.lock | 30 +++++++++++++++++------------- Cargo.toml | 2 +- ethcore/Cargo.toml | 2 +- json/Cargo.toml | 2 +- miner/Cargo.toml | 2 +- rpc/Cargo.toml | 2 +- sync/Cargo.toml | 2 +- util/Cargo.toml | 2 +- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79ca26582..8ef60cbc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ name = "parity" version = "1.1.0" dependencies = [ - "clippy 0.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.54 (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)", @@ -96,11 +96,12 @@ dependencies = [ [[package]] name = "clippy" -version = "0.0.50" +version = "0.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "regex-syntax 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -209,7 +210,7 @@ dependencies = [ name = "ethcore" version = "1.1.0" dependencies = [ - "clippy 0.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.54 (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 1.1.0", @@ -235,7 +236,7 @@ dependencies = [ name = "ethcore-rpc" version = "1.1.0" dependencies = [ - "clippy 0.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.54 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.1.0", "ethcore 1.1.0", "ethcore-util 1.1.0", @@ -259,7 +260,7 @@ dependencies = [ "arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "bigint 0.1.0", "chrono 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.54 (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)", @@ -303,7 +304,7 @@ dependencies = [ name = "ethminer" version = "1.1.0" dependencies = [ - "clippy 0.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.54 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.1.0", "ethcore-util 1.1.0", @@ -317,7 +318,7 @@ dependencies = [ name = "ethsync" version = "1.1.0" dependencies = [ - "clippy 0.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.54 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.1.0", "ethcore-util 1.1.0", @@ -709,11 +710,6 @@ dependencies = [ "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex-syntax" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "regex-syntax" version = "0.3.0" @@ -895,6 +891,14 @@ name = "tiny-keccak" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "toml" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "traitobject" version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml index fd1d16cff..ac097a05f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ fdlimit = { path = "util/fdlimit" } daemonize = "0.2" number_prefix = "0.2" rpassword = "0.1" -clippy = { version = "0.0.50", optional = true } +clippy = { version = "0.0.54", optional = true } ethcore = { path = "ethcore" } ethcore-util = { path = "util" } ethsync = { path = "sync" } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 1d16cc34a..3683222b1 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -17,7 +17,7 @@ ethcore-util = { path = "../util" } evmjit = { path = "../evmjit", optional = true } ethash = { path = "../ethash" } num_cpus = "0.2" -clippy = { version = "0.0.50", optional = true } +clippy = { version = "0.0.54", optional = true } crossbeam = "0.1.5" lazy_static = "0.1" ethcore-devtools = { path = "../devtools" } diff --git a/json/Cargo.toml b/json/Cargo.toml index 61599c331..91f8b8431 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -10,7 +10,7 @@ rustc-serialize = "0.3" serde = "0.7.0" serde_json = "0.7.0" serde_macros = { version = "0.7.0", optional = true } -clippy = { version = "0.0.50", optional = true } +clippy = { version = "0.0.54", optional = true } [build-dependencies] serde_codegen = { version = "0.7.0", optional = true } diff --git a/miner/Cargo.toml b/miner/Cargo.toml index cd56aee9e..2d5bf8e61 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -17,7 +17,7 @@ log = "0.3" env_logger = "0.3" rustc-serialize = "0.3" rayon = "0.3.1" -clippy = { version = "0.0.50", optional = true } +clippy = { version = "0.0.54", optional = true } [features] default = [] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 88b69e82c..ca8004728 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -22,7 +22,7 @@ ethminer = { path = "../miner" } rustc-serialize = "0.3" transient-hashmap = "0.1" serde_macros = { version = "0.7.0", optional = true } -clippy = { version = "0.0.50", optional = true } +clippy = { version = "0.0.54", optional = true } [build-dependencies] serde_codegen = { version = "0.7.0", optional = true } diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 877f4e6c8..91732fea8 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Ethcore Date: Fri, 18 Mar 2016 10:14:19 +0100 Subject: [PATCH 09/11] Fixing warnings --- ethcore/src/evm/ext.rs | 1 + ethcore/src/evm/interpreter.rs | 1 + parity/main.rs | 3 ++- util/src/journaldb/archivedb.rs | 4 +++- util/src/journaldb/earlymergedb.rs | 2 ++ util/src/journaldb/overlayrecentdb.rs | 2 ++ util/src/journaldb/refcounteddb.rs | 10 ++++++---- util/src/misc.rs | 2 +- util/src/network/ip_utils.rs | 6 ++++-- 9 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ethcore/src/evm/ext.rs b/ethcore/src/evm/ext.rs index f4172f10a..4986b12c8 100644 --- a/ethcore/src/evm/ext.rs +++ b/ethcore/src/evm/ext.rs @@ -67,6 +67,7 @@ pub trait Ext { /// Returns Err, if we run out of gas. /// Otherwise returns call_result which contains gas left /// and true if subcall was successfull. + #[cfg_attr(feature="dev", allow(too_many_arguments))] fn call(&mut self, gas: &U256, sender_address: &Address, diff --git a/ethcore/src/evm/interpreter.rs b/ethcore/src/evm/interpreter.rs index 7491321cb..b29fc0d41 100644 --- a/ethcore/src/evm/interpreter.rs +++ b/ethcore/src/evm/interpreter.rs @@ -521,6 +521,7 @@ impl Interpreter { Ok(overflowing!(offset.overflowing_add(size.clone()))) } + #[cfg_attr(feature="dev", allow(too_many_arguments))] fn exec_instruction(&self, gas: Gas, params: &ActionParams, diff --git a/parity/main.rs b/parity/main.rs index b8cc2a0f0..c7e534993 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -370,7 +370,7 @@ impl Configuration { fn init_nodes(&self, spec: &Spec) -> Vec { match self.args.flag_bootnodes { - Some(ref x) if x.len() > 0 => x.split(',').map(|s| { + Some(ref x) if !x.is_empty() => x.split(',').map(|s| { Self::normalize_enode(s).unwrap_or_else(|| { die!("{}: Invalid node address format given for a boot node.", s) }) @@ -409,6 +409,7 @@ impl Configuration { ret } + #[cfg_attr(feature="dev", allow(useless_format))] fn client_config(&self) -> ClientConfig { let mut client_config = ClientConfig::default(); match self.args.flag_cache { diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index 83a80b7c2..76f0ecc50 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -175,6 +175,8 @@ impl JournalDB for ArchiveDB { #[cfg(test)] mod tests { + #![cfg_attr(feature="dev", allow(blacklisted_name))] + use common::*; use super::*; use hashdb::*; @@ -371,7 +373,7 @@ mod tests { jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap(); } } - + #[test] fn reopen_fork() { let mut dir = ::std::env::temp_dir(); diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index 7cb00b993..15dcacd6a 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -527,6 +527,8 @@ impl JournalDB for EarlyMergeDB { #[cfg(test)] mod tests { + #![cfg_attr(feature="dev", allow(blacklisted_name))] + use common::*; use super::*; use super::super::traits::JournalDB; diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index efbd26c3b..102e23407 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -358,6 +358,8 @@ impl HashDB for OverlayRecentDB { #[cfg(test)] mod tests { + #![cfg_attr(feature="dev", allow(blacklisted_name))] + use common::*; use super::*; use hashdb::*; diff --git a/util/src/journaldb/refcounteddb.rs b/util/src/journaldb/refcounteddb.rs index 590964247..a8c3ff12b 100644 --- a/util/src/journaldb/refcounteddb.rs +++ b/util/src/journaldb/refcounteddb.rs @@ -28,7 +28,7 @@ use std::env; /// Implementation of the HashDB trait for a disk-backed database with a memory overlay /// and latent-removal semantics. /// -/// Like OverlayDB, there is a memory overlay; `commit()` must be called in order to +/// Like OverlayDB, there is a memory overlay; `commit()` must be called in order to /// write operations out to disk. Unlike OverlayDB, `remove()` operations do not take effect /// immediately. Rather some age (based on a linear but arbitrary metric) must pass before /// the removals actually take effect. @@ -113,7 +113,7 @@ impl JournalDB for RefCountedDB { } fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, H256)>) -> Result { - // journal format: + // journal format: // [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ] // [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ] // [era, n] => [ ... ] @@ -121,7 +121,7 @@ impl JournalDB for RefCountedDB { // TODO: store last_era, reclaim_period. // when we make a new commit, we journal the inserts and removes. - // for each end_era that we journaled that we are no passing by, + // for each end_era that we journaled that we are no passing by, // we remove all of its removes assuming it is canonical and all // of its inserts otherwise. @@ -147,7 +147,7 @@ impl JournalDB for RefCountedDB { r.append(&self.inserts); r.append(&self.removes); try!(batch.put(&last, r.as_raw())); - + trace!(target: "rcdb", "new journal for time #{}.{} => {}: inserts={:?}, removes={:?}", now, index, id, self.inserts, self.removes); self.inserts.clear(); @@ -194,6 +194,8 @@ impl JournalDB for RefCountedDB { #[cfg(test)] mod tests { + #![cfg_attr(feature="dev", allow(blacklisted_name))] + use common::*; use super::*; use super::super::traits::JournalDB; diff --git a/util/src/misc.rs b/util/src/misc.rs index 76accf93b..159381603 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -88,7 +88,7 @@ pub fn version_data() -> Bytes { u32::from_str(env!("CARGO_PKG_VERSION_PATCH")).unwrap(); s.append(&v); s.append(&"Parity"); - s.append(&format!("{}", rustc_version())); + s.append(&rustc_version()); s.append(&&Target::os()[0..2]); s.out() } diff --git a/util/src/network/ip_utils.rs b/util/src/network/ip_utils.rs index 9696c601d..b37a47064 100644 --- a/util/src/network/ip_utils.rs +++ b/util/src/network/ip_utils.rs @@ -42,7 +42,7 @@ impl SocketAddrExt for Ipv4Addr { fn is_global_s(&self) -> bool { !self.is_private() && !self.is_loopback() && !self.is_link_local() && - !self.is_broadcast() && !self.is_documentation() + !self.is_broadcast() && !self.is_documentation() } } @@ -216,6 +216,8 @@ fn can_map_external_address_or_fail() { #[test] fn ipv4_properties() { + + #![cfg_attr(feature="dev", allow(too_many_arguments))] fn check(octets: &[u8; 4], unspec: bool, loopback: bool, private: bool, link_local: bool, global: bool, multicast: bool, broadcast: bool, documentation: bool) { @@ -262,7 +264,7 @@ fn ipv6_properties() { assert_eq!(ip.is_global_s(), global); } - // unspec loopbk global + // unspec loopbk global check("::", true, false, true); check("::1", false, true, false); } From 942d38fb134f34f37016120080d531d3a7f1b329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 18 Mar 2016 10:22:00 +0100 Subject: [PATCH 10/11] Removing allow dead_code --- miner/src/transaction_queue.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/miner/src/transaction_queue.rs b/miner/src/transaction_queue.rs index 71d845e38..0f2ec6ec7 100644 --- a/miner/src/transaction_queue.rs +++ b/miner/src/transaction_queue.rs @@ -306,8 +306,6 @@ impl TransactionQueue { self.minimal_gas_price = min_gas_price; } - // Will be used when rpc merged - #[allow(dead_code)] /// Returns current status for this queue pub fn status(&self) -> TransactionQueueStatus { TransactionQueueStatus { @@ -456,8 +454,6 @@ impl TransactionQueue { self.future.enforce_limit(&mut self.by_hash); } - // Will be used when mining merged - #[allow(dead_code)] /// Returns top transactions from the queue ordered by priority. pub fn top_transactions(&self) -> Vec { self.current.by_priority From 7d77324765dd0b4f632b80d26b6774c9fd7b244a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 18 Mar 2016 14:22:25 +0100 Subject: [PATCH 11/11] BlockGasLimit taken from push_transaction result --- ethcore/src/client/client.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 2c011047d..c62364dce 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -419,36 +419,28 @@ impl BlockChainClient for Client where V: Verifier { // Add transactions let block_number = b.block().header().number(); let min_tx_gas = U256::from(self.engine.schedule(&b.env_info()).tx_gas); - let gas_limit = *b.block().header().gas_limit(); - let mut gas_left = gas_limit; let mut invalid_transactions = HashSet::new(); for tx in transactions { - // Stop early if we are sure that no other transaction will be included - if gas_left < min_tx_gas { - break; - } - - // TODO [todr] It seems that calculating gas_left here doesn't look nice. After moving this function - // to miner crate we should consider rewriting this logic in some better way. - if tx.gas > gas_left { - trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", tx.hash()); - continue; - } - // Push transaction to block let hash = tx.hash(); let import = b.push_transaction(tx, None); + match import { + Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, .. })) => { + trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", hash); + // Exit early if gas left is smaller then min_tx_gas + if gas_limit - gas_used < min_tx_gas { + break; + } + }, Err(e) => { invalid_transactions.insert(hash); trace!(target: "miner", "Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}", block_number, hash, e); }, - Ok(receipt) => { - gas_left = gas_limit - receipt.gas_used; - } + _ => {} } }