diff --git a/README.md b/README.md index be31c49243e..0775238509f 100644 --- a/README.md +++ b/README.md @@ -296,10 +296,6 @@ Caching, Importing Blocks, and Block Information ```bash ethcore-logger ``` -* C bindings library for the Parity Ethereum client - ```bash - parity-clib - ``` * Parity Ethereum JSON-RPC Servers ```bash parity-rpc @@ -318,7 +314,7 @@ Caching, Importing Blocks, and Block Information journaldb keccak-hasher len-caching-lock macros memory-cache memzero migration-rocksdb ethcore-network ethcore-network-devp2p panic_hook patricia-trie-ethereum registrar rlp_compress rlp_derive parity-runtime stats - time-utils triehash-ethereum unexpected parity-version + triehash-ethereum unexpected parity-version ```

diff --git a/ethcore/engines/authority-round/Cargo.toml b/ethcore/engines/authority-round/Cargo.toml index 11b46be2bdd..a6272164c93 100644 --- a/ethcore/engines/authority-round/Cargo.toml +++ b/ethcore/engines/authority-round/Cargo.toml @@ -31,7 +31,6 @@ parity-bytes = "0.1" parking_lot = "0.9" rand = "0.7" rlp = "0.4.0" -time-utils = { path = "../../../util/time-utils" } unexpected = { path = "../../../util/unexpected" } validator-set = { path = "../validator-set" } diff --git a/ethcore/engines/authority-round/src/lib.rs b/ethcore/engines/authority-round/src/lib.rs index 7d4c6e86c0f..9ec32d98bf5 100644 --- a/ethcore/engines/authority-round/src/lib.rs +++ b/ethcore/engines/authority-round/src/lib.rs @@ -62,7 +62,6 @@ use rlp::{encode, Decodable, DecoderError, Encodable, RlpStream, Rlp}; use ethereum_types::{H256, H520, Address, U128, U256}; use parity_bytes::Bytes; use parking_lot::{Mutex, RwLock}; -use time_utils::CheckedSystemTime; use common_types::{ ancestry_action::AncestryAction, BlockNumber, @@ -759,10 +758,10 @@ fn verify_timestamp(step: &Step, header_step: u64) -> Result<(), BlockError> { // Returning it further won't recover the sync process. trace!(target: "engine", "verify_timestamp: block too early"); - let found = CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(oob.found)) + let found = UNIX_EPOCH.checked_add(Duration::from_secs(oob.found)) .ok_or(BlockError::TimestampOverflow)?; - let max = oob.max.and_then(|m| CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(m))); - let min = oob.min.and_then(|m| CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(m))); + let max = oob.max.and_then(|m| UNIX_EPOCH.checked_add(Duration::from_secs(m))); + let min = oob.min.and_then(|m| UNIX_EPOCH.checked_add(Duration::from_secs(m))); let new_oob = OutOfBounds { min, max, found }; diff --git a/ethcore/engines/clique/Cargo.toml b/ethcore/engines/clique/Cargo.toml index 7a73f04c815..dc4d966e259 100644 --- a/ethcore/engines/clique/Cargo.toml +++ b/ethcore/engines/clique/Cargo.toml @@ -22,7 +22,6 @@ macros = { path = "../../../util/macros" } rand = "0.7" parking_lot = "0.9" rlp = "0.4.0" -time-utils = { path = "../../../util/time-utils" } unexpected = { path = "../../../util/unexpected" } [dev-dependencies] diff --git a/ethcore/engines/clique/src/block_state.rs b/ethcore/engines/clique/src/block_state.rs index a6f8103571e..3685c468736 100644 --- a/ethcore/engines/clique/src/block_state.rs +++ b/ethcore/engines/clique/src/block_state.rs @@ -28,7 +28,6 @@ use common_types::{ use ethereum_types::{Address, H64}; use log::{debug, trace}; use rand::Rng; -use time_utils::CheckedSystemTime; use unexpected::Mismatch; use crate::{ @@ -273,7 +272,7 @@ impl CliqueBlockState { // This is a quite bad API because we must mutate both variables even when already `inturn` fails // That's why we can't return early and must have the `if-else` in the end pub fn calc_next_timestamp(&mut self, timestamp: u64, period: u64) -> Result<(), Error> { - let inturn = CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(timestamp.saturating_add(period))); + let inturn = UNIX_EPOCH.checked_add(Duration::from_secs(timestamp.saturating_add(period))); self.next_timestamp_inturn = inturn; diff --git a/ethcore/engines/clique/src/lib.rs b/ethcore/engines/clique/src/lib.rs index 6638897edb3..f5c8bc32a7f 100644 --- a/ethcore/engines/clique/src/lib.rs +++ b/ethcore/engines/clique/src/lib.rs @@ -84,7 +84,6 @@ use macros::map; use parking_lot::RwLock; use rand::Rng; use unexpected::{Mismatch, OutOfBounds}; -use time_utils::CheckedSystemTime; use common_types::{ BlockNumber, ids::BlockId, @@ -571,7 +570,7 @@ impl Engine for Clique { // Don't waste time checking blocks from the future { - let limit = CheckedSystemTime::checked_add(SystemTime::now(), Duration::from_secs(self.period)) + let limit = SystemTime::now().checked_add(Duration::from_secs(self.period)) .ok_or(BlockError::TimestampOverflow)?; // This should succeed under the constraints that the system clock works @@ -581,7 +580,7 @@ impl Engine for Clique { let hdr = Duration::from_secs(header.timestamp()); if hdr > limit_as_dur { - let found = CheckedSystemTime::checked_add(UNIX_EPOCH, hdr).ok_or(BlockError::TimestampOverflow)?; + let found = UNIX_EPOCH.checked_add(hdr).ok_or(BlockError::TimestampOverflow)?; Err(BlockError::TemporarilyInvalid(OutOfBounds { min: None, @@ -692,8 +691,8 @@ impl Engine for Clique { // Ensure that the block's timestamp isn't too close to it's parent let limit = parent.timestamp().saturating_add(self.period); if limit > header.timestamp() { - let max = CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(header.timestamp())); - let found = CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(limit)) + let max = UNIX_EPOCH.checked_add(Duration::from_secs(header.timestamp())); + let found = UNIX_EPOCH.checked_add(Duration::from_secs(limit)) .ok_or(BlockError::TimestampOverflow)?; Err(BlockError::InvalidTimestamp(OutOfBounds { diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index 9139c35425a..fd453dbb6c9 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -44,7 +44,6 @@ serde_derive = "1.0" serde_json = "1.0" spec = { path = "../spec" } state-db = { path = "../state-db" } -time-utils = { path = "../../util/time-utils" } tiny-keccak = "1.4" trace = { path = "../trace" } transaction-pool = "2.0.1" diff --git a/ethcore/private-tx/src/lib.rs b/ethcore/private-tx/src/lib.rs index a0ebb2cbdba..498e6789f80 100644 --- a/ethcore/private-tx/src/lib.rs +++ b/ethcore/private-tx/src/lib.rs @@ -71,9 +71,6 @@ extern crate derive_more; extern crate rlp_derive; extern crate vm; -#[cfg(not(time_checked_add))] -extern crate time_utils; - #[cfg(test)] extern crate env_logger; diff --git a/ethcore/private-tx/src/log.rs b/ethcore/private-tx/src/log.rs index 44b473bca2e..aefeba41012 100644 --- a/ethcore/private-tx/src/log.rs +++ b/ethcore/private-tx/src/log.rs @@ -26,9 +26,6 @@ use parking_lot::RwLock; use serde::ser::{Serializer, SerializeSeq}; use error::Error; -#[cfg(not(time_checked_add))] -use time_utils::CheckedSystemTime; - /// Maximum amount of stored private transaction logs. const MAX_JOURNAL_LEN: usize = 1000; @@ -331,9 +328,6 @@ mod tests { use parking_lot::RwLock; use super::{TransactionLog, Logging, PrivateTxStatus, LogsSerializer, ValidatorLog}; - #[cfg(not(time_checked_add))] - use time_utils::CheckedSystemTime; - struct StringLogSerializer { string_log: RwLock, } diff --git a/ethcore/verification/Cargo.toml b/ethcore/verification/Cargo.toml index 3943413ab0e..fc3202756eb 100644 --- a/ethcore/verification/Cargo.toml +++ b/ethcore/verification/Cargo.toml @@ -27,7 +27,6 @@ parity-bytes = "0.1.0" parity-util-mem = "0.3.0" parking_lot = "0.9" rlp = "0.4.2" -time-utils = { path = "../../util/time-utils" } triehash = { package = "triehash-ethereum", version = "0.2", path = "../../util/triehash-ethereum" } unexpected = { path = "../../util/unexpected" } diff --git a/ethcore/verification/src/verification.rs b/ethcore/verification/src/verification.rs index 6c21004d83b..2c5fcc46db5 100644 --- a/ethcore/verification/src/verification.rs +++ b/ethcore/verification/src/verification.rs @@ -42,8 +42,6 @@ use common_types::{ verification::Unverified, }; -use time_utils::CheckedSystemTime; - /// Phase 1 quick block verification. Only does checks that are cheap. Operates on a single block pub fn verify_block_basic(block: &Unverified, engine: &dyn Engine, check_seal: bool) -> Result<(), Error> { verify_header_params(&block.header, engine, check_seal)?; @@ -341,7 +339,7 @@ pub(crate) fn verify_header_time(header: &Header) -> Result<(), Error> { // this will resist overflow until `year 2037` let max_time = SystemTime::now() + ACCEPTABLE_DRIFT; let invalid_threshold = max_time + ACCEPTABLE_DRIFT * 9; - let timestamp = CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::from_secs(header.timestamp())) + let timestamp = UNIX_EPOCH.checked_add(Duration::from_secs(header.timestamp())) .ok_or(BlockError::TimestampOverflow)?; if timestamp > invalid_threshold { @@ -370,9 +368,9 @@ fn verify_parent(header: &Header, parent: &Header, engine: &dyn Engine) -> Resul if !engine.is_timestamp_valid(header.timestamp(), parent.timestamp()) { let now = SystemTime::now(); - let min = CheckedSystemTime::checked_add(now, Duration::from_secs(parent.timestamp().saturating_add(1))) + let min = now.checked_add(Duration::from_secs(parent.timestamp().saturating_add(1))) .ok_or(BlockError::TimestampOverflow)?; - let found = CheckedSystemTime::checked_add(now, Duration::from_secs(header.timestamp())) + let found = now.checked_add(Duration::from_secs(header.timestamp())) .ok_or(BlockError::TimestampOverflow)?; return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: None, min: Some(min), found }.into()))) } diff --git a/util/time-utils/Cargo.toml b/util/time-utils/Cargo.toml deleted file mode 100644 index 38e7dd02c68..00000000000 --- a/util/time-utils/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "time-utils" -version = "0.1.0" -authors = ["Parity Technologies "] -description = "Time utilities for checked arithmetic" -license = "GPL3" -edition = "2018" - -[dependencies] diff --git a/util/time-utils/src/lib.rs b/util/time-utils/src/lib.rs deleted file mode 100644 index 85aad4afc07..00000000000 --- a/util/time-utils/src/lib.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -use std::time::{Duration, SystemTime, UNIX_EPOCH}; - -/// Temporary trait for `checked operations` on SystemTime until these are available in the standard library -pub trait CheckedSystemTime { - /// Returns `Some` when the result less or equal to `i32::max_value` to prevent `SystemTime` to panic because - /// it is platform specific, possible representations are i32, i64, u64 or Duration. `None` otherwise - fn checked_add(self, _d: Duration) -> Option; - /// Returns `Some` when the result is successful and `None` when it is not - fn checked_sub(self, _d: Duration) -> Option; -} - -impl CheckedSystemTime for SystemTime { - fn checked_add(self, dur: Duration) -> Option { - let this_dur = self.duration_since(UNIX_EPOCH).ok()?; - let total_time = this_dur.checked_add(dur)?; - - if total_time.as_secs() <= i32::max_value() as u64 { - Some(self + dur) - } else { - None - } - } - - fn checked_sub(self, dur: Duration) -> Option { - let this_dur = self.duration_since(UNIX_EPOCH).ok()?; - let total_time = this_dur.checked_sub(dur)?; - - if total_time.as_secs() <= i32::max_value() as u64 { - Some(self - dur) - } else { - None - } - } -} - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - use super::CheckedSystemTime; - use std::time::{Duration, SystemTime, UNIX_EPOCH}; - - assert!(CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::new(i32::max_value() as u64 + 1, 0)).is_none()); - assert!(CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::new(i32::max_value() as u64, 0)).is_some()); - assert!(CheckedSystemTime::checked_add(UNIX_EPOCH, Duration::new(i32::max_value() as u64 - 1, 1_000_000_000)).is_some()); - - assert!(CheckedSystemTime::checked_sub(UNIX_EPOCH, Duration::from_secs(120)).is_none()); - assert!(CheckedSystemTime::checked_sub(SystemTime::now(), Duration::from_secs(1000)).is_some()); - } -}