From 32f2a3e75d0b72ab15db404637263d0cfed093ca Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 8 Sep 2020 10:55:14 +0300 Subject: [PATCH] nicer check using Time objects --- node/modules/services.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/node/modules/services.go b/node/modules/services.go index 8d3455c015f..40b319e8541 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -1,6 +1,8 @@ package modules import ( + "time" + "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" eventbus "github.com/libp2p/go-eventbus" @@ -75,13 +77,13 @@ func RunBlockSync(h host.Host, svc *blocksync.BlockSyncService) { } func waitForSync(stmgr *stmgr.StateManager, epochs int, subscribe func()) { - nearsync := uint64(epochs) * uint64(build.BlockDelaySecs) //nolint + nearsync := time.Duration(epochs*int(build.BlockDelaySecs)) * time.Second // early check, are we synced at start up? ts := stmgr.ChainStore().GetHeaviestTipSet() timestamp := ts.MinTimestamp() - now := uint64(build.Clock.Now().Unix()) - if timestamp > now-nearsync { + timestampTime := time.Unix(int64(timestamp), 0) + if build.Clock.Since(timestampTime) < nearsync { subscribe() return } @@ -100,8 +102,8 @@ func waitForSync(stmgr *stmgr.StateManager, epochs int, subscribe func()) { } } - now := uint64(build.Clock.Now().Unix()) - if latest > now-nearsync { + latestTime := time.Unix(int64(latest), 0) + if build.Clock.Since(latestTime) < nearsync { subscribe() return store.ErrNotifeeDone }