Skip to content

Commit

Permalink
ui for sector fail
Browse files Browse the repository at this point in the history
  • Loading branch information
snadrus committed May 3, 2024
1 parent c9ab4e6 commit 672221d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
17 changes: 16 additions & 1 deletion cmd/curio/guidedsetup/guidedsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,22 @@ func configToDB(d *MigrationData) {

chainApiInfo := fmt.Sprintf("%s:%s", string(token), ainfo.Addr)

d.MinerID, err = SaveConfigToLayerMigrateSectors(d.MinerConfigPath, chainApiInfo)
shouldErrPrompt := func() bool {
i, _, err := (&promptui.Select{
Label: d.T("Unmigratable sectors found. Do you want to continue?"),
Items: []string{
d.T("Yes, continue"),
d.T("No, abort")},
Templates: d.selectTemplates,
}).Run()
if err != nil {
d.say(notice, "Aborting migration.", err.Error())
os.Exit(1)
}
return i == 1
}

d.MinerID, err = SaveConfigToLayerMigrateSectors(d.MinerConfigPath, chainApiInfo, shouldErrPrompt)
if err != nil {
d.say(notice, "Error saving config to layer: %s. Aborting Migration", err.Error())
os.Exit(1)
Expand Down
10 changes: 5 additions & 5 deletions cmd/curio/guidedsetup/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (

const FlagMinerRepoDeprecation = "storagerepo"

func SaveConfigToLayerMigrateSectors(minerRepoPath, chainApiInfo string) (minerAddress address.Address, err error) {
func SaveConfigToLayerMigrateSectors(minerRepoPath, chainApiInfo string, unmigSectorShouldFail func() bool) (minerAddress address.Address, err error) {
_, say := SetupLanguage()
ctx := context.Background()

Expand Down Expand Up @@ -116,7 +116,7 @@ func SaveConfigToLayerMigrateSectors(minerRepoPath, chainApiInfo string) (minerA

if err := MigrateSectors(ctx, addr, mmeta, db, func(nSectors int) {
say(plain, "Migrating metadata for %d sectors.", nSectors)
}); err != nil {
}, unmigSectorShouldFail); err != nil {
return address.Address{}, xerrors.Errorf("migrating sectors: %w", err)
}

Expand Down Expand Up @@ -281,7 +281,7 @@ func coalescePtrs[A any](a, b *A) *A {
return b
}

func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.Batching, db *harmonydb.DB, logMig func(int)) error {
func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.Batching, db *harmonydb.DB, logMig func(int), unmigSectorShouldFail func() bool) error {
mid, err := address.IDFromAddress(maddr)
if err != nil {
return xerrors.Errorf("getting miner ID: %w", err)
Expand Down Expand Up @@ -320,8 +320,8 @@ func MigrateSectors(ctx context.Context, maddr address.Address, mmeta datastore.
fmt.Printf(" %s: %d\n", state, count)
}

if os.Getenv("CURIO_SKIP_UNMIGRATABLE_SECTORS") != "1" {
return xerrors.Errorf("cannot migrate sectors with these states. Set CURIO_SKIP_UNMIGRATABLE_SECTORS=1 to proceed anyway")
if unmigSectorShouldFail() {
return xerrors.Errorf("aborting migration because sectors were found that are not migratable.")
}
}

Expand Down
10 changes: 9 additions & 1 deletion cmd/curio/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ var sealMigrateLMSectorsCmd = &cli.Command{
Usage: "Path to miner repo",
Value: "~/.lotusminer",
},
&cli.BoolFlag{
Name: "seal-ignore",
Usage: "Ignore sectors that cannot be migrated",
Value: false,
EnvVars: []string{"CURUO_MIGRATE_SEAL_IGNORE"},
},
},
Action: func(cctx *cli.Context) error {
ctx := lcli.ReqContext(cctx)
Expand Down Expand Up @@ -196,9 +202,11 @@ var sealMigrateLMSectorsCmd = &cli.Command{
return xerrors.Errorf("parsing miner actor address: %w", err)
}

unmigSectorShouldFail := func() bool { return !cctx.Bool("seal-ignore") }

err = guidedsetup.MigrateSectors(ctx, addr, mmeta, db, func(n int) {
fmt.Printf("Migrating %d sectors\n", n)
})
}, unmigSectorShouldFail)
if err != nil {
return xerrors.Errorf("migrating sectors: %w", err)
}
Expand Down

0 comments on commit 672221d

Please sign in to comment.