Skip to content

Commit

Permalink
make timestamp u64
Browse files Browse the repository at this point in the history
  • Loading branch information
chirag-bgh committed Sep 11, 2023
1 parent bbefdba commit 5cbb1ac
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion mev-build-rs/src/mempool_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ impl BlindedBlockProvider for Builder {
&self,
registrations: &mut [SignedValidatorRegistration],
) -> Result<(), Error> {
let current_time = get_current_unix_time_in_nanos();
let current_time = match get_current_unix_time_in_nanos().try_into() {
Ok(time) => time,
Err(_) => return Err(Error::OverflowError),
};
self.validator_registry.validate_registrations(
registrations,
current_time,
Expand Down
6 changes: 5 additions & 1 deletion mev-relay-rs/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ impl BlindedBlockProvider for Relay {
&self,
registrations: &mut [SignedValidatorRegistration],
) -> Result<(), Error> {
let current_time = get_current_unix_time_in_nanos();
let current_time = match get_current_unix_time_in_nanos().try_into() {
Ok(time) => time,
Err(_) => return Err(Error::OverflowError),
};

self.validator_registry.validate_registrations(
registrations,
current_time,
Expand Down
7 changes: 5 additions & 2 deletions mev-relay-rs/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::relay::Relay;
use beacon_api_client::mainnet::Client;
use ethereum_consensus::{crypto::SecretKey, state_transition::Context};
use ethereum_consensus::{crypto::SecretKey, networks, state_transition::Context};
use futures::StreamExt;
use mev_rs::{blinded_block_provider::Server as BlindedBlockProviderServer, Error, Network};
use serde::Deserialize;
Expand Down Expand Up @@ -58,7 +58,10 @@ impl Service {

let context =
if let Some(context) = context { context } else { Context::try_from(&network)? };
let clock = context.clock().unwrap();
let clock = context.clock().unwrap_or_else(|| {
let genesis_time = networks::typical_genesis_time(&context);
context.clock_at(genesis_time)
});
let context = Arc::new(context);
let genesis_details = beacon_node.get_genesis_details().await?;
let genesis_validators_root = genesis_details.genesis_validators_root;
Expand Down
2 changes: 2 additions & 0 deletions mev-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum Error {
#[cfg(feature = "engine-proxy")]
#[error("{0}")]
EngineApi(#[from] crate::engine_api_proxy::Error),
#[error("Overflow error, value too large")]
OverflowError,
}

#[cfg(feature = "api")]
Expand Down
8 changes: 4 additions & 4 deletions mev-rs/src/validator_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub enum Error {

fn validate_registration_is_not_from_future(
timestamp: u64,
current_timestamp: u128,
current_timestamp: u64,
) -> Result<(), Error> {
if u128::from(timestamp) > current_timestamp + 10 {
if timestamp > current_timestamp + 10 {
Err(Error::InvalidTimestamp)
} else {
Ok(())
Expand Down Expand Up @@ -125,7 +125,7 @@ impl ValidatorRegistry {
pub fn validate_registrations(
&self,
registrations: &mut [SignedValidatorRegistration],
current_timestamp: u128,
current_timestamp: u64,
context: &Context,
) -> Result<(), Error> {
for registration in registrations.iter_mut() {
Expand All @@ -138,7 +138,7 @@ impl ValidatorRegistry {
fn validate_registration(
&self,
registration: &mut SignedValidatorRegistration,
current_timestamp: u128,
current_timestamp: u64,
context: &Context,
) -> Result<(), Error> {
let mut state = self.state.lock();
Expand Down

0 comments on commit 5cbb1ac

Please sign in to comment.