Skip to content

Commit

Permalink
Merge pull request #4396 from filecoin-project/feat/syncwait-watch
Browse files Browse the repository at this point in the history
sync wait --watch
  • Loading branch information
magik6k authored Oct 14, 2020
2 parents d02d4bc + ab4f051 commit 6de8236
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
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

0 comments on commit 6de8236

Please sign in to comment.