Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Remove time-utils #11410

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
vorot93 marked this conversation as resolved.
Show resolved Hide resolved
```

</p></details>
Expand Down
1 change: 0 additions & 1 deletion ethcore/engines/authority-round/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
7 changes: 3 additions & 4 deletions ethcore/engines/authority-round/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for authority-round the issue of SystemTime being platform dependant doesn't really matter, since we use it in the error path here anyway.


let new_oob = OutOfBounds { min, max, found };

Expand Down
1 change: 0 additions & 1 deletion ethcore/engines/clique/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions ethcore/engines/clique/src/block_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the tricky part that needs to be audited


self.next_timestamp_inturn = inturn;

Expand Down
9 changes: 4 additions & 5 deletions ethcore/engines/clique/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it doesn't matter if we're not taking 2038 problem into account as self.period is a config param and if it's misconfigured, it's not going to work anyway

.ok_or(BlockError::TimestampOverflow)?;

// This should succeed under the constraints that the system clock works
Expand All @@ -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)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here we're in the error path anyway


Err(BlockError::TemporarilyInvalid(OutOfBounds {
min: None,
Expand Down Expand Up @@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error path again

.ok_or(BlockError::TimestampOverflow)?;

Err(BlockError::InvalidTimestamp(OutOfBounds {
Expand Down
1 change: 0 additions & 1 deletion ethcore/private-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 0 additions & 6 deletions ethcore/private-tx/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String>,
}
Expand Down
1 change: 0 additions & 1 deletion ethcore/verification/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
8 changes: 3 additions & 5 deletions ethcore/verification/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())))
}
Expand Down
9 changes: 0 additions & 9 deletions util/time-utils/Cargo.toml

This file was deleted.

66 changes: 0 additions & 66 deletions util/time-utils/src/lib.rs

This file was deleted.