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

Commit e1c1ecf

Browse files
authored
2.4.2 beta backports (#10488)
* version: bump beta * Сaching through docker volume (#10477) * _old codebase_ before docker update * before docker update, testing runnr * docker update, testing the caching * distributed job cargo homes * distributed job cargo homes 2 * distributed job cargo homes 3 * dockerfile with gitlab checkout, audit uses template * dockerfile gets repo in volume * change builds_dir * trying docker cache for repo * repo cached automatically * after script is not concatenated * check sccache non-cacheable reasons nature * watch cache * log sccache * log sccache 2 * debug log sccache * fix debug log sccache * fix debug log sccache 2 * debug log cache 3 * debug log cache 3 * trace log all sccache * test wo cargo cache * test w removed cargo cache * report non-cacheable reasons, cargo cache is back and empty * report non-cacheable reasons, cargo cache is back and empty 2 * report non-cacheable reasons, cargo cache is back and empty 3 * wrap into after_script * restore CI tags `qa` -> `linux-docker` * return to main runners, this will fail until config on runners And Dockerfile won't be updated * typo fix CI lint * return to docker tag * fix win&mac build (#10486) add CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" * fix(extract `timestamp_checked_add` as lib) (#10383) * fix(extract `timestamp_checked_add` as lib) * fix(whisper types): remove unused `EmptyTopics` * fix(time-lib): feature-flag to use time-lib or std This commit adds conditional compilation checks that falls back to `our time-lib` when `time_checked_add` is not available in the standard library Note, `time_checked_add` covers both `checked_add` and `checked_sub` * fix(grumble): use cfg_attr to define rustc feature
1 parent 72c8b79 commit e1c1ecf

File tree

14 files changed

+165
-73
lines changed

14 files changed

+165
-73
lines changed

.gitlab-ci.yml

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ variables:
99
GIT_STRATEGY: fetch
1010
GIT_SUBMODULE_STRATEGY: recursive
1111
CI_SERVER_NAME: "GitLab CI"
12-
CARGO_HOME: "${CI_PROJECT_DIR}/.cargo"
1312
CARGO_TARGET: x86_64-unknown-linux-gnu
1413

15-
.no_git: &no_git #disable git strategy
14+
.no_git: &no_git # disable git strategy
1615
variables:
1716
GIT_STRATEGY: none
1817
GIT_SUBMODULE_STRATEGY: none
@@ -32,12 +31,17 @@ variables:
3231
paths:
3332
- artifacts/
3433

35-
.docker-cache-status: &docker-cache-status
36-
dependencies: []
34+
.docker-cache-status: &docker-cache-status
35+
variables:
36+
CARGO_HOME: "/cargo/${CI_JOB_NAME}"
3737
before_script:
38+
- SCCACHE_ERROR_LOG=/builds/parity/parity-ethereum/sccache_error.log RUST_LOG=sccache::server=debug sccache --start-server
3839
- sccache -s
3940
after_script:
40-
- sccache -s
41+
- echo "All crate-types:"
42+
- grep 'parse_arguments.*--crate-type' sccache_error.log | sed -re 's/.*"--crate-type", "([^"]+)".*/\1/' | sort | uniq -c
43+
- echo "Non-cacheable reasons:"
44+
- grep CannotCache sccache_error.log | sed -re 's/.*CannotCache\((.+)\).*/\1/' | sort | uniq -c
4145
tags:
4246
- linux-docker
4347

@@ -47,50 +51,68 @@ cargo-check 0 3:
4751
<<: *docker-cache-status
4852
script:
4953
- time cargo check --target $CARGO_TARGET --locked --no-default-features
54+
- sccache -s
5055

5156
cargo-check 1 3:
5257
stage: test
5358
<<: *docker-cache-status
5459
script:
5560
- time cargo check --target $CARGO_TARGET --locked --manifest-path util/io/Cargo.toml --no-default-features
61+
- sccache -s
5662

5763
cargo-check 2 3:
5864
stage: test
5965
<<: *docker-cache-status
6066
script:
6167
- time cargo check --target $CARGO_TARGET --locked --manifest-path util/io/Cargo.toml --features "mio"
68+
- sccache -s
6269

6370
cargo-audit:
6471
stage: test
72+
<<: *docker-cache-status
6573
script:
6674
- cargo audit
67-
tags:
68-
- linux-docker
75+
- sccache -s
6976

7077
validate-chainspecs:
7178
stage: test
7279
<<: *docker-cache-status
7380
script:
7481
- ./scripts/gitlab/validate-chainspecs.sh
82+
- sccache -s
7583

7684
test-cpp:
7785
stage: build
7886
<<: *docker-cache-status
7987
script:
8088
- ./scripts/gitlab/test-cpp.sh
89+
- sccache -s
8190

8291
test-linux:
8392
stage: build
8493
<<: *docker-cache-status
8594
script:
8695
- ./scripts/gitlab/test-linux.sh
96+
- sccache -s
97+
98+
build-android:
99+
stage: build
100+
image: parity/rust-android:gitlab-ci
101+
variables:
102+
CARGO_TARGET: armv7-linux-androideabi
103+
script:
104+
- scripts/gitlab/build-linux.sh
105+
tags:
106+
- linux-docker
107+
<<: *collect_artifacts
87108

88109
build-linux: &build-linux
89110
stage: build
90111
only: *releaseable_branches
91112
<<: *docker-cache-status
92113
script:
93114
- scripts/gitlab/build-linux.sh
115+
- sccache -s
94116
<<: *collect_artifacts
95117

96118
build-linux-i386:
@@ -116,6 +138,7 @@ build-darwin:
116138
only: *releaseable_branches
117139
variables:
118140
CARGO_TARGET: x86_64-apple-darwin
141+
CARGO_HOME: "${CI_PROJECT_DIR}/.cargo"
119142
CC: gcc
120143
CXX: g++
121144
script:
@@ -129,6 +152,7 @@ build-windows:
129152
only: *releaseable_branches
130153
variables:
131154
CARGO_TARGET: x86_64-pc-windows-msvc
155+
CARGO_HOME: "${CI_PROJECT_DIR}/.cargo"
132156
script:
133157
- sh scripts/gitlab/build-windows.sh
134158
tags:
@@ -138,7 +162,7 @@ build-windows:
138162
publish-docker:
139163
stage: publish
140164
only: *releaseable_branches
141-
cache: {}
165+
cache: {}
142166
dependencies:
143167
- build-linux
144168
tags:
@@ -152,7 +176,7 @@ publish-snap: &publish-snap
152176
image: snapcore/snapcraft
153177
variables:
154178
BUILD_ARCH: amd64
155-
cache: {}
179+
cache: {}
156180
dependencies:
157181
- build-linux
158182
tags:
@@ -228,19 +252,9 @@ publish-docs:
228252
- tags
229253
except:
230254
- nightly
231-
cache: {}
255+
cache: {}
232256
script:
233257
- scripts/gitlab/publish-docs.sh
234258
tags:
235259
- linux-docker
236260

237-
build-android:
238-
stage: build
239-
image: parity/rust-android:gitlab-ci
240-
variables:
241-
CARGO_TARGET: armv7-linux-androideabi
242-
script:
243-
- scripts/gitlab/build-linux.sh
244-
tags:
245-
- linux-docker
246-
<<: *collect_artifacts

Cargo.lock

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description = "Parity Ethereum client"
33
name = "parity-ethereum"
44
# NOTE Make sure to update util/version/Cargo.toml as well
5-
version = "2.4.1"
5+
version = "2.4.2"
66
license = "GPL-3.0"
77
authors = ["Parity Technologies <admin@parity.io>"]
88

@@ -138,7 +138,8 @@ members = [
138138
"util/triehash-ethereum",
139139
"util/keccak-hasher",
140140
"util/patricia-trie-ethereum",
141-
"util/fastmap"
141+
"util/fastmap",
142+
"util/time-utils"
142143
]
143144

144145
[patch.crates-io]

ethcore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ serde = "1.0"
6464
serde_derive = "1.0"
6565
stats = { path = "../util/stats" }
6666
tempdir = {version="0.3", optional = true}
67+
time-utils = { path = "../util/time-utils" }
6768
trace-time = "0.1"
6869
triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" }
6970
unexpected = { path = "../util/unexpected" }

ethcore/src/engines/authority_round/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ use types::header::{Header, ExtendedHeader};
4747
use types::ancestry_action::AncestryAction;
4848
use unexpected::{Mismatch, OutOfBounds};
4949

50+
#[cfg(not(time_checked_add))]
51+
use time_utils::CheckedSystemTime;
52+
5053
mod finality;
5154

5255
/// `AuthorityRound` params.
@@ -570,8 +573,15 @@ fn verify_timestamp(step: &Step, header_step: u64) -> Result<(), BlockError> {
570573
// NOTE This error might be returned only in early stage of verification (Stage 1).
571574
// Returning it further won't recover the sync process.
572575
trace!(target: "engine", "verify_timestamp: block too early");
573-
let oob = oob.map(|n| SystemTime::now() + Duration::from_secs(n));
574-
Err(BlockError::TemporarilyInvalid(oob).into())
576+
577+
let now = SystemTime::now();
578+
let found = now.checked_add(Duration::from_secs(oob.found)).ok_or(BlockError::TimestampOverflow)?;
579+
let max = oob.max.and_then(|m| now.checked_add(Duration::from_secs(m)));
580+
let min = oob.min.and_then(|m| now.checked_add(Duration::from_secs(m)));
581+
582+
let new_oob = OutOfBounds { min, max, found };
583+
584+
Err(BlockError::TemporarilyInvalid(new_oob).into())
575585
},
576586
Ok(_) => Ok(()),
577587
}
@@ -607,6 +617,7 @@ fn combine_proofs(signal_number: BlockNumber, set_proof: &[u8], finality_proof:
607617
stream.out()
608618
}
609619

620+
610621
fn destructure_proofs(combined: &[u8]) -> Result<(BlockNumber, &[u8], &[u8]), Error> {
611622
let rlp = Rlp::new(combined);
612623
Ok((
@@ -622,7 +633,7 @@ trait AsMillis {
622633

623634
impl AsMillis for Duration {
624635
fn as_millis(&self) -> u64 {
625-
self.as_secs()*1_000 + (self.subsec_nanos()/1_000_000) as u64
636+
self.as_secs() * 1_000 + (self.subsec_nanos() / 1_000_000) as u64
626637
}
627638
}
628639

ethcore/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
1616

1717
#![warn(missing_docs, unused_extern_crates)]
18+
#![cfg_attr(feature = "time_checked_add", feature(time_checked_add))]
1819

1920
//! Ethcore library
2021
//!
@@ -149,6 +150,9 @@ extern crate fetch;
149150
#[cfg(all(test, feature = "price-info"))]
150151
extern crate parity_runtime;
151152

153+
#[cfg(not(time_checked_add))]
154+
extern crate time_utils;
155+
152156
pub mod block;
153157
pub mod builtin;
154158
pub mod client;

ethcore/src/verification/verification.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,8 @@ use types::{BlockNumber, header::Header};
4040
use types::transaction::SignedTransaction;
4141
use verification::queue::kind::blocks::Unverified;
4242

43-
44-
/// Returns `Ok<SystemTime>` when the result less or equal to `i32::max_value` to prevent `SystemTime` to panic because
45-
/// it is platform specific, may be i32 or i64.
46-
///
47-
/// `Err<BlockError::TimestampOver` otherwise.
48-
///
49-
// FIXME: @niklasad1 - remove this when and use `SystemTime::checked_add`
50-
// when https://github.com/rust-lang/rust/issues/55940 is stabilized.
51-
fn timestamp_checked_add(sys: SystemTime, d2: Duration) -> Result<SystemTime, BlockError> {
52-
let d1 = sys.duration_since(UNIX_EPOCH).map_err(|_| BlockError::TimestampOverflow)?;
53-
let total_time = d1.checked_add(d2).ok_or(BlockError::TimestampOverflow)?;
54-
55-
if total_time.as_secs() <= i32::max_value() as u64 {
56-
Ok(sys + d2)
57-
} else {
58-
Err(BlockError::TimestampOverflow)
59-
}
60-
}
43+
#[cfg(not(time_checked_add))]
44+
use time_utils::CheckedSystemTime;
6145

6246
/// Preprocessed block data gathered in `verify_block_unordered` call
6347
pub struct PreverifiedBlock {
@@ -323,9 +307,11 @@ pub fn verify_header_params(header: &Header, engine: &EthEngine, is_full: bool,
323307

324308
if is_full {
325309
const ACCEPTABLE_DRIFT: Duration = Duration::from_secs(15);
310+
// this will resist overflow until `year 2037`
326311
let max_time = SystemTime::now() + ACCEPTABLE_DRIFT;
327312
let invalid_threshold = max_time + ACCEPTABLE_DRIFT * 9;
328-
let timestamp = timestamp_checked_add(UNIX_EPOCH, Duration::from_secs(header.timestamp()))?;
313+
let timestamp = UNIX_EPOCH.checked_add(Duration::from_secs(header.timestamp()))
314+
.ok_or(BlockError::TimestampOverflow)?;
329315

330316
if timestamp > invalid_threshold {
331317
return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: Some(max_time), min: None, found: timestamp })))
@@ -347,8 +333,11 @@ fn verify_parent(header: &Header, parent: &Header, engine: &EthEngine) -> Result
347333
let gas_limit_divisor = engine.params().gas_limit_bound_divisor;
348334

349335
if !engine.is_timestamp_valid(header.timestamp(), parent.timestamp()) {
350-
let min = timestamp_checked_add(SystemTime::now(), Duration::from_secs(parent.timestamp().saturating_add(1)))?;
351-
let found = timestamp_checked_add(SystemTime::now(), Duration::from_secs(header.timestamp()))?;
336+
let now = SystemTime::now();
337+
let min = now.checked_add(Duration::from_secs(parent.timestamp().saturating_add(1)))
338+
.ok_or(BlockError::TimestampOverflow)?;
339+
let found = now.checked_add(Duration::from_secs(header.timestamp()))
340+
.ok_or(BlockError::TimestampOverflow)?;
352341
return Err(From::from(BlockError::InvalidTimestamp(OutOfBounds { max: None, min: Some(min), found })))
353342
}
354343
if header.number() != parent.number() + 1 {
@@ -835,11 +824,4 @@ mod tests {
835824
check_fail(unordered_test(&create_test_block_with_data(&header, &bad_transactions, &[]), &engine), TooManyTransactions(keypair.address()));
836825
unordered_test(&create_test_block_with_data(&header, &good_transactions, &[]), &engine).unwrap();
837826
}
838-
839-
#[test]
840-
fn checked_add_systime_dur() {
841-
assert!(timestamp_checked_add(UNIX_EPOCH, Duration::new(i32::max_value() as u64 + 1, 0)).is_err());
842-
assert!(timestamp_checked_add(UNIX_EPOCH, Duration::new(i32::max_value() as u64, 0)).is_ok());
843-
assert!(timestamp_checked_add(UNIX_EPOCH, Duration::new(i32::max_value() as u64 - 1, 1_000_000_000)).is_ok());
844-
}
845827
}

0 commit comments

Comments
 (0)