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
This commit is contained in:
Sočik
2019-03-20 09:17:30 +01:00
committed by GitHub
parent 72c8b79035
commit e1c1ecf0a5
14 changed files with 165 additions and 73 deletions

View File

@@ -17,6 +17,8 @@
//! Whisper P2P messaging system as a DevP2P subprotocol, with RPC and Rust
//! interface.
#![cfg_attr(feature = "time_checked_add", feature(time_checked_add))]
extern crate byteorder;
extern crate parity_crypto as crypto;
extern crate ethcore_network as network;
@@ -46,6 +48,9 @@ extern crate log;
#[macro_use]
extern crate serde_derive;
#[cfg(not(time_checked_add))]
extern crate time_utils;
#[cfg(test)]
extern crate serde_json;

View File

@@ -24,6 +24,9 @@ use rlp::{self, DecoderError, RlpStream, Rlp};
use smallvec::SmallVec;
use tiny_keccak::{keccak256, Keccak};
#[cfg(not(time_checked_add))]
use time_utils::CheckedSystemTime;
/// Work-factor proved. Takes 3 parameters: size of message, time to live,
/// and hash.
///
@@ -117,6 +120,7 @@ pub enum Error {
EmptyTopics,
LivesTooLong,
IssuedInFuture,
TimestampOverflow,
ZeroTTL,
}
@@ -133,6 +137,7 @@ impl fmt::Display for Error {
Error::LivesTooLong => write!(f, "Message claims to be issued before the unix epoch."),
Error::IssuedInFuture => write!(f, "Message issued in future."),
Error::ZeroTTL => write!(f, "Message live for zero time."),
Error::TimestampOverflow => write!(f, "Timestamp overflow"),
Error::EmptyTopics => write!(f, "Message has no topics."),
}
}
@@ -226,10 +231,6 @@ impl rlp::Decodable for Envelope {
}
}
/// Error indicating no topics.
#[derive(Debug, Copy, Clone)]
pub struct EmptyTopics;
/// Message creation parameters.
/// Pass this to `Message::create` to make a message.
pub struct CreateParams {
@@ -255,11 +256,11 @@ pub struct Message {
impl Message {
/// Create a message from creation parameters.
/// Panics if TTL is 0.
pub fn create(params: CreateParams) -> Result<Self, EmptyTopics> {
pub fn create(params: CreateParams) -> Result<Self, Error> {
use byteorder::{BigEndian, ByteOrder};
use rand::{Rng, SeedableRng, XorShiftRng};
if params.topics.is_empty() { return Err(EmptyTopics) }
if params.topics.is_empty() { return Err(Error::EmptyTopics) }
let mut rng = {
let mut thread_rng = ::rand::thread_rng();
@@ -270,7 +271,8 @@ impl Message {
assert!(params.ttl > 0);
let expiry = {
let after_mining = SystemTime::now() + Duration::from_millis(params.work);
let after_mining = SystemTime::now().checked_sub(Duration::from_millis(params.work))
.ok_or(Error::TimestampOverflow)?;
let since_epoch = after_mining.duration_since(time::UNIX_EPOCH)
.expect("time after now is after unix epoch; qed");
@@ -357,7 +359,10 @@ impl Message {
(envelope.expiry - envelope.ttl).saturating_sub(LEEWAY_SECONDS)
);
if time::UNIX_EPOCH + issue_time_adjusted > now {
let issue_time_adjusted = time::UNIX_EPOCH.checked_add(issue_time_adjusted)
.ok_or(Error::TimestampOverflow)?;
if issue_time_adjusted > now {
return Err(Error::IssuedInFuture);
}
@@ -400,8 +405,8 @@ impl Message {
}
/// Get the expiry time.
pub fn expiry(&self) -> SystemTime {
time::UNIX_EPOCH + Duration::from_secs(self.envelope.expiry)
pub fn expiry(&self) -> Option<SystemTime> {
time::UNIX_EPOCH.checked_add(Duration::from_secs(self.envelope.expiry))
}
/// Get the topics.

View File

@@ -223,7 +223,10 @@ impl Messages {
}
}
let expiry = message.expiry();
let expiry = match message.expiry() {
Some(time) => time,
_ => return false,
};
self.cumulative_size += message.encoded_size();
@@ -232,8 +235,8 @@ impl Messages {
let sorted_entry = SortedEntry {
slab_id: id,
work_proved: work_proved,
expiry: expiry,
work_proved,
expiry,
};
match self.sorted.binary_search(&sorted_entry) {