nicer check using Time objects

This commit is contained in:
vyzo
2020-11-05 18:08:52 +02:00
parent c6cd699f0d
commit 0e40a04975
+5 -5
View File
@@ -85,13 +85,13 @@ func RunChainExchange(h host.Host, svc exchange.Server) {
}
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
}
@@ -110,8 +110,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
}