Skip to content

Commit

Permalink
Add VidCommitment as parameter to append_da (#3846)
Browse files Browse the repository at this point in the history
* add vid commitment to append_da

* fix
  • Loading branch information
bfish713 authored Nov 5, 2024
1 parent a10e400 commit a75a93f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/example-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async-lock = { workspace = true }
bitvec = { workspace = true }
ethereum-types = { workspace = true }
hotshot-task = { path = "../task" }
jf-vid = { workspace = true }
vbs = { workspace = true }
url = { workspace = true }
reqwest = { workspace = true }
Expand Down
11 changes: 8 additions & 3 deletions crates/example-types/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
sync::Arc,
};

use crate::testable_delay::{DelayConfig, SupportedTraitTypesForAsyncDelay, TestableDelay};
use anyhow::{bail, Result};
use async_lock::RwLock;
use async_trait::async_trait;
Expand All @@ -23,10 +24,10 @@ use hotshot_types::{
storage::Storage,
},
utils::View,
vid::VidSchemeType,
vote::HasViewNumber,
};

use crate::testable_delay::{DelayConfig, SupportedTraitTypesForAsyncDelay, TestableDelay};
use jf_vid::VidScheme;

type VidShares<TYPES> = HashMap<
<TYPES as NodeType>::View,
Expand Down Expand Up @@ -117,7 +118,11 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
Ok(())
}

async fn append_da(&self, proposal: &Proposal<TYPES, DaProposal<TYPES>>) -> Result<()> {
async fn append_da(
&self,
proposal: &Proposal<TYPES, DaProposal<TYPES>>,
_vid_commit: <VidSchemeType as VidScheme>::Commit,
) -> Result<()> {
if self.should_return_err {
bail!("Failed to append VID proposal to storage");
}
Expand Down
16 changes: 7 additions & 9 deletions crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,19 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
)
);

self.storage
.write()
.await
.append_da(proposal)
.await
.wrap()
.context(error!("Failed to append DA proposal to storage"))?;

let txns = Arc::clone(&proposal.data.encoded_transactions);
let num_nodes = self.quorum_membership.total_nodes(self.cur_epoch);
let payload_commitment =
spawn_blocking(move || vid_commitment(&txns, num_nodes)).await;
#[cfg(async_executor_impl = "tokio")]
let payload_commitment = payload_commitment.unwrap();

self.storage
.write()
.await
.append_da(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(
Expand Down
8 changes: 7 additions & 1 deletion crates/types/src/traits/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::collections::BTreeMap;

use anyhow::Result;
use async_trait::async_trait;
use jf_vid::VidScheme;

use super::node_implementation::NodeType;
use crate::{
Expand All @@ -21,6 +22,7 @@ use crate::{
event::HotShotAction,
message::Proposal,
simple_certificate::{QuorumCertificate, UpgradeCertificate},
vid::VidSchemeType,
};

/// Abstraction for storing a variety of consensus payload datum.
Expand All @@ -29,7 +31,11 @@ pub trait Storage<TYPES: NodeType>: Send + Sync + Clone {
/// Add a proposal to the stored VID proposals.
async fn append_vid(&self, proposal: &Proposal<TYPES, VidDisperseShare<TYPES>>) -> Result<()>;
/// Add a proposal to the stored DA proposals.
async fn append_da(&self, proposal: &Proposal<TYPES, DaProposal<TYPES>>) -> Result<()>;
async fn append_da(
&self,
proposal: &Proposal<TYPES, DaProposal<TYPES>>,
vid_commit: <VidSchemeType as VidScheme>::Commit,
) -> Result<()>;
/// Add a proposal we sent to the store
async fn append_proposal(
&self,
Expand Down

0 comments on commit a75a93f

Please sign in to comment.