Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining *2 types #3932

Merged
merged 18 commits into from
Dec 6, 2024
21 changes: 20 additions & 1 deletion crates/example-types/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use async_lock::RwLock;
use async_trait::async_trait;
use hotshot_types::{
consensus::CommitmentMap,
data::{DaProposal, Leaf, Leaf2, QuorumProposal, QuorumProposal2, VidDisperseShare},
data::{
DaProposal, DaProposal2, Leaf, Leaf2, QuorumProposal, QuorumProposal2, VidDisperseShare,
},
event::HotShotAction,
message::Proposal,
simple_certificate::{QuorumCertificate2, UpgradeCertificate},
Expand All @@ -38,6 +40,7 @@ type VidShares<TYPES> = HashMap<
pub struct TestStorageState<TYPES: NodeType> {
vids: VidShares<TYPES>,
das: HashMap<TYPES::View, Proposal<TYPES, DaProposal<TYPES>>>,
da2s: HashMap<TYPES::View, Proposal<TYPES, DaProposal2<TYPES>>>,
proposals: BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal<TYPES>>>,
proposals2: BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal2<TYPES>>>,
high_qc: Option<hotshot_types::simple_certificate::QuorumCertificate<TYPES>>,
Expand All @@ -51,6 +54,7 @@ impl<TYPES: NodeType> Default for TestStorageState<TYPES> {
Self {
vids: HashMap::new(),
das: HashMap::new(),
da2s: HashMap::new(),
proposals: BTreeMap::new(),
proposals2: BTreeMap::new(),
high_qc: None,
Expand Down Expand Up @@ -142,6 +146,21 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
.insert(proposal.data.view_number, proposal.clone());
Ok(())
}
async fn append_da2(
&self,
proposal: &Proposal<TYPES, DaProposal2<TYPES>>,
_vid_commit: <VidSchemeType as VidScheme>::Commit,
) -> Result<()> {
if self.should_return_err {
bail!("Failed to append VID proposal to storage");
}
Self::run_delay_settings_from_config(&self.delay_config).await;
let mut inner = self.inner.write().await;
inner
.da2s
.insert(proposal.data.view_number, proposal.clone());
Ok(())
}
async fn append_proposal(
&self,
proposal: &Proposal<TYPES, QuorumProposal<TYPES>>,
Expand Down
40 changes: 22 additions & 18 deletions crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use async_trait::async_trait;
use hotshot_task::task::TaskState;
use hotshot_types::{
consensus::{Consensus, OuterConsensus},
data::{DaProposal, PackedBundle},
data::{DaProposal2, PackedBundle},
event::{Event, EventType},
message::{Proposal, UpgradeLock},
simple_certificate::DaCertificate,
simple_vote::{DaData, DaVote},
simple_certificate::DaCertificate2,
simple_vote::{DaData2, DaVote2},
traits::{
block_contents::vid_commitment,
election::Membership,
Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct DaTaskState<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Version
pub network: Arc<I::Network>,

/// A map of `DaVote` collector tasks.
pub vote_collectors: VoteCollectorsMap<TYPES, DaVote<TYPES>, DaCertificate<TYPES>, V>,
pub vote_collectors: VoteCollectorsMap<TYPES, DaVote2<TYPES>, DaCertificate2<TYPES>, V>,

/// This Nodes public key
pub public_key: TYPES::SignatureKey,
Expand Down Expand Up @@ -143,8 +143,11 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
}
HotShotEvent::DaProposalValidated(proposal, sender) => {
let cur_view = self.consensus.read().await.cur_view();
let view_number = proposal.data.view_number();
let epoch_number = proposal.data.epoch_number;

ensure!(
cur_view <= proposal.data.view_number() + 1,
cur_view <= view_number + 1,
debug!(
"Validated DA proposal for prior view but it's too old now Current view {:?}, DA Proposal view {:?}",
cur_view,
Expand All @@ -155,7 +158,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
// Proposal is fresh and valid, notify the application layer
broadcast_event(
Event {
view_number: self.cur_view,
view_number,
event: EventType::DaProposal {
proposal: proposal.clone(),
sender: sender.clone(),
Expand All @@ -166,31 +169,31 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
.await;

ensure!(
self.membership
.has_da_stake(&self.public_key, self.cur_epoch),
self.membership.has_da_stake(&self.public_key, epoch_number),
debug!(
"We were not chosen for consensus committee on {:?}",
self.cur_view
"We were not chosen for consensus committee for view {:?} in epoch {:?}",
view_number, epoch_number
)
);

let txns = Arc::clone(&proposal.data.encoded_transactions);
let num_nodes = self.membership.total_nodes(self.cur_epoch);
let num_nodes = self.membership.total_nodes(epoch_number);
let payload_commitment =
spawn_blocking(move || vid_commitment(&txns, num_nodes)).await;
let payload_commitment = payload_commitment.unwrap();

self.storage
.write()
.await
.append_da(proposal, payload_commitment)
.append_da2(proposal, payload_commitment)
.await
.wrap()
.context(error!("Failed to append DA proposal to storage"))?;
let view_number = proposal.data.view_number();
// Generate and send vote
let vote = DaVote::create_signed_vote(
DaData {
let vote = DaVote2::create_signed_vote(
DaData2 {
payload_commit: payload_commitment,
epoch: epoch_number,
},
view_number,
&self.public_key,
Expand Down Expand Up @@ -225,14 +228,13 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
let pk = self.private_key.clone();
let public_key = self.public_key.clone();
let chan = event_stream.clone();
let current_epoch = self.cur_epoch;
spawn(async move {
Consensus::calculate_and_update_vid(
OuterConsensus::new(Arc::clone(&consensus.inner_consensus)),
view_number,
membership,
&pk,
current_epoch,
epoch_number,
)
.await;
if let Some(Some(vid_share)) = consensus
Expand Down Expand Up @@ -303,6 +305,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
encoded_transactions,
metadata,
view_number,
epoch_number,
..
} = packed_bundle;
let view_number = *view_number;
Expand All @@ -315,11 +318,12 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
TYPES::SignatureKey::sign(&self.private_key, &encoded_transactions_hash)
.wrap()?;

let data: DaProposal<TYPES> = DaProposal {
let data: DaProposal2<TYPES> = DaProposal2 {
encoded_transactions: Arc::clone(encoded_transactions),
metadata: metadata.clone(),
// Upon entering a new view we want to send a DA Proposal for the next view -> Is it always the case that this is cur_view + 1?
view_number,
epoch_number: *epoch_number,
};

let message = Proposal {
Expand Down
86 changes: 43 additions & 43 deletions crates/task-impls/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ use either::Either;
use hotshot_task::task::TaskEvent;
use hotshot_types::{
data::{
DaProposal, Leaf2, PackedBundle, QuorumProposal2, UpgradeProposal, VidDisperse,
DaProposal2, Leaf2, PackedBundle, QuorumProposal2, UpgradeProposal, VidDisperse,
VidDisperseShare,
},
message::Proposal,
request_response::ProposalRequestPayload,
simple_certificate::{
DaCertificate, QuorumCertificate, QuorumCertificate2, TimeoutCertificate,
UpgradeCertificate, ViewSyncCommitCertificate2, ViewSyncFinalizeCertificate2,
ViewSyncPreCommitCertificate2,
DaCertificate2, QuorumCertificate, QuorumCertificate2, TimeoutCertificate,
UpgradeCertificate, ViewSyncCommitCertificate, ViewSyncFinalizeCertificate,
ViewSyncPreCommitCertificate,
},
simple_vote::{
DaVote, QuorumVote2, TimeoutVote, UpgradeVote, ViewSyncCommitVote, ViewSyncFinalizeVote,
DaVote2, QuorumVote2, TimeoutVote, UpgradeVote, ViewSyncCommitVote, ViewSyncFinalizeVote,
ViewSyncPreCommitVote,
},
traits::{
Expand Down Expand Up @@ -80,15 +80,15 @@ pub enum HotShotEvent<TYPES: NodeType> {
/// Send a timeout vote to the network; emitted by consensus task replicas
TimeoutVoteSend(TimeoutVote<TYPES>),
/// A DA proposal has been received from the network; handled by the DA task
DaProposalRecv(Proposal<TYPES, DaProposal<TYPES>>, TYPES::SignatureKey),
DaProposalRecv(Proposal<TYPES, DaProposal2<TYPES>>, TYPES::SignatureKey),
/// A DA proposal has been validated; handled by the DA task and VID task
DaProposalValidated(Proposal<TYPES, DaProposal<TYPES>>, TYPES::SignatureKey),
DaProposalValidated(Proposal<TYPES, DaProposal2<TYPES>>, TYPES::SignatureKey),
/// A DA vote has been received by the network; handled by the DA task
DaVoteRecv(DaVote<TYPES>),
DaVoteRecv(DaVote2<TYPES>),
/// A Data Availability Certificate (DAC) has been received by the network; handled by the consensus task
DaCertificateRecv(DaCertificate<TYPES>),
DaCertificateRecv(DaCertificate2<TYPES>),
/// A DAC is validated.
DaCertificateValidated(DaCertificate<TYPES>),
DaCertificateValidated(DaCertificate2<TYPES>),
/// Send a quorum proposal to the network; emitted by the leader in the consensus task
QuorumProposalSend(Proposal<TYPES, QuorumProposal2<TYPES>>, TYPES::SignatureKey),
/// Send a quorum vote to the next leader; emitted by a replica in the consensus task after seeing a valid quorum proposal
Expand Down Expand Up @@ -117,15 +117,15 @@ pub enum HotShotEvent<TYPES: NodeType> {
/// A quorum proposal was requested by a node for a view.
QuorumProposalResponseRecv(Proposal<TYPES, QuorumProposal2<TYPES>>),
/// Send a DA proposal to the DA committee; emitted by the DA leader (which is the same node as the leader of view v + 1) in the DA task
DaProposalSend(Proposal<TYPES, DaProposal<TYPES>>, TYPES::SignatureKey),
DaProposalSend(Proposal<TYPES, DaProposal2<TYPES>>, TYPES::SignatureKey),
/// Send a DA vote to the DA leader; emitted by DA committee members in the DA task after seeing a valid DA proposal
DaVoteSend(DaVote<TYPES>),
DaVoteSend(DaVote2<TYPES>),
/// The next leader has collected enough votes to form a QC; emitted by the next leader in the consensus task; an internal event only
QcFormed(Either<QuorumCertificate<TYPES>, TimeoutCertificate<TYPES>>),
/// The next leader has collected enough votes to form a QC; emitted by the next leader in the consensus task; an internal event only
Qc2Formed(Either<QuorumCertificate2<TYPES>, TimeoutCertificate<TYPES>>),
/// The DA leader has collected enough votes to form a DAC; emitted by the DA leader in the DA task; sent to the entire network via the networking task
DacSend(DaCertificate<TYPES>, TYPES::SignatureKey),
DacSend(DaCertificate2<TYPES>, TYPES::SignatureKey),
/// The current view has changed; emitted by the replica in the consensus task or replica in the view sync task; received by almost all other tasks
ViewChange(TYPES::View, TYPES::Epoch),
/// Timeout for the view sync protocol; emitted by a replica in the view sync task
Expand All @@ -145,19 +145,19 @@ pub enum HotShotEvent<TYPES: NodeType> {
/// Send a `ViewSyncFinalizeVote` from the network; emitted by a replica in the view sync task
ViewSyncFinalizeVoteSend(ViewSyncFinalizeVote<TYPES>),

/// Receive a `ViewSyncPreCommitCertificate2` from the network; received by a replica in the view sync task
ViewSyncPreCommitCertificate2Recv(ViewSyncPreCommitCertificate2<TYPES>),
/// Receive a `ViewSyncCommitCertificate2` from the network; received by a replica in the view sync task
ViewSyncCommitCertificate2Recv(ViewSyncCommitCertificate2<TYPES>),
/// Receive a `ViewSyncFinalizeCertificate2` from the network; received by a replica in the view sync task
ViewSyncFinalizeCertificate2Recv(ViewSyncFinalizeCertificate2<TYPES>),
/// Receive a `ViewSyncPreCommitCertificate` from the network; received by a replica in the view sync task
ViewSyncPreCommitCertificateRecv(ViewSyncPreCommitCertificate<TYPES>),
/// Receive a `ViewSyncCommitCertificate` from the network; received by a replica in the view sync task
ViewSyncCommitCertificateRecv(ViewSyncCommitCertificate<TYPES>),
/// Receive a `ViewSyncFinalizeCertificate` from the network; received by a replica in the view sync task
ViewSyncFinalizeCertificateRecv(ViewSyncFinalizeCertificate<TYPES>),

/// Send a `ViewSyncPreCommitCertificate2` from the network; emitted by a relay in the view sync task
ViewSyncPreCommitCertificate2Send(ViewSyncPreCommitCertificate2<TYPES>, TYPES::SignatureKey),
/// Send a `ViewSyncCommitCertificate2` from the network; emitted by a relay in the view sync task
ViewSyncCommitCertificate2Send(ViewSyncCommitCertificate2<TYPES>, TYPES::SignatureKey),
/// Send a `ViewSyncFinalizeCertificate2` from the network; emitted by a relay in the view sync task
ViewSyncFinalizeCertificate2Send(ViewSyncFinalizeCertificate2<TYPES>, TYPES::SignatureKey),
/// Send a `ViewSyncPreCommitCertificate` from the network; emitted by a relay in the view sync task
ViewSyncPreCommitCertificateSend(ViewSyncPreCommitCertificate<TYPES>, TYPES::SignatureKey),
/// Send a `ViewSyncCommitCertificate` from the network; emitted by a relay in the view sync task
ViewSyncCommitCertificateSend(ViewSyncCommitCertificate<TYPES>, TYPES::SignatureKey),
/// Send a `ViewSyncFinalizeCertificate` from the network; emitted by a relay in the view sync task
ViewSyncFinalizeCertificateSend(ViewSyncFinalizeCertificate<TYPES>, TYPES::SignatureKey),

/// Trigger the start of the view sync protocol; emitted by view sync task; internal trigger only
ViewSyncTrigger(TYPES::View),
Expand Down Expand Up @@ -289,12 +289,12 @@ impl<TYPES: NodeType> HotShotEvent<TYPES> {
| HotShotEvent::ViewSyncPreCommitVoteSend(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncFinalizeVoteRecv(vote)
| HotShotEvent::ViewSyncFinalizeVoteSend(vote) => Some(vote.view_number()),
HotShotEvent::ViewSyncPreCommitCertificate2Recv(cert)
| HotShotEvent::ViewSyncPreCommitCertificate2Send(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncCommitCertificate2Recv(cert)
| HotShotEvent::ViewSyncCommitCertificate2Send(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncFinalizeCertificate2Recv(cert)
| HotShotEvent::ViewSyncFinalizeCertificate2Send(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncPreCommitCertificateRecv(cert)
| HotShotEvent::ViewSyncPreCommitCertificateSend(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncCommitCertificateRecv(cert)
| HotShotEvent::ViewSyncCommitCertificateSend(cert, _) => Some(cert.view_number()),
HotShotEvent::ViewSyncFinalizeCertificateRecv(cert)
| HotShotEvent::ViewSyncFinalizeCertificateSend(cert, _) => Some(cert.view_number()),
HotShotEvent::SendPayloadCommitmentAndMetadata(_, _, _, view_number, _, _) => {
Some(*view_number)
}
Expand Down Expand Up @@ -451,45 +451,45 @@ impl<TYPES: NodeType> Display for HotShotEvent<TYPES> {
"ViewSyncFinalizeVoteSend(view_number={:?})",
vote.view_number()
),
HotShotEvent::ViewSyncPreCommitCertificate2Recv(cert) => {
HotShotEvent::ViewSyncPreCommitCertificateRecv(cert) => {
write!(
f,
"ViewSyncPreCommitCertificate2Recv(view_number={:?})",
"ViewSyncPreCommitCertificateRecv(view_number={:?})",
cert.view_number()
)
}
HotShotEvent::ViewSyncCommitCertificate2Recv(cert) => {
HotShotEvent::ViewSyncCommitCertificateRecv(cert) => {
write!(
f,
"ViewSyncCommitCertificate2Recv(view_number={:?})",
"ViewSyncCommitCertificateRecv(view_number={:?})",
cert.view_number()
)
}
HotShotEvent::ViewSyncFinalizeCertificate2Recv(cert) => {
HotShotEvent::ViewSyncFinalizeCertificateRecv(cert) => {
write!(
f,
"ViewSyncFinalizeCertificate2Recv(view_number={:?})",
"ViewSyncFinalizeCertificateRecv(view_number={:?})",
cert.view_number()
)
}
HotShotEvent::ViewSyncPreCommitCertificate2Send(cert, _) => {
HotShotEvent::ViewSyncPreCommitCertificateSend(cert, _) => {
write!(
f,
"ViewSyncPreCommitCertificate2Send(view_number={:?})",
"ViewSyncPreCommitCertificateSend(view_number={:?})",
cert.view_number()
)
}
HotShotEvent::ViewSyncCommitCertificate2Send(cert, _) => {
HotShotEvent::ViewSyncCommitCertificateSend(cert, _) => {
write!(
f,
"ViewSyncCommitCertificate2Send(view_number={:?})",
"ViewSyncCommitCertificateSend(view_number={:?})",
cert.view_number()
)
}
HotShotEvent::ViewSyncFinalizeCertificate2Send(cert, _) => {
HotShotEvent::ViewSyncFinalizeCertificateSend(cert, _) => {
write!(
f,
"ViewSyncFinalizeCertificate2Send(view_number={:?})",
"ViewSyncFinalizeCertificateSend(view_number={:?})",
cert.view_number()
)
}
Expand Down
Loading
Loading