diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-31 12:51:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-31 12:51:54 +0800 |
commit | eccdddbff92c1588e628f874d73ae557351c76f7 (patch) | |
tree | 799e888f2223e53d88391b15f507226208ef349c /core/agreement-state.go | |
parent | 43a5264814bf318e6bd133fb0df51351f0811ddb (diff) | |
download | dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.gz dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.bz2 dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.lz dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.xz dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.tar.zst dexon-consensus-eccdddbff92c1588e628f874d73ae557351c76f7.zip |
core: Add a repeat vote state. (#280)
Diffstat (limited to 'core/agreement-state.go')
-rw-r--r-- | core/agreement-state.go | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/core/agreement-state.go b/core/agreement-state.go index 56c6c27..77195ac 100644 --- a/core/agreement-state.go +++ b/core/agreement-state.go @@ -19,7 +19,6 @@ package core import ( "fmt" - "math" "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/types" @@ -40,6 +39,7 @@ const ( statePreCommit stateCommit stateForward + stateRepeatVote ) var nullBlockHash = common.Hash{} @@ -127,26 +127,54 @@ func (s *commitState) nextState() (agreementState, error) { } else { hash = skipBlockHash } - s.a.recv.ProposeVote(&types.Vote{ + vote := &types.Vote{ Type: types.VoteCom, BlockHash: hash, Period: s.a.period, - }) - return newForwardState(s.a), nil + } + s.a.recv.ProposeVote(vote) + return newForwardState(s.a, vote), nil } // ----- ForwardState ----- type forwardState struct { - a *agreementData + a *agreementData + vote *types.Vote } -func newForwardState(a *agreementData) *forwardState { - return &forwardState{a: a} +func newForwardState(a *agreementData, vote *types.Vote) *forwardState { + return &forwardState{ + a: a, + vote: vote, + } } func (s *forwardState) state() agreementStateType { return stateForward } -func (s *forwardState) clocks() int { return math.MaxInt32 } +func (s *forwardState) clocks() int { return 4 } func (s *forwardState) nextState() (agreementState, error) { + return newRepeatVoteState(s.a, s.vote), nil +} + +// ----- RepeatVoteState ----- +// repeateVoteState is a special state to ensure the assumption in the consensus +// algorithm that every vote will eventually arrive for all nodes. +type repeatVoteState struct { + a *agreementData + vote *types.Vote +} + +func newRepeatVoteState(a *agreementData, vote *types.Vote) *repeatVoteState { + return &repeatVoteState{ + a: a, + vote: vote, + } +} + +func (s *repeatVoteState) state() agreementStateType { return stateRepeatVote } +func (s *repeatVoteState) clocks() int { return 4 } + +func (s *repeatVoteState) nextState() (agreementState, error) { + s.a.recv.ProposeVote(s.vote) return s, nil } |