From fbe6ddc62f7ebed15c6705f108d36d889c15e73d Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Wed, 3 Apr 2019 13:42:25 +0800 Subject: dex: get synced consensus before sleep (#331) --- dex/blockproposer.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'dex/blockproposer.go') diff --git a/dex/blockproposer.go b/dex/blockproposer.go index c035eda7c..0b66a6cc1 100644 --- a/dex/blockproposer.go +++ b/dex/blockproposer.go @@ -193,6 +193,7 @@ Loop: log.Debug("Listen chain head event until synced") + nextDMoment := time.Now().Unix() // Listen chain head event until synced. ListenLoop: for { @@ -244,9 +245,8 @@ ListenLoop: // We set T_i = 600 to be safe. interval := int64(600) - nextDMoment := (time.Now().Unix()/interval + 1) * interval + nextDMoment = (time.Now().Unix()/interval + 1) * interval log.Info("Sleeping until next starting time", "time", nextDMoment) - time.Sleep(time.Duration(nextDMoment-time.Now().Unix()) * time.Second) b.dex.protocolManager.SetReceiveCoreMessage(true) consensusSync.ForceSync(true) @@ -254,5 +254,7 @@ ListenLoop: } } - return consensusSync.GetSyncedConsensus() + con, err := consensusSync.GetSyncedConsensus() + time.Sleep(time.Duration(nextDMoment-time.Now().Unix()) * time.Second) + return con, err } -- cgit v1.2.3