From 3fe38163f5a02d5fd5b35ebe6044db0f6b708f1d Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Wed, 22 Feb 2017 19:17:02 +0100 Subject: [PATCH] [beta] Backporting #4633 (#4640) * Tweak some checks. (#4633) * Tweak some checks. * Fixed build and added a difficulty test * v1.5.4 --- Cargo.lock | 42 ++++++++++++------------ Cargo.toml | 2 +- ethcore/src/ethereum/ethash.rs | 18 ++++++++++ ethcore/src/header.rs | 2 +- ethcore/src/verification/queue/kind.rs | 2 +- ethcore/src/verification/verification.rs | 14 ++++---- mac/Parity.pkgproj | 2 +- nsis/installer.nsi | 2 +- util/Cargo.toml | 2 +- 9 files changed, 53 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f0ecce0f..2382683a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "parity" -version = "1.5.3" +version = "1.5.4" dependencies = [ "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -23,7 +23,7 @@ dependencies = [ "ethcore-rpc 1.5.0", "ethcore-signer 1.5.0", "ethcore-stratum 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "ethsync 1.5.0", "evmbin 1.5.0", "fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -373,7 +373,7 @@ dependencies = [ "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", "ethcore-ipc-nano 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "ethjson 0.1.0", "ethkey 0.2.0", "ethstore 0.1.0", @@ -421,7 +421,7 @@ dependencies = [ "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-devtools 1.5.0", "ethcore-rpc 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "fetch 0.1.0", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.0-a.0 (git+https://github.com/ethcore/hyper)", @@ -469,7 +469,7 @@ name = "ethcore-ipc" version = "1.5.0" dependencies = [ "ethcore-devtools 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "nanomsg 0.5.1 (git+https://github.com/ethcore/nanomsg.rs.git)", "semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -516,7 +516,7 @@ dependencies = [ "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", "ethcore-ipc-nano 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "nanomsg 0.5.1 (git+https://github.com/ethcore/nanomsg.rs.git)", "semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -531,7 +531,7 @@ dependencies = [ "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", "ethcore-network 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.1.0", "smallvec 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -543,7 +543,7 @@ name = "ethcore-logger" version = "1.5.0" dependencies = [ "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -559,7 +559,7 @@ dependencies = [ "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-devtools 1.5.0", "ethcore-io 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "ethcrypto 0.1.0", "ethkey 0.2.0", "igd 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -586,7 +586,7 @@ dependencies = [ "ethcore-devtools 1.5.0", "ethcore-io 1.5.0", "ethcore-ipc 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "ethcrypto 0.1.0", "ethjson 0.1.0", "ethkey 0.2.0", @@ -621,7 +621,7 @@ dependencies = [ "ethcore-devtools 1.5.0", "ethcore-io 1.5.0", "ethcore-rpc 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -640,7 +640,7 @@ dependencies = [ "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", "ethcore-ipc-nano 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "jsonrpc-tcp-server 0.1.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -651,7 +651,7 @@ dependencies = [ [[package]] name = "ethcore-util" -version = "1.5.3" +version = "1.5.4" dependencies = [ "ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -700,7 +700,7 @@ dependencies = [ name = "ethjson" version = "0.1.0" dependencies = [ - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -756,7 +756,7 @@ dependencies = [ "ethcore-ipc-nano 1.5.0", "ethcore-light 1.5.0", "ethcore-network 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "ethkey 0.2.0", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -773,7 +773,7 @@ version = "1.5.0" dependencies = [ "docopt 0.6.80 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -975,7 +975,7 @@ version = "1.5.0" dependencies = [ "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1500,7 +1500,7 @@ name = "parity-hash-fetch" version = "1.5.0" dependencies = [ "ethabi 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "fetch 0.1.0", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1525,7 +1525,7 @@ version = "1.4.0" dependencies = [ "ethcore-rpc 1.5.0", "ethcore-signer 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 4.0.0 (git+https://github.com/ethcore/jsonrpc.git?branch=mio-old)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1571,7 +1571,7 @@ dependencies = [ "ethcore 1.5.0", "ethcore-ipc 1.5.0", "ethcore-ipc-codegen 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "ethsync 1.5.0", "ipc-common-types 1.5.0", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1851,7 +1851,7 @@ version = "1.4.0" dependencies = [ "ethcore-bigint 0.1.2", "ethcore-rpc 1.5.0", - "ethcore-util 1.5.3", + "ethcore-util 1.5.4", "futures 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc-client 1.4.0", "rpassword 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index e1a1f10c7..76561fc55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "Parity Ethereum client" name = "parity" -version = "1.5.3" +version = "1.5.4" license = "GPL-3.0" authors = ["Parity Technologies "] build = "build.rs" diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 87a15497d..1dde0619e 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -850,4 +850,22 @@ mod tests { ethash.populate_from_parent(&mut header, &parent, U256::from(150_000), U256::from(150_002)); assert_eq!(*header.gas_limit(), U256::from(150_002)); } + + #[test] + fn difficulty_max_timestamp() { + let spec = new_homestead_test(); + let ethparams = get_default_ethash_params(); + let ethash = Ethash::new(spec.params, ethparams, BTreeMap::new()); + + let mut parent_header = Header::default(); + parent_header.set_number(1000000); + parent_header.set_difficulty(U256::from_str("b69de81a22b").unwrap()); + parent_header.set_timestamp(1455404053); + let mut header = Header::default(); + header.set_number(parent_header.number() + 1); + header.set_timestamp(u64::max_value()); + + let difficulty = ethash.calculate_difficulty(&header, &parent_header); + assert_eq!(U256::from(12543204905719u64), difficulty); + } } diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index adc51717d..1cb19b167 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -276,7 +276,7 @@ impl Decodable for Header { number: r.val_at(8)?, gas_limit: r.val_at(9)?, gas_used: r.val_at(10)?, - timestamp: r.val_at(11)?, + timestamp: min(r.val_at::(11)?, u64::max_value().into()).as_u64(), extra_data: r.val_at(12)?, seal: vec![], hash: RefCell::new(Some(r.as_raw().sha3())), diff --git a/ethcore/src/verification/queue/kind.rs b/ethcore/src/verification/queue/kind.rs index 3ce86ad47..79ba0bf07 100644 --- a/ethcore/src/verification/queue/kind.rs +++ b/ethcore/src/verification/queue/kind.rs @@ -186,7 +186,7 @@ pub mod headers { type Verified = Header; fn create(input: Self::Input, engine: &Engine) -> Result { - verify_header_params(&input, engine).map(|_| input) + verify_header_params(&input, engine, true).map(|_| input) } fn verify(unverified: Self::Unverified, engine: &Engine, check_seal: bool) -> Result { diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 2ff4c8963..6e2ba4492 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -51,12 +51,12 @@ impl HeapSizeOf for PreverifiedBlock { /// Phase 1 quick block verification. Only does checks that are cheap. Operates on a single block pub fn verify_block_basic(header: &Header, bytes: &[u8], engine: &Engine) -> Result<(), Error> { - verify_header_params(&header, engine)?; + verify_header_params(&header, engine, true)?; verify_block_integrity(bytes, &header.transactions_root(), &header.uncles_hash())?; engine.verify_block_basic(&header, Some(bytes))?; for u in UntrustedRlp::new(bytes).at(2)?.iter().map(|rlp| rlp.as_val::
()) { let u = u?; - verify_header_params(&u, engine)?; + verify_header_params(&u, engine, false)?; engine.verify_block_basic(&u, None)?; } // Verify transactions. @@ -195,7 +195,7 @@ pub fn verify_block_final(expected: &Header, got: &Header) -> Result<(), Error> } /// Check basic header parameters. -pub fn verify_header_params(header: &Header, engine: &Engine) -> Result<(), Error> { +pub fn verify_header_params(header: &Header, engine: &Engine, is_full: bool) -> Result<(), Error> { if header.number() >= From::from(BlockNumber::max_value()) { return Err(From::from(BlockError::RidiculousNumber(OutOfBounds { max: Some(From::from(BlockNumber::max_value())), min: None, found: header.number() }))) } @@ -210,9 +210,11 @@ pub fn verify_header_params(header: &Header, engine: &Engine) -> Result<(), Erro if header.number() != 0 && header.extra_data().len() > maximum_extra_data_size { return Err(From::from(BlockError::ExtraDataOutOfBounds(OutOfBounds { min: None, max: Some(maximum_extra_data_size), found: header.extra_data().len() }))); } - let max_time = get_time().sec as u64 + 30; - if header.timestamp() > max_time { - return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: Some(max_time), min: None, found: header.timestamp() }))) + if is_full { + let max_time = get_time().sec as u64 + 30; + if header.timestamp() > max_time { + return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: Some(max_time), min: None, found: header.timestamp() }))) + } } Ok(()) } diff --git a/mac/Parity.pkgproj b/mac/Parity.pkgproj index 55711cb53..389b126fb 100755 --- a/mac/Parity.pkgproj +++ b/mac/Parity.pkgproj @@ -578,7 +578,7 @@ OVERWRITE_PERMISSIONS VERSION - 1.5.3 + 1.5.4 UUID 2DCD5B81-7BAF-4DA1-9251-6274B089FD36 diff --git a/nsis/installer.nsi b/nsis/installer.nsi index 9ebfc0d66..1ca32ab94 100644 --- a/nsis/installer.nsi +++ b/nsis/installer.nsi @@ -10,7 +10,7 @@ !define DESCRIPTION "Fast, light, robust Ethereum implementation" !define VERSIONMAJOR 1 !define VERSIONMINOR 5 -!define VERSIONBUILD 3 +!define VERSIONBUILD 4 !define ARGS "--warp" !define FIRST_START_ARGS "ui --warp --mode=passive" diff --git a/util/Cargo.toml b/util/Cargo.toml index 2915706e3..a2a4c6e58 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -3,7 +3,7 @@ description = "Ethcore utility library" homepage = "http://parity.io" license = "GPL-3.0" name = "ethcore-util" -version = "1.5.3" +version = "1.5.4" authors = ["Parity Technologies "] build = "build.rs"