Skip to content

Commit

Permalink
[cherry-pick #18204] Cherry pick refactoring of sui-test-validator
Browse files Browse the repository at this point in the history
…crate into `sui` to release v1.28 branch (#18436)

This PR integrates `sui-test-validator` binary into `sui start`, but
keeps the crate for now before being deprecated.
- the default behaviour of the existing `sui start` is preserved
- the default `sui-test-validator` behaviour can be achieved by passing
two flags: `sui start --force-regenesis --with-faucet`.
- adds a `sui-test-validator.sh` bash script that is executable to keep
backward compatibility with the previous binary
- keeps the `sui-test-validator` binary for now.
- changed default port for GraphQL to 9125

One difference in flag/options usage is that `sui-test-validator` used
to start `graphql` service when the `graphql-port` arg was passed. To
keep it consistent across all three services, they each have their own
flag to use to start the service with default host and port, and a port
can be provided to it as well:
- `--with-faucet` or `--with-faucet=9123`
- `--with-indexer` or `--with-indexer=9124`
- `--with-graphql` or `--with-graphql=9125`

Previously, `sui-test-validator` exposed a few flags and options (see
orig code

[here](https://github.com/MystenLabs/sui/blob/4f52e053f2869328d9fe62501853fbd93c8624d7/crates/sui-test-validator/src/main.rs#L30-L85)),
which were migrated to `sui start`. There are two new flags in `sui
start`, `--with-graphql` and `--with-faucet`, to make it easier to start
these services with default values. Due to this, the bash script checks
for multiple flags and their values and tries to ensure everything is
passed correctly.

`sui-test-validator` implemented a simple faucet wrapper of the
`sui-faucet` crate. This was moved into `faucet.rs` module in `sui`
crate.

Given that there are three extra services that can be started, plus a
configuration variable to start the network without a fullnode, here is
an explanation of what each service requires:
`graphql requires indexer` - without an indexer, the GraphQL will have
no data to serve. `--with-indexer` will be implied if `--with-graphql`
is passed. `indexer requires fullnode` - without a fullnode, the indexer
will start ingesting mainnet data with default settings. The program
throws an error here.

Existing tests.

---

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol:
- [ ] Nodes (Validators and Full nodes):
- [ ] Indexer:
- [ ] JSON-RPC:
- [ ] GraphQL:
- [x] CLI: Integrated `sui-test-validator` into `sui start`.

`sui start` can now be used to also start an indexer, a GraphQL service,
or a faucet. Note that you need to build `sui` with `--features
indexer`, and have installed `libpq` to start the indexer and GraphQL
services. By default, this feature is turned off to preserve backward
compatibility of `sui start`. Alternatively, you can download the latest
release and use the `sui-pg` binary, which is built using the `indexer`
feature.
- the default behaviour of the existing `sui start` is preserved
- the default `sui-test-validator` behaviour can be achieved by passing
two flags: `sui start --force-regenesis --with-faucet`.
- adds a `sui-test-validator.sh` bash script to `sui/scripts` folder
that is executable to keep backward compatibility with the previous
binary
- [ ] Rust SDK:
  • Loading branch information
stefan-mysten authored Jun 27, 2024
1 parent 590b870 commit 0249e7f
Show file tree
Hide file tree
Showing 20 changed files with 1,150 additions and 522 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ jobs:
if: ${{ env.s3_archive_exist == '' }}
shell: bash
run: |
[ -f ~/.cargo/env ] && source ~/.cargo/env ; cargo build --bin sui --release --features indexer && mv target/release/sui target/release/sui-pg
[ -f ~/.cargo/env ] && source ~/.cargo/env ; cargo build --release && cargo build --profile=dev --bin sui
- name: Rename binaries for ${{ matrix.os }}
Expand All @@ -159,6 +160,10 @@ jobs:
mv ./target/release/${binary}${{ env.extention }} ${{ env.TMP_BUILD_DIR }}/${binary}${{ env.extention }}
done
# sui-pg is a special binary that is built with the indexer feature for sui start cmd
export binary='sui-pg' | tr -d $'\r')
mv ./target/release/${binary}${{ env.extention }} ${{ env.TMP_BUILD_DIR }}/${binary}${{ env.extention }}
mv ./target/debug/sui${{ env.extention }} ${{ env.TMP_BUILD_DIR }}/sui-debug${{ env.extention }}
tar -cvzf ./tmp/sui-${{ env.sui_tag }}-${{ env.os_type }}.tgz -C ${{ env.TMP_BUILD_DIR }} .
[[ ${{ env.sui_tag }} == *"testnet"* ]] && aws s3 cp ./tmp/sui-${{ env.sui_tag }}-${{ env.os_type }}.tgz s3://sui-releases/releases/sui-${{ env.sui_tag }}-${{ env.os_type }}.tgz || true
Expand Down
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion binary-build-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"sui-node",
"sui-tool",
"sui-faucet",
"sui-test-validator",
"sui-data-ingestion",
"sui-bridge",
"sui-bridge-cli",
"sui-graphql-rpc",
"sui-test-validator",
"move-analyzer"
],
"internal_binaries": [
Expand Down
1 change: 0 additions & 1 deletion crates/sui-cluster-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ sui-indexer.workspace = true
sui-faucet.workspace = true
sui-graphql-rpc.workspace = true
sui-swarm.workspace = true
sui.workspace = true
sui-swarm-config.workspace = true
sui-json-rpc-types.workspace = true
sui-sdk.workspace = true
Expand Down
16 changes: 16 additions & 0 deletions crates/sui-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ pub fn sui_config_dir() -> Result<PathBuf, anyhow::Error> {
})
}

/// Check if the genesis blob exists in the given directory or the default directory.
pub fn genesis_blob_exists(config_dir: Option<PathBuf>) -> bool {
if let Some(dir) = config_dir {
dir.join(SUI_GENESIS_FILENAME).exists()
} else if let Some(config_env) = std::env::var_os("SUI_CONFIG_DIR") {
Path::new(&config_env).join(SUI_GENESIS_FILENAME).exists()
} else if let Some(home) = dirs::home_dir() {
let mut config = PathBuf::new();
config.push(&home);
config.extend([SUI_DIR, SUI_CONFIG_DIR, SUI_GENESIS_FILENAME]);
config.exists()
} else {
false
}
}

pub fn validator_config_file(address: Multiaddr, i: usize) -> String {
multiaddr_to_filename(address).unwrap_or(format!("validator-config-{}.yaml", i))
}
Expand Down
1 change: 0 additions & 1 deletion crates/sui-faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ rocksdb.workspace = true
tempfile.workspace = true
parking_lot.workspace = true

sui.workspace = true
sui-json-rpc-types.workspace = true
sui-types.workspace = true
sui-config.workspace = true
Expand Down
13 changes: 12 additions & 1 deletion crates/sui-faucet/src/faucet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod simple_faucet;
mod write_ahead_log;
pub use self::simple_faucet::SimpleFaucet;
use clap::Parser;
use std::{net::Ipv4Addr, path::PathBuf};
use std::{net::Ipv4Addr, path::PathBuf, sync::Arc};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FaucetReceipt {
Expand Down Expand Up @@ -44,6 +44,17 @@ pub enum BatchSendStatusType {
DISCARDED,
}

pub struct AppState<F = Arc<SimpleFaucet>> {
pub faucet: F,
pub config: FaucetConfig,
}

impl<F> AppState<F> {
pub fn new(faucet: F, config: FaucetConfig) -> Self {
Self { faucet, config }
}
}

#[async_trait]
pub trait Faucet {
/// Send `Coin<SUI>` of the specified amount to the recipient
Expand Down
Loading

0 comments on commit 0249e7f

Please sign in to comment.