Skip to content

Commit

Permalink
remove ws config from test and swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkuo committed Nov 27, 2022
1 parent 6dda3cc commit b4da44d
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 120 deletions.
24 changes: 1 addition & 23 deletions crates/sui-cluster-test/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub trait Cluster {
Self: Sized;

fn fullnode_url(&self) -> &str;
fn websocket_url(&self) -> Option<&str>;
fn user_key(&self) -> AccountKeyPair;

/// Returns faucet url in a remote cluster.
Expand Down Expand Up @@ -107,9 +106,7 @@ impl Cluster for RemoteRunningCluster {
fn fullnode_url(&self) -> &str {
&self.fullnode_url
}
fn websocket_url(&self) -> Option<&str> {
None
}

fn user_key(&self) -> AccountKeyPair {
get_key_pair().1
}
Expand All @@ -126,7 +123,6 @@ pub struct LocalNewCluster {
test_cluster: TestCluster,
fullnode_url: String,
faucet_key: AccountKeyPair,
websocket_url: Option<String>,
}

impl LocalNewCluster {
Expand All @@ -149,20 +145,11 @@ impl Cluster for LocalNewCluster {
.port()
});

let websocket_port = options.websocket_address.as_ref().map(|addr| {
addr.parse::<SocketAddr>()
.expect("Unable to parse fullnode address")
.port()
});

let mut cluster_builder = TestClusterBuilder::new().set_genesis_config(genesis_config);

if let Some(rpc_port) = fullnode_port {
cluster_builder = cluster_builder.set_fullnode_rpc_port(rpc_port);
}
if let Some(ws_port) = websocket_port {
cluster_builder = cluster_builder.set_fullnode_ws_port(ws_port);
}

let mut test_cluster = cluster_builder.build().await?;

Expand All @@ -187,18 +174,13 @@ impl Cluster for LocalNewCluster {
test_cluster,
fullnode_url,
faucet_key,
websocket_url: options.websocket_address.clone(),
})
}

fn fullnode_url(&self) -> &str {
&self.fullnode_url
}

fn websocket_url(&self) -> Option<&str> {
self.websocket_url.as_deref()
}

fn user_key(&self) -> AccountKeyPair {
get_key_pair().1
}
Expand All @@ -224,10 +206,6 @@ impl Cluster for Box<dyn Cluster + Send + Sync> {
(**self).fullnode_url()
}

fn websocket_url(&self) -> Option<&str> {
(**self).websocket_url()
}

fn user_key(&self) -> AccountKeyPair {
(**self).user_key()
}
Expand Down
3 changes: 0 additions & 3 deletions crates/sui-cluster-test/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub struct ClusterTestOpt {
pub faucet_address: Option<String>,
#[clap(long)]
pub fullnode_address: Option<String>,
#[clap(long)]
pub websocket_address: Option<String>,
}

impl ClusterTestOpt {
Expand All @@ -31,7 +29,6 @@ impl ClusterTestOpt {
env: Env::NewLocal,
faucet_address: None,
fullnode_address: None,
websocket_address: None,
}
}
}
1 change: 0 additions & 1 deletion crates/sui-config/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ impl<R: rand::RngCore + rand::CryptoRng> ConfigBuilder<R> {
metrics_address: utils::available_local_socket_address(),
admin_interface_port: utils::get_available_port(),
json_rpc_address: utils::available_local_socket_address(),
websocket_address: None,
consensus_config: Some(consensus_config),
enable_event_processing: false,
enable_checkpoint: false,
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ pub struct NodeConfig {
pub network_address: Multiaddr,
#[serde(default = "default_json_rpc_address")]
pub json_rpc_address: SocketAddr,
#[serde(default = "default_websocket_address")]
pub websocket_address: Option<SocketAddr>,

#[serde(default = "default_metrics_address")]
pub metrics_address: SocketAddr,
Expand Down
8 changes: 1 addition & 7 deletions crates/sui-config/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ impl NetworkConfig {
}

pub fn generate_fullnode_config(&self) -> NodeConfig {
self.generate_fullnode_config_with_random_dir_name(false, true)
self.generate_fullnode_config_with_random_dir_name(false)
}

/// Generate a fullnode config based on this `NetworkConfig`. This is useful if you want to run
/// a fullnode and have it connect to a network defined by this `NetworkConfig`.
pub fn generate_fullnode_config_with_random_dir_name(
&self,
use_random_dir_name: bool,
enable_websocket: bool,
) -> NodeConfig {
let protocol_key_pair: Arc<AuthorityKeyPair> =
Arc::new(get_key_pair_from_rng(&mut OsRng).1);
Expand Down Expand Up @@ -113,11 +112,6 @@ impl NetworkConfig {
metrics_address: utils::available_local_socket_address(),
admin_interface_port: utils::get_available_port(),
json_rpc_address: utils::available_local_socket_address(),
websocket_address: if enable_websocket {
Some(utils::available_local_socket_address())
} else {
None
},
consensus_config: None,
enable_event_processing,
enable_checkpoint: false,
Expand Down
8 changes: 5 additions & 3 deletions crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ impl SuiNode {

let (tx_reconfigure_consensus, rx_reconfigure_consensus) = channel(100);

let transaction_streamer = config
.websocket_address
.map(|_| Arc::new(TransactionStreamer::new()));
let transaction_streamer = if is_full_node {
Some(Arc::new(TransactionStreamer::new()))
} else {
None
};

let node_sync_store = Arc::new(NodeSyncStore::open_tables_read_write(
config.db_path().join("node_sync_db"),
Expand Down
16 changes: 2 additions & 14 deletions crates/sui-swarm/src/memory/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct SwarmBuilder<R = OsRng> {
initial_accounts_config: Option<GenesisConfig>,
fullnode_count: usize,
fullnode_rpc_addr: Option<SocketAddr>,
websocket_rpc_addr: Option<SocketAddr>,
}

impl SwarmBuilder {
Expand All @@ -39,7 +38,6 @@ impl SwarmBuilder {
initial_accounts_config: None,
fullnode_count: 0,
fullnode_rpc_addr: None,
websocket_rpc_addr: None,
}
}
}
Expand All @@ -53,7 +51,6 @@ impl<R> SwarmBuilder<R> {
initial_accounts_config: self.initial_accounts_config,
fullnode_count: self.fullnode_count,
fullnode_rpc_addr: self.fullnode_rpc_addr,
websocket_rpc_addr: self.websocket_rpc_addr,
}
}

Expand Down Expand Up @@ -94,11 +91,6 @@ impl<R> SwarmBuilder<R> {
self.fullnode_rpc_addr = Some(fullnode_rpc_addr);
self
}

pub fn with_websocket_rpc_addr(mut self, websocket_rpc_addr: SocketAddr) -> Self {
self.websocket_rpc_addr = Some(websocket_rpc_addr);
self
}
}

impl<R: rand::RngCore + rand::CryptoRng> SwarmBuilder<R> {
Expand Down Expand Up @@ -132,12 +124,10 @@ impl<R: rand::RngCore + rand::CryptoRng> SwarmBuilder<R> {

if self.fullnode_count > 0 {
(0..self.fullnode_count).for_each(|_| {
let mut config =
network_config.generate_fullnode_config_with_random_dir_name(true, true);
let mut config = network_config.generate_fullnode_config_with_random_dir_name(true);
if let Some(fullnode_rpc_addr) = self.fullnode_rpc_addr {
config.json_rpc_address = fullnode_rpc_addr;
}
config.websocket_address = self.websocket_rpc_addr;
fullnodes.insert(config.sui_address(), Node::new(config));
});
}
Expand All @@ -159,9 +149,7 @@ impl<R: rand::RngCore + rand::CryptoRng> SwarmBuilder<R> {
.collect();

let fullnodes = if let Some(fullnode_rpc_addr) = self.fullnode_rpc_addr {
let mut config =
network_config.generate_fullnode_config_with_random_dir_name(true, true);
config.websocket_address = self.websocket_rpc_addr;
let mut config = network_config.generate_fullnode_config_with_random_dir_name(true);
config.json_rpc_address = fullnode_rpc_addr;
HashMap::from([(config.sui_address(), Node::new(config))])
} else {
Expand Down
9 changes: 0 additions & 9 deletions crates/sui-test-validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ struct Args {
#[clap(long, default_value = "9000")]
fullnode_rpc_port: u16,

/// Port to start the fullnode websocket RPC server on
#[clap(long, default_value = "9001")]
websocket_rpc_port: u16,

/// Port to start the Sui faucet on
#[clap(long, default_value = "9123")]
faucet_port: u16,
Expand All @@ -56,16 +52,11 @@ async fn main() -> Result<()> {
let cluster = LocalNewCluster::start(&ClusterTestOpt {
env: Env::NewLocal,
fullnode_address: Some(format!("127.0.0.1:{}", args.fullnode_rpc_port)),
websocket_address: Some(format!("127.0.0.1:{}", args.websocket_rpc_port)),
faucet_address: None,
})
.await?;

println!("Fullnode RPC URL: {}", cluster.fullnode_url());
println!(
"Fullnode Websocket URL: {}",
cluster.websocket_url().unwrap()
);

start_faucet(&cluster, args.faucet_port).await?;

Expand Down
1 change: 0 additions & 1 deletion crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ async fn genesis(

let mut fullnode_config = network_config.generate_fullnode_config();
fullnode_config.json_rpc_address = sui_config::node::default_json_rpc_address();
fullnode_config.websocket_address = sui_config::node::default_websocket_address();
fullnode_config.save(sui_config_dir.join(SUI_FULLNODE_CONFIG))?;

for (i, validator) in network_config
Expand Down
22 changes: 11 additions & 11 deletions crates/sui/tests/full_node_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use tokio::time::{sleep, Duration};
#[sim_test]
async fn test_full_node_follows_txes() -> Result<(), anyhow::Error> {
let mut test_cluster = init_cluster_builder_env_aware().build().await?;
let node = start_a_fullnode(&test_cluster.swarm, false).await?;
let node = start_a_fullnode(&test_cluster.swarm).await?;

let context = &mut test_cluster.wallet;

Expand Down Expand Up @@ -84,7 +84,7 @@ async fn test_full_node_follows_txes() -> Result<(), anyhow::Error> {
#[sim_test]
async fn test_full_node_shared_objects() -> Result<(), anyhow::Error> {
let mut test_cluster = init_cluster_builder_env_aware().build().await?;
let node = start_a_fullnode(&test_cluster.swarm, false).await?;
let node = start_a_fullnode(&test_cluster.swarm).await?;

let context = &mut test_cluster.wallet;

Expand Down Expand Up @@ -412,7 +412,7 @@ async fn test_full_node_cold_sync() -> Result<(), anyhow::Error> {
sleep(Duration::from_millis(1000)).await;

// Start a new fullnode that is not on the write path
let node = start_a_fullnode(&test_cluster.swarm, false).await.unwrap();
let node = start_a_fullnode(&test_cluster.swarm).await.unwrap();

wait_for_tx(digest, node.state().clone()).await;

Expand All @@ -434,7 +434,7 @@ async fn test_full_node_sync_flood() -> Result<(), anyhow::Error> {
let context = test_cluster.wallet;

// Start a new fullnode that is not on the write path
let node = start_a_fullnode(&test_cluster.swarm, false).await.unwrap();
let node = start_a_fullnode(&test_cluster.swarm).await.unwrap();

let mut futures = Vec::new();

Expand Down Expand Up @@ -521,10 +521,10 @@ async fn test_full_node_transaction_streaming_basic() -> Result<(), anyhow::Erro
let context = &mut test_cluster.wallet;

// Start a new fullnode that is not on the write path
let fullnode = start_a_fullnode_with_handle(&test_cluster.swarm, None, None, false)
let fullnode = start_a_fullnode_with_handle(&test_cluster.swarm, None)
.await
.unwrap();
let ws_client = fullnode.ws_client.as_ref().unwrap();
let ws_client = fullnode.ws_client;
let node = fullnode.sui_node;

let mut sub: Subscription<SuiTransactionResponse> = ws_client
Expand Down Expand Up @@ -565,7 +565,7 @@ async fn test_full_node_transaction_streaming_basic() -> Result<(), anyhow::Erro
}

// Node Config without websocket_address does not create a transaction streamer
let full_node = start_a_fullnode_with_handle(&test_cluster.swarm, None, None, true).await?;
let full_node = start_a_fullnode_with_handle(&test_cluster.swarm, None).await?;
assert!(full_node.sui_node.state().transaction_streamer.is_none());

Ok(())
Expand All @@ -577,11 +577,11 @@ async fn test_full_node_sub_and_query_move_event_ok() -> Result<(), anyhow::Erro
let context = &mut test_cluster.wallet;

// Start a new fullnode that is not on the write path
let fullnode = start_a_fullnode_with_handle(&test_cluster.swarm, None, None, false)
let fullnode = start_a_fullnode_with_handle(&test_cluster.swarm, None)
.await
.unwrap();
let node = fullnode.sui_node;
let ws_client = fullnode.ws_client.as_ref().unwrap();
let ws_client = fullnode.ws_client;

let mut sub: Subscription<SuiEventEnvelope> = ws_client
.subscribe(
Expand Down Expand Up @@ -896,7 +896,7 @@ async fn test_full_node_event_read_api_ok() -> Result<(), anyhow::Error> {
#[sim_test]
async fn test_full_node_transaction_orchestrator_basic() -> Result<(), anyhow::Error> {
let mut test_cluster = init_cluster_builder_env_aware().build().await?;
let node = start_a_fullnode(&test_cluster.swarm, false).await?;
let node = start_a_fullnode(&test_cluster.swarm).await?;

let context = &mut test_cluster.wallet;
let transaction_orchestrator = node
Expand Down Expand Up @@ -1210,7 +1210,7 @@ async fn test_get_objects_read() -> Result<(), anyhow::Error> {
telemetry_subscribers::init_for_testing();
let mut test_cluster = init_cluster_builder_env_aware().build().await?;
let context = &mut test_cluster.wallet;
let node = start_a_fullnode(&test_cluster.swarm, false).await.unwrap();
let node = start_a_fullnode(&test_cluster.swarm).await.unwrap();

// Create the object
let (sender, object_id, _) = create_devnet_nft(context).await?;
Expand Down
3 changes: 1 addition & 2 deletions crates/sui/tests/transaction_orchestrator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ async fn test_local_execution_with_missing_parents() -> Result<(), anyhow::Error
let mut test_cluster = TestClusterBuilder::new().build().await?;
let context = &mut test_cluster.wallet;

let fullnode_handle =
start_a_fullnode_with_handle(&test_cluster.swarm, None, None, false).await?;
let fullnode_handle = start_a_fullnode_with_handle(&test_cluster.swarm, None).await?;
// Note this node is different from the one connected with WalletContext
let node = &fullnode_handle.sui_node;
let wallet_context_node = &test_cluster.fullnode_handle.as_ref().unwrap().sui_node;
Expand Down
Loading

0 comments on commit b4da44d

Please sign in to comment.