Merge pull request #717 from filecoin-project/feat/sminer-sync-wait

storageminer: Wait for sync
This commit is contained in:
Łukasz Magiera 2019-12-04 02:26:30 +01:00 committed by GitHub
commit 42b59342ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 52 deletions

View File

@ -1,6 +1,7 @@
package cli
import (
"context"
"fmt"
"time"
@ -73,6 +74,11 @@ var syncWaitCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
return SyncWait(ctx, napi)
},
}
func SyncWait(ctx context.Context, napi api.FullNode) error {
for {
state, err := napi.SyncState(ctx)
if err != nil {
@ -116,5 +122,4 @@ var syncWaitCmd = &cli.Command{
case <-time.After(1 * time.Second):
}
}
},
}

View File

@ -80,6 +80,23 @@ var initCmd = &cli.Command{
return xerrors.Errorf("fetching proof parameters: %w", err)
}
log.Info("Trying to connect to full node RPC")
api, closer, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
log.Info("Checking full node sync status")
if !cctx.Bool("genesis-miner") {
if err := lcli.SyncWait(ctx, api); err != nil {
return xerrors.Errorf("sync wait: %w", err)
}
}
log.Info("Checking if repo exists")
repoPath := cctx.String(FlagStorageRepo)
@ -96,15 +113,6 @@ var initCmd = &cli.Command{
return xerrors.Errorf("repo at '%s' is already initialized", cctx.String(FlagStorageRepo))
}
log.Info("Trying to connect to full node RPC")
api, closer, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
log.Info("Checking full node version")
v, err := api.Version(ctx)

View File

@ -35,6 +35,10 @@ var runCmd = &cli.Command{
Usage: "Enable use of GPU for mining operations",
Value: true,
},
&cli.BoolFlag{
Name: "nosync",
Usage: "Don't check full-node sync status",
},
},
Action: func(cctx *cli.Context) error {
if err := build.GetParams(true, false); err != nil {
@ -61,6 +65,14 @@ var runCmd = &cli.Command{
return xerrors.Errorf("lotus-daemon API version doesn't match: local: ", api.Version{APIVersion: build.APIVersion})
}
log.Info("Checking full node sync status")
if !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, nodeApi); err != nil {
return xerrors.Errorf("sync wait: %w", err)
}
}
storageRepoPath := cctx.String(FlagStorageRepo)
r, err := repo.NewFS(storageRepoPath)
if err != nil {