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

[sui-test-validator] update sui-test-validator options and dockerfile #14701

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions crates/sui-cluster-test/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,9 @@ impl LocalNewCluster {
impl Cluster for LocalNewCluster {
async fn start(options: &ClusterTestOpt) -> Result<Self, anyhow::Error> {
let data_ingestion_path = tempdir()?.into_path();
// 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::<SocketAddr>()
.expect("Unable to parse fullnode address")
.port()
});

let indexer_address = options.indexer_address.as_ref().map(|addr| {
Expand Down Expand Up @@ -209,8 +207,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;
Expand Down
46 changes: 23 additions & 23 deletions crates/sui-test-validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ struct Args {
/// We can use any config dir that is generated by the sui genesis.
#[clap(short, long)]
config_dir: Option<std::path::PathBuf>,
/// 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,

/// Address to start the Indexer RPC server on
#[clap(long, default_value = "127.0.0.1:9124")]
indexer_rpc_addr: String,

/// Host to start the GraphQl server on
#[clap(long, default_value = "127.0.0.1")]
Expand All @@ -51,10 +55,6 @@ struct Args {
#[clap(long)]
graphql_port: Option<u16>,

/// Port to start the Indexer RPC server on
#[clap(long, default_value = "9124")]
indexer_rpc_port: u16,

/// Port for the Indexer Postgres DB
/// 5432 is the default port for postgres on Mac
#[clap(long, default_value = "5432")]
Expand Down Expand Up @@ -94,17 +94,17 @@ async fn main() -> Result<()> {
let args = Args::parse();
let Args {
config_dir,
fullnode_rpc_port,
fullnode_rpc_addr,
indexer_rpc_addr,
graphql_host,
graphql_port,
indexer_rpc_port,
pg_port,
pg_host,
pg_db_name,
pg_user,
pg_password,
epoch_duration_ms,
faucet_port,
faucet_addr,
with_indexer,
} = args;

Expand All @@ -124,13 +124,12 @@ async fn main() -> Result<()> {

let cluster_config = ClusterTestOpt {
env: Env::NewLocal,

fullnode_address: Some(format!("0.0.0.0:{}", fullnode_rpc_port)),
indexer_address: with_indexer.then_some(format!("0.0.0.0:{}", indexer_rpc_port)),
pg_address: Some(format!(
fullnode_address: Some(fullnode_rpc_addr.clone()),
indexer_address: with_indexer.then_some(indexer_rpc_addr),
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)),
Expand All @@ -148,7 +147,7 @@ async fn main() -> Result<()> {
);
}

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

Ok(())
}
Expand All @@ -157,7 +156,7 @@ struct AppState {
faucet: Arc<dyn FaucetClient + Sync + Send>,
}

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 });
Expand All @@ -179,11 +178,12 @@ async fn start_faucet(cluster: &LocalNewCluster, port: u16) -> Result<()> {
.into_inner(),
);

let addr = SocketAddr::from(([0, 0, 0, 0], port));
let faucet_addr = addr.parse::<SocketAddr>().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?;

Expand Down
12 changes: 12 additions & 0 deletions crates/test-cluster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ pub struct TestClusterBuilder {
additional_objects: Vec<Object>,
num_validators: Option<usize>,
fullnode_rpc_port: Option<u16>,
fullnode_rpc_addr: Option<SocketAddr>,
enable_fullnode_events: bool,
validator_supported_protocol_versions_config: ProtocolVersionsConfig,
// Default to validator_supported_protocol_versions_config, but can be overridden.
Expand Down Expand Up @@ -921,6 +922,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,
Expand Down Expand Up @@ -966,6 +968,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);
Expand Down Expand Up @@ -1416,6 +1423,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);
}
Expand Down
36 changes: 36 additions & 0 deletions docker/sui-test-validator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Build application
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.75-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 consensus consensus
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 curl
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
35 changes: 35 additions & 0 deletions docker/sui-test-validator/build.sh
Original file line number Diff line number Diff line change
@@ -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" \
"$@"
Loading