Skip to content

Commit

Permalink
Condense config structs (MystenLabs#1879)
Browse files Browse the repository at this point in the history
* Removed authority priv info struct
  • Loading branch information
oxade authored May 10, 2022
1 parent 3a48452 commit b89ee44
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 70 deletions.
6 changes: 3 additions & 3 deletions faucet/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{anyhow, bail};
use std::path::Path;
use sui::{
config::{
AuthorityPrivateInfo, Config, GatewayConfig, GatewayType, GenesisConfig, WalletConfig,
AuthorityInfo, Config, GatewayConfig, GatewayType, GenesisConfig, WalletConfig,
SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG,
},
keystore::KeystoreType,
Expand Down Expand Up @@ -81,7 +81,7 @@ pub async fn start_test_network(
let authorities = genesis_config
.authorities
.into_iter()
.map(|info| AuthorityPrivateInfo { port: 0, ..info })
.map(|info| AuthorityInfo { port: 0, ..info })
.collect();
genesis_config.authorities = authorities;

Expand All @@ -99,7 +99,7 @@ pub async fn start_test_network(
.into_iter()
.zip(&network.spawned_authorities)
.map(|(mut info, server)| {
info.base_port = server.get_port();
info.port = server.get_port();
info
})
.collect::<Vec<_>>();
Expand Down
1 change: 0 additions & 1 deletion sui/src/benchmark/load_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ pub struct MultiFixedRateLoadGenerator {
/// Anything below 10ms causes degradation in resolution
pub period_us: u64,

//pub network_config: Vec<AuthorityPrivateInfo>,
pub tick_notifier: Arc<Notify>,

/// Number of TCP connections to open
Expand Down
5 changes: 2 additions & 3 deletions sui/src/bin/bench_configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use std::{
use sui::{
benchmark::bench_types::RemoteLoadGenConfig,
config::{
AccountConfig, AuthorityPrivateInfo, Config, GenesisConfig, NetworkConfig,
ObjectConfigRange,
AccountConfig, AuthorityInfo, Config, GenesisConfig, NetworkConfig, ObjectConfigRange,
},
};

Expand Down Expand Up @@ -65,7 +64,7 @@ fn main() {
port + 1,
);

let auth = AuthorityPrivateInfo {
let auth = AuthorityInfo {
address: validator_address,
host,
port,
Expand Down
8 changes: 4 additions & 4 deletions sui/src/config/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Display for GatewayType {
let authorities = config
.authorities
.iter()
.map(|info| format!("{}:{}", info.host, info.base_port));
.map(|info| format!("{}:{}", info.host, info.port));
writeln!(
writer,
"Authorities : {:?}",
Expand Down Expand Up @@ -91,7 +91,7 @@ impl GatewayConfig {
let voting_rights = self
.authorities
.iter()
.map(|authority| (authority.name, 1))
.map(|authority| (authority.public_key, 1))
.collect();
Committee::new(self.epoch, voting_rights)
}
Expand All @@ -101,12 +101,12 @@ impl GatewayConfig {
for authority in &self.authorities {
let client = NetworkAuthorityClient::new(NetworkClient::new(
authority.host.clone(),
authority.base_port,
authority.port,
self.buffer_size,
self.send_timeout,
self.recv_timeout,
));
authority_clients.insert(authority.name, client);
authority_clients.insert(authority.public_key, client);
}
authority_clients
}
Expand Down
44 changes: 8 additions & 36 deletions sui/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,8 @@ pub const AUTHORITIES_DB_NAME: &str = "authorities_db";
pub const DEFAULT_STARTING_PORT: u16 = 10000;
pub const CONSENSUS_DB_NAME: &str = "consensus_db";

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AuthorityInfo {
#[serde(serialize_with = "bytes_as_hex", deserialize_with = "bytes_from_hex")]
pub name: AuthorityName,
pub host: String,
pub base_port: u16,
}

#[derive(Serialize, Debug, Clone)]
pub struct AuthorityPrivateInfo {
pub struct AuthorityInfo {
pub address: SuiAddress,
pub public_key: PublicKeyBytes,
pub host: String,
Expand All @@ -80,19 +72,6 @@ pub struct AuthorityPrivateInfo {
pub consensus_address: SocketAddr,
}

impl AuthorityPrivateInfo {
pub fn copy(&self) -> Self {
Self {
address: self.address,
host: self.host.clone(),
port: self.port,
db_path: self.db_path.clone(),
stake: self.stake,
consensus_address: self.consensus_address,
public_key: self.public_key,
}
}
}
type AuthorityKeys = (Vec<PublicKeyBytes>, KeyPair);

// Warning: to_socket_addrs() is blocking and can fail. Be careful where you use it.
Expand All @@ -106,7 +85,7 @@ fn socket_addr_from_hostport(host: &str, port: u16) -> SocketAddr {
}

// Custom deserializer with optional default fields
impl<'de> Deserialize<'de> for AuthorityPrivateInfo {
impl<'de> Deserialize<'de> for AuthorityInfo {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>,
Expand Down Expand Up @@ -148,7 +127,7 @@ impl<'de> Deserialize<'de> for AuthorityPrivateInfo {
socket_addr_from_hostport("127.0.0.1", port)
};

Ok(AuthorityPrivateInfo {
Ok(AuthorityInfo {
address: SuiAddress::from(&public_key_bytes),
public_key: public_key_bytes,
host,
Expand Down Expand Up @@ -192,7 +171,7 @@ impl Display for WalletConfig {
#[derive(Serialize, Deserialize)]
pub struct NetworkConfig {
pub epoch: EpochId,
pub authorities: Vec<AuthorityPrivateInfo>,
pub authorities: Vec<AuthorityInfo>,
pub buffer_size: usize,
pub loaded_move_packages: Vec<(PathBuf, ObjectID)>,
pub key_pair: KeyPair,
Expand All @@ -202,14 +181,7 @@ impl Config for NetworkConfig {}

impl NetworkConfig {
pub fn get_authority_infos(&self) -> Vec<AuthorityInfo> {
self.authorities
.iter()
.map(|info| AuthorityInfo {
name: info.public_key,
host: info.host.clone(),
base_port: info.port,
})
.collect()
self.authorities.clone()
}

pub fn make_narwhal_committee(&self) -> ConsensusCommittee<Ed25519PublicKey> {
Expand Down Expand Up @@ -263,7 +235,7 @@ impl From<&NetworkConfig> for Committee {
#[derive(Serialize, Deserialize)]
#[serde(default)]
pub struct GenesisConfig {
pub authorities: Vec<AuthorityPrivateInfo>,
pub authorities: Vec<AuthorityInfo>,
pub accounts: Vec<AccountConfig>,
pub move_packages: Vec<PathBuf>,
pub sui_framework_lib_path: PathBuf,
Expand Down Expand Up @@ -345,7 +317,7 @@ impl GenesisConfig {
let mut authorities = Vec::with_capacity(num_authorities);
for _ in 0..num_authorities {
// Get default authority config from deserialization logic.
let mut authority = AuthorityPrivateInfo::deserialize(Value::String(String::new()))?;
let mut authority = AuthorityInfo::deserialize(Value::String(String::new()))?;
authority.db_path = working_dir
.join(AUTHORITIES_DB_NAME)
.join(encode_bytes_hex(&authority.public_key));
Expand Down Expand Up @@ -468,7 +440,7 @@ impl<C> DerefMut for PersistedConfig<C> {

/// Make a default Narwhal-compatible committee.
pub fn make_default_narwhal_committee(
authorities: &[AuthorityPrivateInfo],
authorities: &[AuthorityInfo],
) -> Result<ConsensusCommittee<Ed25519PublicKey>, anyhow::Error> {
let mut ports = Vec::new();
for _ in authorities {
Expand Down
16 changes: 8 additions & 8 deletions sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
use crate::{
config::{
make_default_narwhal_committee, sui_config_dir, AuthorityInfo, AuthorityPrivateInfo,
Config, GatewayConfig, GatewayType, GenesisConfig, NetworkConfig, PersistedConfig,
WalletConfig, CONSENSUS_DB_NAME, SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG,
make_default_narwhal_committee, sui_config_dir, AuthorityInfo, Config, GatewayConfig,
GatewayType, GenesisConfig, NetworkConfig, PersistedConfig, WalletConfig,
CONSENSUS_DB_NAME, SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG,
},
keystore::{Keystore, KeystoreType, SuiKeystore},
};
Expand Down Expand Up @@ -524,7 +524,7 @@ pub async fn genesis(
}

pub async fn make_server(
authority: &AuthorityPrivateInfo,
authority: &AuthorityInfo,
key_pair: &KeyPair,
committee: &Committee,
buffer_size: usize,
Expand Down Expand Up @@ -557,7 +557,7 @@ pub async fn make_server(
}

async fn make_server_with_genesis_ctx(
authority: &AuthorityPrivateInfo,
authority: &AuthorityInfo,
key_pair: &KeyPair,
committee: &Committee,
preload_modules: Vec<Vec<CompiledModule>>,
Expand Down Expand Up @@ -597,7 +597,7 @@ async fn make_server_with_genesis_ctx(
/// Spawn all the subsystems run by a Sui authority: a consensus node, a sui authority server,
/// and a consensus listener bridging the consensus node and the sui authority.
pub async fn make_authority(
authority: &AuthorityPrivateInfo,
authority: &AuthorityInfo,
key_pair: &KeyPair,
buffer_size: usize,
state: AuthorityState,
Expand Down Expand Up @@ -648,12 +648,12 @@ pub async fn make_authority(
for info in &network {
let client = NetworkAuthorityClient::new(NetworkClient::new(
info.host.clone(),
info.base_port,
info.port,
buffer_size,
Duration::from_secs(5),
Duration::from_secs(5),
));
authority_clients.insert(info.name, client);
authority_clients.insert(info.public_key, client);
}

let _active_authority = ActiveAuthority::new(authority_state.clone(), authority_clients)?;
Expand Down
6 changes: 3 additions & 3 deletions sui/src/unit_tests/sui_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::anyhow;
use std::path::Path;
use sui::{
config::{
AuthorityPrivateInfo, Config, GatewayConfig, GatewayType, GenesisConfig, WalletConfig,
AuthorityInfo, Config, GatewayConfig, GatewayType, GenesisConfig, WalletConfig,
SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG,
},
keystore::KeystoreType,
Expand Down Expand Up @@ -58,7 +58,7 @@ pub async fn start_test_network(
genesis_config.authorities = genesis_config
.authorities
.into_iter()
.map(|info| AuthorityPrivateInfo { port: 0, ..info })
.map(|info| AuthorityInfo { port: 0, ..info })
.collect();

let (network_config, accounts, mut keystore) = genesis(genesis_config, None).await?;
Expand All @@ -75,7 +75,7 @@ pub async fn start_test_network(
.into_iter()
.zip(&network.spawned_authorities)
.map(|(mut info, server)| {
info.base_port = server.get_port();
info.port = server.get_port();
info
})
.collect::<Vec<_>>();
Expand Down
13 changes: 5 additions & 8 deletions sui/tests/shared_objects_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use sui::config::AuthorityPrivateInfo;
use sui::config::AuthorityInfo;
use sui_core::authority_client::{AuthorityAPI, NetworkAuthorityClient};
use sui_network::network::NetworkClient;
use sui_types::{
Expand All @@ -24,7 +24,7 @@ use test_utils::{
/// Submit a certificate containing only owned-objects to all authorities.
async fn submit_single_owner_transaction(
transaction: Transaction,
configs: &[AuthorityPrivateInfo],
configs: &[AuthorityInfo],
) -> Vec<TransactionInfoResponse> {
let certificate = make_certificates(vec![transaction]).pop().unwrap();
let txn = ConfirmationTransaction { certificate };
Expand All @@ -41,7 +41,7 @@ async fn submit_single_owner_transaction(
responses
}

fn get_client(config: &AuthorityPrivateInfo) -> NetworkAuthorityClient {
fn get_client(config: &AuthorityInfo) -> NetworkAuthorityClient {
let network_config = NetworkClient::new(
config.host.clone(),
config.port,
Expand All @@ -58,7 +58,7 @@ fn get_client(config: &AuthorityPrivateInfo) -> NetworkAuthorityClient {
/// may drop transactions. The certificate is submitted to every Sui authority.
async fn submit_shared_object_transaction(
transaction: Transaction,
configs: &[AuthorityPrivateInfo],
configs: &[AuthorityInfo],
) -> Vec<SuiResult<TransactionInfoResponse>> {
let certificate = make_certificates(vec![transaction]).pop().unwrap();
let message = ConsensusTransaction::UserTransaction(certificate);
Expand All @@ -85,10 +85,7 @@ async fn submit_shared_object_transaction(
}

/// Helper function to publish the move package of a simple shared counter.
async fn publish_counter_package(
gas_object: Object,
configs: &[AuthorityPrivateInfo],
) -> ObjectRef {
async fn publish_counter_package(gas_object: Object, configs: &[AuthorityInfo]) -> ObjectRef {
let transaction = publish_move_package_transaction(gas_object);
let replies = submit_single_owner_transaction(transaction, configs).await;
let mut package_refs = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions test_utils/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{test_committee, test_keys};
use narwhal_config::Parameters as ConsensusParameters;
use std::{path::PathBuf, sync::Arc};
use sui::{
config::{make_default_narwhal_committee, utils::get_available_port, AuthorityPrivateInfo},
config::{make_default_narwhal_committee, utils::get_available_port, AuthorityInfo},
sui_commands::make_authority,
};
use sui_adapter::genesis;
Expand All @@ -24,7 +24,7 @@ pub fn test_authority_store() -> AuthorityStore {
}

/// Make an authority config for each of the `TEST_COMMITTEE_SIZE` authorities in the test committee.
pub fn test_authority_configs() -> (Vec<AuthorityPrivateInfo>, Vec<KeyPair>) {
pub fn test_authority_configs() -> (Vec<AuthorityInfo>, Vec<KeyPair>) {
let test_keys = test_keys();
let key_pair = test_keys
.iter()
Expand All @@ -36,7 +36,7 @@ pub fn test_authority_configs() -> (Vec<AuthorityPrivateInfo>, Vec<KeyPair>) {
let authority_port = get_available_port();
let consensus_port = get_available_port();

AuthorityPrivateInfo {
AuthorityInfo {
address,
public_key: *key.public_key_bytes(),
host: "127.0.0.1".to_string(),
Expand Down Expand Up @@ -80,7 +80,7 @@ where
/// Spawn all authorities in the test committee into a separate tokio task.
pub async fn spawn_test_authorities<I>(
objects: I,
authorities: &[AuthorityPrivateInfo],
authorities: &[AuthorityInfo],
key_pairs: &[KeyPair],
) -> Vec<AuthorityServerHandle>
where
Expand Down

0 comments on commit b89ee44

Please sign in to comment.