diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-15 12:05:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-15 12:05:30 +0800 |
commit | 7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258 (patch) | |
tree | 31ea26a7e082e16f1091152f58a9bf04c5ba40b9 | |
parent | 07ca4b1c5b0c193d621d5fc62f10a4eb083ced39 (diff) | |
download | dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.tar dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.tar.gz dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.tar.bz2 dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.tar.lz dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.tar.xz dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.tar.zst dexon-consensus-7b68cc8fa60d91a7c6ed2f78dc851da48d1fc258.zip |
core: Fix issues in syncing mode (#329)
-rw-r--r-- | core/agreement-state.go | 18 | ||||
-rw-r--r-- | core/agreement.go | 8 | ||||
-rw-r--r-- | core/consensus.go | 6 |
3 files changed, 32 insertions, 0 deletions
diff --git a/core/agreement-state.go b/core/agreement-state.go index 9023799..77f2933 100644 --- a/core/agreement-state.go +++ b/core/agreement-state.go @@ -40,6 +40,7 @@ const ( stateCommit stateForward statePullVote + stateSleep ) var nullBlockHash = common.Hash{} @@ -156,3 +157,20 @@ func (s *pullVoteState) clocks() int { return 4 } func (s *pullVoteState) nextState() (agreementState, error) { return s, nil } + +// ----- SleepState ----- +// sleepState is a special state after BA has output and waits for restart. +type sleepState struct { + a *agreementData +} + +func newSleepState(a *agreementData) *sleepState { + return &sleepState{a: a} +} + +func (s *sleepState) state() agreementStateType { return stateSleep } +func (s *sleepState) clocks() int { return 65536 } + +func (s *sleepState) nextState() (agreementState, error) { + return s, nil +} diff --git a/core/agreement.go b/core/agreement.go index f31b7ef..8d47a87 100644 --- a/core/agreement.go +++ b/core/agreement.go @@ -250,6 +250,14 @@ func (a *agreement) agreementID() types.Position { // nextState is called at the specific clock time. func (a *agreement) nextState() (err error) { + if func() bool { + a.lock.RLock() + defer a.lock.RUnlock() + return a.hasOutput + }() { + a.state = newSleepState(a.data) + return + } a.state, err = a.state.nextState() return } diff --git a/core/consensus.go b/core/consensus.go index 931b2db..a8fd3c8 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -839,6 +839,12 @@ func (con *Consensus) proposeEmptyBlock( // ProcessVote is the entry point to submit ont vote to a Consensus instance. func (con *Consensus) ProcessVote(vote *types.Vote) (err error) { + if vote.Position.ChainID >= uint32(len(con.baModules)) { + return nil + } + if isStop(con.baModules[vote.Position.ChainID].agreementID()) { + return nil + } v := vote.Clone() err = con.baModules[v.Position.ChainID].processVote(v) return err |