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

Commit

Permalink
fix(whisper expiry): current time + work + ttl (#10587)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 authored and TriplEight committed Apr 15, 2019
1 parent 6fcd775 commit 92e770e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions whisper/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ impl Message {

let mut rng = {
let mut thread_rng = ::rand::thread_rng();

XorShiftRng::from_seed(thread_rng.gen::<[u32; 4]>())
};

assert!(params.ttl > 0);

let expiry = {
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");
let since_epoch = SystemTime::now()
.checked_add(Duration::from_secs(params.ttl))
.and_then(|t| t.checked_add(Duration::from_millis(params.work)))
.ok_or(Error::TimestampOverflow)?
.duration_since(time::UNIX_EPOCH).expect("time after now is after unix epoch; qed");

// round up the sub-second to next whole second.
since_epoch.as_secs() + if since_epoch.subsec_nanos() == 0 { 0 } else { 1 }
Expand Down

0 comments on commit 92e770e

Please sign in to comment.