From a9adec178d9555f6cf0a4ca4f1c7f8d1531f884e Mon Sep 17 00:00:00 2001 From: Federico Franzoni <8609060+fed-franz@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:54:47 +0200 Subject: [PATCH] consensus: use get_current_timestamp --- consensus/src/proposal/block_generator.rs | 4 ++-- consensus/src/proposal/step.rs | 8 +++----- consensus/src/ratification/step.rs | 6 ++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/consensus/src/proposal/block_generator.rs b/consensus/src/proposal/block_generator.rs index 1d92fabe6a..e53a0585e4 100644 --- a/consensus/src/proposal/block_generator.rs +++ b/consensus/src/proposal/block_generator.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::commons::{get_current_timestamp, RoundUpdate}; +use crate::commons::RoundUpdate; use crate::operations::{CallParams, Operations, Voter}; use node_data::ledger::{ to_str, Attestation, Block, Fault, IterationsInfo, Seed, Slash, @@ -15,9 +15,9 @@ use crate::merkle::merkle_root; use crate::config::MINIMUM_BLOCK_TIME; use dusk_bytes::Serializable; -use node_data::ledger; use node_data::message::payload::Candidate; use node_data::message::{ConsensusHeader, Message, SignInfo, StepMessage}; +use node_data::{get_current_timestamp, ledger}; use std::sync::Arc; use std::time::Instant; use tracing::{debug, info}; diff --git a/consensus/src/proposal/step.rs b/consensus/src/proposal/step.rs index 9ca5c97198..ec89979aa3 100644 --- a/consensus/src/proposal/step.rs +++ b/consensus/src/proposal/step.rs @@ -8,11 +8,12 @@ use crate::commons::{ConsensusError, Database}; use crate::execution_ctx::ExecutionCtx; use crate::msg_handler::{HandleMsgOutput, MsgHandler}; use crate::operations::Operations; +use node_data::get_current_timestamp; use node_data::ledger::IterationsInfo; use node_data::message::Message; use std::cmp; use std::sync::Arc; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::time::Duration; use tokio::sync::Mutex; use crate::config; @@ -109,10 +110,7 @@ impl ProposalStep { /// Waits until the next slot is reached async fn wait_until_next_slot(tip_timestamp: u64) { - let current_time_secs = SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("valid unix epoch") - .as_secs(); + let current_time_secs = get_current_timestamp(); let next_slot_timestamp = tip_timestamp + MINIMUM_BLOCK_TIME; if current_time_secs >= next_slot_timestamp { diff --git a/consensus/src/ratification/step.rs b/consensus/src/ratification/step.rs index dcbf3eaa77..24335a6a3d 100644 --- a/consensus/src/ratification/step.rs +++ b/consensus/src/ratification/step.rs @@ -4,18 +4,16 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::commons::{ - get_current_timestamp, ConsensusError, Database, RoundUpdate, -}; +use crate::commons::{ConsensusError, Database, RoundUpdate}; use crate::execution_ctx::ExecutionCtx; use crate::operations::Operations; use std::marker::PhantomData; use crate::msg_handler::{HandleMsgOutput, MsgHandler}; use crate::ratification::handler; -use node_data::message; use node_data::message::payload::{self, ValidationResult}; use node_data::message::{AsyncQueue, Message, Payload, StepMessage}; +use node_data::{get_current_timestamp, message}; use std::sync::Arc; use tokio::sync::Mutex;