diff --git a/Cargo.lock b/Cargo.lock index 057c4a6b83375..b8cf61a53e4f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6232,6 +6232,7 @@ dependencies = [ "sui-core", "sui-framework", "sui-network", + "sui-node", "sui-types", "tempfile", "tokio", diff --git a/crates/sui/src/make.rs b/crates/sui/src/make.rs index c2c1561d553bb..729558fbdef78 100644 --- a/crates/sui/src/make.rs +++ b/crates/sui/src/make.rs @@ -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 { @@ -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 { - 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, - )) -} diff --git a/crates/sui/src/sui_commands.rs b/crates/sui/src/sui_commands.rs index 5a05ef2735862..a1b8ce47a12c8 100644 --- a/crates/sui/src/sui_commands.rs +++ b/crates/sui/src/sui_commands.rs @@ -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")] diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index 2202fce7ce4db..72eebe3725519 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -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"} diff --git a/crates/test-utils/src/authority.rs b/crates/test-utils/src/authority.rs index 8e597038bf376..c2784bc363fa7 100644 --- a/crates/test-utils/src/authority.rs +++ b/crates/test-utils/src/authority.rs @@ -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(); @@ -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( - objects: I, - config: &NetworkConfig, -) -> Vec +pub async fn spawn_test_authorities(objects: I, config: &NetworkConfig) -> Vec where I: IntoIterator + 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 }