Skip to content

Commit

Permalink
fix: timestamp include genesis delay
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Oct 17, 2024
1 parent 2f7badd commit 68e59a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/api/src/builder/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use uuid::Uuid;

use crate::{
builder::{error::BuilderApiError, traits::BlockSimulator, BlockSimRequest, DbInfo, OptimisticVersion},
get_genesis_time,
gossiper::{
traits::GossipClientTrait,
types::{BroadcastHeaderParams, BroadcastPayloadParams, GossipedMessage},
Expand Down Expand Up @@ -1646,7 +1647,8 @@ fn sanity_check_block_submission(
payload_attributes: &PayloadAttributesUpdate,
chain_info: &ChainInfo,
) -> Result<(), BuilderApiError> {
let expected_timestamp = chain_info.genesis_time_in_secs + (bid_trace.slot * chain_info.seconds_per_slot);
let genesis_time = get_genesis_time(chain_info);
let expected_timestamp = genesis_time + (bid_trace.slot * chain_info.seconds_per_slot);
if payload.timestamp() != expected_timestamp {
return Err(BuilderApiError::IncorrectTimestamp { got: payload.timestamp(), expected: expected_timestamp });
}
Expand Down
9 changes: 9 additions & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(clippy::too_many_arguments)]

use helix_common::chain_info::ChainInfo;

pub mod builder;
pub mod constraints;
pub mod gossiper;
Expand All @@ -16,3 +18,10 @@ pub mod test_utils;
mod grpc {
include!(concat!(env!("OUT_DIR"), "/gossip.rs"));
}

pub fn get_genesis_time(chain_info: &ChainInfo) -> u64 {
match chain_info.context.genesis_time() {
Ok(genesis_time) => genesis_time,
Err(_) => chain_info.genesis_time_in_secs + chain_info.context.genesis_delay,
}
}
7 changes: 5 additions & 2 deletions crates/api/src/proposer/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use crate::{
api::{MAX_GATEWAY_ELECTION_SIZE, MAX_SET_CONSTRAINTS_SIZE},
SET_CONSTRAINTS_CUTOFF_NS,
},
get_genesis_time,
gossiper::{
traits::GossipClientTrait,
types::{BroadcastGetPayloadParams, GossipedMessage},
Expand Down Expand Up @@ -849,7 +850,8 @@ where
}

// Constraints cannot be set more than `SET_CONSTRAINTS_CUTOFF_NS` into the requested slot.
let slot_start_timestamp = self.chain_info.genesis_time_in_secs + (constraints.slot() * self.chain_info.seconds_per_slot);
let genesis_time = get_genesis_time(&self.chain_info);
let slot_start_timestamp = genesis_time + (constraints.slot() * self.chain_info.seconds_per_slot);
let ns_into_slot = (receive_ns as i64).saturating_sub((slot_start_timestamp * 1_000_000_000) as i64);
if ns_into_slot > SET_CONSTRAINTS_CUTOFF_NS {
return Err(ProposerApiError::SetConstraintsTooLate { ns_into_slot: ns_into_slot as u64, cutoff: SET_CONSTRAINTS_CUTOFF_NS as u64 });
Expand Down Expand Up @@ -1319,7 +1321,8 @@ where

/// Calculates the time information for a given slot.
fn calculate_slot_time_info(chain_info: &ChainInfo, slot: u64, request_time: u64) -> (i64, Duration) {
let slot_start_timestamp_in_secs = chain_info.genesis_time_in_secs + (slot * chain_info.seconds_per_slot);
let genesis_time = get_genesis_time(chain_info);
let slot_start_timestamp_in_secs = genesis_time + (slot * chain_info.seconds_per_slot);
let ms_into_slot = (request_time / 1_000_000) as i64 - (slot_start_timestamp_in_secs * 1000) as i64;
let duration_until_slot_start = chain_info.clock.duration_until_slot(slot);

Expand Down

0 comments on commit 68e59a0

Please sign in to comment.