aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-05 11:44:49 +0800
committerGitHub <noreply@github.com>2018-11-05 11:44:49 +0800
commit900643e2ac8c953d10fd3f8f56b9d49ad5b825f6 (patch)
treec02ae2606e19021894e1035162ddd33c971c063a /core
parent740c5775e4fe97eaacd8c8bfe8f39076018565ab (diff)
downloaddexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.tar
dexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.tar.gz
dexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.tar.bz2
dexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.tar.lz
dexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.tar.xz
dexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.tar.zst
dexon-consensus-900643e2ac8c953d10fd3f8f56b9d49ad5b825f6.zip
core: New BA (#295)
Diffstat (limited to 'core')
-rw-r--r--core/agreement.go8
-rw-r--r--core/agreement_test.go4
2 files changed, 7 insertions, 5 deletions
diff --git a/core/agreement.go b/core/agreement.go
index 80c0e2c..f31b7ef 100644
--- a/core/agreement.go
+++ b/core/agreement.go
@@ -160,7 +160,7 @@ func (a *agreement) restart(
a.data.requiredVote = len(notarySet)/3*2 + 1
a.data.leader.restart(crs)
a.data.lockValue = nullBlockHash
- a.data.lockRound = 1
+ a.data.lockRound = 0
a.fastForward = make(chan uint64, 1)
a.hasOutput = false
a.state = newInitialState(a.data)
@@ -237,7 +237,10 @@ func (a *agreement) clocks() int {
// pullVotes returns if current agreement requires more votes to continue.
func (a *agreement) pullVotes() bool {
- return a.state.state() == statePullVote
+ a.data.lock.RLock()
+ defer a.data.lock.RUnlock()
+ return a.state.state() == statePullVote ||
+ (a.state.state() == statePreCommit && (a.data.period%3) == 0)
}
// agreementID returns the current agreementID.
@@ -345,7 +348,6 @@ func (a *agreement) processVote(vote *types.Vote) error {
vote.BlockHash != a.data.lockValue {
a.data.lockValue = hash
a.data.lockRound = vote.Period
- a.fastForward <- a.data.period + 1
return nil
}
// Condition 2.
diff --git a/core/agreement_test.go b/core/agreement_test.go
index 74687ca..127e9e7 100644
--- a/core/agreement_test.go
+++ b/core/agreement_test.go
@@ -236,12 +236,12 @@ func (s *AgreementTestSuite) TestFastForwardCond1() {
select {
case <-a.done():
+ s.FailNow("Unexpected fast forward.")
default:
- s.FailNow("Expecting fast forward.")
}
s.Equal(hash, a.data.lockValue)
s.Equal(uint64(2), a.data.lockRound)
- s.Equal(uint64(4), a.data.period)
+ s.Equal(uint64(3), a.data.period)
// No fast forward if vote.BlockHash == SKIP
a.data.lockRound = 6