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

feat: add --depth flag to snapshot export #3330

Merged
merged 6 commits into from
Aug 9, 2023
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

- [#3316](https://github.com/ChainSafe/forest/pull/3316): Add
`forest-tool benchmark` commands.
- [#3330](https://github.com/ChainSafe/forest/pull/3330): Add `--depth` flag to
`forest-cli snapshot export`.

### Changed

Expand Down
14 changes: 13 additions & 1 deletion src/cli/subcommands/snapshot_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub enum SnapshotCommands {
/// Tipset to start the export from, default is the chain head
#[arg(short, long)]
tipset: Option<i64>,
/// How many state-roots to include. Lower limit is 900 for `calibnet` and `mainnet`.
lemmih marked this conversation as resolved.
Show resolved Hide resolved
#[arg(short, long)]
depth: Option<crate::chain::ChainEpochDelta>,
},

/// Fetches the most recent snapshot from a trusted, pre-defined location.
Expand Down Expand Up @@ -102,6 +105,7 @@ impl SnapshotCommands {
skip_checksum,
dry_run,
tipset,
depth,
} => {
let chain_head = match chain_head(&config.client.rpc_token).await {
Ok(head) => head.0,
Expand Down Expand Up @@ -130,13 +134,21 @@ impl SnapshotCommands {

let params = ChainExportParams {
epoch,
recent_roots: config.chain.recent_state_roots,
recent_roots: depth.unwrap_or(config.chain.recent_state_roots),
output_path: temp_path.to_path_buf(),
tipset_keys: TipsetKeysJson(chain_head.key().clone()),
skip_checksum,
dry_run,
};

let finality = config.chain.policy.chain_finality.min(epoch);
if params.recent_roots < finality {
bail!(
"For {}, depth has to be at least {finality}.",
config.chain.network
);
}

let handle = tokio::spawn({
let tmp_file = temp_path.to_owned();
let output_path = output_path.clone();
Expand Down