diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index 6cc06a8e30..78a629a192 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -1,6 +1,6 @@ // Sets features for Rust Analyzer, since some features are required to be set for compilation { - "rust-analyzer.cargo.features": [ - "full-ci" - ], + "rust-analyzer.cargo.extraEnv": { + "RUSTFLAGS": "--cfg async_executor_impl=\"async-std\" --cfg async_channel_impl=\"async-std\"" + }, } \ No newline at end of file diff --git a/crates/hotshot-signature-key/src/bn254/bn254_pub.rs b/crates/hotshot-signature-key/src/bn254/bn254_pub.rs index c25fad4be0..714ee98687 100644 --- a/crates/hotshot-signature-key/src/bn254/bn254_pub.rs +++ b/crates/hotshot-signature-key/src/bn254/bn254_pub.rs @@ -134,6 +134,12 @@ impl SignatureKey for BN254Pub { } } + fn get_public_key(entry: &Self::StakeTableEntry) -> Self { + Self { + pub_key: entry.stake_key, + } + } + fn get_public_parameter( stake_entries: Vec, threshold: U256, diff --git a/crates/hotshot/examples/infra/mod.rs b/crates/hotshot/examples/infra/mod.rs index efd3b8169d..6fafd81727 100644 --- a/crates/hotshot/examples/infra/mod.rs +++ b/crates/hotshot/examples/infra/mod.rs @@ -52,7 +52,7 @@ pub fn load_config_from_file( > = config_toml.into(); // Generate network's public keys - config.config.known_nodes = (0..config.config.total_nodes.get()) + let known_nodes = (0..config.config.total_nodes.get()) .map(|node_id| { TYPES::SignatureKey::generated_from_seed_indexed( config.seed, @@ -63,7 +63,7 @@ pub fn load_config_from_file( .collect(); config.config.known_nodes_with_stake = (0..config.config.total_nodes.get()) - .map(|node_id| config.config.known_nodes[node_id].get_stake_table_entry(1u64)) + .map(|node_id| known_nodes[node_id].get_stake_table_entry(1u64)) .collect(); config diff --git a/crates/hotshot/examples/infra/modDA.rs b/crates/hotshot/examples/infra/modDA.rs index 729cbfd79f..fca5b4b64d 100644 --- a/crates/hotshot/examples/infra/modDA.rs +++ b/crates/hotshot/examples/infra/modDA.rs @@ -215,7 +215,6 @@ pub trait RunDA< // Get KeyPair for certificate Aggregation let (pk, sk) = TYPES::SignatureKey::generated_from_seed_indexed(config.seed, config.node_index); - let known_nodes = config.config.known_nodes.clone(); let known_nodes_with_stake = config.config.known_nodes_with_stake.clone(); let entry = pk.get_stake_table_entry(1u64); @@ -240,7 +239,6 @@ pub trait RunDA< let exchanges = NODE::Exchanges::create( known_nodes_with_stake.clone(), - known_nodes.clone(), (quorum_election_config, committee_election_config), ( quorum_network.clone(), diff --git a/crates/hotshot/src/lib.rs b/crates/hotshot/src/lib.rs index fa435e1f1d..34a50ea7ec 100644 --- a/crates/hotshot/src/lib.rs +++ b/crates/hotshot/src/lib.rs @@ -114,7 +114,6 @@ pub struct SystemContextInner> { /// Configuration items for this hotshot instance config: HotShotConfig< - TYPES::SignatureKey, ::StakeTableEntry, TYPES::ElectionConfigType, >, @@ -178,7 +177,6 @@ impl> SystemContext { private_key: ::PrivateKey, nonce: u64, config: HotShotConfig< - TYPES::SignatureKey, ::StakeTableEntry, TYPES::ElectionConfigType, >, @@ -405,7 +403,6 @@ impl> SystemContext { private_key: ::PrivateKey, node_id: u64, config: HotShotConfig< - TYPES::SignatureKey, ::StakeTableEntry, TYPES::ElectionConfigType, >, diff --git a/crates/hotshot/src/traits/election/static_committee.rs b/crates/hotshot/src/traits/election/static_committee.rs index 2c95746d4b..0f0d94feae 100644 --- a/crates/hotshot/src/traits/election/static_committee.rs +++ b/crates/hotshot/src/traits/election/static_committee.rs @@ -19,12 +19,8 @@ use tracing::debug; #[derive(Clone, Debug, Eq, PartialEq)] pub struct GeneralStaticCommittee, PUBKEY: SignatureKey> { - /// All the nodes participating - nodes: Vec, /// All the nodes participating and their stake nodes_with_stake: Vec, - /// The nodes on the static committee - committee_nodes: Vec, /// The nodes on the static committee and their stake committee_nodes_with_stake: Vec, /// Node type phantom @@ -41,11 +37,9 @@ impl, PUBKEY: SignatureKey> { /// Creates a new dummy elector #[must_use] - pub fn new(nodes: Vec, nodes_with_stake: Vec) -> Self { + pub fn new(_nodes: Vec, nodes_with_stake: Vec) -> Self { Self { - nodes: nodes.clone(), nodes_with_stake: nodes_with_stake.clone(), - committee_nodes: nodes, committee_nodes_with_stake: nodes_with_stake, _type_phantom: PhantomData, _leaf_phantom: PhantomData, @@ -107,8 +101,9 @@ where /// Index the vector of public keys with the current view number fn get_leader(&self, view_number: TYPES::Time) -> PUBKEY { - let index = (*view_number % self.nodes.len() as u64) as usize; - self.nodes[index].clone() + let index = (*view_number % self.nodes_with_stake.len() as u64) as usize; + let res = self.nodes_with_stake[index].clone(); + TYPES::SignatureKey::get_public_key(&res) } /// Simply make the partial signature @@ -119,7 +114,8 @@ where ) -> std::result::Result>, ElectionError> { // TODO ED Below let pub_key = PUBKEY::from_private(private_key); - if !self.committee_nodes.contains(&pub_key) { + let entry = pub_key.get_stake_table_entry(1u64); + if !self.committee_nodes_with_stake.contains(&entry) { return Ok(None); } let mut message: Vec = vec![]; @@ -137,7 +133,8 @@ where ) -> Result, ElectionError> { match token { Checked::Valid(t) | Checked::Unchecked(t) => { - if self.committee_nodes.contains(&pub_key) { + let entry = pub_key.get_stake_table_entry(1u64); + if self.committee_nodes_with_stake.contains(&entry) { Ok(Checked::Valid(t)) } else { Ok(Checked::Inval(t)) @@ -153,18 +150,13 @@ where fn create_election( keys_qc: Vec, - keys: Vec, config: TYPES::ElectionConfigType, ) -> Self { - let mut committee_nodes = keys.clone(); let mut committee_nodes_with_stake = keys_qc.clone(); - committee_nodes.truncate(config.num_nodes.try_into().unwrap()); debug!("Election Membership Size: {}", config.num_nodes); committee_nodes_with_stake.truncate(config.num_nodes.try_into().unwrap()); Self { nodes_with_stake: keys_qc, - nodes: keys, - committee_nodes, committee_nodes_with_stake, _type_phantom: PhantomData, _leaf_phantom: PhantomData, @@ -172,21 +164,24 @@ where } fn total_nodes(&self) -> usize { - self.committee_nodes.len() + self.committee_nodes_with_stake.len() } fn success_threshold(&self) -> NonZeroU64 { - NonZeroU64::new(((self.committee_nodes.len() as u64 * 2) / 3) + 1).unwrap() + NonZeroU64::new(((self.committee_nodes_with_stake.len() as u64 * 2) / 3) + 1).unwrap() } fn failure_threshold(&self) -> NonZeroU64 { - NonZeroU64::new(((self.committee_nodes.len() as u64) / 3) + 1).unwrap() + NonZeroU64::new(((self.committee_nodes_with_stake.len() as u64) / 3) + 1).unwrap() } fn get_committee( &self, _view_number: ::Time, ) -> std::collections::BTreeSet<::SignatureKey> { - self.committee_nodes.clone().into_iter().collect() + // Transfer from committee_nodes_with_stake to pure committee_nodes + (0..(self.committee_nodes_with_stake.len())) + .map(|node_id| ::SignatureKey::get_public_key(&self.committee_nodes_with_stake[node_id])) + .collect() } } diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 061ab256d5..0f6fc4e96d 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -4,6 +4,7 @@ use std::{ num::NonZeroUsize, time::Duration, }; +use std::marker::PhantomData; #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] pub struct Libp2pConfig { pub bootstrap_nodes: Vec<(SocketAddr, Vec)>, @@ -65,9 +66,10 @@ pub struct NetworkConfig { pub key_type_name: String, pub election_config_type_name: String, pub libp2p_config: Option, - pub config: HotShotConfig, + pub config: HotShotConfig, pub web_server_config: Option, pub da_web_server_config: Option, + _key_type_phantom: PhantomData, } impl Default for NetworkConfig { @@ -85,6 +87,7 @@ impl Default for NetworkConfig { election_config_type_name: std::any::type_name::().to_string(), web_server_config: None, da_web_server_config: None, + _key_type_phantom: PhantomData, } } } @@ -152,6 +155,7 @@ impl From for NetworkConfig { start_delay_seconds: val.start_delay_seconds, web_server_config: val.web_server_config, da_web_server_config: val.da_web_server_config, + _key_type_phantom: PhantomData, } } } @@ -183,14 +187,13 @@ pub struct HotShotConfigFile { pub propose_max_round_time: Duration, } -impl From for HotShotConfig { +impl From for HotShotConfig { fn from(val: HotShotConfigFile) -> Self { HotShotConfig { execution_type: ExecutionType::Continuous, total_nodes: val.total_nodes, max_transactions: val.max_transactions, min_transactions: val.min_transactions, - known_nodes: Vec::new(), known_nodes_with_stake: Vec::new(), da_committee_size: val.committee_nodes, next_view_timeout: val.next_view_timeout, diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index 4391fc43e6..574cc8c38a 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -174,7 +174,7 @@ where fn post_ready(&mut self) -> Result<(), ServerError> { self.nodes_connected += 1; println!("Nodes connected: {}", self.nodes_connected); - if self.nodes_connected >= self.config.config.known_nodes.len().try_into().unwrap() { + if self.nodes_connected >= self.config.config.known_nodes_with_stake.len().try_into().unwrap() { self.start = true; } Ok(()) diff --git a/crates/testing/src/task_helpers.rs b/crates/testing/src/task_helpers.rs index 13868721d4..3d2cbe3bf5 100644 --- a/crates/testing/src/task_helpers.rs +++ b/crates/testing/src/task_helpers.rs @@ -47,7 +47,6 @@ pub async fn build_system_handle( >>::block_genesis()) .unwrap(); - let known_nodes = config.known_nodes.clone(); let known_nodes_with_stake = config.known_nodes_with_stake.clone(); let private_key = ::generated_from_seed_indexed([0u8; 32], node_id).1; let public_key = ::SignatureKey::from_private(&private_key); @@ -67,7 +66,6 @@ pub async fn build_system_handle( let exchanges = >::Exchanges::create( known_nodes_with_stake.clone(), - known_nodes.clone(), (quorum_election_config, committee_election_config), networks, public_key, diff --git a/crates/testing/src/test_builder.rs b/crates/testing/src/test_builder.rs index f1db2a9320..326debb69b 100644 --- a/crates/testing/src/test_builder.rs +++ b/crates/testing/src/test_builder.rs @@ -219,7 +219,6 @@ impl TestMetadata { num_bootstrap: num_bootstrap_nodes, min_transactions, max_transactions: NonZeroUsize::new(99999).unwrap(), - known_nodes, known_nodes_with_stake, da_committee_size, next_view_timeout: 500, @@ -247,7 +246,7 @@ impl TestMetadata { } = timing_data; let mod_config = // TODO this should really be using the timing config struct - |a: &mut HotShotConfig::StakeTableEntry, TYPES::ElectionConfigType>| { + |a: &mut HotShotConfig<::StakeTableEntry, TYPES::ElectionConfigType>| { a.next_view_timeout = next_view_timeout; a.timeout_ratio = timeout_ratio; a.round_start_delay = round_start_delay; diff --git a/crates/testing/src/test_launcher.rs b/crates/testing/src/test_launcher.rs index 4a7e6bd9b1..cbc8ba64bb 100644 --- a/crates/testing/src/test_launcher.rs +++ b/crates/testing/src/test_launcher.rs @@ -94,7 +94,6 @@ where pub storage: Generator<>::Storage>, /// configuration used to generate each hotshot node pub config: HotShotConfig< - TYPES::SignatureKey, ::StakeTableEntry, TYPES::ElectionConfigType, >, @@ -198,7 +197,6 @@ impl> TestLauncher::StakeTableEntry, TYPES::ElectionConfigType, >, diff --git a/crates/testing/src/test_runner.rs b/crates/testing/src/test_runner.rs index 57c82d24e9..777d8769f5 100644 --- a/crates/testing/src/test_runner.rs +++ b/crates/testing/src/test_runner.rs @@ -234,7 +234,6 @@ where storage: I::Storage, initializer: HotShotInitializer, config: HotShotConfig< - TYPES::SignatureKey, ::StakeTableEntry, TYPES::ElectionConfigType, >, @@ -250,7 +249,6 @@ where let node_id = self.next_node_id; self.next_node_id += 1; - let known_nodes = config.known_nodes.clone(); let known_nodes_with_stake = config.known_nodes_with_stake.clone(); // Generate key pair for certificate aggregation let private_key = TYPES::SignatureKey::generated_from_seed_indexed([0u8; 32], node_id).1; @@ -265,7 +263,6 @@ where let committee_election_config = I::committee_election_config_generator(); let exchanges = I::Exchanges::create( known_nodes_with_stake.clone(), - known_nodes.clone(), ( quorum_election_config, committee_election_config(config.da_committee_size as u64), diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index e574bef876..c1b447c117 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -36,7 +36,7 @@ pub enum ExecutionType { /// Holds configuration for a `HotShot` #[derive(Clone, custom_debug::Debug, serde::Serialize, serde::Deserialize)] -pub struct HotShotConfig { +pub struct HotShotConfig { /// Whether to run one view or continuous views pub execution_type: ExecutionType, /// Total number of nodes in the network @@ -45,8 +45,6 @@ pub struct HotShotConfig { pub min_transactions: usize, /// Maximum transactions per block pub max_transactions: NonZeroUsize, - /// List of known node's public keys, including own, sorted by nonce () - pub known_nodes: Vec, /// List of known node's public keys and stake value for certificate aggregation, serving as public parameter pub known_nodes_with_stake: Vec, /// List of DA committee nodes for static DA committe diff --git a/crates/types/src/traits/election.rs b/crates/types/src/traits/election.rs index 81a173e954..a138de6ce9 100644 --- a/crates/types/src/traits/election.rs +++ b/crates/types/src/traits/election.rs @@ -221,7 +221,6 @@ pub trait Membership: /// TODO may want to move this to a testableelection trait fn create_election( entries: Vec<::StakeTableEntry>, - keys: Vec, config: TYPES::ElectionConfigType, ) -> Self; @@ -291,7 +290,6 @@ pub trait ConsensusExchange: Send + Sync { /// Join a [`ConsensusExchange`] with the given identity (`pk` and `sk`). fn create( entries: Vec<::StakeTableEntry>, - keys: Vec, config: TYPES::ElectionConfigType, network: Self::Networking, pk: TYPES::SignatureKey, @@ -609,7 +607,6 @@ impl< fn create( entries: Vec<::StakeTableEntry>, - keys: Vec, config: TYPES::ElectionConfigType, network: Self::Networking, pk: TYPES::SignatureKey, @@ -617,7 +614,7 @@ impl< sk: ::PrivateKey, ) -> Self { let membership = >::Membership::create_election( - entries, keys, config, + entries, config, ); Self { network, @@ -929,7 +926,6 @@ impl< fn create( entries: Vec<::StakeTableEntry>, - keys: Vec, config: TYPES::ElectionConfigType, network: Self::Networking, pk: TYPES::SignatureKey, @@ -937,7 +933,7 @@ impl< sk: ::PrivateKey, ) -> Self { let membership = >::Membership::create_election( - entries, keys, config, + entries, config, ); Self { network, @@ -1288,7 +1284,6 @@ impl< fn create( entries: Vec<::StakeTableEntry>, - keys: Vec, config: TYPES::ElectionConfigType, network: Self::Networking, pk: TYPES::SignatureKey, @@ -1296,7 +1291,7 @@ impl< sk: ::PrivateKey, ) -> Self { let membership = >::Membership::create_election( - entries, keys, config, + entries, config, ); Self { network, diff --git a/crates/types/src/traits/node_implementation.rs b/crates/types/src/traits/node_implementation.rs index 8ba5abdebb..451d071e07 100644 --- a/crates/types/src/traits/node_implementation.rs +++ b/crates/types/src/traits/node_implementation.rs @@ -166,7 +166,6 @@ pub trait ExchangesType, MESSA /// Create all exchanges. fn create( entries: Vec<::StakeTableEntry>, - keys: Vec, configs: Self::ElectionConfigs, networks: ( >::Networking, @@ -257,7 +256,6 @@ where fn create( entries: Vec<::StakeTableEntry>, - keys: Vec, configs: Self::ElectionConfigs, networks: ( >::Networking, @@ -270,7 +268,6 @@ where ) -> Self { let quorum_exchange = QUORUMEXCHANGE::create( entries.clone(), - keys.clone(), configs.0.clone(), networks.0, pk.clone(), @@ -279,7 +276,6 @@ where ); let view_sync_exchange = VIEWSYNCEXCHANGE::create( entries.clone(), - keys.clone(), configs.0, networks.2, pk.clone(), @@ -287,7 +283,7 @@ where sk.clone(), ); let committee_exchange = - COMMITTEEEXCHANGE::create(entries, keys, configs.1, networks.1, pk, entry, sk); + COMMITTEEEXCHANGE::create(entries, configs.1, networks.1, pk, entry, sk); Self { quorum_exchange, diff --git a/crates/types/src/traits/signature_key.rs b/crates/types/src/traits/signature_key.rs index 5daed175bd..d8f79a080e 100644 --- a/crates/types/src/traits/signature_key.rs +++ b/crates/types/src/traits/signature_key.rs @@ -101,6 +101,9 @@ pub trait SignatureKey: /// get the stake table entry from the public key and stake value fn get_stake_table_entry(&self, stake: u64) -> Self::StakeTableEntry; + /// only get the public key from the stake table entry + fn get_public_key(entry: &Self::StakeTableEntry) -> Self; + /// get the public parameter for the assembled signature checking fn get_public_parameter( stake_entries: Vec,