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 343d33e commit 32f2a3e
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 32f2a3e

Please sign in to comment.