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 version check for block header creation #3510

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions crates/example-types/src/auction_results_provider_types.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use anyhow::{bail, Result};
use async_trait::async_trait;
use hotshot_types::traits::{
auction_results_provider::{AuctionResultsProvider, HasUrls},
node_implementation::NodeType,
auction_results_provider::AuctionResultsProvider,
node_implementation::{HasUrls, NodeType},
};
use serde::{Deserialize, Serialize};
use url::Url;

/// A mock result for the auction solver. This type is just a pointer to a URL.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Default)]
pub struct TestAuctionResult {
/// The URL of the builder to reach out to.
pub urls: Vec<Url>,
Expand All @@ -22,10 +22,10 @@ impl HasUrls for TestAuctionResult {

/// The test auction results type is used to mimic the results from the Solver.
#[derive(Clone, Debug, Default)]
pub struct TestAuctionResultsProvider {
pub struct TestAuctionResultsProvider<TYPES: NodeType> {
/// We intentionally allow for the results to be pre-cooked for the unit test to gurantee a
/// particular outcome is met.
pub solver_results: TestAuctionResult,
pub solver_results: TYPES::AuctionResult,

/// A canned type to ensure that an error is thrown in absence of a true fault-injectible
/// system for logical tests. This will guarantee that `fetch_auction_result` always throws an
Expand All @@ -39,17 +39,15 @@ pub struct TestAuctionResultsProvider {
}

#[async_trait]
impl<TYPES: NodeType> AuctionResultsProvider<TYPES> for TestAuctionResultsProvider {
type AuctionResult = TestAuctionResult;

impl<TYPES: NodeType> AuctionResultsProvider<TYPES> for TestAuctionResultsProvider<TYPES> {
/// Mock fetching the auction results, with optional error injection to simulate failure cases
/// in the solver.
async fn fetch_auction_result(&self, view_number: TYPES::Time) -> Result<Self::AuctionResult> {
async fn fetch_auction_result(&self, view_number: TYPES::Time) -> Result<TYPES::AuctionResult> {
if let Some(url) = &self.broadcast_url {
let resp =
reqwest::get(url.join(&format!("/v0/api/auction_results/{}", *view_number))?)
.await?
.json::<TestAuctionResult>()
.json::<TYPES::AuctionResult>()
.await?;

Ok(resp)
Expand Down
6 changes: 2 additions & 4 deletions crates/example-types/src/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use time::OffsetDateTime;
use vbs::version::Version;

use crate::{
auction_results_provider_types::TestAuctionResult,
node_types::TestTypes,
state_types::{TestInstanceState, TestValidatedState},
};
Expand Down Expand Up @@ -244,7 +243,6 @@ impl<TYPES: NodeType<BlockHeader = Self, BlockPayload = TestBlockPayload>> Block
for TestBlockHeader
{
type Error = std::convert::Infallible;
type AuctionResult = TestAuctionResult;

async fn new_legacy(
_parent_state: &TYPES::ValidatedState,
Expand Down Expand Up @@ -281,7 +279,7 @@ impl<TYPES: NodeType<BlockHeader = Self, BlockPayload = TestBlockPayload>> Block
_metadata: <TYPES::BlockPayload as BlockPayload<TYPES>>::Metadata,
_builder_fee: Vec<BuilderFee<TYPES>>,
_vid_common: VidCommon,
_auction_results: Option<Self::AuctionResult>,
_auction_results: Option<TYPES::AuctionResult>,
_version: Version,
) -> Result<Self, Self::Error> {
unimplemented!()
Expand Down Expand Up @@ -317,7 +315,7 @@ impl<TYPES: NodeType<BlockHeader = Self, BlockPayload = TestBlockPayload>> Block
self.builder_commitment.clone()
}

fn get_auction_results(&self) -> Option<Self::AuctionResult> {
fn get_auction_results(&self) -> Option<TYPES::AuctionResult> {
unimplemented!()
}
}
Expand Down
12 changes: 7 additions & 5 deletions crates/example-types/src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
use vbs::version::StaticVersion;

use crate::{
auction_results_provider_types::TestAuctionResultsProvider,
auction_results_provider_types::{TestAuctionResult, TestAuctionResultsProvider},
block_types::{TestBlockHeader, TestBlockPayload, TestTransaction},
state_types::{TestInstanceState, TestValidatedState},
storage_types::TestStorage,
Expand All @@ -38,6 +38,7 @@ use crate::{
/// to select our traits
pub struct TestTypes;
impl NodeType for TestTypes {
type AuctionResult = TestAuctionResult;
type Base = StaticVersion<0, 1>;
type Upgrade = StaticVersion<0, 2>;
const UPGRADE_HASH: [u8; 32] = [
Expand Down Expand Up @@ -72,6 +73,7 @@ impl NodeType for TestTypes {
/// to select our traits
pub struct TestConsecutiveLeaderTypes;
impl NodeType for TestConsecutiveLeaderTypes {
type AuctionResult = TestAuctionResult;
type Base = StaticVersion<0, 1>;
type Upgrade = StaticVersion<0, 2>;
const UPGRADE_HASH: [u8; 32] = [
Expand Down Expand Up @@ -116,23 +118,23 @@ pub type StaticMembership = StaticCommittee<TestTypes>;
impl<TYPES: NodeType> NodeImplementation<TYPES> for PushCdnImpl {
type Network = PushCdnNetwork<TYPES>;
type Storage = TestStorage<TYPES>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TYPES>;
}

impl<TYPES: NodeType> NodeImplementation<TYPES> for MemoryImpl {
type Network = MemoryNetwork<TYPES::SignatureKey>;
type Storage = TestStorage<TYPES>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TYPES>;
}

impl<TYPES: NodeType> NodeImplementation<TYPES> for CombinedImpl {
type Network = CombinedNetworks<TYPES>;
type Storage = TestStorage<TYPES>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TYPES>;
}

impl<TYPES: NodeType> NodeImplementation<TYPES> for Libp2pImpl {
type Network = Libp2pNetwork<TYPES::SignatureKey>;
type Storage = TestStorage<TYPES>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TYPES>;
}
2 changes: 1 addition & 1 deletion crates/examples/combined/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type Network = CombinedNetworks<TestTypes>;
impl NodeImplementation<TestTypes> for NodeImpl {
type Network = Network;
type Storage = TestStorage<TestTypes>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TestTypes>;
}
/// convenience type alias
pub type ThisRun = CombinedDaRun<TestTypes>;
12 changes: 6 additions & 6 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pub trait RunDa<
TYPES,
Network = NETWORK,
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
Expand Down Expand Up @@ -406,7 +406,7 @@ pub trait RunDa<
initializer,
ConsensusMetricsValue::default(),
TestStorage::<TYPES>::default(),
TestAuctionResultsProvider::default(),
TestAuctionResultsProvider::<TYPES>::default(),
)
.await
.expect("Could not init hotshot")
Expand Down Expand Up @@ -604,7 +604,7 @@ impl<
TYPES,
Network = PushCdnNetwork<TYPES>,
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> RunDa<TYPES, PushCdnNetwork<TYPES>, NODE> for PushCdnDaRun<TYPES>
where
Expand Down Expand Up @@ -681,7 +681,7 @@ impl<
TYPES,
Network = Libp2pNetwork<TYPES::SignatureKey>,
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> RunDa<TYPES, Libp2pNetwork<TYPES::SignatureKey>, NODE> for Libp2pDaRun<TYPES>
where
Expand Down Expand Up @@ -767,7 +767,7 @@ impl<
TYPES,
Network = CombinedNetworks<TYPES>,
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> RunDa<TYPES, CombinedNetworks<TYPES>, NODE> for CombinedDaRun<TYPES>
where
Expand Down Expand Up @@ -837,7 +837,7 @@ pub async fn main_entry_point<
TYPES,
Network = NETWORK,
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
RUNDA: RunDa<TYPES, NETWORK, NODE>,
>(
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/libp2p/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type Network = Libp2pNetwork<<TestTypes as NodeType>::SignatureKey>;
impl NodeImplementation<TestTypes> for NodeImpl {
type Network = Network;
type Storage = TestStorage<TestTypes>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TestTypes>;
}
/// convenience type alias
pub type ThisRun = Libp2pDaRun<TestTypes>;
2 changes: 1 addition & 1 deletion crates/examples/push-cdn/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Network = PushCdnNetwork<TestTypes>;
impl NodeImplementation<TestTypes> for NodeImpl {
type Network = Network;
type Storage = TestStorage<TestTypes>;
type AuctionResultsProvider = TestAuctionResultsProvider;
type AuctionResultsProvider = TestAuctionResultsProvider<TestTypes>;
}

/// Convenience type alias
Expand Down
6 changes: 4 additions & 2 deletions crates/hotshot/src/traits/election/static_committee.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::{marker::PhantomData, num::NonZeroU64};

use ethereum_types::U256;
use hotshot_types::traits::network::Topic;
// use ark_bls12_381::Parameters as Param381;
use hotshot_types::traits::signature_key::StakeTableEntryType;
use hotshot_types::{
signature_key::BLSPubKey,
traits::{election::Membership, node_implementation::NodeType, signature_key::SignatureKey},
traits::{
election::Membership, network::Topic, node_implementation::NodeType,
signature_key::SignatureKey,
},
PeerConfig,
};
#[cfg(feature = "randomized-leader-election")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::{marker::PhantomData, num::NonZeroU64};

use ethereum_types::U256;
use hotshot_types::traits::network::Topic;
// use ark_bls12_381::Parameters as Param381;
use hotshot_types::traits::signature_key::StakeTableEntryType;
use hotshot_types::{
signature_key::BLSPubKey,
traits::{election::Membership, node_implementation::NodeType, signature_key::SignatureKey},
traits::{
election::Membership, network::Topic, node_implementation::NodeType,
signature_key::SignatureKey,
},
PeerConfig,
};
use tracing::debug;
Expand Down
Loading