From 23b1651a49df5ee34632fd754d10f7969b9623c2 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:06:33 -0400 Subject: [PATCH 1/9] init --- crates/hotshot/src/traits/election/static_committee.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index 555050b89a..73de2603e4 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -16,7 +16,6 @@ use hotshot_types::{ }, PeerConfig, }; -#[cfg(feature = "randomized-leader-election")] use rand::{rngs::StdRng, Rng}; #[derive(Clone, Debug, Eq, PartialEq, Hash)] @@ -136,9 +135,14 @@ impl Membership for GeneralStaticCommittee { )))] /// Index the vector of public keys with the current view number fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { - let index = usize::try_from(*view_number % self.eligible_leaders.len() as u64).unwrap(); + let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number); + let randomized_view_number: usize = rng.gen(); + let index = randomized_view_number % self.eligible_leaders.len(); let res = self.eligible_leaders[index].clone(); TYPES::SignatureKey::public_key(&res) +// let index = *view_number as usize % self.eligible_leaders.len(); +// let res = self.eligible_leaders[index].clone(); +// TYPES::SignatureKey::public_key(&res) } #[cfg(feature = "fixed-leader-election")] @@ -150,7 +154,7 @@ impl Membership for GeneralStaticCommittee { { panic!("fixed_leader_for_gpuvid is not set correctly."); } - let index = usize::try_from(*view_number % self.fixed_leader_for_gpuvid as u64).unwrap(); + let index = *view_number as usize % self.fixed_leader_for_gpuvid; let res = self.eligible_leaders[index].clone(); TYPES::SignatureKey::public_key(&res) } From 332472f59ea4c136877a922558203768a2f256a2 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:01:35 -0400 Subject: [PATCH 2/9] reorganize/remove features --- crates/examples/Cargo.toml | 1 - crates/examples/infra/mod.rs | 22 +-- crates/hotshot/Cargo.toml | 2 - crates/hotshot/src/traits/election.rs | 2 + .../traits/election/randomized_committee.rs | 155 ++++++++++++++++++ .../src/traits/election/static_committee.rs | 45 +---- .../static_committee_leader_two_views.rs | 9 - crates/orchestrator/Cargo.toml | 4 - crates/orchestrator/src/client.rs | 2 - crates/orchestrator/src/lib.rs | 22 --- crates/testing/src/helpers.rs | 10 +- crates/testing/src/test_runner.rs | 10 +- crates/testing/tests/tests_1/network_task.rs | 18 +- crates/types/src/traits/election.rs | 1 - 14 files changed, 176 insertions(+), 127 deletions(-) create mode 100644 crates/hotshot/src/traits/election/randomized_committee.rs diff --git a/crates/examples/Cargo.toml b/crates/examples/Cargo.toml index b004023a27..80c0423510 100644 --- a/crates/examples/Cargo.toml +++ b/crates/examples/Cargo.toml @@ -18,7 +18,6 @@ bin-orchestrator = ["clap"] docs = [] doc-images = [] hotshot-testing = ["hotshot/hotshot-testing"] -randomized-leader-election = [] fixed-leader-election = [] # Common diff --git a/crates/examples/infra/mod.rs b/crates/examples/infra/mod.rs index 26caa3dd1b..7edff0f6bd 100755 --- a/crates/examples/infra/mod.rs +++ b/crates/examples/infra/mod.rs @@ -380,7 +380,16 @@ pub trait RunDa< let network = self.network(); - let all_nodes = config.config.known_nodes_with_stake.clone(); + let all_nodes = if cfg!(feature = "fixed-leader-election") { + let mut vec = config.config.known_nodes_with_stake.clone(); + + vec.truncate(config.config.fixed_leader_for_gpuvid); + + vec + } else { + config.config.known_nodes_with_stake.clone() + }; + let da_nodes = config.config.known_da_nodes.clone(); // Create the quorum membership from all nodes @@ -388,19 +397,12 @@ pub trait RunDa< all_nodes.clone(), all_nodes.clone(), Topic::Global, - #[cfg(feature = "fixed-leader-election")] - config.config.fixed_leader_for_gpuvid, ); // Create the quorum membership from all nodes, specifying the committee // as the known da nodes - let da_membership = ::Membership::new( - all_nodes.clone(), - da_nodes, - Topic::Da, - #[cfg(feature = "fixed-leader-election")] - config.config.fixed_leader_for_gpuvid, - ); + let da_membership = + ::Membership::new(all_nodes.clone(), da_nodes, Topic::Da); let memberships = Memberships { quorum_membership: quorum_membership.clone(), diff --git a/crates/hotshot/Cargo.toml b/crates/hotshot/Cargo.toml index 9dd8e2a35a..b96a366530 100644 --- a/crates/hotshot/Cargo.toml +++ b/crates/hotshot/Cargo.toml @@ -21,8 +21,6 @@ bin-orchestrator = ["clap"] docs = [] doc-images = [] hotshot-testing = [] -randomized-leader-election = [] -fixed-leader-election = [] [dependencies] anyhow = { workspace = true } diff --git a/crates/hotshot/src/traits/election.rs b/crates/hotshot/src/traits/election.rs index d00e7806b0..4f9212705f 100644 --- a/crates/hotshot/src/traits/election.rs +++ b/crates/hotshot/src/traits/election.rs @@ -6,6 +6,8 @@ //! elections used for consensus +/// leader completely randomized every view +pub mod randomized_committee; /// static (round robin) committee election pub mod static_committee; /// static (round robin leader for 2 consecutive views) committee election diff --git a/crates/hotshot/src/traits/election/randomized_committee.rs b/crates/hotshot/src/traits/election/randomized_committee.rs new file mode 100644 index 0000000000..b3df85fe59 --- /dev/null +++ b/crates/hotshot/src/traits/election/randomized_committee.rs @@ -0,0 +1,155 @@ +// 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 . + +use std::{cmp::max, collections::BTreeMap, num::NonZeroU64}; + +use ethereum_types::U256; +use hotshot_types::{ + traits::{ + election::Membership, + network::Topic, + node_implementation::NodeType, + signature_key::{SignatureKey, StakeTableEntryType}, + }, + PeerConfig, +}; +use rand::{rngs::StdRng, Rng}; + +#[derive(Clone, Debug, Eq, PartialEq, Hash)] + +/// The static committee election +pub struct GeneralStaticCommittee { + /// The nodes eligible for leadership. + /// NOTE: This is currently a hack because the DA leader needs to be the quorum + /// leader but without voting rights. + eligible_leaders: Vec<::StakeTableEntry>, + + /// The nodes on the committee and their stake + stake_table: Vec<::StakeTableEntry>, + + /// The nodes on the committee and their stake, indexed by public key + indexed_stake_table: + BTreeMap::StakeTableEntry>, + + /// The network topic of the committee + committee_topic: Topic, +} + +/// static committee using a vrf kp +pub type RandomizedCommittee = GeneralStaticCommittee; + +impl Membership for GeneralStaticCommittee { + /// Create a new election + fn new( + eligible_leaders: Vec::SignatureKey>>, + committee_members: Vec::SignatureKey>>, + committee_topic: Topic, + ) -> Self { + // For each eligible leader, get the stake table entry + let eligible_leaders: Vec<::StakeTableEntry> = + eligible_leaders + .iter() + .map(|member| member.stake_table_entry.clone()) + .filter(|entry| entry.stake() > U256::zero()) + .collect(); + + // For each member, get the stake table entry + let members: Vec<::StakeTableEntry> = + committee_members + .iter() + .map(|member| member.stake_table_entry.clone()) + .filter(|entry| entry.stake() > U256::zero()) + .collect(); + + // Index the stake table by public key + let indexed_stake_table: BTreeMap< + TYPES::SignatureKey, + ::StakeTableEntry, + > = members + .iter() + .map(|entry| (TYPES::SignatureKey::public_key(entry), entry.clone())) + .collect(); + + Self { + eligible_leaders, + stake_table: members, + indexed_stake_table, + committee_topic, + } + } + + /// Get the stake table for the current view + fn stake_table( + &self, + ) -> Vec<<::SignatureKey as SignatureKey>::StakeTableEntry> { + self.stake_table.clone() + } + + /// Get all members of the committee for the current view + fn committee_members( + &self, + _view_number: ::Time, + ) -> std::collections::BTreeSet<::SignatureKey> { + self.stake_table + .iter() + .map(TYPES::SignatureKey::public_key) + .collect() + } + + /// Get the stake table entry for a public key + fn stake( + &self, + pub_key: &::SignatureKey, + ) -> Option<::StakeTableEntry> { + // Only return the stake if it is above zero + self.indexed_stake_table.get(pub_key).cloned() + } + + /// Check if a node has stake in the committee + fn has_stake(&self, pub_key: &::SignatureKey) -> bool { + self.indexed_stake_table + .get(pub_key) + .is_some_and(|x| x.stake() > U256::zero()) + } + + /// Get the network topic for the committee + fn committee_topic(&self) -> Topic { + self.committee_topic.clone() + } + + /// Index the vector of public keys with the current view number + fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { + let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number); + let randomized_view_number: usize = rng.gen(); + let index = randomized_view_number % self.eligible_leaders.len(); + let res = self.eligible_leaders[index].clone(); + TYPES::SignatureKey::public_key(&res) + } + + /// Get the total number of nodes in the committee + fn total_nodes(&self) -> usize { + self.stake_table.len() + } + + /// Get the voting success threshold for the committee + fn success_threshold(&self) -> NonZeroU64 { + NonZeroU64::new(((self.stake_table.len() as u64 * 2) / 3) + 1).unwrap() + } + + /// Get the voting failure threshold for the committee + fn failure_threshold(&self) -> NonZeroU64 { + NonZeroU64::new(((self.stake_table.len() as u64) / 3) + 1).unwrap() + } + + /// Get the voting upgrade threshold for the committee + fn upgrade_threshold(&self) -> NonZeroU64 { + NonZeroU64::new(max( + (self.stake_table.len() as u64 * 9) / 10, + ((self.stake_table.len() as u64 * 2) / 3) + 1, + )) + .unwrap() + } +} diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index 73de2603e4..f1ed97c8e7 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -16,7 +16,6 @@ use hotshot_types::{ }, PeerConfig, }; -use rand::{rngs::StdRng, Rng}; #[derive(Clone, Debug, Eq, PartialEq, Hash)] @@ -34,12 +33,6 @@ pub struct GeneralStaticCommittee { indexed_stake_table: BTreeMap::StakeTableEntry>, - // /// The members of the committee - // committee_members: BTreeSet, - #[cfg(feature = "fixed-leader-election")] - /// The number of fixed leaders for gpuvid - fixed_leader_for_gpuvid: usize, - /// The network topic of the committee committee_topic: Topic, } @@ -53,7 +46,6 @@ impl Membership for GeneralStaticCommittee { eligible_leaders: Vec::SignatureKey>>, committee_members: Vec::SignatureKey>>, committee_topic: Topic, - #[cfg(feature = "fixed-leader-election")] fixed_leader_for_gpuvid: usize, ) -> Self { // For each eligible leader, get the stake table entry let eligible_leaders: Vec<::StakeTableEntry> = @@ -85,8 +77,6 @@ impl Membership for GeneralStaticCommittee { stake_table: members, indexed_stake_table, committee_topic, - #[cfg(feature = "fixed-leader-election")] - fixed_leader_for_gpuvid, } } @@ -129,42 +119,9 @@ impl Membership for GeneralStaticCommittee { self.committee_topic.clone() } - #[cfg(not(any( - feature = "randomized-leader-election", - feature = "fixed-leader-election" - )))] /// Index the vector of public keys with the current view number fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { - let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number); - let randomized_view_number: usize = rng.gen(); - let index = randomized_view_number % self.eligible_leaders.len(); - let res = self.eligible_leaders[index].clone(); - TYPES::SignatureKey::public_key(&res) -// let index = *view_number as usize % self.eligible_leaders.len(); -// let res = self.eligible_leaders[index].clone(); -// TYPES::SignatureKey::public_key(&res) - } - - #[cfg(feature = "fixed-leader-election")] - /// Only get leader in fixed set - /// Index the fixed vector (first fixed_leader_for_gpuvid element) of public keys with the current view number - fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { - if self.fixed_leader_for_gpuvid <= 0 - || self.fixed_leader_for_gpuvid > self.eligible_leaders.len() - { - panic!("fixed_leader_for_gpuvid is not set correctly."); - } - let index = *view_number as usize % self.fixed_leader_for_gpuvid; - let res = self.eligible_leaders[index].clone(); - TYPES::SignatureKey::public_key(&res) - } - - #[cfg(feature = "randomized-leader-election")] - /// Index the vector of public keys with a random number generated using the current view number as a seed - fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { - let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number); - let randomized_view_number: usize = rng.gen(); - let index = randomized_view_number % self.eligible_leaders.len(); + let index = *view_number as usize % self.eligible_leaders.len(); let res = self.eligible_leaders[index].clone(); TYPES::SignatureKey::public_key(&res) } 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 9aed92f531..085d6ac349 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 @@ -33,12 +33,6 @@ pub struct StaticCommitteeLeaderForTwoViews { indexed_stake_table: BTreeMap::StakeTableEntry>, - // /// The members of the committee - // committee_members: BTreeSet, - #[cfg(feature = "fixed-leader-election")] - /// The number of fixed leaders for gpuvid - fixed_leader_for_gpuvid: usize, - /// The network topic of the committee committee_topic: Topic, } @@ -52,7 +46,6 @@ impl Membership for StaticCommitteeLeaderForTwoViews::SignatureKey>>, committee_members: Vec::SignatureKey>>, committee_topic: Topic, - #[cfg(feature = "fixed-leader-election")] fixed_leader_for_gpuvid: usize, ) -> Self { // For each eligible leader, get the stake table entry let eligible_leaders: Vec<::StakeTableEntry> = @@ -84,8 +77,6 @@ impl Membership for StaticCommitteeLeaderForTwoViews OrchestratorState { } } - /// get election type in use - #[must_use] - pub fn election_type() -> String { - // leader is chosen in index order - #[cfg(not(any( - feature = "randomized-leader-election", - feature = "fixed-leader-election" - )))] - let election_type = "static-leader-selection".to_string(); - - // leader is from a fixed set - #[cfg(feature = "fixed-leader-election")] - let election_type = "fixed-leader-election".to_string(); - - // leader is randomly chosen - #[cfg(feature = "randomized-leader-election")] - let election_type = "randomized-leader-election".to_string(); - - election_type - } - /// Output the results to a csv file according to orchestrator state pub fn output_to_csv(&self) { let output_csv = BenchResultsDownloadConfig { @@ -173,7 +152,6 @@ impl OrchestratorState { transactions_per_round: self.config.transactions_per_round, transaction_size: self.bench_results.transaction_size_in_bytes, rounds: self.config.rounds, - leader_election_type: OrchestratorState::::election_type(), partial_results: self.bench_results.partial_results.clone(), avg_latency_in_sec: self.bench_results.avg_latency_in_sec, minimum_latency_in_sec: self.bench_results.minimum_latency_in_sec, diff --git a/crates/testing/src/helpers.rs b/crates/testing/src/helpers.rs index a5a992784c..9b5af4d1c6 100644 --- a/crates/testing/src/helpers.rs +++ b/crates/testing/src/helpers.rs @@ -90,16 +90,8 @@ pub async fn build_system_handle< all_nodes.clone(), all_nodes.clone(), Topic::Global, - #[cfg(feature = "fixed-leader-election")] - config.fixed_leader_for_gpuvid, - ), - da_membership: TYPES::Membership::new( - all_nodes, - da_nodes, - Topic::Da, - #[cfg(feature = "fixed-leader-election")] - config.fixed_leader_for_gpuvid, ), + da_membership: TYPES::Membership::new(all_nodes, da_nodes, Topic::Da), }; SystemContext::init( diff --git a/crates/testing/src/test_runner.rs b/crates/testing/src/test_runner.rs index 6a24730d31..dd917b9d96 100644 --- a/crates/testing/src/test_runner.rs +++ b/crates/testing/src/test_runner.rs @@ -444,16 +444,8 @@ where all_nodes.clone(), all_nodes.clone(), Topic::Global, - #[cfg(feature = "fixed-leader-election")] - config.fixed_leader_for_gpuvid, - ), - da_membership: ::Membership::new( - all_nodes, - da_nodes, - Topic::Da, - #[cfg(feature = "fixed-leader-election")] - config.fixed_leader_for_gpuvid, ), + da_membership: ::Membership::new(all_nodes, da_nodes, Topic::Da), }; config.builder_urls = builder_urls .clone() diff --git a/crates/testing/tests/tests_1/network_task.rs b/crates/testing/tests/tests_1/network_task.rs index 322640b054..cb623926d1 100644 --- a/crates/testing/tests/tests_1/network_task.rs +++ b/crates/testing/tests/tests_1/network_task.rs @@ -59,13 +59,8 @@ async fn test_network_task() { let all_nodes = config.known_nodes_with_stake.clone(); - let membership = ::Membership::new( - all_nodes.clone(), - all_nodes, - Topic::Global, - #[cfg(feature = "fixed-leader-election")] - config.fixed_leader_for_gpuvid, - ); + let membership = + ::Membership::new(all_nodes.clone(), all_nodes, Topic::Global); let network_state: NetworkEventTaskState, _> = NetworkEventTaskState { channel: network.clone(), @@ -140,13 +135,8 @@ async fn test_network_storage_fail() { let all_nodes = config.known_nodes_with_stake.clone(); let upgrade_lock = UpgradeLock::::new(); - let membership = ::Membership::new( - all_nodes.clone(), - all_nodes, - Topic::Global, - #[cfg(feature = "fixed-leader-election")] - config.fixed_leader_for_gpuvid, - ); + let membership = + ::Membership::new(all_nodes.clone(), all_nodes, Topic::Global); let network_state: NetworkEventTaskState, _> = NetworkEventTaskState { channel: network.clone(), diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index 2db04c283e..7a9b556d1f 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -21,7 +21,6 @@ pub trait Membership: eligible_leaders: Vec>, committee_members: Vec>, committee_topic: Topic, - #[cfg(feature = "fixed-leader-election")] fixed_leader_for_gpuvid: usize, ) -> Self; /// Get all participants in the committee (including their stake) From dc6cdf29630fb5f169ec074e9a3d378fa4b9bba8 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:44:01 -0400 Subject: [PATCH 3/9] use randomized leader rotation in test --- crates/example-types/src/node_types.rs | 30 +++++++++++++++++++ .../src/traits/election/static_committee.rs | 1 + crates/testing/tests/tests_1/test_success.rs | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/example-types/src/node_types.rs b/crates/example-types/src/node_types.rs index c5e5c6a3a9..f14b44131f 100644 --- a/crates/example-types/src/node_types.rs +++ b/crates/example-types/src/node_types.rs @@ -6,6 +6,7 @@ use hotshot::traits::{ election::{ + randomized_committee::RandomizedCommittee, static_committee::{GeneralStaticCommittee, StaticCommittee}, static_committee_leader_two_views::StaticCommitteeLeaderForTwoViews, }, @@ -56,6 +57,35 @@ impl NodeType for TestTypes { type BuilderSignatureKey = BuilderKey; } +#[derive( + Copy, + Clone, + Debug, + Default, + Hash, + PartialEq, + Eq, + PartialOrd, + Ord, + serde::Serialize, + serde::Deserialize, +)] +/// filler struct to implement node type and allow us +/// to select our traits +pub struct TestTypesRandomizedLeader; +impl NodeType for TestTypesRandomizedLeader { + type AuctionResult = TestAuctionResult; + type Time = ViewNumber; + type BlockHeader = TestBlockHeader; + type BlockPayload = TestBlockPayload; + type SignatureKey = BLSPubKey; + type Transaction = TestTransaction; + type ValidatedState = TestValidatedState; + type InstanceState = TestInstanceState; + type Membership = RandomizedCommittee; + type BuilderSignatureKey = BuilderKey; +} + #[derive( Copy, Clone, diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index f1ed97c8e7..9a2997a53b 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -121,6 +121,7 @@ impl Membership for GeneralStaticCommittee { /// Index the vector of public keys with the current view number fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { + #[allow(clippy::cast_possible_truncation)] let index = *view_number as usize % self.eligible_leaders.len(); let res = self.eligible_leaders[index].clone(); TYPES::SignatureKey::public_key(&res) diff --git a/crates/testing/tests/tests_1/test_success.rs b/crates/testing/tests/tests_1/test_success.rs index 266f97ab5b..be70024ecf 100644 --- a/crates/testing/tests/tests_1/test_success.rs +++ b/crates/testing/tests/tests_1/test_success.rs @@ -25,7 +25,7 @@ use hotshot_testing::{ cross_tests!( TestName: test_success, Impls: [MemoryImpl, Libp2pImpl, PushCdnImpl], - Types: [TestTypes], + Types: [TestTypes, TestTypesRandomizedCommittee], Versions: [TestVersions], Ignore: false, Metadata: { From 96a1d28216dced1566012885f62d0fa0425416fd Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:19:30 -0400 Subject: [PATCH 4/9] fix --- crates/testing/tests/tests_1/test_success.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/testing/tests/tests_1/test_success.rs b/crates/testing/tests/tests_1/test_success.rs index be70024ecf..c4ba56416c 100644 --- a/crates/testing/tests/tests_1/test_success.rs +++ b/crates/testing/tests/tests_1/test_success.rs @@ -6,14 +6,14 @@ use std::time::Duration; +use hotshot_example_types::node_types::{ + Libp2pImpl, MemoryImpl, PushCdnImpl, TestConsecutiveLeaderTypes, TestTypes, + TestTypesRandomizedLeader, TestVersions, +}; #[cfg(feature = "dependency-tasks")] use hotshot_example_types::testable_delay::{ DelayConfig, DelayOptions, DelaySettings, SupportedTraitTypesForAsyncDelay, }; -use hotshot_example_types::{ - node_types::{Libp2pImpl, MemoryImpl, PushCdnImpl, TestConsecutiveLeaderTypes, TestVersions}, - state_types::TestTypes, -}; use hotshot_macros::cross_tests; use hotshot_testing::{ block_builder::SimpleBuilderImplementation, @@ -25,7 +25,7 @@ use hotshot_testing::{ cross_tests!( TestName: test_success, Impls: [MemoryImpl, Libp2pImpl, PushCdnImpl], - Types: [TestTypes, TestTypesRandomizedCommittee], + Types: [TestTypes, TestTypesRandomizedLeader], Versions: [TestVersions], Ignore: false, Metadata: { From 179e76497ccba9d5ea05a074b0ea975db5221e12 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:01:16 -0400 Subject: [PATCH 5/9] update --- crates/testing/tests/tests_2/catchup.rs | 458 ++++++++++-------------- 1 file changed, 187 insertions(+), 271 deletions(-) diff --git a/crates/testing/tests/tests_2/catchup.rs b/crates/testing/tests/tests_2/catchup.rs index 06a0099847..4e4cb38f99 100644 --- a/crates/testing/tests/tests_2/catchup.rs +++ b/crates/testing/tests/tests_2/catchup.rs @@ -4,6 +4,24 @@ // You should have received a copy of the MIT License // along with the HotShot repository. If not, see . +use std::time::Duration; + +use hotshot_example_types::node_types::{ + CombinedImpl, PushCdnImpl, TestTypes, TestTypesRandomizedLeader, TestVersions, +}; +#[cfg(feature = "dependency-tasks")] +use hotshot_example_types::testable_delay::{ + DelayConfig, DelayOptions, DelaySettings, SupportedTraitTypesForAsyncDelay, +}; +use hotshot_macros::cross_tests; +use hotshot_testing::{ + block_builder::SimpleBuilderImplementation, + completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription}, + overall_safety_task::OverallSafetyPropertiesDescription, + spinning_task::{ChangeNode, NodeAction, SpinningTaskDescription}, + test_builder::{TestDescription, TimingData}, +}; + #[cfg(test)] #[cfg_attr(async_executor_impl = "tokio", tokio::test(flavor = "multi_thread"))] #[cfg_attr(async_executor_impl = "async-std", async_std::test)] @@ -301,274 +319,172 @@ async fn test_catchup_reload() { .await; } -#[cfg(test)] -#[cfg_attr(async_executor_impl = "tokio", tokio::test(flavor = "multi_thread"))] -#[cfg_attr(async_executor_impl = "async-std", async_std::test)] -async fn test_all_restart() { - use std::time::Duration; - - use hotshot_example_types::node_types::{CombinedImpl, TestTypes, TestVersions}; - use hotshot_testing::{ - block_builder::SimpleBuilderImplementation, - completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription}, - overall_safety_task::OverallSafetyPropertiesDescription, - spinning_task::{ChangeNode, NodeAction, SpinningTaskDescription}, - test_builder::{TestDescription, TimingData}, - }; - - async_compatibility_layer::logging::setup_logging(); - async_compatibility_layer::logging::setup_backtrace(); - let timing_data = TimingData { - next_view_timeout: 2000, - round_start_delay: 500, - ..Default::default() - }; - let mut metadata: TestDescription = - TestDescription::default(); - let mut catchup_nodes = vec![]; - for i in 0..20 { - catchup_nodes.push(ChangeNode { - idx: i, - updown: NodeAction::RestartDown(0), - }) - } - - metadata.timing_data = timing_data; - metadata.start_nodes = 20; - metadata.num_nodes_with_stake = 20; - - metadata.spinning_properties = SpinningTaskDescription { - // Restart all the nodes in view 13 - node_changes: vec![(13, catchup_nodes)], - }; - metadata.view_sync_properties = - hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 20); - - metadata.completion_task_description = - CompletionTaskDescription::TimeBasedCompletionTaskBuilder( - TimeBasedCompletionTaskDescription { - duration: Duration::from_secs(60), - }, - ); - metadata.overall_safety_properties = OverallSafetyPropertiesDescription { - // Make sure we keep committing rounds after the catchup, but not the full 50. - num_successful_views: 22, - num_failed_views: 15, - ..Default::default() - }; - - metadata - .gen_launcher(0) - .launch() - .run_test::() - .await; -} - -#[cfg(test)] -#[cfg_attr(async_executor_impl = "tokio", tokio::test(flavor = "multi_thread"))] -#[cfg_attr(async_executor_impl = "async-std", async_std::test)] -async fn test_all_restart_cdn() { - use std::time::Duration; - - use hotshot_example_types::node_types::{PushCdnImpl, TestTypes, TestVersions}; - use hotshot_testing::{ - block_builder::SimpleBuilderImplementation, - completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription}, - overall_safety_task::OverallSafetyPropertiesDescription, - spinning_task::{ChangeNode, NodeAction, SpinningTaskDescription}, - test_builder::{TestDescription, TimingData}, - }; - - async_compatibility_layer::logging::setup_logging(); - async_compatibility_layer::logging::setup_backtrace(); - let timing_data = TimingData { - next_view_timeout: 2000, - round_start_delay: 500, - ..Default::default() - }; - let mut metadata: TestDescription = - TestDescription::default(); - let mut catchup_nodes = vec![]; - for i in 0..20 { - catchup_nodes.push(ChangeNode { - idx: i, - updown: NodeAction::RestartDown(0), - }) - } - - metadata.timing_data = timing_data; - metadata.start_nodes = 20; - metadata.num_nodes_with_stake = 20; - - metadata.spinning_properties = SpinningTaskDescription { - // Restart all the nodes in view 13 - node_changes: vec![(13, catchup_nodes)], - }; - metadata.view_sync_properties = - hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 20); - - metadata.completion_task_description = - CompletionTaskDescription::TimeBasedCompletionTaskBuilder( - TimeBasedCompletionTaskDescription { - duration: Duration::from_secs(60), - }, - ); - metadata.overall_safety_properties = OverallSafetyPropertiesDescription { - // Make sure we keep committing rounds after the catchup, but not the full 50. - num_successful_views: 22, - num_failed_views: 15, - ..Default::default() - }; - - metadata - .gen_launcher(0) - .launch() - .run_test::() - .await; -} - -/// This test case ensures that proposals persist off of a restart. We demonstrate this by -/// artificially removing node 0 (the only DA committee member) from the candidate pool, -/// meaning that the entire DA also does not have the proposal, but we're still able to -/// move on because the *leader* does have the proposal. -#[cfg(test)] -#[cfg_attr(async_executor_impl = "tokio", tokio::test(flavor = "multi_thread"))] -#[cfg_attr(async_executor_impl = "async-std", async_std::test)] -async fn test_all_restart_one_da() { - use std::time::Duration; - - use hotshot_example_types::node_types::{CombinedImpl, TestTypes, TestVersions}; - use hotshot_testing::{ - block_builder::SimpleBuilderImplementation, - completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription}, - overall_safety_task::OverallSafetyPropertiesDescription, - spinning_task::{ChangeNode, NodeAction, SpinningTaskDescription}, - test_builder::{TestDescription, TimingData}, - }; - - async_compatibility_layer::logging::setup_logging(); - async_compatibility_layer::logging::setup_backtrace(); - let timing_data = TimingData { - next_view_timeout: 2000, - round_start_delay: 500, - ..Default::default() - }; - let mut metadata: TestDescription = - TestDescription::default(); - - let mut catchup_nodes = vec![]; - for i in 0..20 { - catchup_nodes.push(ChangeNode { - idx: i, - updown: NodeAction::RestartDown(0), - }) - } - - metadata.timing_data = timing_data; - metadata.start_nodes = 20; - metadata.num_nodes_with_stake = 20; - - // Explicitly make the DA tiny to exaggerate a missing proposal. - metadata.da_staked_committee_size = 1; - - metadata.spinning_properties = SpinningTaskDescription { - // Restart all the nodes in view 13 - node_changes: vec![(13, catchup_nodes)], - }; - metadata.view_sync_properties = - hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 20); - - metadata.completion_task_description = - CompletionTaskDescription::TimeBasedCompletionTaskBuilder( - TimeBasedCompletionTaskDescription { - duration: Duration::from_secs(60), - }, - ); - metadata.overall_safety_properties = OverallSafetyPropertiesDescription { - // Make sure we keep committing rounds after the catchup, but not the full 50. - num_successful_views: 22, - num_failed_views: 15, - ..Default::default() - }; - - metadata - .gen_launcher(0) - .launch() - .run_test::() - .await; -} - -#[cfg(test)] -#[cfg_attr(async_executor_impl = "tokio", tokio::test(flavor = "multi_thread"))] -#[cfg_attr(async_executor_impl = "async-std", async_std::test)] -async fn test_staggered_restart() { - use std::time::Duration; - - use hotshot_example_types::node_types::{CombinedImpl, TestTypes, TestVersions}; - use hotshot_testing::{ - block_builder::SimpleBuilderImplementation, - completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription}, - overall_safety_task::OverallSafetyPropertiesDescription, - spinning_task::{ChangeNode, NodeAction, SpinningTaskDescription}, - test_builder::TestDescription, - }; - - async_compatibility_layer::logging::setup_logging(); - async_compatibility_layer::logging::setup_backtrace(); - let mut metadata: TestDescription = - TestDescription::default(); - - let mut down_da_nodes = vec![]; - for i in 1..4 { - down_da_nodes.push(ChangeNode { - idx: i, - updown: NodeAction::RestartDown(20), - }); - } - - let mut down_regular_nodes = vec![]; - for i in 4..10 { - down_regular_nodes.push(ChangeNode { - idx: i, - updown: NodeAction::RestartDown(0), - }); - } - // restart the last da so it gets the new libp2p routing table - down_regular_nodes.push(ChangeNode { - idx: 0, - updown: NodeAction::RestartDown(0), - }); - - metadata.start_nodes = 10; - metadata.num_nodes_with_stake = 10; - - // Explicitly make the DA small to simulate real network. - metadata.da_staked_committee_size = 4; - - metadata.spinning_properties = SpinningTaskDescription { - // Restart all the nodes in view 13 - node_changes: vec![(13, down_da_nodes), (33, down_regular_nodes)], - }; - metadata.view_sync_properties = - hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 50); - - // Give the test some extra time because we are purposely timing out views - metadata.completion_task_description = - CompletionTaskDescription::TimeBasedCompletionTaskBuilder( - TimeBasedCompletionTaskDescription { - duration: Duration::from_secs(240), - }, - ); - metadata.overall_safety_properties = OverallSafetyPropertiesDescription { - // Make sure we keep committing rounds after the catchup, but not the full 50. - num_successful_views: 22, - num_failed_views: 30, - ..Default::default() - }; - - metadata - .gen_launcher(0) - .launch() - .run_test::() - .await; -} +cross_tests!( + TestName: test_all_restart, + Impls: [CombinedImpl, PushCdnImpl], + Types: [TestTypes, TestTypesRandomizedLeader], + Versions: [TestVersions], + Ignore: false, + Metadata: { + let timing_data = TimingData { + next_view_timeout: 2000, + round_start_delay: 500, + ..Default::default() + }; + let mut metadata = TestDescription::default(); + let mut catchup_nodes = vec![]; + + for i in 0..20 { + catchup_nodes.push(ChangeNode { + idx: i, + updown: NodeAction::RestartDown(0), + }) + } + + metadata.timing_data = timing_data; + metadata.start_nodes = 20; + metadata.num_nodes_with_stake = 20; + + metadata.spinning_properties = SpinningTaskDescription { + // Restart all the nodes in view 13 + node_changes: vec![(13, catchup_nodes)], + }; + metadata.view_sync_properties = + hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 20); + + metadata.completion_task_description = + CompletionTaskDescription::TimeBasedCompletionTaskBuilder( + TimeBasedCompletionTaskDescription { + duration: Duration::from_secs(60), + }, + ); + metadata.overall_safety_properties = OverallSafetyPropertiesDescription { + // Make sure we keep committing rounds after the catchup, but not the full 50. + num_successful_views: 22, + num_failed_views: 15, + ..Default::default() + }; + + metadata + }, +); + +// This test case ensures that proposals persist off of a restart. We demonstrate this by +// artificially removing node 0 (the only DA committee member) from the candidate pool, +// meaning that the entire DA also does not have the proposal, but we're still able to +// move on because the *leader* does have the proposal. +cross_tests!( + TestName: test_all_restart_one_da, + Impls: [CombinedImpl], + Types: [TestTypes], + Versions: [TestVersions], + Ignore: false, + Metadata: { + let timing_data = TimingData { + next_view_timeout: 2000, + round_start_delay: 500, + ..Default::default() + }; + let mut metadata: TestDescription = + TestDescription::default(); + + let mut catchup_nodes = vec![]; + for i in 0..20 { + catchup_nodes.push(ChangeNode { + idx: i, + updown: NodeAction::RestartDown(0), + }) + } + + metadata.timing_data = timing_data; + metadata.start_nodes = 20; + metadata.num_nodes_with_stake = 20; + + // Explicitly make the DA tiny to exaggerate a missing proposal. + metadata.da_staked_committee_size = 1; + + metadata.spinning_properties = SpinningTaskDescription { + // Restart all the nodes in view 13 + node_changes: vec![(13, catchup_nodes)], + }; + metadata.view_sync_properties = + hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 20); + + metadata.completion_task_description = + CompletionTaskDescription::TimeBasedCompletionTaskBuilder( + TimeBasedCompletionTaskDescription { + duration: Duration::from_secs(60), + }, + ); + metadata.overall_safety_properties = OverallSafetyPropertiesDescription { + // Make sure we keep committing rounds after the catchup, but not the full 50. + num_successful_views: 22, + num_failed_views: 15, + ..Default::default() + }; + + + metadata + }, +); + +cross_tests!( + TestName: test_staggered_restart, + Impls: [CombinedImpl], + Types: [TestTypes], + Versions: [TestVersions], + Ignore: false, + Metadata: { + let mut metadata = TestDescription::default(); + + let mut down_da_nodes = vec![]; + for i in 1..4 { + down_da_nodes.push(ChangeNode { + idx: i, + updown: NodeAction::RestartDown(20), + }); + } + + let mut down_regular_nodes = vec![]; + for i in 4..10 { + down_regular_nodes.push(ChangeNode { + idx: i, + updown: NodeAction::RestartDown(0), + }); + } + // restart the last da so it gets the new libp2p routing table + down_regular_nodes.push(ChangeNode { + idx: 0, + updown: NodeAction::RestartDown(0), + }); + + metadata.start_nodes = 10; + metadata.num_nodes_with_stake = 10; + + // Explicitly make the DA small to simulate real network. + metadata.da_staked_committee_size = 4; + + metadata.spinning_properties = SpinningTaskDescription { + // Restart all the nodes in view 13 + node_changes: vec![(13, down_da_nodes), (33, down_regular_nodes)], + }; + metadata.view_sync_properties = + hotshot_testing::view_sync_task::ViewSyncTaskDescription::Threshold(0, 50); + + // Give the test some extra time because we are purposely timing out views + metadata.completion_task_description = + CompletionTaskDescription::TimeBasedCompletionTaskBuilder( + TimeBasedCompletionTaskDescription { + duration: Duration::from_secs(240), + }, + ); + metadata.overall_safety_properties = OverallSafetyPropertiesDescription { + // Make sure we keep committing rounds after the catchup, but not the full 50. + num_successful_views: 22, + num_failed_views: 30, + ..Default::default() + }; + + metadata + }, +); From fc6f415580db1db6dab332c558656ee295af91c6 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:42:59 -0400 Subject: [PATCH 6/9] pass committee type to orchestrator via BenchResults --- crates/examples/infra/mod.rs | 11 +++++++++++ .../src/traits/election/randomized_committee.rs | 11 +++++++++++ .../hotshot/src/traits/election/static_committee.rs | 11 +++++++++++ .../election/static_committee_leader_two_views.rs | 11 +++++++++++ crates/orchestrator/src/client.rs | 5 +++++ crates/orchestrator/src/lib.rs | 1 + crates/types/src/traits/election.rs | 3 +++ 7 files changed, 53 insertions(+) diff --git a/crates/examples/infra/mod.rs b/crates/examples/infra/mod.rs index 7edff0f6bd..70f48a7725 100755 --- a/crates/examples/infra/mod.rs +++ b/crates/examples/infra/mod.rs @@ -558,6 +558,12 @@ pub trait RunDa< } let consensus_lock = context.hotshot.consensus(); let consensus = consensus_lock.read().await; + let num_eligible_leaders = context + .hotshot + .memberships + .quorum_membership + .committee_leaders(TYPES::Time::genesis()) + .len(); let total_num_views = usize::try_from(consensus.locked_view().u64()).unwrap(); // `failed_num_views` could include uncommitted views let failed_num_views = total_num_views - num_successful_commits; @@ -575,6 +581,7 @@ pub trait RunDa< / total_time_elapsed_sec; let avg_latency_in_sec = total_latency / num_latency; println!("[{node_index}]: throughput: {throughput_bytes_per_sec} bytes/sec, avg_latency: {avg_latency_in_sec} sec."); + BenchResults { partial_results: "Unset".to_string(), avg_latency_in_sec, @@ -587,6 +594,10 @@ pub trait RunDa< total_time_elapsed_in_sec: total_time_elapsed.as_secs(), total_num_views, failed_num_views, + committee_type: format!( + "{} with {num_eligible_leaders} eligible leaders", + std::any::type_name::() + ), } } else { // all values with zero diff --git a/crates/hotshot/src/traits/election/randomized_committee.rs b/crates/hotshot/src/traits/election/randomized_committee.rs index b3df85fe59..d25a676829 100644 --- a/crates/hotshot/src/traits/election/randomized_committee.rs +++ b/crates/hotshot/src/traits/election/randomized_committee.rs @@ -99,6 +99,17 @@ impl Membership for GeneralStaticCommittee { .collect() } + /// Get all eligible leaders of the committee for the current view + fn committee_leaders( + &self, + _view_number: ::Time, + ) -> std::collections::BTreeSet<::SignatureKey> { + self.eligible_leaders + .iter() + .map(TYPES::SignatureKey::public_key) + .collect() + } + /// Get the stake table entry for a public key fn stake( &self, diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index 9a2997a53b..19272b64e4 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -98,6 +98,17 @@ impl Membership for GeneralStaticCommittee { .collect() } + /// Get all eligible leaders of the committee for the current view + fn committee_leaders( + &self, + _view_number: ::Time, + ) -> std::collections::BTreeSet<::SignatureKey> { + self.eligible_leaders + .iter() + .map(TYPES::SignatureKey::public_key) + .collect() + } + /// Get the stake table entry for a public key fn stake( &self, 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 085d6ac349..c6556559f1 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 @@ -98,6 +98,17 @@ impl Membership for StaticCommitteeLeaderForTwoViews::Time, + ) -> std::collections::BTreeSet<::SignatureKey> { + self.eligible_leaders + .iter() + .map(TYPES::SignatureKey::public_key) + .collect() + } + /// Get the stake table entry for a public key fn stake( &self, diff --git a/crates/orchestrator/src/client.rs b/crates/orchestrator/src/client.rs index ad38264c5b..a58f76f400 100644 --- a/crates/orchestrator/src/client.rs +++ b/crates/orchestrator/src/client.rs @@ -48,6 +48,8 @@ pub struct BenchResults { pub total_num_views: usize, /// The number of failed views during benchmarking pub failed_num_views: usize, + /// The membership committee type used + pub committee_type: String, } impl BenchResults { @@ -55,6 +57,7 @@ impl BenchResults { pub fn printout(&self) { println!("====================="); println!("{0} Benchmark results:", self.partial_results); + println!("Committee type: {}", self.committee_type); println!( "Average latency: {} seconds, Minimum latency: {} seconds, Maximum latency: {} seconds", self.avg_latency_in_sec, self.minimum_latency_in_sec, self.maximum_latency_in_sec @@ -113,6 +116,8 @@ pub struct BenchResultsDownloadConfig { pub total_num_views: usize, /// The number of failed views during benchmarking pub failed_num_views: usize, + /// The membership committee type used + pub committee_type: String, } // VALIDATOR diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index 4e79ec0419..2090eaf273 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -162,6 +162,7 @@ impl OrchestratorState { total_time_elapsed_in_sec: self.bench_results.total_time_elapsed_in_sec, total_num_views: self.bench_results.total_num_views, failed_num_views: self.bench_results.failed_num_views, + committee_type: self.bench_results.committee_type.clone(), }; // Open the CSV file in append mode let results_csv_file = OpenOptions::new() diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index 7a9b556d1f..b03bf8a843 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -29,6 +29,9 @@ pub trait Membership: /// Get all participants in the committee for a specific view fn committee_members(&self, view_number: TYPES::Time) -> BTreeSet; + /// Get all leaders in the committee for a specific view + fn committee_leaders(&self, view_number: TYPES::Time) -> BTreeSet; + /// Get the stake table entry for a public key, returns `None` if the /// key is not in the table fn stake( From d55c22d60dfecfd0cad0d0e83dc2419d8352e0d2 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:21:43 -0400 Subject: [PATCH 7/9] use gen_range --- crates/hotshot/src/traits/election/randomized_committee.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/hotshot/src/traits/election/randomized_committee.rs b/crates/hotshot/src/traits/election/randomized_committee.rs index d25a676829..dd0d4e2758 100644 --- a/crates/hotshot/src/traits/election/randomized_committee.rs +++ b/crates/hotshot/src/traits/election/randomized_committee.rs @@ -134,9 +134,12 @@ impl Membership for GeneralStaticCommittee { /// Index the vector of public keys with the current view number fn leader(&self, view_number: TYPES::Time) -> TYPES::SignatureKey { let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number); - let randomized_view_number: usize = rng.gen(); - let index = randomized_view_number % self.eligible_leaders.len(); + + let randomized_view_number: u64 = rng.gen_range(0..=u64::MAX); + let index = randomized_view_number as usize % self.eligible_leaders.len(); + let res = self.eligible_leaders[index].clone(); + TYPES::SignatureKey::public_key(&res) } From c4162a1873574004fb4fbe30aa9c73af8c2826ea Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:25:28 -0400 Subject: [PATCH 8/9] clippy --- crates/hotshot/src/traits/election/randomized_committee.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/hotshot/src/traits/election/randomized_committee.rs b/crates/hotshot/src/traits/election/randomized_committee.rs index dd0d4e2758..e27697e211 100644 --- a/crates/hotshot/src/traits/election/randomized_committee.rs +++ b/crates/hotshot/src/traits/election/randomized_committee.rs @@ -136,6 +136,7 @@ impl Membership for GeneralStaticCommittee { let mut rng: StdRng = rand::SeedableRng::seed_from_u64(*view_number); let randomized_view_number: u64 = rng.gen_range(0..=u64::MAX); + #[allow(clippy::cast_possible_truncation)] let index = randomized_view_number as usize % self.eligible_leaders.len(); let res = self.eligible_leaders[index].clone(); From e6f739d933c355e08bbffbf2bbf1819f9475f381 Mon Sep 17 00:00:00 2001 From: ss-es <155648797+ss-es@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:33:58 -0400 Subject: [PATCH 9/9] rename --- crates/example-types/src/node_types.rs | 5 ++--- .../hotshot/src/traits/election/randomized_committee.rs | 8 +++----- crates/hotshot/src/traits/election/static_committee.rs | 7 ++----- .../traits/election/static_committee_leader_two_views.rs | 3 --- crates/hotshot/src/traits/networking/libp2p_network.rs | 3 ++- crates/testing/tests/tests_3/memory_network.rs | 4 ++-- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/crates/example-types/src/node_types.rs b/crates/example-types/src/node_types.rs index 2dcfc6ef18..a8f06976c3 100644 --- a/crates/example-types/src/node_types.rs +++ b/crates/example-types/src/node_types.rs @@ -6,8 +6,7 @@ use hotshot::traits::{ election::{ - randomized_committee::RandomizedCommittee, - static_committee::{GeneralStaticCommittee, StaticCommittee}, + randomized_committee::RandomizedCommittee, static_committee::StaticCommittee, static_committee_leader_two_views::StaticCommitteeLeaderForTwoViews, }, implementations::{CombinedNetworks, Libp2pNetwork, MemoryNetwork, PushCdnNetwork}, @@ -53,7 +52,7 @@ impl NodeType for TestTypes { type Transaction = TestTransaction; type ValidatedState = TestValidatedState; type InstanceState = TestInstanceState; - type Membership = GeneralStaticCommittee; + type Membership = StaticCommittee; type BuilderSignatureKey = BuilderKey; } diff --git a/crates/hotshot/src/traits/election/randomized_committee.rs b/crates/hotshot/src/traits/election/randomized_committee.rs index e27697e211..b761eb1ee2 100644 --- a/crates/hotshot/src/traits/election/randomized_committee.rs +++ b/crates/hotshot/src/traits/election/randomized_committee.rs @@ -21,7 +21,8 @@ use rand::{rngs::StdRng, Rng}; #[derive(Clone, Debug, Eq, PartialEq, Hash)] /// The static committee election -pub struct GeneralStaticCommittee { + +pub struct RandomizedCommittee { /// The nodes eligible for leadership. /// NOTE: This is currently a hack because the DA leader needs to be the quorum /// leader but without voting rights. @@ -38,10 +39,7 @@ pub struct GeneralStaticCommittee { committee_topic: Topic, } -/// static committee using a vrf kp -pub type RandomizedCommittee = GeneralStaticCommittee; - -impl Membership for GeneralStaticCommittee { +impl Membership for RandomizedCommittee { /// Create a new election fn new( eligible_leaders: Vec::SignatureKey>>, diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index 19272b64e4..69cc5ce9c2 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -20,7 +20,7 @@ use hotshot_types::{ #[derive(Clone, Debug, Eq, PartialEq, Hash)] /// The static committee election -pub struct GeneralStaticCommittee { +pub struct StaticCommittee { /// The nodes eligible for leadership. /// NOTE: This is currently a hack because the DA leader needs to be the quorum /// leader but without voting rights. @@ -37,10 +37,7 @@ pub struct GeneralStaticCommittee { committee_topic: Topic, } -/// static committee using a vrf kp -pub type StaticCommittee = GeneralStaticCommittee; - -impl Membership for GeneralStaticCommittee { +impl Membership for StaticCommittee { /// Create a new election fn new( eligible_leaders: Vec::SignatureKey>>, 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 c6556559f1..9ce83c14a0 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 @@ -37,9 +37,6 @@ pub struct StaticCommitteeLeaderForTwoViews { committee_topic: Topic, } -/// static committee using a vrf kp -pub type StaticCommittee = StaticCommitteeLeaderForTwoViews; - impl Membership for StaticCommitteeLeaderForTwoViews { /// Create a new election fn new( diff --git a/crates/hotshot/src/traits/networking/libp2p_network.rs b/crates/hotshot/src/traits/networking/libp2p_network.rs index 9e3df13052..1a7220a6e0 100644 --- a/crates/hotshot/src/traits/networking/libp2p_network.rs +++ b/crates/hotshot/src/traits/networking/libp2p_network.rs @@ -1145,9 +1145,10 @@ impl ConnectedNetwork for Libp2pNetwork { #[cfg(test)] mod test { mod derive_multiaddr { - use super::super::*; use std::net::Ipv6Addr; + use super::super::*; + /// Test derivation of a valid IPv4 address -> Multiaddr #[test] fn test_v4_valid() { diff --git a/crates/testing/tests/tests_3/memory_network.rs b/crates/testing/tests/tests_3/memory_network.rs index 21db37e42d..38b2da02e1 100644 --- a/crates/testing/tests/tests_3/memory_network.rs +++ b/crates/testing/tests/tests_3/memory_network.rs @@ -10,7 +10,7 @@ use std::{sync::Arc, time::Duration}; use async_compatibility_layer::{art::async_timeout, logging::setup_logging}; use hotshot::{ traits::{ - election::static_committee::GeneralStaticCommittee, + election::static_committee::StaticCommittee, implementations::{MasterMap, MemoryNetwork}, NodeImplementation, }, @@ -60,7 +60,7 @@ impl NodeType for Test { type Transaction = TestTransaction; type ValidatedState = TestValidatedState; type InstanceState = TestInstanceState; - type Membership = GeneralStaticCommittee; + type Membership = StaticCommittee; type BuilderSignatureKey = BuilderKey; }