From 6325e79f8d058fef004c1d966cb0b86e7119d1c8 Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 13 Nov 2024 14:42:18 -0500 Subject: [PATCH] add event for epoch changes --- crates/examples/Cargo.toml | 4 - crates/examples/push-cdn/whitelist-adapter.rs | 86 ------------------- crates/hotshot/src/lib.rs | 9 +- .../traits/election/randomized_committee.rs | 3 +- .../src/traits/election/static_committee.rs | 3 +- .../static_committee_leader_two_views.rs | 3 +- crates/types/src/event.rs | 25 ++++++ crates/types/src/stake_table.rs | 14 ++- crates/types/src/traits/election.rs | 5 +- crates/types/src/traits/network.rs | 2 +- 10 files changed, 50 insertions(+), 104 deletions(-) delete mode 100644 crates/examples/push-cdn/whitelist-adapter.rs diff --git a/crates/examples/Cargo.toml b/crates/examples/Cargo.toml index dc6434bb75..5bd1a5b7e7 100644 --- a/crates/examples/Cargo.toml +++ b/crates/examples/Cargo.toml @@ -76,10 +76,6 @@ path = "push-cdn/broker.rs" name = "cdn-marshal" path = "push-cdn/marshal.rs" -[[example]] -name = "whitelist-push-cdn" -path = "push-cdn/whitelist-adapter.rs" - [dependencies] async-broadcast = { workspace = true } async-lock = { workspace = true } diff --git a/crates/examples/push-cdn/whitelist-adapter.rs b/crates/examples/push-cdn/whitelist-adapter.rs deleted file mode 100644 index e855a41aba..0000000000 --- a/crates/examples/push-cdn/whitelist-adapter.rs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2021-2024 Espresso Systems (espressosys.com) -// This file is part of the HotShot repository. - -// You should have received a copy of the MIT License -// along with the HotShot repository. If not, see . - -//! The whitelist is an adaptor that is able to update the allowed public keys for -//! all brokers. Right now, we do this by asking the orchestrator for the list of -//! allowed public keys. In the future, we will pull the stake table from the L1. - -use std::{str::FromStr, sync::Arc}; - -use anyhow::{Context, Result}; -use cdn_broker::reexports::discovery::{DiscoveryClient, Embedded, Redis}; -use clap::Parser; -use hotshot_example_types::node_types::TestTypes; -use hotshot_orchestrator::client::OrchestratorClient; -use hotshot_types::{ - network::NetworkConfig, - traits::{node_implementation::NodeType, signature_key::SignatureKey}, -}; -use surf_disco::Url; - -#[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] -/// The main component of the push CDN. -struct Args { - /// The discovery client endpoint (including scheme) to connect to. - /// With the local discovery feature, this is a file path. - /// With the remote (redis) discovery feature, this is a redis URL (e.g. `redis://127.0.0.1:6789`). - #[arg(short, long)] - discovery_endpoint: String, - - /// The URL the orchestrator is running on. This should be something like `http://localhost:5555` - #[arg(short, long)] - orchestrator_url: String, - - /// Whether or not to use the local discovery client - #[arg(short, long)] - local_discovery: bool, -} - -#[tokio::main] -async fn main() -> Result<()> { - // Parse the command line arguments - let args = Args::parse(); - - // Initialize tracing - tracing_subscriber::fmt::init(); - - // Create a new `OrchestratorClient` from the supplied URL - let orchestrator_client = OrchestratorClient::new( - Url::from_str(&args.orchestrator_url).with_context(|| "Invalid URL")?, - ); - - // Attempt to get the config from the orchestrator. - // Loops internally until the config is received. - let config: NetworkConfig<::SignatureKey> = - orchestrator_client.get_config_after_collection().await; - - tracing::info!("Received config from orchestrator"); - - // Extrapolate the state_ver_keys from the config and convert them to a compatible format - let whitelist = config - .config - .known_nodes_with_stake - .iter() - .map(|k| Arc::from(k.stake_table_entry.stake_key.to_bytes())) - .collect(); - - if args.local_discovery { - ::new(args.discovery_endpoint, None) - .await? - .set_whitelist(whitelist) - .await?; - } else { - ::new(args.discovery_endpoint, None) - .await? - .set_whitelist(whitelist) - .await?; - } - - tracing::info!("Posted config to discovery endpoint"); - - Ok(()) -} diff --git a/crates/hotshot/src/lib.rs b/crates/hotshot/src/lib.rs index 05ccea0a0c..fc29483107 100644 --- a/crates/hotshot/src/lib.rs +++ b/crates/hotshot/src/lib.rs @@ -90,14 +90,7 @@ pub struct MarketplaceConfig> { pub fallback_builder_url: Url, } -/// Bundle of all the memberships a consensus instance uses -#[derive(Clone)] -pub struct Memberships { - /// The entire quorum - pub quorum_membership: TYPES::Membership, - /// The DA nodes - pub da_membership: TYPES::Membership, -} +pub use hotshot_types::stake_table::Memberships; /// Holds the state needed to participate in `HotShot` consensus pub struct SystemContext, V: Versions> { diff --git a/crates/hotshot/src/traits/election/randomized_committee.rs b/crates/hotshot/src/traits/election/randomized_committee.rs index 401a3102e2..e4d33ca9f4 100644 --- a/crates/hotshot/src/traits/election/randomized_committee.rs +++ b/crates/hotshot/src/traits/election/randomized_committee.rs @@ -17,9 +17,10 @@ use hotshot_types::{ PeerConfig, }; use rand::{rngs::StdRng, Rng}; +use serde::{Deserialize, Serialize}; use utils::anytrace::Result; -#[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] /// The static committee election diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index 258a2cfeda..4fe2150425 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -16,9 +16,10 @@ use hotshot_types::{ }, PeerConfig, }; +use serde::{Deserialize, Serialize}; use utils::anytrace::Result; -#[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] /// The static committee election pub struct StaticCommittee { diff --git a/crates/hotshot/src/traits/election/static_committee_leader_two_views.rs b/crates/hotshot/src/traits/election/static_committee_leader_two_views.rs index 8658744e71..3fcbcb1de3 100644 --- a/crates/hotshot/src/traits/election/static_committee_leader_two_views.rs +++ b/crates/hotshot/src/traits/election/static_committee_leader_two_views.rs @@ -16,9 +16,10 @@ use hotshot_types::{ }, PeerConfig, }; +use serde::{Deserialize, Serialize}; use utils::anytrace::Result; -#[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] /// The static committee election pub struct StaticCommitteeLeaderForTwoViews { diff --git a/crates/types/src/event.rs b/crates/types/src/event.rs index f9d48779e8..6536a5d2b8 100644 --- a/crates/types/src/event.rs +++ b/crates/types/src/event.rs @@ -15,6 +15,7 @@ use crate::{ error::HotShotError, message::Proposal, simple_certificate::QuorumCertificate, + stake_table::Memberships, traits::{node_implementation::NodeType, ValidatedState}, }; /// A status event emitted by a `HotShot` instance @@ -178,7 +179,31 @@ pub enum EventType { /// Serialized data of the message data: Vec, }, + + /// An epoch transition was started + EpochTransitionStarted { + /// The new epoch number + epoch: TYPES::Epoch, + + /// The initial stake table before the epoch transition + pre_update_stake_table: Memberships, + + /// The final stake table after the epoch transition + /// completes + post_update_stake_table: Memberships, + }, + + /// An epoch transition was completed + EpochTransitionFinished { + /// The new epoch number + epoch: TYPES::Epoch, + + /// The final stake table after the epoch transition + /// completes + post_update_stake_table: Memberships, + }, } + #[derive(Debug, Serialize, Deserialize, Clone, Copy)] /// A list of actions that we track for nodes pub enum HotShotAction { diff --git a/crates/types/src/stake_table.rs b/crates/types/src/stake_table.rs index eddfd1caef..1f2240f36a 100644 --- a/crates/types/src/stake_table.rs +++ b/crates/types/src/stake_table.rs @@ -9,7 +9,19 @@ use ethereum_types::U256; use serde::{Deserialize, Serialize}; -use crate::traits::signature_key::{SignatureKey, StakeTableEntryType}; +use crate::traits::{ + node_implementation::NodeType, + signature_key::{SignatureKey, StakeTableEntryType}, +}; + +/// Bundle of all the memberships a consensus instance uses +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Memberships { + /// The entire quorum + pub quorum_membership: TYPES::Membership, + /// The DA nodes + pub da_membership: TYPES::Membership, +} /// Stake table entry #[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Hash, Eq)] diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index aa313fc64a..73b2fdfcba 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -7,13 +7,16 @@ //! The election trait, used to decide which node is the leader and determine if a vote is valid. use std::{collections::BTreeSet, fmt::Debug, num::NonZeroU64}; +use serde::{de::DeserializeOwned, Serialize}; use utils::anytrace::Result; use super::{network::Topic, node_implementation::NodeType}; use crate::{traits::signature_key::SignatureKey, PeerConfig}; /// A protocol for determining membership in and participating in a committee. -pub trait Membership: Clone + Debug + Send + Sync { +pub trait Membership: + Clone + Debug + Send + Sync + Serialize + DeserializeOwned +{ /// The error type returned by methods like `lookup_leader`. type Error: std::fmt::Display; diff --git a/crates/types/src/traits/network.rs b/crates/types/src/traits/network.rs index 5a01560832..c492cee069 100644 --- a/crates/types/src/traits/network.rs +++ b/crates/types/src/traits/network.rs @@ -588,7 +588,7 @@ impl NetworkReliability for ChaosNetwork { } /// Used when broadcasting messages -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Topic { /// The `Global` topic goes out to all nodes Global,