From 00335441cee3b8cca76c2b87dd9637aec2c773c0 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Tue, 19 Sep 2023 11:24:12 -0700 Subject: [PATCH 1/5] Auto remove existing chain if importing chain file or snapshot --- cmd/lotus/daemon.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 7271a6e5380..dd61c9f8a1f 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -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 { lr, err := repo.NewFS(cctx.String("repo")) if err != nil { return xerrors.Errorf("error opening fs repo: %w", err) @@ -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 From 10a9eb2155ffffd5e8c7ad4d8f76f32627b6c102 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Wed, 20 Sep 2023 09:33:53 -0700 Subject: [PATCH 2/5] Address review comments --- cmd/lotus/daemon.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index dd61c9f8a1f..0fccc94a263 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -279,7 +279,27 @@ var DaemonCmd = &cli.Command{ willImportChain = true } - if cctx.Bool("remove-existing-chain") || willImportChain { + willRemoveChain := cctx.Bool("remove-existing-chain") + if willImportChain && !willRemoveChain { + // Confirm with the user about the intention to remove chain data. + reader := bufio.NewReader(os.Stdin) + fmt.Print("Importing chain or snapshot will by default delete existing local chain data. Do you want to proceed and delete? (yes/no): ") + userInput, err := reader.ReadString('\n') + if err != nil { + return xerrors.Errorf("reading user input: %w", err) + } + userInput = strings.ToLower(strings.TrimSpace(userInput)) + + if userInput == "yes" { + willRemoveChain = true + } else if userInput == "no" { + willRemoveChain = false + } else { + return fmt.Errorf("Invalid input. Please answer with 'yes' or 'no'.") + } + } + + if willRemoveChain { lr, err := repo.NewFS(cctx.String("repo")) if err != nil { return xerrors.Errorf("error opening fs repo: %w", err) From bdffac300a2b9ab3f424566a1bd94cad17086660 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Wed, 20 Sep 2023 09:39:59 -0700 Subject: [PATCH 3/5] Add to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba9dc94a1c..d7a48e62bae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ This feature release requires a **minimum Go version of v1.19.12 or higher to su - feat: Lotus Gateway: add MpoolPending, ChainGetBlock and MinerGetBaseInfo ([filecoin-project/lotus#10929](https://github.com/filecoin-project/lotus/pull/10929)) ## Improvements + - chore: Auto remove local chain data when importing chain file or snapshot ([filecoin-project/lotus#11277](https://github.com/filecoin-project/lotus/pull/11277)) - chore: update ffi & fvm ([filecoin-project/lotus#11040](https://github.com/filecoin-project/lotus/pull/11040)) - feat: Make sure we don't store duplidate actor events caused to reorgs in events.db ([filecoin-project/lotus#11015](https://github.com/filecoin-project/lotus/pull/11015)) - sealing: Use only non-assigned deals when selecting snap sectors ([filecoin-project/lotus#11002](https://github.com/filecoin-project/lotus/pull/11002)) From 5b9914790c61e2cf4047d49b24abb650b796e657 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Thu, 21 Sep 2023 02:15:26 -0700 Subject: [PATCH 4/5] Fix lint --- cmd/lotus/daemon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 0fccc94a263..58c326586a7 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -295,7 +295,7 @@ var DaemonCmd = &cli.Command{ } else if userInput == "no" { willRemoveChain = false } else { - return fmt.Errorf("Invalid input. Please answer with 'yes' or 'no'.") + return fmt.Errorf("invalid input. please answer with 'yes' or 'no'") } } From 49044b4c69818de2d1bad6a79ae518c8e7692b02 Mon Sep 17 00:00:00 2001 From: Jie Hou Date: Thu, 21 Sep 2023 09:37:44 -0700 Subject: [PATCH 5/5] Address review comments, again --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7a48e62bae..18a7c394846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Lotus changelog # UNRELEASED +- chore: Auto remove local chain data when importing chain file or snapshot ([filecoin-project/lotus#11277](https://github.com/filecoin-project/lotus/pull/11277)) ## New features - feat: Added new tracing API (**HIGHLY EXPERIMENTAL**) supporting two RPC methods: `trace_block` and `trace_replayBlockTransactions` ([filecoin-project/lotus#11100](https://github.com/filecoin-project/lotus/pull/11100)) @@ -34,7 +35,6 @@ This feature release requires a **minimum Go version of v1.19.12 or higher to su - feat: Lotus Gateway: add MpoolPending, ChainGetBlock and MinerGetBaseInfo ([filecoin-project/lotus#10929](https://github.com/filecoin-project/lotus/pull/10929)) ## Improvements - - chore: Auto remove local chain data when importing chain file or snapshot ([filecoin-project/lotus#11277](https://github.com/filecoin-project/lotus/pull/11277)) - chore: update ffi & fvm ([filecoin-project/lotus#11040](https://github.com/filecoin-project/lotus/pull/11040)) - feat: Make sure we don't store duplidate actor events caused to reorgs in events.db ([filecoin-project/lotus#11015](https://github.com/filecoin-project/lotus/pull/11015)) - sealing: Use only non-assigned deals when selecting snap sectors ([filecoin-project/lotus#11002](https://github.com/filecoin-project/lotus/pull/11002))