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

sync wait --watch #4396

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions cli/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ var syncStatusCmd = &cli.Command{
var syncWaitCmd = &cli.Command{
Name: "wait",
Usage: "Wait for sync to be complete",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "watch",
Usage: "don't exit after node is synced",
},
},
Action: func(cctx *cli.Context) error {
napi, closer, err := GetFullNodeAPI(cctx)
if err != nil {
Expand All @@ -92,7 +98,7 @@ var syncWaitCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)

return SyncWait(ctx, napi)
return SyncWait(ctx, napi, cctx.Bool("watch"))
},
}

Expand Down Expand Up @@ -234,7 +240,7 @@ var syncCheckpointCmd = &cli.Command{
},
}

func SyncWait(ctx context.Context, napi api.FullNode) error {
func SyncWait(ctx context.Context, napi api.FullNode, watch bool) error {
tick := time.Second / 4

lastLines := 0
Expand Down Expand Up @@ -311,7 +317,7 @@ func SyncWait(ctx context.Context, napi api.FullNode) error {

_ = target // todo: maybe print? (creates a bunch of line wrapping issues with most tipsets)

if time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) {
if !watch && time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) {
fmt.Println("\nDone!")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var initCmd = &cli.Command{
log.Info("Checking full node sync status")

if !cctx.Bool("genesis-miner") && !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, api); err != nil {
if err := lcli.SyncWait(ctx, api, false); err != nil {
return xerrors.Errorf("sync wait: %w", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-storage-miner/init_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var initRestoreCmd = &cli.Command{
}

if !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, api); err != nil {
if err := lcli.SyncWait(ctx, api, false); err != nil {
return xerrors.Errorf("sync wait: %w", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-storage-miner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var runCmd = &cli.Command{
log.Info("Checking full node sync status")

if !cctx.Bool("nosync") {
if err := lcli.SyncWait(ctx, nodeApi); err != nil {
if err := lcli.SyncWait(ctx, nodeApi, false); err != nil {
return xerrors.Errorf("sync wait: %w", err)
}
}
Expand Down