Skip to content

Commit

Permalink
Add new leaf type (#3761)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss-es authored Nov 19, 2024
1 parent a56081e commit 7abc4ba
Show file tree
Hide file tree
Showing 49 changed files with 1,082 additions and 422 deletions.
10 changes: 10 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ portpicker = "0.1"
rand = { version = "0.8", features = ["small_rng"] }
rand_chacha = { version = "0.3", default-features = false }
serde = { version = "1", features = ["derive"] }
serde-inline-default = "0.2"
serde_bytes = { version = "0.11" }
serde_json = { version = "1.0" }
sha2 = "0.10"
Expand Down
8 changes: 4 additions & 4 deletions crates/example-types/src/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
use async_trait::async_trait;
use committable::{Commitment, Committable, RawCommitmentBuilder};
use hotshot_types::{
data::{BlockError, Leaf},
data::{BlockError, Leaf2},
traits::{
block_contents::{BlockHeader, BuilderFee, EncodeBytes, TestableBlock, Transaction},
node_implementation::NodeType,
Expand Down Expand Up @@ -272,7 +272,7 @@ pub struct TestBlockHeader {

impl TestBlockHeader {
pub fn new<TYPES: NodeType<BlockHeader = Self>>(
parent_leaf: &Leaf<TYPES>,
parent_leaf: &Leaf2<TYPES>,
payload_commitment: VidCommitment,
builder_commitment: BuilderCommitment,
metadata: TestMetadata,
Expand Down Expand Up @@ -312,7 +312,7 @@ impl<
async fn new_legacy(
_parent_state: &TYPES::ValidatedState,
instance_state: &<TYPES::ValidatedState as ValidatedState<TYPES>>::Instance,
parent_leaf: &Leaf<TYPES>,
parent_leaf: &Leaf2<TYPES>,
payload_commitment: VidCommitment,
builder_commitment: BuilderCommitment,
metadata: <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
Expand All @@ -332,7 +332,7 @@ impl<
async fn new_marketplace(
_parent_state: &TYPES::ValidatedState,
instance_state: &<TYPES::ValidatedState as ValidatedState<TYPES>>::Instance,
parent_leaf: &Leaf<TYPES>,
parent_leaf: &Leaf2<TYPES>,
payload_commitment: VidCommitment,
builder_commitment: BuilderCommitment,
metadata: <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
Expand Down
4 changes: 2 additions & 2 deletions crates/example-types/src/state_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::fmt::Debug;
use async_trait::async_trait;
use committable::{Commitment, Committable};
use hotshot_types::{
data::{fake_commitment, BlockError, Leaf, ViewNumber},
data::{fake_commitment, BlockError, Leaf2, ViewNumber},
traits::{
block_contents::BlockHeader,
node_implementation::NodeType,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<TYPES: NodeType> ValidatedState<TYPES> for TestValidatedState {
async fn validate_and_apply_header(
&self,
instance: &Self::Instance,
_parent_leaf: &Leaf<TYPES>,
_parent_leaf: &Leaf2<TYPES>,
_proposed_header: &TYPES::BlockHeader,
_vid_common: VidCommon,
_version: Version,
Expand Down
79 changes: 72 additions & 7 deletions crates/example-types/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use async_lock::RwLock;
use async_trait::async_trait;
use hotshot_types::{
consensus::CommitmentMap,
data::{DaProposal, Leaf, QuorumProposal, VidDisperseShare},
data::{DaProposal, Leaf, Leaf2, QuorumProposal, QuorumProposal2, VidDisperseShare},
event::HotShotAction,
message::Proposal,
simple_certificate::{QuorumCertificate, UpgradeCertificate},
simple_certificate::{QuorumCertificate2, UpgradeCertificate},
traits::{
node_implementation::{ConsensusTime, NodeType},
storage::Storage,
Expand All @@ -34,13 +34,14 @@ type VidShares<TYPES> = HashMap<
<TYPES as NodeType>::View,
HashMap<<TYPES as NodeType>::SignatureKey, Proposal<TYPES, VidDisperseShare<TYPES>>>,
>;

#[derive(Clone, Debug)]
pub struct TestStorageState<TYPES: NodeType> {
vids: VidShares<TYPES>,
das: HashMap<TYPES::View, Proposal<TYPES, DaProposal<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>>,
high_qc2: Option<hotshot_types::simple_certificate::QuorumCertificate2<TYPES>>,
action: TYPES::View,
epoch: TYPES::Epoch,
}
Expand All @@ -51,7 +52,9 @@ impl<TYPES: NodeType> Default for TestStorageState<TYPES> {
vids: HashMap::new(),
das: HashMap::new(),
proposals: BTreeMap::new(),
proposals2: BTreeMap::new(),
high_qc: None,
high_qc2: None,
action: TYPES::View::genesis(),
epoch: TYPES::Epoch::genesis(),
}
Expand Down Expand Up @@ -91,11 +94,11 @@ impl<TYPES: NodeType> TestableDelay for TestStorage<TYPES> {
impl<TYPES: NodeType> TestStorage<TYPES> {
pub async fn proposals_cloned(
&self,
) -> BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal<TYPES>>> {
self.inner.read().await.proposals.clone()
) -> BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal2<TYPES>>> {
self.inner.read().await.proposals2.clone()
}
pub async fn high_qc_cloned(&self) -> Option<QuorumCertificate<TYPES>> {
self.inner.read().await.high_qc.clone()
pub async fn high_qc_cloned(&self) -> Option<QuorumCertificate2<TYPES>> {
self.inner.read().await.high_qc2.clone()
}
pub async fn decided_upgrade_certificate(&self) -> Option<UpgradeCertificate<TYPES>> {
self.decided_upgrade_certificate.read().await.clone()
Expand Down Expand Up @@ -153,6 +156,20 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
.insert(proposal.data.view_number, proposal.clone());
Ok(())
}
async fn append_proposal2(
&self,
proposal: &Proposal<TYPES, QuorumProposal2<TYPES>>,
) -> 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
.proposals2
.insert(proposal.data.view_number, proposal.clone());
Ok(())
}

async fn record_action(
&self,
Expand Down Expand Up @@ -188,6 +205,25 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
}
Ok(())
}

async fn update_high_qc2(
&self,
new_high_qc: hotshot_types::simple_certificate::QuorumCertificate2<TYPES>,
) -> Result<()> {
if self.should_return_err {
bail!("Failed to update high qc to storage");
}
Self::run_delay_settings_from_config(&self.delay_config).await;
let mut inner = self.inner.write().await;
if let Some(ref current_high_qc) = inner.high_qc2 {
if new_high_qc.view_number() > current_high_qc.view_number() {
inner.high_qc2 = Some(new_high_qc);
}
} else {
inner.high_qc2 = Some(new_high_qc);
}
Ok(())
}
async fn update_undecided_state(
&self,
_leafs: CommitmentMap<Leaf<TYPES>>,
Expand All @@ -199,6 +235,17 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
Self::run_delay_settings_from_config(&self.delay_config).await;
Ok(())
}
async fn update_undecided_state2(
&self,
_leafs: CommitmentMap<Leaf2<TYPES>>,
_state: BTreeMap<TYPES::View, View<TYPES>>,
) -> Result<()> {
if self.should_return_err {
bail!("Failed to update high qc to storage");
}
Self::run_delay_settings_from_config(&self.delay_config).await;
Ok(())
}
async fn update_decided_upgrade_certificate(
&self,
decided_upgrade_certificate: Option<UpgradeCertificate<TYPES>>,
Expand All @@ -207,4 +254,22 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {

Ok(())
}

async fn migrate_consensus(
&self,
_convert_leaf: fn(Leaf<TYPES>) -> Leaf2<TYPES>,
convert_proposal: fn(
Proposal<TYPES, QuorumProposal<TYPES>>,
) -> Proposal<TYPES, QuorumProposal2<TYPES>>,
) -> Result<()> {
let mut storage_writer = self.inner.write().await;

for (view, proposal) in storage_writer.proposals.clone().iter() {
storage_writer
.proposals2
.insert(*view, convert_proposal(proposal.clone()));
}

Ok(())
}
}
1 change: 0 additions & 1 deletion crates/examples/push-cdn/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use cdn_broker::{
reexports::{crypto::signature::KeyPair, def::hook::NoMessageHook},
Broker,
};

use cdn_marshal::Marshal;
use hotshot::{
helpers::initialize_logging,
Expand Down
Loading

0 comments on commit 7abc4ba

Please sign in to comment.