From 4355b42f0457f8ee835088293c3904c2a0aca6f8 Mon Sep 17 00:00:00 2001 From: UnMaykr <98741738+unmaykr-aftermath@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:29:49 -0300 Subject: [PATCH] feat(crates/sui): add --with-data-ingestion to 'sui start' (#20472) ## 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 --with-indexer` to also have checkpoints written to ``. May be useful for inspecting the data - Use `sui start --data-ingestion-dir ` to only have checkpoints written to ``, but not start an indexer service P.s.: every time I ran `sui start --with-data-ingestion=` (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> --- crates/sui/src/sui_commands.rs | 22 +++++++++++++++++----- crates/sui/tests/cli_tests.rs | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/sui/src/sui_commands.rs b/crates/sui/src/sui_commands.rs index 8a539ade6fbbe..4ad70d523a5be 100644 --- a/crates/sui/src/sui_commands.rs +++ b/crates/sui/src/sui_commands.rs @@ -203,6 +203,13 @@ pub enum SuiCommand { #[clap(long)] epoch_duration_ms: Option, + /// 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, + /// Start the network without a fullnode #[clap(long = "no-full-node")] no_full_node: bool, @@ -368,6 +375,7 @@ impl SuiCommand { indexer_feature_args, fullnode_rpc_port, + data_ingestion_dir, no_full_node, epoch_duration_ms, } => { @@ -378,6 +386,7 @@ impl SuiCommand { force_regenesis, epoch_duration_ms, fullnode_rpc_port, + data_ingestion_dir, no_full_node, ) .await?; @@ -597,6 +606,7 @@ async fn start( force_regenesis: bool, epoch_duration_ms: Option, fullnode_rpc_port: u16, + mut data_ingestion_dir: Option, no_full_node: bool, ) -> Result<(), anyhow::Error> { if force_regenesis { @@ -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(); @@ -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 */ diff --git a/crates/sui/tests/cli_tests.rs b/crates/sui/tests/cli_tests.rs index 9c171705b4172..3a1a86fef4d31 100644 --- a/crates/sui/tests/cli_tests.rs +++ b/crates/sui/tests/cli_tests.rs @@ -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,