diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-02-13 10:32:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-13 10:32:53 +0800 |
commit | 7f57f843e14dc1c75c8747bd0e65ee3ee6de6d72 (patch) | |
tree | 3d156111ac48bc2e2aaa6177e0d7311ce2257184 | |
parent | 8ba8902ca54f2c29fb20231821b71b720f467985 (diff) | |
download | dexon-consensus-7f57f843e14dc1c75c8747bd0e65ee3ee6de6d72.tar.gz dexon-consensus-7f57f843e14dc1c75c8747bd0e65ee3ee6de6d72.tar.zst dexon-consensus-7f57f843e14dc1c75c8747bd0e65ee3ee6de6d72.zip |
core: fast forward should close previous done() channel (#444)
* core: fast forward faster
* core: modify unit test
-rw-r--r-- | core/agreement.go | 3 | ||||
-rw-r--r-- | core/agreement_test.go | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/core/agreement.go b/core/agreement.go index 1870a50..10ba354 100644 --- a/core/agreement.go +++ b/core/agreement.go @@ -468,6 +468,7 @@ func (a *agreement) processVote(vote *types.Vote) error { a.data.lockIter = vote.Period } a.fastForward <- vote.Period + close(a.doneChan) return nil } } @@ -493,6 +494,7 @@ func (a *agreement) processVote(vote *types.Vote) error { a.data.recv.PullBlocks(hashes) } a.fastForward <- vote.Period + 1 + close(a.doneChan) return nil } return nil @@ -513,7 +515,6 @@ func (a *agreement) done() <-chan struct{} { } a.data.setPeriod(period) a.state = newPreCommitState(a.data) - close(a.doneChan) a.doneChan = make(chan struct{}) return closedchan default: diff --git a/core/agreement_test.go b/core/agreement_test.go index f49fd7d..4ddff8d 100644 --- a/core/agreement_test.go +++ b/core/agreement_test.go @@ -404,6 +404,7 @@ func (s *AgreementTestSuite) TestFastForwardCond2() { return true, nil }) a.data.period = 1 + done := a.done() hash := common.NewRandomHash() for nID := range a.notarySet { vote := s.prepareVote(nID, types.VotePreCom, hash, uint64(2)) @@ -414,6 +415,11 @@ func (s *AgreementTestSuite) TestFastForwardCond2() { } select { + case <-done: + default: + s.FailNow("Expecting fast forward for pending done() call.") + } + select { case <-a.done(): default: s.FailNow("Expecting fast forward.") @@ -443,6 +449,7 @@ func (s *AgreementTestSuite) TestFastForwardCond3() { return true, nil }) a.data.period = 1 + done := a.done() for nID := range a.notarySet { vote := s.prepareVote(nID, types.VoteCom, common.NewRandomHash(), uint64(2)) votes = append(votes, vote) @@ -453,6 +460,11 @@ func (s *AgreementTestSuite) TestFastForwardCond3() { } select { + case <-done: + default: + s.FailNow("Expecting fast forward for pending done() call.") + } + select { case <-a.done(): default: s.FailNow("Expecting fast forward.") |