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

Update AuRa check_future ; handling step transitions #11896

Open
wants to merge 1 commit 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
33 changes: 20 additions & 13 deletions ethcore/engines/authority-round/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,26 @@ impl Step {
})
}

/// Finds the remaining duration of the current step. Returns `None` if there was a counter
/// under- or overflow.
fn opt_duration_remaining(&self) -> Option<Duration> {
let next_step = self.load().checked_add(1)?;
/// Convert a given step number to the corresponding expected time
fn step_to_time(&self, step: u64) -> Option<u64> {
let StepDurationInfo { transition_step, transition_timestamp, step_duration } =
self.durations.iter()
.take_while(|info| info.transition_step < next_step)
.take_while(|info| info.transition_step < step)
.last()
.expect("durations cannot be empty")
.expect("durations cannot be empty.")
.clone();
let next_time = transition_timestamp
.checked_add(next_step.checked_sub(transition_step)?.checked_mul(step_duration)?)?;

let time = transition_timestamp
.checked_add(step.checked_sub(transition_step)?.checked_mul(step_duration)?)?;
Some(time)
}


/// Finds the remaining duration of the current step. Returns `None` if there was a counter
/// under- or overflow.
fn opt_duration_remaining(&self) -> Option<Duration> {
let next_step = self.load().checked_add(1)?;
let next_time = self.step_to_time(next_step)?;
Some(Duration::from_secs(next_time.saturating_sub(unix_now().as_secs())))
}

Expand Down Expand Up @@ -318,13 +326,12 @@ impl Step {
Err(None)
// wait a bit for blocks in near future
} else if given > current {
let d = self.durations.iter().take_while(|info| info.transition_step <= current).last()
.expect("Duration map has at least a 0 entry.")
.step_duration;
let current_time = self.step_to_time(current).ok_or(None)?;
let given_time = self.step_to_time(given).ok_or(None)?;
Err(Some(OutOfBounds {
min: None,
max: Some(d * current),
found: d * given,
max: Some(current_time),
found: given_time,
}))
} else {
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions ethcore/verification/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,9 @@ fn verify_parent(header: &Header, parent: &Header, engine: &dyn Engine) -> Resul
"Parent hash should already have been verified; qed");

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 = CheckedSystemTime::checked_add(UNIX_EPOCH, 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 = CheckedSystemTime::checked_add(UNIX_EPOCH, 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