Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swarm config refactoring #12117

Merged
merged 1 commit into from
May 25, 2023
Merged

Swarm config refactoring #12117

merged 1 commit into from
May 25, 2023

Conversation

lxfind
Copy link
Contributor

@lxfind lxfind commented May 20, 2023

This PR does a series of refactoring on how we construct node config and swarm configs to make it cleaner:

  1. Renames utils.rs in sui-config/ to local_ip_utils.rs, and moved all the IP and port management port into it. Now it contains a manager to generate new IPs and new ports for simtest; for non-simtest it always use localhost and new available port.
  2. Previously we start fullnode inside TestCluster, which runs on the client node in simtest. This created a lot of tech debt. This PR moves all fullnode creation into Swarm. Now we can start arbitrary number of fullnodes in a Swarm. When starting TestCluster, it uses Swarm to launch a fullnode, and keep a copy of the fullnode handle locally for rpc access.
  3. Also added the ability to start more fullnodes after a test cluster started running, inside swarm. This means we could also run those fullnodes in a container, managed by the swarm.
  4. Heavy use of the builder pattern: added ValidatorGenesisConfigBuilder to build a ValidatorGenesisConfig; added ValidatorConfigBuilder and FullnodeConfigBuilder to build their node configs.
  5. Removed a number of unused fields in ConfigBuilder and SwarmBuilder.

This this PR, we should be able to start removing all the code that spawns individual nodes instead of inside a container.

@vercel
Copy link

vercel bot commented May 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
offline-signer-helper ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 25, 2023 3:37am
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) May 25, 2023 3:37am
explorer-storybook ⬜️ Ignored (Inspect) May 25, 2023 3:37am
sui-wallet-kit ⬜️ Ignored (Inspect) May 25, 2023 3:37am
wallet-adapter ⬜️ Ignored (Inspect) May 25, 2023 3:37am

// Converts a /ip{4,6}/-/tcp/-[/-] Multiaddr to SocketAddr.
// Useful when an external library only accepts SocketAddr, e.g. to start a local server.
// See `client::endpoint_from_multiaddr()` for converting to Endpoint for clients.
pub fn to_socket_addr(&self) -> Result<SocketAddr> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-functional-change

/// Get a list of nodes that we don't want to kill in the crash recovery tests.
/// This includes the client node which is the node that is running the test, as well as
/// rpc fullnode which are needed to run the benchmark.
fn get_keep_alive_nodes(cluster: &TestCluster) -> HashSet<sui_simulator::task::NodeId> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added such that crash recovery tests don't kill the rpc fullnode

@@ -0,0 +1,140 @@
// Copyright (c) Mysten Labs, Inc.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rename of utils.rs, but also with consolidated ip management for both simtest and non-simtest

genesis_config: Option<GenesisConfig>,
reference_gas_price: Option<u64>,
additional_objects: Vec<Object>,
with_swarm: bool,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of fields are deleted since they are never needed

fn get_key_path(key_pair: &AuthorityKeyPair) -> String {
let public_key: AuthorityPublicKeyBytes = key_pair.public().into();
let mut key_path = Hex::encode(public_key);
key_path.truncate(12);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: make this 12 a constant? or comment what it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from old code. It's just to name the directory name of the validator using validator's public key, but make it shorter

Comment on lines 19 to 20
SocketAddr::V4(v4) => format!("/ip4/{}/udp/{}", v4.ip(), v4.port()),
SocketAddr::V6(v6) => format!("/ip6/{}/udp/{}", v6.ip(), v6.port()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to only be used for udp addresses and not tcp ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out-of-dated code, removed.

Copy link
Contributor

@mystenmark mystenmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small comments - LGTM otherwise


pub async fn spawn_new_fullnode(&mut self, config: NodeConfig) -> SuiNodeHandle {
let name = config.protocol_public_key();
let node = Node::new(config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great if we could add something to the name of the fullnode nodes so that they can be distinguished from validators in the logs

crates/sui/tests/full_node_tests.rs Show resolved Hide resolved
@lxfind lxfind force-pushed the swarm-start-fullnode-in-container branch from 25b48bd to 8169ced Compare May 25, 2023 03:37
@lxfind lxfind merged commit cd6bbe0 into main May 25, 2023
@lxfind lxfind deleted the swarm-start-fullnode-in-container branch May 25, 2023 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants