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: Lotus Daemon CLI: Auto remove existing chain if importing chain file or snapshot #11277

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Changes from 1 commit
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
19 changes: 12 additions & 7 deletions cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,17 @@ var DaemonCmd = &cli.Command{
}
}

if cctx.Bool("remove-existing-chain") {
chainfile := cctx.String("import-chain")
snapshot := cctx.String("import-snapshot")
willImportChain := false
if chainfile != "" || snapshot != "" {
if chainfile != "" && snapshot != "" {
return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'")
}
willImportChain = true
}

if cctx.Bool("remove-existing-chain") || willImportChain {
Copy link
Member

Choose a reason for hiding this comment

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

should we specify the behaviour expected if remove-existing-chain is set to be false yet willImportChain is true? warning & remove, or error out? or follow remove-existing-chainto not remove and continue with import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, maybe we should just error out. Otherwise we are somehow creating undefined behaviors?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mb1896 What I would suggest is:

  • if remove-existing-chain, just remove the chain
  • if it's not specified, prompt the user with a y/n question asking whether they want the chain to be deleted -- if yes, do so, if not proceed without doing so

Copy link
Contributor Author

@mb1896 mb1896 Sep 20, 2023

Choose a reason for hiding this comment

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

Thanks for the comments! Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arajasek Please take another look.

lr, err := repo.NewFS(cctx.String("repo"))
if err != nil {
return xerrors.Errorf("error opening fs repo: %w", err)
Expand All @@ -289,12 +299,7 @@ var DaemonCmd = &cli.Command{
}
}

chainfile := cctx.String("import-chain")
snapshot := cctx.String("import-snapshot")
if chainfile != "" || snapshot != "" {
if chainfile != "" && snapshot != "" {
return fmt.Errorf("cannot specify both 'import-snapshot' and 'import-chain'")
}
if willImportChain {
var issnapshot bool
if chainfile == "" {
chainfile = snapshot
Expand Down