Skip to content

Commit

Permalink
Separate versioning from NodeType (#3555)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss-es authored Aug 12, 2024
1 parent fbf4c81 commit 3e38cdf
Show file tree
Hide file tree
Showing 79 changed files with 1,082 additions and 869 deletions.
28 changes: 15 additions & 13 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 hotshot::traits::{
use hotshot_types::{
data::ViewNumber,
signature_key::{BLSPubKey, BuilderKey},
traits::node_implementation::NodeType,
traits::node_implementation::{NodeType, Versions},
};
use serde::{Deserialize, Serialize};
use vbs::version::StaticVersion;
Expand Down Expand Up @@ -45,12 +45,6 @@ use crate::{
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] = [
1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0,
];
type Time = ViewNumber;
type BlockHeader = TestBlockHeader;
type BlockPayload = TestBlockPayload;
Expand Down Expand Up @@ -80,12 +74,6 @@ impl NodeType for TestTypes {
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] = [
1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0,
];
type Time = ViewNumber;
type BlockHeader = TestBlockHeader;
type BlockPayload = TestBlockPayload;
Expand Down Expand Up @@ -144,3 +132,17 @@ impl<TYPES: NodeType> NodeImplementation<TYPES> for Libp2pImpl {
type Storage = TestStorage<TYPES>;
type AuctionResultsProvider = TestAuctionResultsProvider<TYPES>;
}

#[derive(Clone, Debug, Copy)]
pub struct TestVersions {}

impl Versions for TestVersions {
type Base = StaticVersion<0, 1>;
type Upgrade = StaticVersion<0, 2>;
const UPGRADE_HASH: [u8; 32] = [
1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0,
];

type Marketplace = StaticVersion<0, 3>;
}
3 changes: 2 additions & 1 deletion crates/example-types/src/state_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// along with the HotShot repository. If not, see <https://mit-license.org/>.

//! Implementations for examples and tests only
use std::fmt::Debug;

use async_trait::async_trait;
use committable::{Commitment, Committable};
use hotshot_types::{
Expand All @@ -19,7 +21,6 @@ use hotshot_types::{
};
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use vbs::version::Version;

pub use crate::node_types::TestTypes;
Expand Down
16 changes: 9 additions & 7 deletions crates/examples/combined/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use hotshot::{
traits::implementations::{KeyPair, TestingDef, WrappedSignatureKey},
types::SignatureKey,
};
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::ValidatorArgs;
use hotshot_types::traits::node_implementation::NodeType;
use infra::{gen_local_address, BUILDER_BASE_PORT, VALIDATOR_BASE_PORT};
Expand Down Expand Up @@ -146,12 +146,14 @@ async fn main() {
let builder_address = gen_local_address::<BUILDER_BASE_PORT>(i);

let node = async_spawn(async move {
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(ValidatorArgs {
url: orchestrator_url,
advertise_address: Some(advertise_address),
builder_address: Some(builder_address),
network_config_file: None,
})
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(
ValidatorArgs {
url: orchestrator_url,
advertise_address: Some(advertise_address),
builder_address: Some(builder_address),
network_config_file: None,
},
)
.await;
});
nodes.push(node);
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/combined/multi-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use async_compatibility_layer::{
logging::{setup_backtrace, setup_logging},
};
use clap::Parser;
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::{MultiValidatorArgs, ValidatorArgs};
use tracing::instrument;

Expand All @@ -36,7 +36,7 @@ async fn main() {
let args = args.clone();

let node = async_spawn(async move {
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(
ValidatorArgs::from_multi_args(args, node_index),
)
.await;
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/combined/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{net::SocketAddr, str::FromStr};

use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use clap::Parser;
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::ValidatorArgs;
use local_ip_address::local_ip;
use tracing::{debug, instrument};
Expand Down Expand Up @@ -42,5 +42,5 @@ async fn main() {
);

debug!("connecting to orchestrator at {:?}", args.url);
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(args).await;
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(args).await;
}
36 changes: 21 additions & 15 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use hotshot_types::{
block_contents::{BlockHeader, TestableBlock},
election::Membership,
network::{ConnectedNetwork, Topic},
node_implementation::{ConsensusTime, NodeType},
node_implementation::{ConsensusTime, NodeType, Versions},
states::TestableState,
},
HotShotConfig, PeerConfig, ValidatorConfig,
Expand Down Expand Up @@ -347,6 +347,7 @@ pub trait RunDa<
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
V: Versions,
> where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Expand All @@ -364,7 +365,7 @@ pub trait RunDa<
/// # Panics if it cannot generate a genesis block, fails to initialize HotShot, or cannot
/// get the anchored view
/// Note: sequencing leaf does not have state, so does not return state
async fn initialize_state_and_hotshot(&self) -> SystemContextHandle<TYPES, NODE> {
async fn initialize_state_and_hotshot(&self) -> SystemContextHandle<TYPES, NODE, V> {
let initializer =
hotshot::HotShotInitializer::<TYPES>::from_genesis(TestInstanceState::default())
.await
Expand Down Expand Up @@ -430,7 +431,7 @@ pub trait RunDa<
#[allow(clippy::too_many_lines)]
async fn run_hotshot(
&self,
context: SystemContextHandle<TYPES, NODE>,
context: SystemContextHandle<TYPES, NODE, V>,
transactions: &mut Vec<TestTransaction>,
transactions_to_send_per_round: u64,
transaction_size_in_bytes: u64,
Expand Down Expand Up @@ -619,7 +620,8 @@ impl<
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> RunDa<TYPES, PushCdnNetwork<TYPES>, NODE> for PushCdnDaRun<TYPES>
V: Versions,
> RunDa<TYPES, PushCdnNetwork<TYPES>, NODE, V> for PushCdnDaRun<TYPES>
where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Expand Down Expand Up @@ -696,7 +698,8 @@ impl<
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> RunDa<TYPES, Libp2pNetwork<TYPES::SignatureKey>, NODE> for Libp2pDaRun<TYPES>
V: Versions,
> RunDa<TYPES, Libp2pNetwork<TYPES::SignatureKey>, NODE, V> for Libp2pDaRun<TYPES>
where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Expand Down Expand Up @@ -782,7 +785,8 @@ impl<
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
> RunDa<TYPES, CombinedNetworks<TYPES>, NODE> for CombinedDaRun<TYPES>
V: Versions,
> RunDa<TYPES, CombinedNetworks<TYPES>, NODE, V> for CombinedDaRun<TYPES>
where
<TYPES as NodeType>::ValidatedState: TestableState<TYPES>,
<TYPES as NodeType>::BlockPayload: TestableBlock<TYPES>,
Expand All @@ -794,20 +798,21 @@ where
libp2p_advertise_address: Option<SocketAddr>,
) -> CombinedDaRun<TYPES> {
// Initialize our Libp2p network
let libp2p_network: Libp2pDaRun<TYPES> = <Libp2pDaRun<TYPES> as RunDa<
TYPES,
Libp2pNetwork<TYPES::SignatureKey>,
Libp2pImpl,
>>::initialize_networking(
config.clone(), libp2p_advertise_address
)
.await;
let libp2p_network: Libp2pDaRun<TYPES> =
<Libp2pDaRun<TYPES> as RunDa<
TYPES,
Libp2pNetwork<TYPES::SignatureKey>,
Libp2pImpl,
V,
>>::initialize_networking(config.clone(), libp2p_advertise_address)
.await;

// Initialize our CDN network
let cdn_network: PushCdnDaRun<TYPES> = <PushCdnDaRun<TYPES> as RunDa<
TYPES,
PushCdnNetwork<TYPES>,
PushCdnImpl,
V,
>>::initialize_networking(
config.clone(), libp2p_advertise_address
)
Expand Down Expand Up @@ -852,7 +857,8 @@ pub async fn main_entry_point<
Storage = TestStorage<TYPES>,
AuctionResultsProvider = TestAuctionResultsProvider<TYPES>,
>,
RUNDA: RunDa<TYPES, NETWORK, NODE>,
V: Versions,
RUNDA: RunDa<TYPES, NETWORK, NODE, V>,
>(
args: ValidatorArgs,
) where
Expand Down
16 changes: 9 additions & 7 deletions crates/examples/libp2p/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use async_compatibility_layer::{
art::async_spawn,
logging::{setup_backtrace, setup_logging},
};
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::ValidatorArgs;
use infra::{gen_local_address, BUILDER_BASE_PORT, VALIDATOR_BASE_PORT};
use tracing::instrument;
Expand Down Expand Up @@ -51,12 +51,14 @@ async fn main() {
let builder_address = gen_local_address::<BUILDER_BASE_PORT>(i);
let orchestrator_url = orchestrator_url.clone();
let node = async_spawn(async move {
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(ValidatorArgs {
url: orchestrator_url,
advertise_address: Some(advertise_address),
builder_address: Some(builder_address),
network_config_file: None,
})
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(
ValidatorArgs {
url: orchestrator_url,
advertise_address: Some(advertise_address),
builder_address: Some(builder_address),
network_config_file: None,
},
)
.await;
});
nodes.push(node);
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/libp2p/multi-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use async_compatibility_layer::{
logging::{setup_backtrace, setup_logging},
};
use clap::Parser;
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::{MultiValidatorArgs, ValidatorArgs};
use tracing::instrument;

Expand All @@ -36,7 +36,7 @@ async fn main() {
let args = args.clone();

let node = async_spawn(async move {
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(
ValidatorArgs::from_multi_args(args, node_index),
)
.await;
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/libp2p/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{net::SocketAddr, str::FromStr};

use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use clap::Parser;
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::ValidatorArgs;
use local_ip_address::local_ip;
use tracing::{debug, instrument};
Expand Down Expand Up @@ -41,5 +41,5 @@ async fn main() {
);

debug!("connecting to orchestrator at {:?}", args.url);
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(args).await;
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(args).await;
}
16 changes: 9 additions & 7 deletions crates/examples/push-cdn/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use hotshot::{
traits::implementations::{TestingDef, WrappedSignatureKey},
types::SignatureKey,
};
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::ValidatorArgs;
use hotshot_types::traits::node_implementation::NodeType;
use infra::{gen_local_address, BUILDER_BASE_PORT};
Expand Down Expand Up @@ -140,12 +140,14 @@ async fn main() {
let orchestrator_url = orchestrator_url.clone();
let builder_address = gen_local_address::<BUILDER_BASE_PORT>(i);
let node = async_spawn(async move {
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(ValidatorArgs {
url: orchestrator_url,
advertise_address: None,
builder_address: Some(builder_address),
network_config_file: None,
})
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(
ValidatorArgs {
url: orchestrator_url,
advertise_address: None,
builder_address: Some(builder_address),
network_config_file: None,
},
)
.await;
});
nodes.push(node);
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/push-cdn/multi-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use async_compatibility_layer::{
logging::{setup_backtrace, setup_logging},
};
use clap::Parser;
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::{MultiValidatorArgs, ValidatorArgs};
use tracing::instrument;

Expand All @@ -36,7 +36,7 @@ async fn main() {
let args = args.clone();

let node = async_spawn(async move {
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(
ValidatorArgs::from_multi_args(args, node_index),
)
.await;
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/push-cdn/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! A validator
use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use clap::Parser;
use hotshot_example_types::state_types::TestTypes;
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
use hotshot_orchestrator::client::ValidatorArgs;
use tracing::{debug, instrument};

Expand All @@ -28,5 +28,5 @@ async fn main() {
setup_backtrace();
let args = ValidatorArgs::parse();
debug!("connecting to orchestrator at {:?}", args.url);
infra::main_entry_point::<TestTypes, Network, NodeImpl, ThisRun>(args).await;
infra::main_entry_point::<TestTypes, Network, NodeImpl, TestVersions, ThisRun>(args).await;
}
Loading

0 comments on commit 3e38cdf

Please sign in to comment.