From 47e3d3516a285faaa32001f3f5593aceb88b671c Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:02:54 -0400 Subject: [PATCH] Clean up consensus import groups (#3331) --- crates/hotshot/src/tasks/mod.rs | 3 +- .../src/traits/networking/push_cdn_network.rs | 3 +- crates/task-impls/src/consensus/helpers.rs | 77 ++++++++----------- crates/task-impls/src/consensus/mod.rs | 31 ++++---- crates/task-impls/src/quorum_vote/mod.rs | 11 +-- 5 files changed, 54 insertions(+), 71 deletions(-) diff --git a/crates/hotshot/src/tasks/mod.rs b/crates/hotshot/src/tasks/mod.rs index b55801b828..165ca013e5 100644 --- a/crates/hotshot/src/tasks/mod.rs +++ b/crates/hotshot/src/tasks/mod.rs @@ -5,7 +5,6 @@ pub mod task_state; use std::{sync::Arc, time::Duration}; -use crate::{tasks::task_state::CreateTaskState, types::SystemContextHandle, ConsensusApi}; use async_compatibility_layer::art::{async_sleep, async_spawn}; use hotshot_task::task::Task; #[cfg(not(feature = "dependency-tasks"))] @@ -37,6 +36,8 @@ use hotshot_types::{ }; use vbs::version::StaticVersionType; +use crate::{tasks::task_state::CreateTaskState, types::SystemContextHandle, ConsensusApi}; + /// event for global event stream #[derive(Clone, Debug)] pub enum GlobalEvent { diff --git a/crates/hotshot/src/traits/networking/push_cdn_network.rs b/crates/hotshot/src/traits/networking/push_cdn_network.rs index 84fbef4832..97d23c613e 100644 --- a/crates/hotshot/src/traits/networking/push_cdn_network.rs +++ b/crates/hotshot/src/traits/networking/push_cdn_network.rs @@ -1,7 +1,6 @@ #[cfg(feature = "hotshot-testing")] use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; -use std::{collections::BTreeSet, marker::PhantomData}; +use std::{collections::BTreeSet, marker::PhantomData, sync::Arc}; #[cfg(feature = "hotshot-testing")] use std::{path::Path, time::Duration}; diff --git a/crates/task-impls/src/consensus/helpers.rs b/crates/task-impls/src/consensus/helpers.rs index 369517b7bd..8354662009 100644 --- a/crates/task-impls/src/consensus/helpers.rs +++ b/crates/task-impls/src/consensus/helpers.rs @@ -1,44 +1,14 @@ -use crate::{events::HotShotEvent, helpers::broadcast_event}; - -#[cfg(not(feature = "dependency-tasks"))] -use crate::{events::ProposalMissing, request::REQUEST_TIMEOUT}; - -#[cfg(not(feature = "dependency-tasks"))] -use super::ConsensusTaskState; -#[cfg(not(feature = "dependency-tasks"))] -use crate::{ - consensus::{update_view, view_change::SEND_VIEW_CHANGE_EVENT}, - helpers::AnyhowTracing, +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, }; -#[cfg(not(feature = "dependency-tasks"))] -use anyhow::bail; + use anyhow::{ensure, Context, Result}; -#[cfg(not(feature = "dependency-tasks"))] -use async_broadcast::broadcast; use async_broadcast::Sender; -#[cfg(not(feature = "dependency-tasks"))] -use async_compatibility_layer::art::async_timeout; -#[cfg(not(feature = "dependency-tasks"))] -use async_compatibility_layer::art::{async_sleep, async_spawn}; use async_lock::RwLock; -#[cfg(not(feature = "dependency-tasks"))] #[cfg(async_executor_impl = "async-std")] use async_std::task::JoinHandle; -#[cfg(not(feature = "dependency-tasks"))] -use chrono::Utc; use committable::{Commitment, Committable}; -#[cfg(not(feature = "dependency-tasks"))] -use core::time::Duration; -#[cfg(not(feature = "dependency-tasks"))] -use futures::FutureExt; -#[cfg(not(feature = "dependency-tasks"))] -use hotshot_types::{ - consensus::CommitmentAndMetadata, - traits::{ - node_implementation::{ConsensusTime, NodeImplementation}, - storage::Storage, - }, -}; use hotshot_types::{ consensus::{Consensus, View}, data::{Leaf, QuorumProposal, ViewChangeEvidence}, @@ -52,21 +22,38 @@ use hotshot_types::{ utils::{Terminator, ViewInner}, vote::{Certificate, HasViewNumber}, }; -#[cfg(not(feature = "dependency-tasks"))] -use hotshot_types::{data::null_block, message::GeneralConsensusMessage, simple_vote::QuorumData}; -#[cfg(not(feature = "dependency-tasks"))] -use std::marker::PhantomData; -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; #[cfg(async_executor_impl = "tokio")] use tokio::task::JoinHandle; -#[cfg(not(feature = "dependency-tasks"))] -use tracing::error; use tracing::{debug, info, warn}; #[cfg(not(feature = "dependency-tasks"))] -use vbs::version::Version; +use { + super::ConsensusTaskState, + crate::{ + consensus::{update_view, view_change::SEND_VIEW_CHANGE_EVENT}, + helpers::AnyhowTracing, + }, + crate::{events::ProposalMissing, request::REQUEST_TIMEOUT}, + anyhow::bail, + async_broadcast::broadcast, + async_compatibility_layer::art::async_timeout, + async_compatibility_layer::art::{async_sleep, async_spawn}, + chrono::Utc, + core::time::Duration, + futures::FutureExt, + hotshot_types::{ + consensus::CommitmentAndMetadata, + traits::{ + node_implementation::{ConsensusTime, NodeImplementation}, + storage::Storage, + }, + }, + hotshot_types::{data::null_block, message::GeneralConsensusMessage, simple_vote::QuorumData}, + std::marker::PhantomData, + tracing::error, + vbs::version::Version, +}; + +use crate::{events::HotShotEvent, helpers::broadcast_event}; /// Validate the state and safety and liveness of a proposal then emit /// a `QuorumProposalValidated` event. diff --git a/crates/task-impls/src/consensus/mod.rs b/crates/task-impls/src/consensus/mod.rs index 436e20d550..59263b0b6b 100644 --- a/crates/task-impls/src/consensus/mod.rs +++ b/crates/task-impls/src/consensus/mod.rs @@ -2,20 +2,12 @@ use std::{collections::BTreeMap, sync::Arc}; use anyhow::Result; use async_broadcast::{Receiver, Sender}; -#[cfg(not(feature = "dependency-tasks"))] -use async_compatibility_layer::art::async_spawn; use async_lock::RwLock; #[cfg(async_executor_impl = "async-std")] use async_std::task::JoinHandle; use async_trait::async_trait; use futures::future::join_all; use hotshot_task::task::TaskState; -#[cfg(not(feature = "dependency-tasks"))] -use hotshot_types::data::VidDisperseShare; -#[cfg(not(feature = "dependency-tasks"))] -use hotshot_types::message::Proposal; -#[cfg(not(feature = "dependency-tasks"))] -use hotshot_types::vid::vid_scheme; use hotshot_types::{ consensus::{CommitmentAndMetadata, Consensus}, data::{QuorumProposal, ViewChangeEvidence}, @@ -29,22 +21,25 @@ use hotshot_types::{ }, vote::HasViewNumber, }; -#[cfg(not(feature = "dependency-tasks"))] -use hotshot_types::{traits::storage::Storage, vote::Certificate}; -#[cfg(not(feature = "dependency-tasks"))] -use jf_vid::VidScheme; #[cfg(async_executor_impl = "tokio")] use tokio::task::JoinHandle; -#[cfg(not(feature = "dependency-tasks"))] -use tracing::info; use tracing::{debug, error, instrument, warn}; use vbs::version::Version; - #[cfg(not(feature = "dependency-tasks"))] -use crate::consensus::helpers::{ - handle_quorum_proposal_recv, handle_quorum_proposal_validated, publish_proposal_if_able, - update_state_and_vote_if_able, +use { + crate::consensus::helpers::{ + handle_quorum_proposal_recv, handle_quorum_proposal_validated, publish_proposal_if_able, + update_state_and_vote_if_able, + }, + async_compatibility_layer::art::async_spawn, + hotshot_types::data::VidDisperseShare, + hotshot_types::message::Proposal, + hotshot_types::vid::vid_scheme, + hotshot_types::{traits::storage::Storage, vote::Certificate}, + jf_vid::VidScheme, + tracing::info, }; + use crate::{ consensus::view_change::{update_view, DONT_SEND_VIEW_CHANGE_EVENT}, events::{HotShotEvent, HotShotTaskCompleted}, diff --git a/crates/task-impls/src/quorum_vote/mod.rs b/crates/task-impls/src/quorum_vote/mod.rs index 4d7731beed..3461afc4ab 100644 --- a/crates/task-impls/src/quorum_vote/mod.rs +++ b/crates/task-impls/src/quorum_vote/mod.rs @@ -1,10 +1,5 @@ use std::{collections::HashMap, sync::Arc}; -use crate::{ - events::HotShotEvent, - helpers::{broadcast_event, cancel_task}, - quorum_vote::handlers::handle_quorum_proposal_validated, -}; use anyhow::{bail, ensure, Context, Result}; use async_broadcast::{Receiver, Sender}; use async_lock::RwLock; @@ -41,6 +36,12 @@ use tokio::task::JoinHandle; use tracing::{debug, error, instrument, trace, warn}; use vbs::version::Version; +use crate::{ + events::HotShotEvent, + helpers::{broadcast_event, cancel_task}, + quorum_vote::handlers::handle_quorum_proposal_validated, +}; + /// Event handlers for `QuorumProposalValidated`. mod handlers;