diff --git a/Cargo.lock b/Cargo.lock index dfbcd44263..cdf6358c73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5900,9 +5900,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.112" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d1bd37ce2324cf3bf85e5a25f96eb4baf0d5aa6eba43e7ae8958870c4ec48ed" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ "itoa", "ryu", diff --git a/crates/hotshot/src/traits/networking/web_server_network.rs b/crates/hotshot/src/traits/networking/web_server_network.rs index 8733595c9f..794e068b43 100644 --- a/crates/hotshot/src/traits/networking/web_server_network.rs +++ b/crates/hotshot/src/traits/networking/web_server_network.rs @@ -252,6 +252,8 @@ impl Inner { }; while self.running.load(Ordering::Relaxed) { + async_sleep(additional_wait).await; + let endpoint = match message_purpose { MessagePurpose::Proposal => config::get_proposal_route(view_number), MessagePurpose::LatestQuorumProposal => config::get_latest_quorum_proposal_route(), @@ -437,7 +439,6 @@ impl Inner { async_sleep(self.wait_between_polls).await; } } - async_sleep(additional_wait).await; } let maybe_event = receiver.try_recv(); match maybe_event { diff --git a/crates/hotshot/src/traits/storage/memory_storage.rs b/crates/hotshot/src/traits/storage/memory_storage.rs index 2fa7d04b72..adaff123f2 100644 --- a/crates/hotshot/src/traits/storage/memory_storage.rs +++ b/crates/hotshot/src/traits/storage/memory_storage.rs @@ -148,7 +148,6 @@ mod test { header, Some(payload), dummy_leaf_commit, - Vec::new(), <::SignatureKey as SignatureKey>::genesis_proposer_pk(), ) } diff --git a/crates/libp2p-networking/Cargo.toml b/crates/libp2p-networking/Cargo.toml index 29058167a0..96467a6bd0 100644 --- a/crates/libp2p-networking/Cargo.toml +++ b/crates/libp2p-networking/Cargo.toml @@ -27,7 +27,7 @@ libp2p-swarm-derive = { workspace = true } libp2p-identity = { workspace = true } rand = { workspace = true } serde = { workspace = true } -serde_json = "1.0.112" +serde_json = "1.0.113" snafu = { workspace = true } tide = { version = "0.16", optional = true, default-features = false, features = [ "h1-server", diff --git a/crates/task-impls/src/consensus.rs b/crates/task-impls/src/consensus.rs index eb4c335e60..6b862f4063 100644 --- a/crates/task-impls/src/consensus.rs +++ b/crates/task-impls/src/consensus.rs @@ -219,7 +219,6 @@ impl, A: ConsensusApi + parent_commitment, block_header: proposal.block_header.clone(), block_payload: None, - rejected: Vec::new(), proposer_id: self.quorum_membership.get_leader(view), }; let Ok(vote) = QuorumVote::::create_signed_vote( @@ -305,7 +304,6 @@ impl, A: ConsensusApi + parent_commitment, block_header: proposal.block_header.clone(), block_payload: None, - rejected: Vec::new(), proposer_id: self.quorum_membership.get_leader(view), }; @@ -538,7 +536,6 @@ impl, A: ConsensusApi + parent_commitment: justify_qc.get_data().leaf_commit, block_header: proposal.data.block_header.clone(), block_payload: None, - rejected: Vec::new(), proposer_id: sender, }; let state = ::from_header( @@ -611,7 +608,6 @@ impl, A: ConsensusApi + parent_commitment, block_header: proposal.data.block_header.clone(), block_payload: None, - rejected: Vec::new(), proposer_id: sender.clone(), }; let leaf_commitment = leaf.commit(); @@ -1234,7 +1230,6 @@ impl, A: ConsensusApi + parent_commitment: parent_leaf.commit(), block_header: block_header.clone(), block_payload: None, - rejected: vec![], proposer_id: self.api.public_key().clone(), }; diff --git a/crates/task-impls/src/view_sync.rs b/crates/task-impls/src/view_sync.rs index bc0222930c..a123cee52f 100644 --- a/crates/task-impls/src/view_sync.rs +++ b/crates/task-impls/src/view_sync.rs @@ -40,7 +40,7 @@ use hotshot_types::{ }, }; use snafu::Snafu; -use std::{collections::HashMap, fmt::Debug, sync::Arc, time::Duration}; +use std::{collections::BTreeMap, collections::HashMap, fmt::Debug, sync::Arc, time::Duration}; #[cfg(async_executor_impl = "tokio")] use tokio::task::JoinHandle; use tracing::{debug, error, info, instrument, warn}; @@ -61,9 +61,9 @@ pub enum ViewSyncPhase { /// Stub of a view sync error pub struct ViewSyncTaskError {} -/// Type alias for a map from View Number to Vote Task +/// Type alias for a map from View Number to Relay to Vote Task type RelayMap = - HashMap<::Time, VoteCollectionTaskState>; + HashMap<::Time, BTreeMap>>; /// Main view sync task state pub struct ViewSyncTaskState< @@ -197,12 +197,13 @@ impl< ) { // This certificate is old, we can throw it away // If next view = cert round, then that means we should already have a task running for it - let mut task_map = self.replica_task_map.write().await; if self.current_view > view { debug!("Already in a higher view than the view sync message"); return; } + let mut task_map = self.replica_task_map.write().await; + if let Some(replica_task) = task_map.remove(&view) { // Forward event then return debug!("Forwarding message"); @@ -276,7 +277,9 @@ impl< HotShotEvent::ViewSyncPreCommitVoteRecv(ref vote) => { let mut map = self.pre_commit_relay_map.write().await; let vote_view = vote.get_view_number(); - if let Some(relay_task) = map.remove(&vote_view) { + let relay = vote.get_data().relay; + let relay_map = map.entry(vote_view).or_insert(BTreeMap::new()); + if let Some(relay_task) = relay_map.remove(&relay) { debug!("Forwarding message"); let result = relay_task.handle_event(event.clone()).await; @@ -284,17 +287,12 @@ impl< // The protocol has finished return; } - - map.insert(vote_view, result.1); + relay_map.insert(relay, result.1); return; } // We do not have a relay task already running, so start one - if self - .membership - .get_leader(vote_view + vote.get_data().relay) - != self.public_key - { + if self.membership.get_leader(vote_view + relay) != self.public_key { // TODO ED This will occur because everyone is pulling down votes for now. Will be fixed in `https://github.com/EspressoSystems/HotShot/issues/1471` debug!("View sync vote sent to wrong leader"); return; @@ -310,14 +308,16 @@ impl< }; let vote_collector = create_vote_accumulator(&info, vote.clone(), event).await; if let Some(vote_task) = vote_collector { - map.insert(vote_view, vote_task); + relay_map.insert(relay, vote_task); } } HotShotEvent::ViewSyncCommitVoteRecv(ref vote) => { let mut map = self.commit_relay_map.write().await; let vote_view = vote.get_view_number(); - if let Some(relay_task) = map.remove(&vote_view) { + let relay = vote.get_data().relay; + let relay_map = map.entry(vote_view).or_insert(BTreeMap::new()); + if let Some(relay_task) = relay_map.remove(&relay) { debug!("Forwarding message"); let result = relay_task.handle_event(event.clone()).await; @@ -326,16 +326,12 @@ impl< return; } - map.insert(vote_view, result.1); + relay_map.insert(relay, result.1); return; } // We do not have a relay task already running, so start one - if self - .membership - .get_leader(vote_view + vote.get_data().relay) - != self.public_key - { + if self.membership.get_leader(vote_view + relay) != self.public_key { // TODO ED This will occur because everyone is pulling down votes for now. Will be fixed in `https://github.com/EspressoSystems/HotShot/issues/1471` debug!("View sync vote sent to wrong leader"); return; @@ -351,14 +347,16 @@ impl< }; let vote_collector = create_vote_accumulator(&info, vote.clone(), event).await; if let Some(vote_task) = vote_collector { - map.insert(vote_view, vote_task); + relay_map.insert(relay, vote_task); } } HotShotEvent::ViewSyncFinalizeVoteRecv(ref vote) => { let mut map = self.finalize_relay_map.write().await; let vote_view = vote.get_view_number(); - if let Some(relay_task) = map.remove(&vote_view) { + let relay = vote.get_data().relay; + let relay_map = map.entry(vote_view).or_insert(BTreeMap::new()); + if let Some(relay_task) = relay_map.remove(&relay) { debug!("Forwarding message"); let result = relay_task.handle_event(event.clone()).await; @@ -367,16 +365,12 @@ impl< return; } - map.insert(vote_view, result.1); + relay_map.insert(relay, result.1); return; } // We do not have a relay task already running, so start one - if self - .membership - .get_leader(vote_view + vote.get_data().relay) - != self.public_key - { + if self.membership.get_leader(vote_view + relay) != self.public_key { // TODO ED This will occur because everyone is pulling down votes for now. Will be fixed in `https://github.com/EspressoSystems/HotShot/issues/1471` debug!("View sync vote sent to wrong leader"); return; @@ -392,7 +386,7 @@ impl< }; let vote_collector = create_vote_accumulator(&info, vote.clone(), event).await; if let Some(vote_task) = vote_collector { - map.insert(vote_view, vote_task); + relay_map.insert(relay, vote_task); } } diff --git a/crates/task-impls/src/vote.rs b/crates/task-impls/src/vote.rs index bf20a7bad9..93986834e8 100644 --- a/crates/task-impls/src/vote.rs +++ b/crates/task-impls/src/vote.rs @@ -2,7 +2,6 @@ use std::{collections::HashMap, fmt::Debug, marker::PhantomData, sync::Arc}; use crate::events::HotShotEvent; use async_trait::async_trait; -use bitvec::prelude::*; use either::Either::{self, Left, Right}; use hotshot_task::{ event_stream::{ChannelStream, EventStream}, @@ -202,8 +201,7 @@ where } let new_accumulator = VoteAccumulator { vote_outcomes: HashMap::new(), - sig_lists: Vec::new(), - signers: bitvec![0;info. membership.total_nodes()], + signers: HashMap::new(), phantom: PhantomData, }; diff --git a/crates/testing/src/task_helpers.rs b/crates/testing/src/task_helpers.rs index 08acae040c..9ca92cacdd 100644 --- a/crates/testing/src/task_helpers.rs +++ b/crates/testing/src/task_helpers.rs @@ -255,7 +255,6 @@ async fn build_quorum_proposal_and_signature( parent_commitment: parent_leaf.commit(), block_header: block_header.clone(), block_payload: None, - rejected: vec![], proposer_id: *api.public_key(), }; @@ -316,7 +315,6 @@ async fn build_quorum_proposal_and_signature( parent_commitment: parent_leaf.commit(), block_header: block_header.clone(), block_payload: None, - rejected: vec![], proposer_id: quorum_membership.get_leader(ViewNumber::new(cur_view)), }; let signature_new_view = diff --git a/crates/testing/tests/consensus_task.rs b/crates/testing/tests/consensus_task.rs index 058eb8a320..b5cdcc7887 100644 --- a/crates/testing/tests/consensus_task.rs +++ b/crates/testing/tests/consensus_task.rs @@ -61,7 +61,6 @@ async fn build_vote( parent_commitment, block_header: proposal.block_header, block_payload: None, - rejected: Vec::new(), proposer_id: membership.get_leader(view), }; let vote = QuorumVote::::create_signed_vote( diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 3d43d017b3..ffe6b819d4 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -48,7 +48,7 @@ tracing = { workspace = true } typenum = { workspace = true } [dev-dependencies] -serde_json = "1.0.112" +serde_json = "1.0.113" [target.'cfg(all(async_executor_impl = "async-std"))'.dependencies] async-std = { workspace = true } diff --git a/crates/types/src/data.rs b/crates/types/src/data.rs index 5d42e0da71..66537bdb73 100644 --- a/crates/types/src/data.rs +++ b/crates/types/src/data.rs @@ -326,9 +326,6 @@ pub struct Leaf { /// It may be empty for nodes not in the DA committee. pub block_payload: Option, - /// Transactions that were marked for rejection while collecting the block. - pub rejected: Vec<::Transaction>, - /// the proposer id of the leaf pub proposer_id: TYPES::SignatureKey, } @@ -339,7 +336,6 @@ impl PartialEq for Leaf { && self.justify_qc == other.justify_qc && self.parent_commitment == other.parent_commitment && self.block_header == other.block_header - && self.rejected == other.rejected } } @@ -349,7 +345,6 @@ impl Hash for Leaf { self.justify_qc.hash(state); self.parent_commitment.hash(state); self.block_header.hash(state); - self.rejected.hash(state); } } @@ -376,7 +371,6 @@ impl Leaf { parent_commitment: fake_commitment(), block_header: block_header.clone(), block_payload: Some(block_payload), - rejected: Vec::new(), proposer_id: <::SignatureKey as SignatureKey>::genesis_proposer_pk(), } } @@ -443,14 +437,12 @@ impl Leaf { pub fn get_payload_commitment(&self) -> VidCommitment { self.get_block_header().payload_commitment() } - /// Transactions rejected or invalidated by the application of this leaf. - pub fn get_rejected(&self) -> Vec<::Transaction> { - self.rejected.clone() - } + /// Identity of the network participant who proposed this leaf. pub fn get_proposer_id(&self) -> TYPES::SignatureKey { self.proposer_id.clone() } + /// Create a leaf from information stored about a view. pub fn from_stored_view(stored_view: StoredView) -> Self { Self { @@ -459,7 +451,6 @@ impl Leaf { parent_commitment: stored_view.parent, block_header: stored_view.block_header, block_payload: stored_view.block_payload, - rejected: stored_view.rejected, proposer_id: stored_view.proposer_id, } } @@ -559,7 +550,6 @@ where justify_qc: leaf.get_justify_qc(), block_header: leaf.get_block_header().clone(), block_payload: leaf.get_block_payload(), - rejected: leaf.get_rejected(), proposer_id: leaf.get_proposer_id(), } } diff --git a/crates/types/src/traits/storage.rs b/crates/types/src/traits/storage.rs index 4c6e9fe27f..a91c326442 100644 --- a/crates/types/src/traits/storage.rs +++ b/crates/types/src/traits/storage.rs @@ -1,9 +1,7 @@ //! Abstraction over on-disk storage of node state use super::node_implementation::NodeType; -use crate::{ - data::Leaf, simple_certificate::QuorumCertificate, traits::BlockPayload, vote::HasViewNumber, -}; +use crate::{data::Leaf, simple_certificate::QuorumCertificate, vote::HasViewNumber}; use async_trait::async_trait; use commit::Commitment; use derivative::Derivative; @@ -130,8 +128,6 @@ pub struct StoredView { /// /// It may be empty for nodes not in the DA committee. pub block_payload: Option, - /// transactions rejected in this view - pub rejected: Vec, /// the proposer id #[derivative(PartialEq = "ignore")] pub proposer_id: TYPES::SignatureKey, @@ -150,7 +146,6 @@ where block_header: TYPES::BlockHeader, block_payload: Option, parent_commitment: Commitment>, - rejected: Vec<::Transaction>, proposer_id: TYPES::SignatureKey, ) -> Self { Self { @@ -159,7 +154,6 @@ where justify_qc: qc, block_header, block_payload, - rejected, proposer_id, } } diff --git a/crates/types/src/vote.rs b/crates/types/src/vote.rs index 4f80c07e41..808f127562 100644 --- a/crates/types/src/vote.rs +++ b/crates/types/src/vote.rs @@ -5,7 +5,7 @@ use std::{ marker::PhantomData, }; -use bitvec::vec::BitVec; +use bitvec::{bitvec, vec::BitVec}; use commit::Commitment; use either::Either; use ethereum_types::U256; @@ -73,7 +73,14 @@ pub trait Certificate: HasViewNumber { /// Get the vote commitment which the votes commit to fn get_data_commitment(&self) -> Commitment; } - +/// Mapping of vote commitment to sigatures and bitvec +type SignersMap = HashMap< + COMMITMENT, + ( + BitVec, + Vec<::PureAssembledSignatureType>, + ), +>; /// Accumulates votes until a certificate is formed. This implementation works for all simple vote and certificate pairs pub struct VoteAccumulator< TYPES: NodeType, @@ -86,10 +93,9 @@ pub struct VoteAccumulator< TYPES::SignatureKey, ::PureAssembledSignatureType, >, - /// A list of valid signatures for certificate aggregation - pub sig_lists: Vec<::PureAssembledSignatureType>, /// A bitvec to indicate which node is active and send out a valid signature for certificate aggregation, this automatically do uniqueness check - pub signers: BitVec, + /// And a list of valid signatures for certificate aggregation + pub signers: SignersMap, TYPES::SignatureKey>, /// Phantom data to specify the types this accumulator is for pub phantom: PhantomData<(TYPES, VOTE, CERT)>, } @@ -132,13 +138,16 @@ impl, CERT: Certificate, CERT: Certificate::assemble( &real_qc_pp, - self.signers.as_bitslice(), - &self.sig_lists[..], + signers.as_bitslice(), + &sig_list[..], ); let cert = CERT::create_signed_certificate(