From f5109493415c4bc052dca89c03e0528a9c0a4a2a Mon Sep 17 00:00:00 2001 From: vladilen11 Date: Tue, 7 Nov 2023 23:45:58 +0800 Subject: [PATCH 1/5] update sui-test-validator options and dockerfile --- crates/sui-cluster-test/src/cluster.rs | 8 ++---- crates/sui-test-validator/src/main.rs | 38 +++++++++++++------------- crates/test-cluster/src/lib.rs | 12 ++++++++ docker/sui-test-validator/Dockerfile | 35 ++++++++++++++++++++++++ docker/sui-test-validator/build.sh | 35 ++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 24 deletions(-) create mode 100644 docker/sui-test-validator/Dockerfile create mode 100755 docker/sui-test-validator/build.sh diff --git a/crates/sui-cluster-test/src/cluster.rs b/crates/sui-cluster-test/src/cluster.rs index cfb0c99b6d202..9c4b7b4a94d92 100644 --- a/crates/sui-cluster-test/src/cluster.rs +++ b/crates/sui-cluster-test/src/cluster.rs @@ -164,11 +164,9 @@ impl LocalNewCluster { #[async_trait] impl Cluster for LocalNewCluster { async fn start(options: &ClusterTestOpt) -> Result { - // TODO: options should contain port instead of address - let fullnode_port = options.fullnode_address.as_ref().map(|addr| { + let fullnode_address = options.fullnode_address.as_ref().map(|addr| { addr.parse::() .expect("Unable to parse fullnode address") - .port() }); let indexer_address = options.indexer_address.as_ref().map(|addr| { @@ -204,8 +202,8 @@ impl Cluster for LocalNewCluster { } } - if let Some(rpc_port) = fullnode_port { - cluster_builder = cluster_builder.with_fullnode_rpc_port(rpc_port); + if let Some(rpc_addr) = fullnode_address { + cluster_builder = cluster_builder.with_fullnode_rpc_addr(rpc_addr); } let mut test_cluster = cluster_builder.build().await; diff --git a/crates/sui-test-validator/src/main.rs b/crates/sui-test-validator/src/main.rs index cc0d015e91064..1a31a21bcff98 100644 --- a/crates/sui-test-validator/src/main.rs +++ b/crates/sui-test-validator/src/main.rs @@ -34,17 +34,17 @@ struct Args { /// We can use any config dir that is generated by the sui genesis. #[clap(short, long)] config_dir: Option, - /// Port to start the Fullnode RPC server on - #[clap(long, default_value = "9000")] - fullnode_rpc_port: u16, + /// Address to start the Fullnode RPC server on + #[clap(long, default_value = "127.0.0.1:9000")] + fullnode_rpc_addr: String, - /// Port to start the Sui faucet on - #[clap(long, default_value = "9123")] - faucet_port: u16, + /// Address to start the Sui faucet on + #[clap(long, default_value = "127.0.0.1:9123")] + faucet_addr: String, - /// Port to start the Indexer RPC server on - #[clap(long, default_value = "9124")] - indexer_rpc_port: u16, + /// Address to start the Indexer RPC server on + #[clap(long, default_value = "127.0.0.1:9124")] + indexer_rpc_addr: String, /// Port for the Indexer Postgres DB /// 5432 is the default port for postgres on Mac @@ -77,12 +77,12 @@ async fn main() -> Result<()> { let args = Args::parse(); let Args { config_dir, - fullnode_rpc_port, - indexer_rpc_port, + fullnode_rpc_addr, + indexer_rpc_addr, pg_port, pg_host, epoch_duration_ms, - faucet_port, + faucet_addr, with_indexer, use_indexer_experimental_methods, } = args; @@ -96,8 +96,8 @@ async fn main() -> Result<()> { let cluster = LocalNewCluster::start(&ClusterTestOpt { env: Env::NewLocal, - fullnode_address: Some(format!("127.0.0.1:{}", fullnode_rpc_port)), - indexer_address: with_indexer.then_some(format!("127.0.0.1:{}", indexer_rpc_port)), + fullnode_address: Some(fullnode_rpc_addr.clone()), + indexer_address: with_indexer.then_some(indexer_rpc_addr), pg_address: with_indexer.then_some(format!( "postgres://postgres@{pg_host}:{pg_port}/sui_indexer" )), @@ -117,7 +117,7 @@ async fn main() -> Result<()> { ); } - start_faucet(&cluster, faucet_port).await?; + start_faucet(&cluster, faucet_addr).await?; Ok(()) } @@ -126,7 +126,7 @@ struct AppState { faucet: Arc, } -async fn start_faucet(cluster: &LocalNewCluster, port: u16) -> Result<()> { +async fn start_faucet(cluster: &LocalNewCluster, addr: String) -> Result<()> { let faucet = FaucetClientFactory::new_from_cluster(cluster).await; let app_state = Arc::new(AppState { faucet }); @@ -148,11 +148,11 @@ async fn start_faucet(cluster: &LocalNewCluster, port: u16) -> Result<()> { .into_inner(), ); - let addr = SocketAddr::from(([127, 0, 0, 1], port)); + let faucet_addr = addr.parse::().expect("Unable to parse faucet address"); - println!("Faucet URL: http://{}", addr); + println!("Faucet URL: http://{}", faucet_addr); - axum::Server::bind(&addr) + axum::Server::bind(&faucet_addr) .serve(app.into_make_service()) .await?; diff --git a/crates/test-cluster/src/lib.rs b/crates/test-cluster/src/lib.rs index 7bfc892de4e7e..f91037785d3f8 100644 --- a/crates/test-cluster/src/lib.rs +++ b/crates/test-cluster/src/lib.rs @@ -644,6 +644,7 @@ pub struct TestClusterBuilder { additional_objects: Vec, num_validators: Option, fullnode_rpc_port: Option, + fullnode_rpc_addr: Option, enable_fullnode_events: bool, validator_supported_protocol_versions_config: ProtocolVersionsConfig, // Default to validator_supported_protocol_versions_config, but can be overridden. @@ -663,6 +664,7 @@ impl TestClusterBuilder { network_config: None, additional_objects: vec![], fullnode_rpc_port: None, + fullnode_rpc_addr: None, num_validators: None, enable_fullnode_events: false, validator_supported_protocol_versions_config: ProtocolVersionsConfig::Default, @@ -681,6 +683,11 @@ impl TestClusterBuilder { self } + pub fn with_fullnode_rpc_addr(mut self, rpc_addr: SocketAddr) -> Self { + self.fullnode_rpc_addr = Some(rpc_addr); + self + } + pub fn set_genesis_config(mut self, genesis_config: GenesisConfig) -> Self { assert!(self.genesis_config.is_none() && self.network_config.is_none()); self.genesis_config = Some(genesis_config); @@ -904,6 +911,11 @@ impl TestClusterBuilder { if let Some(fullnode_rpc_port) = self.fullnode_rpc_port { builder = builder.with_fullnode_rpc_port(fullnode_rpc_port); } + + if let Some(fullnode_rpc_addr) = self.fullnode_rpc_addr { + builder = builder.with_fullnode_rpc_addr(fullnode_rpc_addr); + } + if let Some(num_unpruned_validators) = self.num_unpruned_validators { builder = builder.with_num_unpruned_validators(num_unpruned_validators); } diff --git a/docker/sui-test-validator/Dockerfile b/docker/sui-test-validator/Dockerfile new file mode 100644 index 0000000000000..a1d04d3f32de6 --- /dev/null +++ b/docker/sui-test-validator/Dockerfile @@ -0,0 +1,35 @@ +# Build application +# +# Copy in all crates, Cargo.toml and Cargo.lock unmodified, +# and build the application. +FROM rust:1.73-bullseye AS builder +ARG PROFILE=release +ARG GIT_REVISION +ENV GIT_REVISION=$GIT_REVISION +WORKDIR "$WORKDIR/sui" +RUN apt-get update && apt-get install -y cmake clang + +COPY Cargo.toml Cargo.lock ./ +COPY crates crates +COPY sui-execution sui-execution +COPY narwhal narwhal +COPY external-crates external-crates + +RUN cargo build --profile ${PROFILE} --bin sui-test-validator + +# Production Image +FROM debian:bullseye-slim AS runtime +# Use jemalloc as memory allocator +RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates libpq-dev +ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so +ARG PROFILE=release +WORKDIR "$WORKDIR/sui" +# Both bench and release profiles copy from release dir +COPY --from=builder /sui/target/release/sui-test-validator /opt/sui/bin/sui-test-validator +# Support legacy usages of /usr/local/bin/sui-test-validator +COPY --from=builder /sui/target/release/sui-test-validator /usr/local/bin + +ARG BUILD_DATE +ARG GIT_REVISION +LABEL build-date=$BUILD_DATE +LABEL git-revision=$GIT_REVISION diff --git a/docker/sui-test-validator/build.sh b/docker/sui-test-validator/build.sh new file mode 100755 index 0000000000000..8e5d9d0f6b62f --- /dev/null +++ b/docker/sui-test-validator/build.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# Copyright (c) Mysten Labs, Inc. +# SPDX-License-Identifier: Apache-2.0 + +# fast fail. +set -e + +DIR="$( cd "$( dirname "$0" )" && pwd )" +REPO_ROOT="$(git rev-parse --show-toplevel)" +DOCKERFILE="$DIR/Dockerfile" +GIT_REVISION="$(git describe --always --dirty --exclude '*')" +BUILD_DATE="$(date -u +'%Y-%m-%d')" + +# option to build using debug symbols +if [ "$1" = "--debug-symbols" ]; then + PROFILE="bench" + echo "Building with full debug info enabled ... WARNING: binary size might significantly increase" + shift +else + PROFILE="release" +fi + +echo +echo "Building sui-test-validator docker image" +echo "Dockerfile: \t$DOCKERFILE" +echo "docker context: $REPO_ROOT" +echo "build date: \t$BUILD_DATE" +echo "git revision: \t$GIT_REVISION" +echo + +docker build -f "$DOCKERFILE" "$REPO_ROOT" \ + --build-arg GIT_REVISION="$GIT_REVISION" \ + --build-arg BUILD_DATE="$BUILD_DATE" \ + --build-arg PROFILE="$PROFILE" \ + "$@" From d412d9f9739a85228ace9c6bf0d2cad6988e5c73 Mon Sep 17 00:00:00 2001 From: vladilen11 Date: Fri, 10 Nov 2023 19:30:41 +0800 Subject: [PATCH 2/5] Some nits. --- docker/sui-test-validator/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/sui-test-validator/Dockerfile b/docker/sui-test-validator/Dockerfile index a1d04d3f32de6..a964167cb9a05 100644 --- a/docker/sui-test-validator/Dockerfile +++ b/docker/sui-test-validator/Dockerfile @@ -20,7 +20,7 @@ RUN cargo build --profile ${PROFILE} --bin sui-test-validator # Production Image FROM debian:bullseye-slim AS runtime # Use jemalloc as memory allocator -RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates libpq-dev +RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates libpq-dev curl ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so ARG PROFILE=release WORKDIR "$WORKDIR/sui" From 6d5ac99506758c011bb39368bd9ea58f60d4e5ca Mon Sep 17 00:00:00 2001 From: vladilen11 Date: Thu, 4 Jul 2024 00:56:31 +0800 Subject: [PATCH 3/5] fix sui-test-validator dockerfile --- docker/sui-test-validator/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/sui-test-validator/Dockerfile b/docker/sui-test-validator/Dockerfile index a964167cb9a05..9f6d1c8b02ebb 100644 --- a/docker/sui-test-validator/Dockerfile +++ b/docker/sui-test-validator/Dockerfile @@ -10,6 +10,7 @@ WORKDIR "$WORKDIR/sui" RUN apt-get update && apt-get install -y cmake clang COPY Cargo.toml Cargo.lock ./ +COPY consensus consensus COPY crates crates COPY sui-execution sui-execution COPY narwhal narwhal From a039a4a02db4bbf4ce72db1994cbcad83bc7d229 Mon Sep 17 00:00:00 2001 From: vladilen11 Date: Thu, 4 Jul 2024 02:01:33 +0800 Subject: [PATCH 4/5] fix sui-test-validator dockerfile --- docker/sui-test-validator/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/sui-test-validator/Dockerfile b/docker/sui-test-validator/Dockerfile index 9f6d1c8b02ebb..97d010e4e439b 100644 --- a/docker/sui-test-validator/Dockerfile +++ b/docker/sui-test-validator/Dockerfile @@ -2,7 +2,7 @@ # # Copy in all crates, Cargo.toml and Cargo.lock unmodified, # and build the application. -FROM rust:1.73-bullseye AS builder +FROM rust:1.75-bullseye AS builder ARG PROFILE=release ARG GIT_REVISION ENV GIT_REVISION=$GIT_REVISION From 04466616d5bd678774073c80d6e3899a1ce61dd8 Mon Sep 17 00:00:00 2001 From: vladilen11 Date: Sun, 7 Jul 2024 22:58:38 +0800 Subject: [PATCH 5/5] fix sui-test-validator bug --- crates/sui-cluster-test/src/cluster.rs | 2 +- crates/sui-test-validator/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/sui-cluster-test/src/cluster.rs b/crates/sui-cluster-test/src/cluster.rs index 44271a8e0ca5b..b98f000671ced 100644 --- a/crates/sui-cluster-test/src/cluster.rs +++ b/crates/sui-cluster-test/src/cluster.rs @@ -166,8 +166,8 @@ impl LocalNewCluster { #[async_trait] impl Cluster for LocalNewCluster { async fn start(options: &ClusterTestOpt) -> Result { - let fullnode_address = options.fullnode_address.as_ref().map(|addr| { let data_ingestion_path = tempdir()?.into_path(); + let fullnode_address = options.fullnode_address.as_ref().map(|addr| { addr.parse::() .expect("Unable to parse fullnode address") }); diff --git a/crates/sui-test-validator/src/main.rs b/crates/sui-test-validator/src/main.rs index f8da09c76a966..badf10f3ee653 100644 --- a/crates/sui-test-validator/src/main.rs +++ b/crates/sui-test-validator/src/main.rs @@ -129,7 +129,7 @@ async fn main() -> Result<()> { pg_address: with_indexer.then_some(format!( "postgres://{pg_user}:{pg_password}@{pg_host}:{pg_port}/{pg_db_name}" )), - faucet_address: Some(format!("127.0.0.1:{}", faucet_port)), + faucet_address: Some(format!("{}", faucet_addr)), epoch_duration_ms, config_dir, graphql_address: graphql_port.map(|p| format!("{}:{}", graphql_host, p)),