Skip to content

Commit

Permalink
feat(crates/sui): add --with-data-ingestion to 'sui start' (#20472)
Browse files Browse the repository at this point in the history
## Description 

Adds the `--data-ingestion-dir` option to `sui start` that allows users
to set a custom data ingestion directory where checkpoint files will be
written to.

This is useful, among other things, for testing a custom [local
reader](https://docs.sui.io/guides/developer/advanced/custom-indexer#local-reader)
indexing setup with low overhead.

This is **not** a breaking change, as `sui start --with-indexer` works
as usual by creating a temporary directory for data ingestion, but now
one can:
- Use `sui start --data-ingestion-dir <path> --with-indexer` to also
have checkpoints written to `<path>`. May be useful for inspecting the
data
- Use `sui start --data-ingestion-dir <path>` to only have checkpoints
written to `<path>`, but not start an indexer service

P.s.: every time I ran `sui start --with-data-ingestion=<path>` (no
other arguments), the network started producing checkpoints from 0. Is
this intended or was the network supposed to pick up from where it left
off? Perhaps it's the full node syncing.

## Test plan 

I tested it locally to verify that the checkpoints are indeed written to
the configured directory. See the screenshot below. `sui start
--with-indexer` still runs without problems and I verified that
checkpoints were committed to the DB.


![image](https://github.com/user-attachments/assets/bbaf4a91-66bc-4456-b9a1-0fe0065b2b0a)

I set `export SUI_CONFIG_DIR=~/.sui/test` for the above.

---

## Release notes

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: Added the `--data-ingestion-dir` option to `sui start` to set
a custom directory where to write the checkpoint files.
- [ ] Rust SDK:
- [ ] REST API:

---------

Co-authored-by: stefan-mysten <135084671+stefan-mysten@users.noreply.github.com>
  • Loading branch information
unmaykr-aftermath and stefan-mysten authored Nov 29, 2024
1 parent 387b0f0 commit 4355b42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 17 additions & 5 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ pub enum SuiCommand {
#[clap(long)]
epoch_duration_ms: Option<u64>,

/// Make the fullnode dump executed checkpoints as files to this directory. This is
/// incompatible with --no-full-node.
///
/// If --with-indexer is set, this defaults to a temporary directory.
#[clap(long, value_name = "DATA_INGESTION_DIR")]
data_ingestion_dir: Option<PathBuf>,

/// Start the network without a fullnode
#[clap(long = "no-full-node")]
no_full_node: bool,
Expand Down Expand Up @@ -368,6 +375,7 @@ impl SuiCommand {

indexer_feature_args,
fullnode_rpc_port,
data_ingestion_dir,
no_full_node,
epoch_duration_ms,
} => {
Expand All @@ -378,6 +386,7 @@ impl SuiCommand {
force_regenesis,
epoch_duration_ms,
fullnode_rpc_port,
data_ingestion_dir,
no_full_node,
)
.await?;
Expand Down Expand Up @@ -597,6 +606,7 @@ async fn start(
force_regenesis: bool,
epoch_duration_ms: Option<u64>,
fullnode_rpc_port: u16,
mut data_ingestion_dir: Option<PathBuf>,
no_full_node: bool,
) -> Result<(), anyhow::Error> {
if force_regenesis {
Expand Down Expand Up @@ -706,14 +716,15 @@ async fn start(
sui_config_path
};

let data_ingestion_path = tempdir()?.into_path();

// the indexer requires to set the fullnode's data ingestion directory
// note that this overrides the default configuration that is set when running the genesis
// command, which sets data_ingestion_dir to None.
if with_indexer.is_some() && data_ingestion_dir.is_none() {
data_ingestion_dir = Some(tempdir()?.into_path())
}

if with_indexer.is_some() {
swarm_builder = swarm_builder.with_data_ingestion_dir(data_ingestion_path.clone());
if let Some(ref dir) = data_ingestion_dir {
swarm_builder = swarm_builder.with_data_ingestion_dir(dir.clone());
}

let mut fullnode_url = sui_config::node::default_json_rpc_address();
Expand Down Expand Up @@ -754,7 +765,8 @@ async fn start(
pg_address.clone(),
None,
None,
Some(data_ingestion_path.clone()),
// We ensured above that this is set to something if --with-indexer is set
data_ingestion_dir,
None,
None, /* start_checkpoint */
None, /* end_checkpoint */
Expand Down
1 change: 1 addition & 0 deletions crates/sui/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn test_genesis() -> Result<(), anyhow::Error> {

// Start network without authorities
let start = SuiCommand::Start {
data_ingestion_dir: None,
config_dir: Some(config),
force_regenesis: false,
with_faucet: None,
Expand Down

0 comments on commit 4355b42

Please sign in to comment.