diff options
-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 |