Skip to content

Commit

Permalink
feat: add --depth flag to snapshot export (#3330)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Jones <joshua.jones@chainsafe.io>
Co-authored-by: Hubert <hubert@chainsafe.io>
  • Loading branch information
3 people authored Aug 9, 2023
1 parent fb5354f commit 9e34264
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
multi-threaded car-backed block stores.
- [#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`.
#[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

0 comments on commit 9e34264

Please sign in to comment.