diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-02-27 11:03:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 11:03:18 +0800 |
commit | 9e18a2b406b58e4b44eea4d5741f71f689f8022c (patch) | |
tree | 5d57be5631f350c833cd9bef3b83d47c404f068d /core/syncer/consensus.go | |
parent | fc8aae4eb1608ce574f853a1b1ecd60014886882 (diff) | |
download | tangerine-consensus-9e18a2b406b58e4b44eea4d5741f71f689f8022c.tar.gz tangerine-consensus-9e18a2b406b58e4b44eea4d5741f71f689f8022c.tar.zst tangerine-consensus-9e18a2b406b58e4b44eea4d5741f71f689f8022c.zip |
syncer: fix syncer panic (#456)
* Fix syncer panic
We can't verify correctness for randomness result from rounds that
corresponding configurations are not ready yet.
* Fix blocks are not confirmed while they should be
Diffstat (limited to 'core/syncer/consensus.go')
-rw-r--r-- | core/syncer/consensus.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/syncer/consensus.go b/core/syncer/consensus.go index 566b3f4..7ba659f 100644 --- a/core/syncer/consensus.go +++ b/core/syncer/consensus.go @@ -73,6 +73,7 @@ type Consensus struct { // lock for accessing all fields. lock sync.RWMutex duringBuffering bool + latestCRSRound uint64 moduleWaitGroup sync.WaitGroup agreementWaitGroup sync.WaitGroup pullChan chan common.Hash @@ -416,6 +417,11 @@ func (con *Consensus) cacheRandomnessResult(r *types.BlockRandomnessResult) { if len(con.blocks) > 0 && r.Position.Older(con.blocks[0].Position) { return true } + if r.Position.Round > con.latestCRSRound { + // We can't process randomness from rounds that its CRS is still + // unknown. + return true + } _, exists := con.randomnessResults[r.BlockHash] return exists }() { @@ -486,6 +492,11 @@ func (con *Consensus) startCRSMonitor() { } con.logger.Debug("CRS is ready", "round", round) lastNotifiedRound = round + func() { + con.lock.Lock() + defer con.lock.Unlock() + con.latestCRSRound = round + }() for func() bool { con.lock.RLock() defer con.lock.RUnlock() |