-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: commit 70cfea62e8bc80eba7d0072e4ecad5f01fc3a2e1 Author: Simon Gellis <[email protected]> Date: Tue Oct 8 17:47:39 2024 -0400 Use a Clock to make time easier to work with commit bebf58bf0358698fd2277af50a5b9ee490cff261 Author: Simon Gellis <[email protected]> Date: Tue Oct 8 16:59:04 2024 -0400 Model coordinates geographically commit 1d577133b39cf9b920ee454984d0775c5f53c0a0 Author: Simon Gellis <[email protected]> Date: Tue Oct 8 14:47:49 2024 -0400 Update data (and variable names) to reflect stake pools commit cba2a17cc8304d852c45a103e2da49bd5361029a Author: Simon Gellis <[email protected]> Date: Tue Oct 8 14:40:54 2024 -0400 Use simplified chainsync/blockfetch to improve sim accuracy
- Loading branch information
1 parent
4616dc1
commit bbce7d5
Showing
9 changed files
with
295 additions
and
175 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::{ | ||
ops::Add, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
use serde::Serialize; | ||
use tokio::time::{self, Sleep}; | ||
|
||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct Timestamp(Duration); | ||
impl Add<Duration> for Timestamp { | ||
type Output = Timestamp; | ||
|
||
fn add(self, rhs: Duration) -> Self::Output { | ||
Timestamp(self.0 + rhs) | ||
} | ||
} | ||
|
||
impl Serialize for Timestamp { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_u128(self.0.as_nanos()) | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Clock { | ||
start: Instant, | ||
} | ||
|
||
impl Clock { | ||
pub fn new(start: Instant) -> Self { | ||
Self { start } | ||
} | ||
|
||
pub fn now(&self) -> Timestamp { | ||
Timestamp(self.start.elapsed()) | ||
} | ||
|
||
pub fn wait_until(&self, timestamp: Timestamp) -> Sleep { | ||
let instant = self.start + timestamp.0; | ||
time::sleep_until(instant.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.