Skip to content

Commit

Permalink
Merge branch 'main' into ss/task-structure-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ss-es committed May 28, 2024
2 parents 2c98abb + d56a69a commit 9208fb0
Show file tree
Hide file tree
Showing 34 changed files with 370 additions and 332 deletions.
2 changes: 1 addition & 1 deletion crates/builder-api/src/block_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct AvailableBlockInfo<TYPES: NodeType> {
#[serde(bound = "")]
pub struct AvailableBlockData<TYPES: NodeType> {
pub block_payload: TYPES::BlockPayload,
pub metadata: <TYPES::BlockPayload as BlockPayload>::Metadata,
pub metadata: <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
pub signature:
<<TYPES as NodeType>::BuilderSignatureKey as BuilderSignatureKey>::BuilderSignature,
pub sender: <TYPES as NodeType>::BuilderSignatureKey,
Expand Down
27 changes: 19 additions & 8 deletions crates/example-types/src/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
sync::Arc,
};

use async_trait::async_trait;
use committable::{Commitment, Committable, RawCommitmentBuilder};
use hotshot_types::{
data::{BlockError, Leaf},
Expand All @@ -21,7 +22,10 @@ use snafu::Snafu;
use time::OffsetDateTime;
use vbs::version::Version;

use crate::{node_types::TestTypes, state_types::TestInstanceState};
use crate::{
node_types::TestTypes,
state_types::{TestInstanceState, TestValidatedState},
};

/// The transaction in a [`TestBlockPayload`].
#[derive(Default, PartialEq, Eq, Hash, Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -134,7 +138,7 @@ impl Display for TestBlockPayload {
}
}

impl TestableBlock for TestBlockPayload {
impl<TYPES: NodeType> TestableBlock<TYPES> for TestBlockPayload {
fn genesis() -> Self {
Self::genesis()
}
Expand All @@ -159,14 +163,17 @@ impl EncodeBytes for TestBlockPayload {
}
}

impl BlockPayload for TestBlockPayload {
#[async_trait]
impl<TYPES: NodeType> BlockPayload<TYPES> for TestBlockPayload {
type Error = BlockError;
type Instance = TestInstanceState;
type Transaction = TestTransaction;
type Metadata = TestMetadata;
type ValidatedState = TestValidatedState;

fn from_transactions(
transactions: impl IntoIterator<Item = Self::Transaction>,
async fn from_transactions(
transactions: impl IntoIterator<Item = Self::Transaction> + Send,
_validated_state: &Self::ValidatedState,
_instance_state: &Self::Instance,
) -> Result<(Self, Self::Metadata), Self::Error> {
let txns_vec: Vec<TestTransaction> = transactions.into_iter().collect();
Expand Down Expand Up @@ -199,6 +206,10 @@ impl BlockPayload for TestBlockPayload {
Self { transactions }
}

fn empty() -> (Self, Self::Metadata) {
(Self::genesis(), TestMetadata)
}

fn builder_commitment(&self, _metadata: &Self::Metadata) -> BuilderCommitment {
let mut digest = sha2::Sha256::new();
for txn in &self.transactions {
Expand Down Expand Up @@ -239,7 +250,7 @@ impl<TYPES: NodeType<BlockHeader = Self, BlockPayload = TestBlockPayload>> Block
parent_leaf: &Leaf<TYPES>,
payload_commitment: VidCommitment,
builder_commitment: BuilderCommitment,
_metadata: <TYPES::BlockPayload as BlockPayload>::Metadata,
_metadata: <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
_builder_fee: BuilderFee<TYPES>,
_vid_common: VidCommon,
_version: Version,
Expand All @@ -264,7 +275,7 @@ impl<TYPES: NodeType<BlockHeader = Self, BlockPayload = TestBlockPayload>> Block
_instance_state: &<TYPES::ValidatedState as ValidatedState<TYPES>>::Instance,
payload_commitment: VidCommitment,
builder_commitment: BuilderCommitment,
_metadata: <TYPES::BlockPayload as BlockPayload>::Metadata,
_metadata: <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
) -> Self {
Self {
block_number: 0,
Expand All @@ -282,7 +293,7 @@ impl<TYPES: NodeType<BlockHeader = Self, BlockPayload = TestBlockPayload>> Block
self.payload_commitment
}

fn metadata(&self) -> &<TYPES::BlockPayload as BlockPayload>::Metadata {
fn metadata(&self) -> &<TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata {
&TestMetadata
}

Expand Down
2 changes: 1 addition & 1 deletion crates/example-types/src/state_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<TYPES: NodeType<BlockPayload = TestBlockPayload>> TestableState<TYPES> for
_state: Option<&Self>,
rng: &mut dyn rand::RngCore,
padding: u64,
) -> <TYPES::BlockPayload as BlockPayload>::Transaction {
) -> <TYPES::BlockPayload as BlockPayload<TYPES>>::Transaction {
/// clippy appeasement for `RANDOM_TX_BASE_SIZE`
const RANDOM_TX_BASE_SIZE: usize = 8;

Expand Down
12 changes: 6 additions & 6 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub trait RunDa<
>,
> where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
TYPES: NodeType<Transaction = TestTransaction>,
Leaf<TYPES>: TestableLeaf,
Self: Sync,
Expand All @@ -353,6 +353,7 @@ pub trait RunDa<
/// Note: sequencing leaf does not have state, so does not return state
async fn initialize_state_and_hotshot(&self) -> SystemContextHandle<TYPES, NODE> {
let initializer = hotshot::HotShotInitializer::<TYPES>::from_genesis(TestInstanceState {})
.await
.expect("Couldn't generate genesis block");

let config = self.config();
Expand Down Expand Up @@ -608,7 +609,7 @@ impl<
> RunDa<TYPES, PushCdnNetwork<TYPES>, PushCdnNetwork<TYPES>, NODE> for PushCdnDaRun<TYPES>
where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Leaf<TYPES>: TestableLeaf,
Self: Sync,
{
Expand Down Expand Up @@ -700,7 +701,7 @@ impl<
> for Libp2pDaRun<TYPES>
where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Leaf<TYPES>: TestableLeaf,
Self: Sync,
{
Expand Down Expand Up @@ -792,7 +793,7 @@ impl<
> RunDa<TYPES, CombinedNetworks<TYPES>, CombinedNetworks<TYPES>, NODE> for CombinedDaRun<TYPES>
where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Leaf<TYPES>: TestableLeaf,
Self: Sync,
{
Expand Down Expand Up @@ -865,7 +866,6 @@ where
pub async fn main_entry_point<
TYPES: NodeType<
Transaction = TestTransaction,
BlockPayload = TestBlockPayload,
BlockHeader = TestBlockHeader,
InstanceState = TestInstanceState,
>,
Expand All @@ -882,7 +882,7 @@ pub async fn main_entry_point<
args: ValidatorArgs,
) where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Leaf<TYPES>: TestableLeaf,
{
setup_logging();
Expand Down
18 changes: 14 additions & 4 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
if self.anchored_leaf.view_number() == TYPES::Time::genesis() {
let (validated_state, state_delta) =
TYPES::ValidatedState::genesis(&self.instance_state);

let qc = Arc::new(
QuorumCertificate::genesis(&validated_state, self.instance_state.as_ref())
.await,
);

broadcast_event(
Event {
view_number: self.anchored_leaf.view_number(),
Expand All @@ -368,7 +374,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
Some(Arc::new(state_delta)),
None,
)]),
qc: Arc::new(QuorumCertificate::genesis(self.instance_state.as_ref())),
qc,
block_size: None,
},
},
Expand Down Expand Up @@ -680,14 +686,18 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
/// initialize from genesis
/// # Errors
/// If we are unable to apply the genesis block to the default state
pub fn from_genesis(instance_state: TYPES::InstanceState) -> Result<Self, HotShotError<TYPES>> {
pub async fn from_genesis(
instance_state: TYPES::InstanceState,
) -> Result<Self, HotShotError<TYPES>> {
let (validated_state, state_delta) = TYPES::ValidatedState::genesis(&instance_state);
let high_qc = QuorumCertificate::genesis(&validated_state, &instance_state).await;

Ok(Self {
inner: Leaf::genesis(&instance_state),
inner: Leaf::genesis(&validated_state, &instance_state).await,
validated_state: Some(Arc::new(validated_state)),
state_delta: Some(Arc::new(state_delta)),
start_view: TYPES::Time::new(0),
high_qc: QuorumCertificate::genesis(&instance_state),
high_qc,
undecided_leafs: Vec::new(),
undecided_state: BTreeMap::new(),
instance_state,
Expand Down
5 changes: 4 additions & 1 deletion crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,15 @@ pub async fn add_consensus_tasks<
>(
handle: &mut SystemContextHandle<TYPES, I>,
) {
handle.add_task(ConsensusTaskState::<TYPES, I>::create_from(handle).await);
handle.add_task(ViewSyncTaskState::<TYPES, I>::create_from(handle).await);
handle.add_task(VidTaskState::<TYPES, I>::create_from(handle).await);
handle.add_task(DaTaskState::<TYPES, I>::create_from(handle).await);
handle.add_task(TransactionTaskState::<TYPES, I, VERSION>::create_from(handle).await);
handle.add_task(UpgradeTaskState::<TYPES, I>::create_from(handle).await);
{
#![cfg(not(feature = "dependency-tasks"))]
handle.add_task(ConsensusTaskState::<TYPES, I>::create_from(handle).await);
}
{
#![cfg(feature = "dependency-tasks")]
handle.add_task(QuorumProposalTaskState::<TYPES, I>::create_from(handle).await);
Expand Down
1 change: 1 addition & 0 deletions crates/hotshot/src/tasks/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, Ver: StaticVersionType>
instance_state: handle.hotshot.instance_state(),
id: handle.hotshot.id,
builder_client: BuilderClient::new(handle.hotshot.config.builder_url.clone()),
decided_upgrade_certificate: None,
}
}
}
Expand Down
Loading

0 comments on commit 9208fb0

Please sign in to comment.