Skip to content

Commit

Permalink
sui: remove make_authority function
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed May 27, 2022
1 parent 9d7ccc7 commit 854bec2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 126 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 0 additions & 91 deletions crates/sui/src/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@

use anyhow::{anyhow, Result};
use futures::future::join_all;
use std::collections::BTreeMap;
use std::sync::Arc;
use std::time::Duration;
use sui_config::NetworkConfig;
use sui_config::NodeConfig;
use sui_core::authority::AuthorityState;
use sui_core::authority_active::ActiveAuthority;
use sui_core::authority_client::NetworkAuthorityClient;
use sui_core::authority_server::AuthorityServer;
use sui_core::consensus_adapter::ConsensusListener;
use sui_node::SuiNode;
use tokio::sync::mpsc::channel;
use tracing::{error, info};

pub struct SuiNetwork {
Expand Down Expand Up @@ -60,84 +50,3 @@ impl SuiNetwork {
Ok(())
}
}

/// 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(
validator_config: &NodeConfig,
state: AuthorityState,
) -> Result<AuthorityServer> {
let (tx_consensus_to_sui, rx_consensus_to_sui) = channel(1_000);
let (tx_sui_to_consensus, rx_sui_to_consensus) = channel(1_000);

let authority_state = Arc::new(state);

// Spawn the consensus node of this authority.
let consensus_config = validator_config
.consensus_config()
.ok_or_else(|| anyhow!("Validator is missing consensus config"))?;
let consensus_keypair = validator_config.key_pair().make_narwhal_keypair();
let consensus_name = consensus_keypair.name.clone();
let consensus_store = narwhal_node::NodeStorage::reopen(consensus_config.db_path());
narwhal_node::Node::spawn_primary(
consensus_keypair,
validator_config
.committee_config()
.narwhal_committee()
.to_owned(),
&consensus_store,
consensus_config.narwhal_config().to_owned(),
/* consensus */ true, // Indicate that we want to run consensus.
/* execution_state */ authority_state.clone(),
/* tx_confirmation */ tx_consensus_to_sui,
)
.await?;
narwhal_node::Node::spawn_workers(
consensus_name,
/* ids */ vec![0], // We run a single worker with id '0'.
validator_config
.committee_config()
.narwhal_committee()
.to_owned(),
&consensus_store,
consensus_config.narwhal_config().to_owned(),
);

// Spawn a consensus listener. It listen for consensus outputs and notifies the
// authority server when a sequenced transaction is ready for execution.
ConsensusListener::spawn(
rx_sui_to_consensus,
rx_consensus_to_sui,
/* max_pending_transactions */ 1_000_000,
);

// If we have network information make authority clients
// to all authorities in the system.
let _active_authority: Option<()> = {
let mut authority_clients = BTreeMap::new();
let mut config = mysten_network::config::Config::new();
config.connect_timeout = Some(Duration::from_secs(5));
config.request_timeout = Some(Duration::from_secs(5));
for validator in validator_config.committee_config().validator_set() {
let channel = config.connect_lazy(validator.network_address()).unwrap();
let client = NetworkAuthorityClient::new(channel);
authority_clients.insert(validator.public_key(), client);
}

let _active_authority = ActiveAuthority::new(authority_state.clone(), authority_clients)?;

// TODO: turn on to start the active part of validators
//
// let join_handle = active_authority.spawn_all_active_processes().await;
// Some(join_handle)
None
};

// Return new authority server. It listen to users transactions and send back replies.
Ok(AuthorityServer::new(
validator_config.network_address().to_owned(),
authority_state,
consensus_config.address().to_owned(),
/* tx_consensus_listener */ tx_sui_to_consensus,
))
}
2 changes: 1 addition & 1 deletion crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sui_types::base_types::decode_bytes_hex;
use sui_types::base_types::SuiAddress;
use tracing::info;

pub use crate::make::{make_authority, SuiNetwork};
pub use crate::make::SuiNetwork;

#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
Expand Down
1 change: 1 addition & 0 deletions crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ sui-config = { path = "../sui-config" }
sui-types = { path = "../sui-types" }
sui-core = { path = "../sui-core" }
sui-network = { path = "../sui-network" }
sui-node = { path = "../sui-node" }
sui = { path = "../sui" }
workspace-hack = { path = "../workspace-hack"}
41 changes: 7 additions & 34 deletions crates/test-utils/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@

use crate::TEST_COMMITTEE_SIZE;
use rand::{prelude::StdRng, SeedableRng};
use std::collections::BTreeMap;
use std::time::Duration;
use std::{collections::BTreeMap, sync::Arc};
use sui::sui_commands::make_authority;
use sui_config::{NetworkConfig, ValidatorInfo};
use sui_core::{
authority::{AuthorityState, AuthorityStore},
authority_aggregator::AuthorityAggregator,
authority_client::NetworkAuthorityClient,
authority_server::AuthorityServerHandle,
authority_aggregator::AuthorityAggregator, authority_client::NetworkAuthorityClient,
safe_client::SafeClient,
};
use sui_node::SuiNode;
use sui_types::{committee::Committee, object::Object};

/// The default network buffer size of a test authority.
pub const NETWORK_BUFFER_SIZE: usize = 65_000;

/// Make a test authority store in a temporary directory.
pub fn test_authority_store() -> AuthorityStore {
let store_path = tempfile::tempdir().unwrap();
AuthorityStore::open(store_path, None)
}

/// Make an authority config for each of the `TEST_COMMITTEE_SIZE` authorities in the test committee.
pub fn test_authority_configs() -> NetworkConfig {
let config_dir = tempfile::tempdir().unwrap().into_path();
Expand All @@ -43,38 +34,20 @@ pub fn test_authority_configs() -> NetworkConfig {
}

/// Spawn all authorities in the test committee into a separate tokio task.
pub async fn spawn_test_authorities<I>(
objects: I,
config: &NetworkConfig,
) -> Vec<AuthorityServerHandle>
pub async fn spawn_test_authorities<I>(objects: I, config: &NetworkConfig) -> Vec<SuiNode>
where
I: IntoIterator<Item = Object> + Clone,
{
let mut handles = Vec::new();
let genesis = sui_config::genesis::Genesis::get_default_genesis();
for validator in config.validator_configs() {
let state = AuthorityState::new(
validator.committee_config().committee(),
validator.public_key(),
Arc::pin(validator.key_pair().copy()),
Arc::new(test_authority_store()),
None,
None,
&genesis,
)
.await;
let node = SuiNode::start(validator).await.unwrap();
let state = node.state();

for o in objects.clone() {
state.insert_genesis_object(o).await
}

let handle = make_authority(validator, state)
.await
.unwrap()
.spawn()
.await
.unwrap();
handles.push(handle);
handles.push(node);
}
handles
}
Expand Down

0 comments on commit 854bec2

Please sign in to comment.