Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timestamp include genesis delay #18

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
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.context.min_genesis_time + 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