Skip to content

Commit

Permalink
push task_state as QuorumProposalRecv task state into helper function…
Browse files Browse the repository at this point in the history
…s, rename consensus2 (#3758)
  • Loading branch information
pls148 authored Oct 15, 2024
1 parent 046649d commit 20910cb
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 128 deletions.
2 changes: 0 additions & 2 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
/// Panics if sending genesis fails
#[instrument(skip_all, target = "SystemContext", fields(id = self.id))]
pub async fn start_consensus(&self) {
tracing::error!("HotShot is running with the dependency tasks feature enabled!!");

#[cfg(all(feature = "rewind", not(debug_assertions)))]
compile_error!("Cannot run rewind in production builds!");

Expand Down
4 changes: 2 additions & 2 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ pub async fn add_consensus_tasks<TYPES: NodeType, I: NodeImplementation<TYPES>,

{
use hotshot_task_impls::{
consensus2::Consensus2TaskState, quorum_proposal::QuorumProposalTaskState,
consensus::ConsensusTaskState, quorum_proposal::QuorumProposalTaskState,
quorum_proposal_recv::QuorumProposalRecvTaskState, quorum_vote::QuorumVoteTaskState,
};

handle.add_task(QuorumProposalTaskState::<TYPES, I, V>::create_from(handle).await);
handle.add_task(QuorumVoteTaskState::<TYPES, I, V>::create_from(handle).await);
handle.add_task(QuorumProposalRecvTaskState::<TYPES, I, V>::create_from(handle).await);
handle.add_task(Consensus2TaskState::<TYPES, I, V>::create_from(handle).await);
handle.add_task(ConsensusTaskState::<TYPES, I, V>::create_from(handle).await);
}

#[cfg(feature = "rewind")]
Expand Down
4 changes: 2 additions & 2 deletions crates/hotshot/src/tasks/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use async_compatibility_layer::art::async_spawn;
use async_trait::async_trait;
use chrono::Utc;
use hotshot_task_impls::{
builder::BuilderClient, consensus2::Consensus2TaskState, da::DaTaskState,
builder::BuilderClient, consensus::ConsensusTaskState, da::DaTaskState,
quorum_proposal::QuorumProposalTaskState, quorum_proposal_recv::QuorumProposalRecvTaskState,
quorum_vote::QuorumVoteTaskState, request::NetworkRequestState, rewind::RewindTaskState,
transactions::TransactionTaskState, upgrade::UpgradeTaskState, vid::VidTaskState,
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState

#[async_trait]
impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState<TYPES, I, V>
for Consensus2TaskState<TYPES, I, V>
for ConsensusTaskState<TYPES, I, V>
{
async fn create_from(handle: &SystemContextHandle<TYPES, I, V>) -> Self {
let consensus = handle.hotshot.consensus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use hotshot_types::{
};
use tracing::{debug, error, instrument};

use super::Consensus2TaskState;
use super::ConsensusTaskState;
use crate::{
consensus2::Versions,
consensus::Versions,
events::HotShotEvent,
helpers::{broadcast_event, cancel_task},
vote_collection::handle_vote,
Expand All @@ -38,7 +38,7 @@ pub(crate) async fn handle_quorum_vote_recv<
vote: &QuorumVote<TYPES>,
event: Arc<HotShotEvent<TYPES>>,
sender: &Sender<Arc<HotShotEvent<TYPES>>>,
task_state: &mut Consensus2TaskState<TYPES, I, V>,
task_state: &mut ConsensusTaskState<TYPES, I, V>,
) -> Result<()> {
// Are we the leader for this view?
ensure!(
Expand Down Expand Up @@ -73,7 +73,7 @@ pub(crate) async fn handle_timeout_vote_recv<
vote: &TimeoutVote<TYPES>,
event: Arc<HotShotEvent<TYPES>>,
sender: &Sender<Arc<HotShotEvent<TYPES>>>,
task_state: &mut Consensus2TaskState<TYPES, I, V>,
task_state: &mut ConsensusTaskState<TYPES, I, V>,
) -> Result<()> {
// Are we the leader for this view?
ensure!(
Expand Down Expand Up @@ -108,7 +108,7 @@ pub(crate) async fn handle_view_change<
>(
new_view_number: TYPES::Time,
sender: &Sender<Arc<HotShotEvent<TYPES>>>,
task_state: &mut Consensus2TaskState<TYPES, I, V>,
task_state: &mut ConsensusTaskState<TYPES, I, V>,
) -> Result<()> {
ensure!(
new_view_number > task_state.cur_view,
Expand Down Expand Up @@ -205,7 +205,7 @@ pub(crate) async fn handle_view_change<
pub(crate) async fn handle_timeout<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions>(
view_number: TYPES::Time,
sender: &Sender<Arc<HotShotEvent<TYPES>>>,
task_state: &mut Consensus2TaskState<TYPES, I, V>,
task_state: &mut ConsensusTaskState<TYPES, I, V>,
) -> Result<()> {
ensure!(
task_state.cur_view < view_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::{events::HotShotEvent, vote_collection::VoteCollectorsMap};
mod handlers;

/// Task state for the Consensus task.
pub struct Consensus2TaskState<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> {
pub struct ConsensusTaskState<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> {
/// Our public key
pub public_key: TYPES::SignatureKey,

Expand Down Expand Up @@ -96,9 +96,9 @@ pub struct Consensus2TaskState<TYPES: NodeType, I: NodeImplementation<TYPES>, V:
/// Lock for a decided upgrade
pub upgrade_lock: UpgradeLock<TYPES, V>,
}
impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> Consensus2TaskState<TYPES, I, V> {
impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> ConsensusTaskState<TYPES, I, V> {
/// Handles a consensus event received on the event stream
#[instrument(skip_all, fields(id = self.id, cur_view = *self.cur_view, last_decided_view = *self.last_decided_view), name = "Consensus replica task", level = "error", target = "Consensus2TaskState")]
#[instrument(skip_all, fields(id = self.id, cur_view = *self.cur_view, last_decided_view = *self.last_decided_view), name = "Consensus replica task", level = "error", target = "ConsensusTaskState")]
pub async fn handle(
&mut self,
event: Arc<HotShotEvent<TYPES>>,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> Consensus2TaskS

#[async_trait]
impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> TaskState
for Consensus2TaskState<TYPES, I, V>
for ConsensusTaskState<TYPES, I, V>
{
type Event = HotShotEvent<TYPES>;

Expand Down
Loading

0 comments on commit 20910cb

Please sign in to comment.