mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-27 01:33:33 +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:
@@ -19,8 +19,8 @@ use lighthouse_network::{
|
||||
};
|
||||
use logging::TimeLatch;
|
||||
use logging::crit;
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
use tracing::{debug, error, trace, warn};
|
||||
@@ -351,6 +351,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
gossip_message: PubsubMessage<T::EthSpec>,
|
||||
should_process: bool,
|
||||
) {
|
||||
let seen_timestamp = self.chain.slot_clock.now_duration().unwrap_or_default();
|
||||
match gossip_message {
|
||||
PubsubMessage::AggregateAndProofAttestation(aggregate_and_proof) => self
|
||||
.handle_beacon_processor_send_result(
|
||||
@@ -358,7 +359,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
message_id,
|
||||
peer_id,
|
||||
*aggregate_and_proof,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
),
|
||||
PubsubMessage::Attestation(subnet_attestation) => self
|
||||
@@ -369,7 +370,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
subnet_attestation.1,
|
||||
subnet_attestation.0,
|
||||
should_process,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
),
|
||||
PubsubMessage::BeaconBlock(block) => self.handle_beacon_processor_send_result(
|
||||
@@ -378,7 +379,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
self.network_globals.client(&peer_id),
|
||||
block,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
),
|
||||
PubsubMessage::BlobSidecar(data) => {
|
||||
@@ -390,7 +391,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
self.network_globals.client(&peer_id),
|
||||
blob_index,
|
||||
blob_sidecar,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -403,7 +404,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
subnet_id,
|
||||
column_sidecar,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -450,7 +451,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
message_id,
|
||||
peer_id,
|
||||
*contribution_and_proof,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -465,7 +466,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
sync_committtee_msg.1,
|
||||
sync_committtee_msg.0,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -480,7 +481,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
message_id,
|
||||
peer_id,
|
||||
*light_client_finality_update,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -496,7 +497,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
message_id,
|
||||
peer_id,
|
||||
*light_client_optimistic_update,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -516,7 +517,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
message_id,
|
||||
peer_id,
|
||||
signed_execution_payload_envelope,
|
||||
timestamp_now(),
|
||||
seen_timestamp,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -642,7 +643,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
sync_request_id,
|
||||
beacon_block,
|
||||
seen_timestamp: timestamp_now(),
|
||||
seen_timestamp: self.chain.slot_clock.now_duration().unwrap_or_default(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -662,7 +663,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
sync_request_id,
|
||||
blob_sidecar,
|
||||
seen_timestamp: timestamp_now(),
|
||||
seen_timestamp: self.chain.slot_clock.now_duration().unwrap_or_default(),
|
||||
});
|
||||
} else {
|
||||
crit!("All blobs by range responses should belong to sync");
|
||||
@@ -699,7 +700,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
sync_request_id,
|
||||
beacon_block,
|
||||
seen_timestamp: timestamp_now(),
|
||||
seen_timestamp: self.chain.slot_clock.now_duration().unwrap_or_default(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -733,7 +734,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
sync_request_id,
|
||||
peer_id,
|
||||
blob_sidecar,
|
||||
seen_timestamp: timestamp_now(),
|
||||
seen_timestamp: self.chain.slot_clock.now_duration().unwrap_or_default(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -767,7 +768,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
sync_request_id,
|
||||
peer_id,
|
||||
data_column,
|
||||
seen_timestamp: timestamp_now(),
|
||||
seen_timestamp: self.chain.slot_clock.now_duration().unwrap_or_default(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -787,7 +788,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
peer_id,
|
||||
sync_request_id,
|
||||
data_column,
|
||||
seen_timestamp: timestamp_now(),
|
||||
seen_timestamp: self.chain.slot_clock.now_duration().unwrap_or_default(),
|
||||
});
|
||||
} else {
|
||||
crit!("All data columns by range responses should belong to sync");
|
||||
@@ -855,9 +856,3 @@ impl<E: EthSpec> HandlerNetworkContext<E> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp_now() -> Duration {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_else(|_| Duration::from_secs(0))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user