mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 06:18:31 +00:00
Refactor timestamp_now (#9094)
#9077 Where possible replaces all instances of `validator_monitor::timestamp_now` with `chain.slot_clock.now_duration().unwrap_or_default()`. Where chain/slot_clock is not available, instead replace it with a convenience function `slot_clock::timestamp_now`. Remove the `validator_monitor::timestamp_now` function. Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
@@ -5,13 +5,12 @@ use crate::kzg_utils::{reconstruct_data_columns, validate_data_columns};
|
||||
use crate::observed_data_sidecars::{
|
||||
Error as ObservedDataSidecarsError, ObservationKey, ObservationStrategy, Observe,
|
||||
};
|
||||
use crate::validator_monitor::timestamp_now;
|
||||
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes, metrics};
|
||||
use educe::Educe;
|
||||
use fork_choice::ProtoBlock;
|
||||
use kzg::{Error as KzgError, Kzg};
|
||||
use proto_array::Block;
|
||||
use slot_clock::SlotClock;
|
||||
use slot_clock::{SlotClock, timestamp_now};
|
||||
use ssz_derive::Encode;
|
||||
use ssz_types::VariableList;
|
||||
use std::iter;
|
||||
@@ -570,8 +569,9 @@ pub fn validate_data_column_sidecar_for_gossip_fulu<T: BeaconChainTypes, O: Obse
|
||||
verify_slot_higher_than_parent(&parent_block, column_slot)?;
|
||||
verify_proposer_and_signature(data_column_fulu, &parent_block, chain)?;
|
||||
let kzg = &chain.kzg;
|
||||
let seen_timestamp = chain.slot_clock.now_duration().unwrap_or_default();
|
||||
let kzg_verified_data_column =
|
||||
verify_kzg_for_data_column(data_column.clone(), kzg, timestamp_now())
|
||||
verify_kzg_for_data_column(data_column.clone(), kzg, seen_timestamp)
|
||||
.map_err(|(_, e)| GossipDataColumnError::InvalidKzgProof(e))?;
|
||||
|
||||
chain
|
||||
|
||||
@@ -19,7 +19,6 @@ use crate::data_column_verification::{KzgVerifiedCustodyDataColumn, KzgVerifiedD
|
||||
use crate::fetch_blobs::fetch_blobs_beacon_adapter::FetchBlobsBeaconAdapter;
|
||||
use crate::kzg_utils::blobs_to_data_column_sidecars;
|
||||
use crate::observed_data_sidecars::ObservationKey;
|
||||
use crate::validator_monitor::timestamp_now;
|
||||
use crate::{
|
||||
AvailabilityProcessingStatus, BeaconChain, BeaconChainError, BeaconChainTypes, BlockError,
|
||||
metrics,
|
||||
@@ -29,6 +28,7 @@ use execution_layer::json_structures::{BlobAndProofV1, BlobAndProofV2};
|
||||
use metrics::{TryExt, inc_counter};
|
||||
#[cfg(test)]
|
||||
use mockall_double::double;
|
||||
use slot_clock::timestamp_now;
|
||||
use ssz_types::FixedVector;
|
||||
use state_processing::per_block_processing::deneb::kzg_commitment_to_versioned_hash;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::io;
|
||||
use std::marker::PhantomData;
|
||||
use std::str::Utf8Error;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::time::Duration;
|
||||
use store::AbstractExecPayload;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use types::consts::altair::{
|
||||
@@ -2085,13 +2085,6 @@ fn register_simulated_attestation(
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the duration since the unix epoch.
|
||||
pub fn timestamp_now() -> Duration {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_else(|_| Duration::from_secs(0))
|
||||
}
|
||||
|
||||
fn u64_to_i64(n: impl Into<u64>) -> i64 {
|
||||
i64::try_from(n.into()).unwrap_or(i64::MAX)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user