From 7bc340956fb1da67c9e9554950dfa0cbbcf4dfe7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 8 Feb 2016 16:57:57 +0100 Subject: [PATCH 01/14] Correct node id for bootnode. --- ethcore/res/ethereum/frontier.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/res/ethereum/frontier.json b/ethcore/res/ethereum/frontier.json index 4f0a836ff..301441958 100644 --- a/ethcore/res/ethereum/frontier.json +++ b/ethcore/res/ethereum/frontier.json @@ -30,7 +30,7 @@ "enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303", "enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303", "enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303", - "enode://859bbe6926fc161d218f62bd2efe0b4f6980205c00a5b928ccee39c94c440b73a054ece5db36beddd71963fbd296af61ec72a591f72a2299f9a046bd6d6ce1a9@parity-node-zero.ethcore.io:30303" + "enode://248f12bc8b18d5289358085520ac78cd8076485211e6d96ab0bc93d6cd25442db0ce3a937dc404f64f207b0b9aed50e25e98ce32af5ac7cb321ff285b97de485@parity-node-zero.ethcore.io:30303" ], "accounts": { "0000000000000000000000000000000000000001": { "builtin": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, From 1ae7db2e035be7b8611dd4414b570ef4512f58b9 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 8 Feb 2016 23:07:14 +0300 Subject: [PATCH 02/14] coverage & panics avoidance --- ethcore/src/ethereum/ethash.rs | 154 +++++++++++++++++++++++++-------- 1 file changed, 120 insertions(+), 34 deletions(-) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 43e3720d2..c4ebb7e62 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -23,8 +23,6 @@ use spec::*; use engine::*; use evm::Schedule; use evm::Factory; -#[cfg(test)] -use tests::helpers::*; /// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum /// mainnet chains in the Olympic, Frontier and Homestead eras. @@ -49,6 +47,17 @@ impl Ethash { }) } + #[cfg(test)] + fn new_test(spec: Spec) -> Ethash { + Ethash { + spec: spec, + pow: EthashManager::new(), + factory: Factory::default(), + u64_params: RwLock::new(HashMap::new()), + u256_params: RwLock::new(HashMap::new()) + } + } + fn u64_param(&self, name: &str) -> u64 { *self.u64_params.write().unwrap().entry(name.to_owned()).or_insert_with(|| self.spec().engine_params.get(name).map_or(0u64, |a| decode(&a))) @@ -123,6 +132,11 @@ impl Engine for Ethash { fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { // check the seal fields. + if header.seal.len() != self.seal_fields() { + return Err(From::from(BlockError::InvalidSealArity( + Mismatch { expected: self.seal_fields(), found: header.seal.len() } + ))); + } try!(UntrustedRlp::new(&header.seal[0]).as_val::()); try!(UntrustedRlp::new(&header.seal[1]).as_val::()); @@ -242,38 +256,110 @@ impl Header { } } -#[test] -fn on_close_block() { +#[cfg(test)] +mod tests { + extern crate ethash; + + use common::*; + use block::*; + use spec::*; + use engine::*; + use evm::Schedule; + use evm::Factory; + use tests::helpers::*; use super::*; - let engine = new_morden().to_engine().unwrap(); - let genesis_header = engine.spec().genesis_header(); - let mut db_result = get_temp_journal_db(); - let mut db = db_result.take(); - engine.spec().ensure_db_good(&mut db); - let last_hashes = vec![genesis_header.hash()]; - let b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]); - let b = b.close(); - assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap()); + use super::super::new_morden; + + #[test] + fn on_close_block() { + let engine = new_morden().to_engine().unwrap(); + let genesis_header = engine.spec().genesis_header(); + let mut db_result = get_temp_journal_db(); + let mut db = db_result.take(); + engine.spec().ensure_db_good(&mut db); + let last_hashes = vec![genesis_header.hash()]; + let b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]); + let b = b.close(); + assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap()); + } + + #[test] + fn on_close_block_with_uncle() { + let engine = new_morden().to_engine().unwrap(); + let genesis_header = engine.spec().genesis_header(); + let mut db_result = get_temp_journal_db(); + let mut db = db_result.take(); + engine.spec().ensure_db_good(&mut db); + let last_hashes = vec![genesis_header.hash()]; + let mut b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]); + let mut uncle = Header::new(); + let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106"); + uncle.author = uncle_author.clone(); + b.push_uncle(uncle).unwrap(); + + let b = b.close(); + assert_eq!(b.state().balance(&Address::zero()), U256::from_str("478eae0e571ba000").unwrap()); + assert_eq!(b.state().balance(&uncle_author), U256::from_str("3cb71f51fc558000").unwrap()); + } + + #[test] + fn has_valid_metadata() { + let engine = Ethash::new_boxed(new_morden()); + assert!(!engine.name().is_empty()); + assert!(engine.version().major >= 1); + } + + #[test] + fn can_return_params() { + let engine = Ethash::new_test(new_morden()); + assert!(engine.u64_param("durationLimit") > 0); + assert!(engine.u256_param("minimumDifficulty") > U256::zero()); + } + + #[test] + fn can_return_factory() { + let engine = Ethash::new_test(new_morden()); + let factory = engine.vm_factory(); + } + + #[test] + fn can_return_schedule() { + let engine = Ethash::new_test(new_morden()); + let schedule = engine.schedule(&EnvInfo { + number: 10000000, + author: x!(0), + timestamp: 0, + difficulty: x!(0), + last_hashes: vec![], + gas_used: x!(0), + gas_limit: x!(0) + }); + + assert!(schedule.stack_limit > 0); + + let schedule = engine.schedule(&EnvInfo { + number: 100, + author: x!(0), + timestamp: 0, + difficulty: x!(0), + last_hashes: vec![], + gas_used: x!(0), + gas_limit: x!(0) + }); + + assert!(!schedule.have_delegate_call); + } + + #[test] + fn can_do_basic_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let header: Header = Header::default(); + + let verify_result = engine.verify_block_basic(&header, None); + + assert!(!verify_result.is_ok()); + } + + // TODO: difficulty test } -#[test] -fn on_close_block_with_uncle() { - use super::*; - let engine = new_morden().to_engine().unwrap(); - let genesis_header = engine.spec().genesis_header(); - let mut db_result = get_temp_journal_db(); - let mut db = db_result.take(); - engine.spec().ensure_db_good(&mut db); - let last_hashes = vec![genesis_header.hash()]; - let mut b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]); - let mut uncle = Header::new(); - let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106"); - uncle.author = uncle_author.clone(); - b.push_uncle(uncle).unwrap(); - - let b = b.close(); - assert_eq!(b.state().balance(&Address::zero()), U256::from_str("478eae0e571ba000").unwrap()); - assert_eq!(b.state().balance(&uncle_author), U256::from_str("3cb71f51fc558000").unwrap()); -} - -// TODO: difficulty test From 22dd075692ba8304575c2f7ea109a989eae830dd Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 8 Feb 2016 23:43:53 +0300 Subject: [PATCH 03/14] proper fail conditions --- ethcore/src/ethereum/ethash.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index c4ebb7e62..f49725ab3 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -351,13 +351,30 @@ mod tests { } #[test] - fn can_do_basic_verification_fail() { + fn can_do_seal_verification_fail() { let engine = Ethash::new_test(new_morden()); let header: Header = Header::default(); let verify_result = engine.verify_block_basic(&header, None); - assert!(!verify_result.is_ok()); + match verify_result { + Err(Error::Block(BlockError::InvalidSealArity(_))) => {}, + _ => { panic!("should be block difficulty error"); } + } + } + + #[test] + fn can_do_difficulty_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]); + + let verify_result = engine.verify_block_basic(&header, None); + + match verify_result { + Err(Error::Block(BlockError::DifficultyOutOfBounds(_))) => {}, + _ => { panic!("should be block difficulty error"); } + } } // TODO: difficulty test From fc0153a5a46c0f14c8948d57bd4c655e5131af1e Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 9 Feb 2016 00:54:33 +0300 Subject: [PATCH 04/14] returning client to the place it should be, cleanup --- ethcore/src/ethereum/ethash.rs | 23 ++++++++++++++++----- ethcore/src/evm/factory.rs | 2 ++ ethcore/src/executive.rs | 5 ++++- ethcore/src/json_tests/mod.rs | 1 - ethcore/src/{json_tests => tests}/client.rs | 2 +- ethcore/src/tests/helpers.rs | 4 ---- ethcore/src/tests/mod.rs | 1 + 7 files changed, 26 insertions(+), 12 deletions(-) rename ethcore/src/{json_tests => tests}/client.rs (99%) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index f49725ab3..7d99a456a 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -262,10 +262,7 @@ mod tests { use common::*; use block::*; - use spec::*; use engine::*; - use evm::Schedule; - use evm::Factory; use tests::helpers::*; use super::*; use super::super::new_morden; @@ -319,7 +316,7 @@ mod tests { #[test] fn can_return_factory() { let engine = Ethash::new_test(new_morden()); - let factory = engine.vm_factory(); + engine.vm_factory(); } #[test] @@ -359,7 +356,7 @@ mod tests { match verify_result { Err(Error::Block(BlockError::InvalidSealArity(_))) => {}, - _ => { panic!("should be block difficulty error"); } + _ => { panic!("should be block seal mismatch error"); } } } @@ -377,6 +374,22 @@ mod tests { } } + #[test] + fn can_do_proof_of_work_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]); + header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap()); + + let verify_result = engine.verify_block_basic(&header, None); + + match verify_result { + Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {}, + _ => { panic!("should be invalid proof of work error"); } + } + + } + // TODO: difficulty test } diff --git a/ethcore/src/evm/factory.rs b/ethcore/src/evm/factory.rs index f1be0e427..4a9bd38ba 100644 --- a/ethcore/src/evm/factory.rs +++ b/ethcore/src/evm/factory.rs @@ -159,11 +159,13 @@ macro_rules! evm_test_ignore( #[test] #[ignore] #[cfg(feature = "jit")] + #[cfg(feature = "ignored-tests")] fn $name_jit() { $name_test(Factory::new(VMType::Jit)); } #[test] #[ignore] + #[cfg(feature = "ignored-tests")] fn $name_int() { $name_test(Factory::new(VMType::Interpreter)); } diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 2d6039953..812dc3acd 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -360,6 +360,7 @@ impl<'a> Executive<'a> { } #[cfg(test)] +#[allow(dead_code)] mod tests { use super::*; use common::*; @@ -599,6 +600,7 @@ mod tests { } // test is incorrect, mk + // TODO: fix (preferred) or remove evm_test_ignore!{test_aba_calls: test_aba_calls_jit, test_aba_calls_int} fn test_aba_calls(factory: Factory) { // 60 00 - push 0 @@ -659,6 +661,7 @@ mod tests { } // test is incorrect, mk + // TODO: fix (preferred) or remove evm_test_ignore!{test_recursive_bomb1: test_recursive_bomb1_jit, test_recursive_bomb1_int} fn test_recursive_bomb1(factory: Factory) { // 60 01 - push 1 @@ -704,6 +707,7 @@ mod tests { } // test is incorrect, mk + // TODO: fix (preferred) or remove evm_test_ignore!{test_transact_simple: test_transact_simple_jit, test_transact_simple_int} fn test_transact_simple(factory: Factory) { let keypair = KeyPair::create().unwrap(); @@ -902,5 +906,4 @@ mod tests { } } } - } diff --git a/ethcore/src/json_tests/mod.rs b/ethcore/src/json_tests/mod.rs index 1cae0fa1d..df67de76d 100644 --- a/ethcore/src/json_tests/mod.rs +++ b/ethcore/src/json_tests/mod.rs @@ -20,7 +20,6 @@ mod test_common; mod transaction; mod executive; mod state; -mod client; mod chain; mod homestead_state; mod homestead_chain; diff --git a/ethcore/src/json_tests/client.rs b/ethcore/src/tests/client.rs similarity index 99% rename from ethcore/src/json_tests/client.rs rename to ethcore/src/tests/client.rs index 2d3166c74..697647187 100644 --- a/ethcore/src/json_tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -15,8 +15,8 @@ // along with Parity. If not, see . use client::{BlockChainClient,Client}; -use super::test_common::*; use tests::helpers::*; +use common::*; #[test] fn created() { diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 9ec36fa93..f5815b718 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#[cfg(feature = "json-tests")] use client::{BlockChainClient, Client}; use std::env; use common::*; @@ -134,7 +133,6 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[&SignedTrans rlp.out() } -#[cfg(feature = "json-tests")] pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult> { let dir = RandomTempPath::new(); @@ -174,7 +172,6 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult } } -#[cfg(feature = "json-tests")] pub fn get_test_client_with_blocks(blocks: Vec) -> GuardedTempResult> { let dir = RandomTempPath::new(); let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); @@ -271,7 +268,6 @@ pub fn get_good_dummy_block() -> Bytes { create_test_block(&block_header) } -#[cfg(feature = "json-tests")] pub fn get_bad_state_dummy_block() -> Bytes { let mut block_header = Header::new(); let test_spec = get_test_spec(); diff --git a/ethcore/src/tests/mod.rs b/ethcore/src/tests/mod.rs index a4e13730a..28c1b3b5b 100644 --- a/ethcore/src/tests/mod.rs +++ b/ethcore/src/tests/mod.rs @@ -15,3 +15,4 @@ // along with Parity. If not, see . pub mod helpers; +mod client; \ No newline at end of file From 9d9c56a054b421ae2456c202e25bf1445769d1ae Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Tue, 9 Feb 2016 10:50:29 +0100 Subject: [PATCH 05/14] Editorconfig file. --- .editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..0ac22f073 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true +[*] +indent_style=tab +indent_size=tab +tab_width=4 +end_of_line=lf +charset=utf-8 +trim_trailing_whitespace=true +max_line_length=120 +insert_final_newline=true + From 83fe91c88f4b34a35aa16415fc328fe96cc18f4b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 11:39:04 +0100 Subject: [PATCH 06/14] Install script avoids compiling on Ubuntu. --- install-parity.sh | 198 ++++++---------------------------------------- 1 file changed, 23 insertions(+), 175 deletions(-) diff --git a/install-parity.sh b/install-parity.sh index 51eb806eb..ea0cfc4b6 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -201,16 +201,16 @@ function run_installer() source /etc/lsb-release if [[ $DISTRIB_ID == "Ubuntu" ]]; then - if [[ $DISTRIB_RELEASE == "14.04" ]]; then - check "Ubuntu-14.04" - isUbuntu1404=true + if [[ $DISTRIB_RELEASE == "14.04" || $DISTRIB_RELEASE == "15.04" || $DISTRIB_RELEASE == "15.10" ]]; then + check "Ubuntu" + isUbuntu=true else - check "Ubuntu, but not 14.04" - isUbuntu1404=false + check "Ubuntu, but version not supported" + isUbuntu=false fi else check "Ubuntu not found" - isUbuntu1404=false + isUbuntu=false fi } @@ -286,32 +286,6 @@ function run_installer() fi } - function find_multirust() - { - depCount=$((depCount+2)) - MULTIRUST_PATH=`which multirust 2>/dev/null` - if [[ -f $MULTIRUST_PATH ]]; then - depFound=$((depFound+1)) - check "multirust" - isMultirust=true - if [[ $(multirust show-default 2>/dev/null | grep nightly | wc -l) == 4 ]]; then - depFound=$((depFound+1)) - check "rust nightly" - isMultirustNightly=true - else - uncheck "rust is not nightly" - isMultirustNightly=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tmultirust -> rust nightly\n" - fi - else - uncheck "multirust is missing" - uncheck "rust nightly is missing" - isMultirust=false - isMultirustNightly=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tmultirust\n" - fi - } - function find_apt() { depCount=$((depCount+1)) @@ -327,112 +301,12 @@ function run_installer() uncheck "apt-get is missing" isApt=false - if [[ $isGCC == false || $isGit == false || $isMake == false || $isCurl == false ]]; then - canContinue=false - errorMessages+="${red}==>${reset} ${b}Couldn't find apt-get:${reset} We can only use apt-get in order to grab our dependencies.\n" - errorMessages+=" Please switch to a distribution such as Debian or Ubuntu or manually install the missing packages.\n" - fi + canContinue=false + errorMessages+="${red}==>${reset} ${b}Couldn't find apt-get:${reset} We can only use apt-get in order to grab our dependencies.\n" + errorMessages+=" Please switch to a distribution such as Debian or Ubuntu or manually install the missing packages.\n" fi } - function find_gcc() - { - depCount=$((depCount+1)) - GCC_PATH=`which g++ 2>/dev/null` - - if [[ -f $GCC_PATH ]] - then - depFound=$((depFound+1)) - check "g++" - isGCC=true - else - uncheck "g++ is missing" - isGCC=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tg++\n" - fi - } - - function find_git() - { - depCount=$((depCount+1)) - GIT_PATH=`which git 2>/dev/null` - - if [[ -f $GIT_PATH ]] - then - depFound=$((depFound+1)) - check "git" - isGit=true - else - uncheck "git is missing" - isGit=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tgit\n" - fi - } - - function find_make() - { - depCount=$((depCount+1)) - MAKE_PATH=`which make 2>/dev/null` - - if [[ -f $MAKE_PATH ]] - then - depFound=$((depFound+1)) - check "make" - isMake=true - else - uncheck "make is missing" - isMake=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tmake\n" - fi - } - - function find_curl() - { - depCount=$((depCount+1)) - CURL_PATH=`which curl 2>/dev/null` - - if [[ -f $CURL_PATH ]] - then - depFound=$((depFound+1)) - check "curl" - isCurl=true - else - uncheck "curl is missing" - isCurl=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tcurl\n" - fi - } - - function ubuntu1404_rocksdb_installer() - { - sudo apt-get update -qq - sudo apt-get install -qq -y software-properties-common - sudo apt-add-repository -y ppa:giskou/librocksdb - sudo apt-get -f -y install - sudo apt-get update -qq - sudo apt-get install -qq -y librocksdb - } - - function linux_rocksdb_installer() - { - if [[ $isUbuntu1404 == true ]]; then - ubuntu1404_rocksdb_installer - else - oldpwd=`pwd` - cd /tmp - exe git clone --branch v4.2 --depth=1 https://github.com/facebook/rocksdb.git - cd rocksdb - exe make shared_lib - sudo cp -a librocksdb.so* /usr/lib - sudo ldconfig - cd /tmp - rm -rf /tmp/rocksdb - cd $oldpwd - fi - } - - - function verify_installation() { ETH_PATH=`which parity 2>/dev/null` @@ -451,58 +325,32 @@ function run_installer() info "Verifying installation" if [[ $OS_TYPE == "linux" ]]; then - find_curl - find_git - find_make - find_gcc find_rocksdb - find_multirust + find_apt - if [[ $isCurl == false || $isGit == false || $isMake == false || $isGCC == false || $isRocksDB == false || $isMultirustNightly == false ]]; then + if [[ $isRocksDB == false || $isApt == false ]]; then abortInstall fi fi } + function ubuntu_rocksdb_bin_installer() + { + sudo apt-get update -qq + sudo apt-get install -qq -y software-properties-common + sudo apt-add-repository -y ppa:ethcore/ethcore + sudo apt-get -f -y install + sudo apt-get update -qq + sudo apt-get install -qq -y librocksdb + } + function linux_deps_installer() { - if [[ $isGCC == false || $isGit == false || $isMake == false || $isCurl == false ]]; then - info "Installing build dependencies..." - sudo apt-get update -qq - if [[ $isGit == false ]]; then - sudo apt-get install -q -y git - fi - if [[ $isGCC == false ]]; then - sudo apt-get install -q -y g++ gcc - fi - if [[ $isMake == false ]]; then - sudo apt-get install -q -y make - fi - if [[ $isCurl == false ]]; then - sudo apt-get install -q -y curl - fi - echo - fi - if [[ $isRocksDB == false ]]; then - info "Installing rocksdb..." - linux_rocksdb_installer + info "Installing rocksdb binaries..." + ubuntu_rocksdb_bin_installer echo fi - - if [[ $isMultirust == false ]]; then - info "Installing multirust..." - curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sudo sh -s -- --yes - echo - fi - - if [[ $isMultirustNightly == false ]]; then - info "Installing rust nightly..." - sudo multirust update nightly - sudo multirust default nightly - echo - fi - } function linux_installer() From b1110272a41bfc327eaa75e0e464a495fabfea6d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 12:09:51 +0100 Subject: [PATCH 07/14] Parity install sceipt cleanups. --- install-parity.sh | 157 +++++++++++++++++++++++++++++++--------------- 1 file changed, 108 insertions(+), 49 deletions(-) diff --git a/install-parity.sh b/install-parity.sh index ea0cfc4b6..53a619358 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -PARITY_DEB_URL=https://github.com/ethcore/parity/releases/download/beta-0.9/parity_0.9.0-0_amd64.deb +PARITY_DEB_URL=https://github.com/ethcore/parity/releases/download/beta-0.9/parity_linux_0.9.0-0_amd64.deb function run_installer() @@ -47,6 +47,7 @@ function run_installer() dim=`tput dim` reverse=`tput rev` reset=`tput sgr0` + n=$'\n' function head() { @@ -94,13 +95,19 @@ function run_installer() ####### Setup methods function wait_for_user() { + if [[ $( ask_user "$1" ) == false ]]; then + abort_install "${red}==>${reset} Process stopped by user. To resume the install run the one-liner command again." + fi + } + + function ask_user() { while : do read -p "${blue}==>${reset} $1 [Y/n] " imp case $imp in - [yY] ) return 0; break ;; - '' ) echo; break ;; - [nN] ) return 1 ;; + [yY] ) echo true; break ;; + '' ) echo true; break ;; + [nN] ) echo false; break ;; * ) echo "Unrecognized option provided. Please provide either 'Y' or 'N'"; esac done @@ -114,11 +121,19 @@ function run_installer() return done } - + function exe() { echo "\$ $@"; "$@" } - + + function sudo() { + if $isSudo; then + `which sudo` "$@" + else + "$@" + fi + } + function detectOS() { if [[ "$OSTYPE" == "linux-gnu" ]] then @@ -130,7 +145,7 @@ function run_installer() get_osx_dependencies else OS_TYPE="win" - abortInstall "${red}==>${reset} ${b}OS not supported:${reset} parity one-liner currently support OS X and Linux.\nFor instructions on installing parity on other platforms please visit ${u}${blue}http://ethcore.io/${reset}" + abortInstall "${red}==>${reset} ${b}OS not supported:${reset} parity one-liner currently support OS X and Linux.${n}For instructions on installing parity on other platforms please visit ${u}${blue}http://ethcore.io/${reset}" fi echo @@ -184,8 +199,8 @@ function run_installer() fi fi - errorMessages+="${red}==>${reset} ${b}Mac OS version too old:${reset} eth requires OS X version ${red}$OSX_REQUIERED_VERSION${reset} at least in order to run.\n" - errorMessages+=" Please update the OS and reload the install process.\n" + errorMessages+="${red}==>${reset} ${b}Mac OS version too old:${reset} eth requires OS X version ${red}$OSX_REQUIERED_VERSION${reset} at least in order to run.${n}" + errorMessages+=" Please update the OS and reload the install process.${n}" } function get_osx_dependencies() @@ -206,11 +221,14 @@ function run_installer() isUbuntu=true else check "Ubuntu, but version not supported" - isUbuntu=false + + errorMessages+="${red}==>${reset} ${b}Ubuntu version not supported:${reset} This script requires Ubuntu version 14.04, 15.04 or 15.10.${n}" + errorMessages+=" Please either upgrade your Ubuntu installation or using the get-deps.ethcore.io script instead, which can help you build Parity.${n}" fi else check "Ubuntu not found" - isUbuntu=false + errorMessages+="${red}==>${reset} ${b}Linux distribution not supported:${reset} This script requires Ubuntu version 14.04, 15.04 or 15.10.${n}" + errorMessages+=" Please either use this on an Ubuntu installation or instead use the get-deps.ethcore.io script, which can help you build Parity.${n}" fi } @@ -218,15 +236,12 @@ function run_installer() { linux_version - find_multirust find_rocksdb find_curl - find_git - find_make - find_gcc find_apt + find_sudo } function find_brew() @@ -242,10 +257,10 @@ function run_installer() uncheck "Homebrew is missing" isBrew=false - INSTALL_FILES+="${blue}${dim}==> Homebrew:${reset}\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/bin/brew\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/Library\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/share/man/man1/brew.1\n" + INSTALL_FILES+="${blue}${dim}==> Homebrew:${reset}${n}" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/bin/brew${n}" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/Library${n}" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/share/man/man1/brew.1${n}" fi depCount=$((depCount+1)) @@ -267,11 +282,57 @@ function run_installer() uncheck "Ruby is missing 🔥" isRuby=false canContinue=false - errorMessages+="${red}==>${reset} ${b}Couldn't find Ruby:${reset} Brew requires Ruby which could not be found.\n" - errorMessages+=" Please install Ruby using these instructions ${u}${blue}https://www.ruby-lang.org/en/documentation/installation/${reset}.\n" + errorMessages+="${red}==>${reset} ${b}Couldn't find Ruby:${reset} Brew requires Ruby which could not be found.${n}" + errorMessages+=" Please install Ruby using these instructions ${u}${blue}https://www.ruby-lang.org/en/documentation/installation/${reset}.${n}" fi } + function find_sudo() + { + depCount=$((depCount+1)) + SUDO_PATH=`which sudo 2>/dev/null` + + if [[ -f $SUDO_PATH ]] + then + depFound=$((depFound+1)) + check "sudo" + isSudo=true + else + uncheck "sudo is missing" + if [[ `whoami` == "root" ]]; then + if [[ $isApt == false && $isMultirust == false ]]; then + canContinue=false + errorMessages+="${red}==>${reset} ${b}Couldn't find sudo:${reset} Sudo is needed for the installation of multirust.${n}" + errorMessages+=" Please ensure you have sudo installed or alternatively install multirust manually.${n}" + fi + + isSudo=false + INSTALL_FILES+="${blue}${dim}==>${reset}\tsudo${n}" + else + canContinue=false + errorMessages+="${red}==>${reset} ${b}Couldn't find sudo:${reset} Root access is needed for parts of this installation.${n}" + errorMessages+=" Please ensure you have sudo installed or alternatively run this script as root.${n}" + fi + fi + } + + function find_curl() + { + depCount=$((depCount+1)) + CURL_PATH=`which curl 2>/dev/null` + + if [[ -f $CURL_PATH ]] + then + depFound=$((depFound+1)) + check "curl" + isCurl=true + else + uncheck "curl is missing" + isCurl=false + INSTALL_FILES+="${blue}${dim}==>${reset}\tcurl${n}" + fi + } + function find_rocksdb() { depCount=$((depCount+1)) @@ -282,7 +343,7 @@ function run_installer() else uncheck "librocksdb is missing" isRocksDB=false - INSTALL_FILES+="${blue}${dim}==>${reset}\tlibrocksdb\n" + INSTALL_FILES+="${blue}${dim}==>${reset}\tlibrocksdb${n}" fi } @@ -302,8 +363,8 @@ function run_installer() isApt=false canContinue=false - errorMessages+="${red}==>${reset} ${b}Couldn't find apt-get:${reset} We can only use apt-get in order to grab our dependencies.\n" - errorMessages+=" Please switch to a distribution such as Debian or Ubuntu or manually install the missing packages.\n" + errorMessages+="${red}==>${reset} ${b}Couldn't find apt-get:${reset} We can only use apt-get in order to grab our dependencies.${n}" + errorMessages+=" Please switch to a distribution such as Debian or Ubuntu or manually install the missing packages.${n}" fi } @@ -334,21 +395,28 @@ function run_installer() fi } - function ubuntu_rocksdb_bin_installer() - { - sudo apt-get update -qq - sudo apt-get install -qq -y software-properties-common - sudo apt-add-repository -y ppa:ethcore/ethcore - sudo apt-get -f -y install - sudo apt-get update -qq - sudo apt-get install -qq -y librocksdb - } - function linux_deps_installer() { + if [[ $isSudo == false ]]; then + info "Installing sudo..." + apt-get install -q -y sudo + echo + fi if [[ $isRocksDB == false ]]; then - info "Installing rocksdb binaries..." - ubuntu_rocksdb_bin_installer + info "Installing rocksdb..." + + sudo apt-get update -qq + sudo apt-get install -qq -y software-properties-common + sudo apt-add-repository -y ppa:ethcore/ethcore + sudo apt-get -f -y install + sudo apt-get update -qq + sudo apt-get install -qq -y librocksdb + + echo + fi + if [[ $isCurl == false ]]; then + info "Installing curl..." + sudo apt-get install -q -y curl echo fi } @@ -361,7 +429,7 @@ function run_installer() info "Installing parity" file=/tmp/parity.deb - wget $PARITY_DEB_URL -qO $file + curl -L $PARITY_DEB_URL > $file sudo dpkg -i $file rm $file } @@ -509,11 +577,9 @@ EOL fi #DEBUG - head "${b}OK,${reset} let's install Parity now!" - if wait_for_user "${b}Last chance!${reset} Sure you want to install this software?" - then + if [[ $(ask_user "${b}Last chance!${reset} Sure you want to install this software?") == true ]]; then install echo echo @@ -521,19 +587,12 @@ EOL finish fi - - - if [[ $OS_TYPE == "linux" ]] - then - echo "Netstats:" - head "Would you like to install and configure a netstats client?" - if wait_for_user "${b}OK,${reset} let's go!" - then + if [[ $OS_TYPE == "linux" && $DISTRIB_ID == "Ubuntu" ]]; then + if [[ $(ask_user "${b}Netstats${reset} Would you like to download, install and configure a Netstats client?${n}${b}${red}WARNING: ${reset}${red}This will need a secret and reconfigure any existing node/NPM installation you have.${reset} ") == true ]]; then install_netstats fi fi - # Display goodbye message finish } From ffadbf1d10ef9463173bad8c0079e5a2d8ec4748 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 12:20:27 +0100 Subject: [PATCH 08/14] Force apt-get update on ubuntu. --- install-parity.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install-parity.sh b/install-parity.sh index 53a619358..02093ca8c 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -397,6 +397,8 @@ function run_installer() function linux_deps_installer() { + sudo apt-get update -qq + if [[ $isSudo == false ]]; then info "Installing sudo..." apt-get install -q -y sudo @@ -405,7 +407,6 @@ function run_installer() if [[ $isRocksDB == false ]]; then info "Installing rocksdb..." - sudo apt-get update -qq sudo apt-get install -qq -y software-properties-common sudo apt-add-repository -y ppa:ethcore/ethcore sudo apt-get -f -y install From 55a29bfa86985122a3a0b8ae4bfcd9038a32aa29 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 9 Feb 2016 03:23:35 -0800 Subject: [PATCH 09/14] unordered verification --- ethcore/src/ethereum/ethash.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 7d99a456a..3e1d7c1bf 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -157,6 +157,11 @@ impl Engine for Ethash { } fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { + if header.seal.len() != self.seal_fields() { + return Err(From::from(BlockError::InvalidSealArity( + Mismatch { expected: self.seal_fields(), found: header.seal.len() } + ))); + } let result = self.pow.compute_light(header.number as u64, &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64()); let mix = Ethash::from_ethash(result.mix_hash); let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(result.value)); @@ -387,7 +392,32 @@ mod tests { Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {}, _ => { panic!("should be invalid proof of work error"); } } + } + #[test] + fn can_do_seal_unordered_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let header: Header = Header::default(); + + let verify_result = engine.verify_block_unordered(&header, None); + + match verify_result { + Err(Error::Block(BlockError::InvalidSealArity(_))) => {}, + _ => { panic!("should be block seal mismatch error"); } + } + } + + #[test] + fn can_do_seal256_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]); + let verify_result = engine.verify_block_unordered(&header, None); + + match verify_result { + Err(Error::Block(BlockError::MismatchedH256SealElement(_))) => {}, + _ => { panic!("should be invalid proof of work error"); } + } } // TODO: difficulty test From 5938b6509752998630ff8422a024daf38c7cb340 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 12:24:36 +0100 Subject: [PATCH 10/14] Additional help at he end of the install; no need to install sudo. --- install-parity.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install-parity.sh b/install-parity.sh index 02093ca8c..60d3471d5 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -397,13 +397,12 @@ function run_installer() function linux_deps_installer() { - sudo apt-get update -qq - - if [[ $isSudo == false ]]; then - info "Installing sudo..." - apt-get install -q -y sudo + if [[ $isRocksDB == false || $isCurl == false ]]; then + info "Preparing apt..." + sudo apt-get update -qq echo fi + if [[ $isRocksDB == false ]]; then info "Installing rocksdb..." @@ -415,6 +414,7 @@ function run_installer() echo fi + if [[ $isCurl == false ]]; then info "Installing curl..." sudo apt-get install -q -y curl @@ -561,8 +561,8 @@ EOL { echo successHeading "All done" - # head "Next steps" - # info "Run ${cyan}\`\`${reset} to get started.${reset}" + head "Next steps" + info "Run ${cyan}\`parity -j\`${reset} to start the Parity Ethereum client.${reset}" echo exit 0 } From 9358e9444c43c0ee3582e9df414a54200b25c3d6 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 9 Feb 2016 03:58:32 -0800 Subject: [PATCH 11/14] unordered h256-pass fix --- ethcore/src/ethereum/ethash.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 3e1d7c1bf..0fc22ddfc 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -361,7 +361,8 @@ mod tests { match verify_result { Err(Error::Block(BlockError::InvalidSealArity(_))) => {}, - _ => { panic!("should be block seal mismatch error"); } + Err(_) => { panic!("should be block seal-arity mismatch error (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, } } @@ -375,7 +376,8 @@ mod tests { match verify_result { Err(Error::Block(BlockError::DifficultyOutOfBounds(_))) => {}, - _ => { panic!("should be block difficulty error"); } + Err(_) => { panic!("should be block difficulty error (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, } } @@ -390,7 +392,8 @@ mod tests { match verify_result { Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {}, - _ => { panic!("should be invalid proof of work error"); } + Err(_) => { panic!("should be invalid proof of work error (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, } } @@ -403,7 +406,8 @@ mod tests { match verify_result { Err(Error::Block(BlockError::InvalidSealArity(_))) => {}, - _ => { panic!("should be block seal mismatch error"); } + Err(_) => { panic!("should be block seal-arity mismatch error (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, } } @@ -416,10 +420,28 @@ mod tests { match verify_result { Err(Error::Block(BlockError::MismatchedH256SealElement(_))) => {}, - _ => { panic!("should be invalid proof of work error"); } + Err(_) => { panic!("should be invalid 256-bit seal fail (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, } } + #[test] + fn can_do_proof_of_work_unordered_verification_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")).to_vec(), rlp::encode(&H64::zero()).to_vec()]); + header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap()); + + let verify_result = engine.verify_block_unordered(&header, None); + + match verify_result { + Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {}, + Err(_) => { panic!("should be invalid proof-of-work fail (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, + } + + } + // TODO: difficulty test } From 095c60d440d9fbad1dc0009fd9800a2cce907e75 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 9 Feb 2016 04:20:18 -0800 Subject: [PATCH 12/14] possible panic resolution, block family tests --- ethcore/src/ethereum/ethash.rs | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 0fc22ddfc..e931080b2 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -175,6 +175,11 @@ impl Engine for Ethash { } fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { + // we should not calculate difficulty for genesis blocks + if header.number() == 0 { + return Err(From::from(BlockError::RidiculousNumber(OutOfBounds { min: Some(1), max: None, found: header.number() }))); + } + // Check difficulty is correct given the two timestamps. let expected_difficulty = self.calculate_difficuty(header, parent); if header.difficulty != expected_difficulty { @@ -439,7 +444,56 @@ mod tests { Err(_) => { panic!("should be invalid proof-of-work fail (got {:?})", verify_result); }, _ => { panic!("Should be error, got Ok"); }, } + } + #[test] + fn can_verify_block_family_genesis_fail() { + let engine = Ethash::new_test(new_morden()); + let header: Header = Header::default(); + let parent_header: Header = Header::default(); + + let verify_result = engine.verify_block_family(&header, &parent_header, None); + + match verify_result { + Err(Error::Block(BlockError::RidiculousNumber(_))) => {}, + Err(_) => { panic!("should be invalid block number fail (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, + } + } + + #[test] + fn can_verify_block_family_difficulty_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_number(2); + let mut parent_header: Header = Header::default(); + parent_header.set_number(1); + + let verify_result = engine.verify_block_family(&header, &parent_header, None); + + match verify_result { + Err(Error::Block(BlockError::InvalidDifficulty(_))) => {}, + Err(_) => { panic!("should be invalid difficulty fail (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, + } + } + + #[test] + fn can_verify_block_family_gas_fail() { + let engine = Ethash::new_test(new_morden()); + let mut header: Header = Header::default(); + header.set_number(2); + header.set_difficulty(U256::from_str("0000000000000000000000000000000000000000000000000000000000020000").unwrap()); + let mut parent_header: Header = Header::default(); + parent_header.set_number(1); + + let verify_result = engine.verify_block_family(&header, &parent_header, None); + + match verify_result { + Err(Error::Block(BlockError::InvalidGasLimit(_))) => {}, + Err(_) => { panic!("should be invalid difficulty fail (got {:?})", verify_result); }, + _ => { panic!("Should be error, got Ok"); }, + } } // TODO: difficulty test From e987a492dc952ff458b697925ef4dcc7d296f2e6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 15:51:48 +0100 Subject: [PATCH 13/14] --chain option for setting which network to go on. Add contents function to util. --- Cargo.toml | 1 + parity/main.rs | 38 ++++++++++++++++++++++++++++++++------ util/src/misc.rs | 9 +++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1eac83ac3..836967631 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ ethcore = { path = "ethcore" } ethsync = { path = "sync" } ethcore-rpc = { path = "rpc", optional = true } fdlimit = { path = "util/fdlimit" } +target_info = "0.1" [features] default = ["rpc"] diff --git a/parity/main.rs b/parity/main.rs index d423caa64..43a249886 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -29,6 +29,7 @@ extern crate log as rlog; extern crate env_logger; extern crate ctrlc; extern crate fdlimit; +extern crate target_info; #[cfg(feature = "rpc")] extern crate ethcore_rpc as rpc; @@ -39,23 +40,25 @@ use rlog::{LogLevelFilter}; use env_logger::LogBuilder; use ctrlc::CtrlC; use util::*; +use ethcore::spec::*; use ethcore::client::*; use ethcore::service::{ClientService, NetSyncMessage}; use ethcore::ethereum; use ethcore::blockchain::CacheSize; use ethsync::EthSync; +use target_info::Target; docopt!(Args derive Debug, " Parity. Ethereum Client. + By Wood/Paronyan/Kotewicz/Drwięga/Volf. + Copyright 2015, 2016 Ethcore (UK) Limited Usage: - parity [options] - parity [options] ... + parity [options] [ ... ] Options: - -l --logging LOGGING Specify the logging level. - -j --jsonrpc Enable the JSON-RPC API sever. - --jsonrpc-url URL Specify URL for JSON-RPC API server [default: 127.0.0.1:8545]. + --chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file + or frontier, mainnet, morden, or testnet [default: frontier]. --listen-address URL Specify the IP/port on which to listen for peers [default: 0.0.0.0:30304]. --public-address URL Specify the IP/port on which peers may connect [default: 0.0.0.0:30304]. @@ -64,6 +67,11 @@ Options: --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]. + -j --jsonrpc Enable the JSON-RPC API sever. + --jsonrpc-url URL Specify URL for JSON-RPC API server [default: 127.0.0.1:8545]. + + -l --logging LOGGING Specify the logging level. + -v --version Show information about version. -h --help Show this screen. ", flag_cache_pref_size: usize, flag_cache_max_size: usize, flag_address: Option); @@ -100,10 +108,28 @@ fn setup_rpc_server(_client: Arc, _sync: Arc, _url: &str) { fn main() { let args: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit()); + if args.flag_version { + println!(" +Parity version {} ({}-{}-{}) +Copyright 2015, 2016 Ethcore (UK) Limited +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + +By Wood/Paronyan/Kotewicz/Drwięga/Volf. +", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os()); + return; + } + setup_log(&args.flag_logging); unsafe { ::fdlimit::raise_fd_limit(); } - let spec = ethereum::new_frontier(); + let spec = match args.flag_chain.as_ref() { + "frontier" | "mainnet" => ethereum::new_frontier(), + "morden" | "testnet" => ethereum::new_morden(), + "olympic" => ethereum::new_olympic(), + f => Spec::from_json_utf8(contents(f).expect("Couldn't read chain specification file. Sure it exists?").as_ref()), + }; let init_nodes = match args.arg_enode.len() { 0 => spec.nodes().clone(), _ => args.arg_enode.clone(), diff --git a/util/src/misc.rs b/util/src/misc.rs index 43027015e..6e2240d33 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -16,6 +16,7 @@ //! Diff misc. +use std::fs::File; use common::*; #[derive(Debug,Clone,PartialEq,Eq)] @@ -53,3 +54,11 @@ pub enum Filth { /// Data has been changed. Dirty, } + +/// Read the whole contents of a file `name`. +pub fn contents(name: &str) -> Result { + let mut file = try!(File::open(name)); + let mut ret: Vec = Vec::new(); + try!(file.read_to_end(&mut ret)); + Ok(ret) +} From 8be5340385f72a4b7fa8c60f6028cfe84fb61934 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 9 Feb 2016 16:19:12 +0100 Subject: [PATCH 14/14] Tabs! --- util/src/misc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/src/misc.rs b/util/src/misc.rs index 6e2240d33..ae3dbc5bf 100644 --- a/util/src/misc.rs +++ b/util/src/misc.rs @@ -58,7 +58,7 @@ pub enum Filth { /// Read the whole contents of a file `name`. pub fn contents(name: &str) -> Result { let mut file = try!(File::open(name)); - let mut ret: Vec = Vec::new(); - try!(file.read_to_end(&mut ret)); - Ok(ret) + let mut ret: Vec = Vec::new(); + try!(file.read_to_end(&mut ret)); + Ok(ret) }