Skip to content

Commit

Permalink
nicer check using Time objects
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Sep 8, 2020
1 parent 1c0c4f8 commit 2df732f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions node/modules/services.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 2df732f

Please sign in to comment.