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

Add --halt-after-import flag to CLI #1835

Merged
merged 12 commits into from
Aug 23, 2022
2 changes: 2 additions & 0 deletions forest/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Client {
pub snapshot: bool,
pub snapshot_height: Option<i64>,
pub snapshot_path: Option<String>,
pub exit_after_import: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to use the same wording as in Lotus which is --halt-after-import.

https://lotus.filecoin.io/lotus/manage/chain-management/#restoring-a-custom-snapshot

Most of Forest cli args are already similar to theirs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know this was a thing. I'll rename it

/// Skips loading import CAR file and assumes it's already been loaded.
/// Will use the CIDs in the header of the file to index the chain.
pub skip_load: bool,
Expand All @@ -44,6 +45,7 @@ impl Default for Client {
rpc_token: None,
snapshot_path: None,
snapshot: false,
exit_after_import: false,
snapshot_height: None,
skip_load: false,
encrypt_keystore: true,
Expand Down
1 change: 1 addition & 0 deletions forest/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod test {
rpc_port: u16::arbitrary(g),
rpc_token: Option::arbitrary(g),
snapshot: bool::arbitrary(g),
exit_after_import: bool::arbitrary(g),
snapshot_height: Option::arbitrary(g),
snapshot_path: Option::arbitrary(g),
skip_load: bool::arbitrary(g),
Expand Down
4 changes: 4 additions & 0 deletions forest/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ pub struct CliOpts {
pub height: Option<i64>,
#[structopt(long, help = "Import a snapshot from a local CAR file or url")]
pub import_snapshot: Option<String>,
#[structopt(long)]
pub import_and_exit: bool,
#[structopt(long, help = "Import a chain from a local CAR file or url")]
pub import_chain: Option<String>,
#[structopt(
Expand Down Expand Up @@ -231,6 +233,8 @@ impl CliOpts {
cfg.client.skip_load = self.skip_load;
}

cfg.client.exit_after_import = self.import_and_exit;

cfg.network.kademlia = self.kademlia.unwrap_or(cfg.network.kademlia);
cfg.network.mdns = self.mdns.unwrap_or(cfg.network.mdns);
if let Some(target_peer_count) = self.target_peer_count {
Expand Down
4 changes: 4 additions & 0 deletions forest/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pub(super) async fn start(config: Config) {

sync_from_snapshot(&config, &state_manager).await;

if config.client.exit_after_import {
cli_error_and_die("Forest finish shutdown.", 0);
}

// Terminate if no snapshot is provided or DB isn't recent enough
match chain_store.heaviest_tipset().await {
None => {
Expand Down