Skip to content

Commit

Permalink
Remove embedded gateway connection mode (MystenLabs#5751)
Browse files Browse the repository at this point in the history
* * remove embedded gateway connection mode
* start fullnode in `sui start`
* added multiple environment configuration for sui cli.
* auto genesis if the sui_config/network.yaml does not exists.

* fix clippy

* add back option of using embedded gateway for sim test

* fix sim test

* fix simtest

* fix test

* separate out embedded gateway from SuiClient

* fix test

* fix test

* preserve keystore and client.yaml during re-genesis

* minor fixes

* fix clippy
  • Loading branch information
patrickkuo authored Nov 3, 2022
1 parent 2b850fc commit 0c0b002
Show file tree
Hide file tree
Showing 24 changed files with 938 additions and 1,063 deletions.
2 changes: 1 addition & 1 deletion crates/sui-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub struct FullNodeProxy {

impl FullNodeProxy {
pub async fn from_url(http_url: &str) -> Result<Self, anyhow::Error> {
let sui_client = SuiClient::new_rpc_client(http_url, None).await?;
let sui_client = SuiClient::new(http_url, None).await?;

let resp = sui_client.read_api().get_committee_info(None).await?;
let epoch = resp.epoch;
Expand Down
19 changes: 7 additions & 12 deletions crates/sui-cluster-test/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use async_trait::async_trait;
use clap::*;
use std::net::SocketAddr;
use sui::client_commands::WalletContext;
use sui::config::SuiClientConfig;
use sui::config::{SuiClientConfig, SuiEnv};
use sui_config::genesis_config::GenesisConfig;
use sui_config::Config;
use sui_config::SUI_KEYSTORE_FILENAME;
use sui_keys::keystore::{AccountKeystore, FileBasedKeystore, Keystore};
use sui_sdk::ClientType;
use sui_swarm::memory::Swarm;
use sui_types::base_types::SuiAddress;
use sui_types::crypto::KeypairTraits;
Expand Down Expand Up @@ -143,12 +142,6 @@ impl Cluster for LocalNewCluster {
// Let the faucet account hold 1000 gas objects on genesis
let genesis_config = GenesisConfig::custom_genesis(4, 1, 1000);

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

// TODO: options should contain port instead of address
let fullnode_port = options.fullnode_address.as_ref().map(|addr| {
addr.parse::<SocketAddr>()
Expand All @@ -164,9 +157,6 @@ impl Cluster for LocalNewCluster {

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

if let Some(rpc_port) = gateway_port {
cluster_builder = cluster_builder.set_gateway_rpc_port(rpc_port);
}
if let Some(rpc_port) = fullnode_port {
cluster_builder = cluster_builder.set_fullnode_rpc_port(rpc_port);
}
Expand Down Expand Up @@ -267,8 +257,13 @@ pub async fn new_wallet_context_from_cluster(
.unwrap();
SuiClientConfig {
keystore,
client_type: ClientType::RPC(fullnode_url.into(), None),
envs: vec![SuiEnv {
alias: "localnet".to_string(),
rpc: fullnode_url.into(),
ws: None,
}],
active_address: Some(address),
active_env: Some("localnet".to_string()),
}
.persisted(&wallet_config_path)
.save()
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 @@ -18,8 +18,6 @@ pub struct ClusterTestOpt {
#[clap(arg_enum)]
pub env: Env,
#[clap(long)]
pub gateway_address: Option<String>,
#[clap(long)]
pub faucet_address: Option<String>,
#[clap(long)]
pub fullnode_address: Option<String>,
Expand All @@ -31,7 +29,6 @@ impl ClusterTestOpt {
pub fn new_local() -> Self {
Self {
env: Env::NewLocal,
gateway_address: None,
faucet_address: None,
fullnode_address: None,
websocket_address: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-cluster-test/src/wallet_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl WalletClient {

let rpc_url = String::from(cluster.fullnode_url());
info!("Use fullnode rpc: {}", &rpc_url);
let fullnode_client = SuiClient::new_rpc_client(&rpc_url, None).await.unwrap();
let fullnode_client = SuiClient::new(&rpc_url, None).await.unwrap();

Self {
wallet_context,
Expand Down
48 changes: 45 additions & 3 deletions crates/sui-config/src/genesis_config.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::{utils, DEFAULT_GAS_PRICE, DEFAULT_STAKE};
use std::collections::{BTreeMap, BTreeSet};

use anyhow::Result;
use multiaddr::Multiaddr;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::collections::{BTreeMap, BTreeSet};
use tracing::info;

use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::committee::StakeUnit;
use sui_types::crypto::{
get_key_pair_from_rng, AccountKeyPair, AuthorityKeyPair, NetworkKeyPair, SuiKeyPair,
};
use sui_types::object::Object;
use sui_types::sui_serde::KeyPairBase64;
use tracing::info;

use crate::node::DEFAULT_GRPC_CONCURRENCY_LIMIT;
use crate::Config;
use crate::{utils, DEFAULT_GAS_PRICE, DEFAULT_STAKE};

#[derive(Serialize, Deserialize)]
pub struct GenesisConfig {
Expand Down Expand Up @@ -204,6 +206,14 @@ impl GenesisConfig {
)
}

pub fn for_local_testing_with_addresses(addresses: Vec<SuiAddress>) -> Self {
Self::custom_genesis_with_addresses(
DEFAULT_NUMBER_OF_AUTHORITIES,
addresses,
DEFAULT_NUMBER_OF_OBJECT_PER_ACCOUNT,
)
}

pub fn custom_genesis(
num_authorities: usize,
num_accounts: usize,
Expand Down Expand Up @@ -235,6 +245,38 @@ impl GenesisConfig {
..Default::default()
}
}

pub fn custom_genesis_with_addresses(
num_authorities: usize,
addresses: Vec<SuiAddress>,
num_objects_per_account: usize,
) -> Self {
assert!(
num_authorities > 0,
"num_authorities should be larger than 0"
);

let mut accounts = Vec::new();
for address in addresses {
let mut objects = Vec::new();
for _ in 0..num_objects_per_account {
objects.push(ObjectConfig {
object_id: ObjectID::random(),
gas_value: DEFAULT_GAS_AMOUNT,
})
}
accounts.push(AccountConfig {
address: Some(address),
gas_objects: objects,
gas_object_ranges: Some(Vec::new()),
})
}

Self {
accounts,
..Default::default()
}
}
}

impl Default for GenesisConfig {
Expand Down
12 changes: 1 addition & 11 deletions crates/sui-faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tap::tap::TapFallible;
#[cfg(test)]
use std::collections::HashSet;

use sui::client_commands::{SuiClientCommands, WalletContext};
use sui::client_commands::WalletContext;
use sui_json_rpc_types::{
SuiExecutionStatus, SuiObjectRead, SuiPaySui, SuiTransactionKind, SuiTransactionResponse,
};
Expand Down Expand Up @@ -52,16 +52,6 @@ impl SimpleFaucet {
.map_err(|err| FaucetError::Wallet(err.to_string()))?;
info!("SimpleFaucet::new with active address: {active_address}");

// Sync to have the latest status
if wallet.client.is_gateway() {
SuiClientCommands::SyncClientState {
address: Some(active_address),
}
.execute(&mut wallet)
.await
.map_err(|err| FaucetError::Wallet(format!("Fail to sync client state: {}", err)))?;
}

let coins = wallet
.gas_objects(active_address)
.await
Expand Down
Loading

0 comments on commit 0c0b002

Please sign in to comment.