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

Conversation

mb1896
Copy link
Contributor

@mb1896 mb1896 commented Sep 19, 2023

Related Issues

Based on the discussion https://filecoinproject.slack.com/archives/CP50PPW2X/p1695108301930859

Proposed Changes

When user wants to import chain file or snapshot, we will by default remove the local chain data, unless the user says otherwise.

Additional Info

None.

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@mb1896 mb1896 requested a review from a team as a code owner September 19, 2023 18:28
@jennijuju
Copy link
Member

please do follow the pr template and fill the relevant part in!

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.

@mb1896 mb1896 changed the title Auto remove existing chain if importing chain file or snapshot Feat: Lotus Daemon CLI: Auto remove existing chain if importing chain file or snapshot Sep 20, 2023
Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

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

LGTM, feel free to merge after addressing minor comments.

CHANGELOG.md Outdated
@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for including this! It needs to be moved up to the UNRELEASED section, though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed

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): ")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Print("Importing chain or snapshot will by default delete existing local chain data. Do you want to proceed and delete? (yes/no): ")
fmt.Print("Do you want to delete existing local chain data as part of the import process? (yes/no): ")

Copy link
Contributor

Choose a reason for hiding this comment

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

(just a bit more clear, there isn't really a default since we're forcing users to specify)

Copy link
Contributor Author

@mb1896 mb1896 Sep 21, 2023

Choose a reason for hiding this comment

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

You are right, however we couldn't differentiate between

  • user not specifying a flag's value
  • user specifically specifying a flag to false

That's why we have to ask for the user's input...

}
userInput = strings.ToLower(strings.TrimSpace(userInput))

if userInput == "yes" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to handle case-sensitivity here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ToLower() function handled it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants