diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-01-24 11:49:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-24 11:49:25 +0800 |
commit | b6ca251bcb6e1a19a7276afe68bf37a4372670fa (patch) | |
tree | b1aac8e9759f150d58009020cd92b579e766895c /core/agreement.go | |
parent | 779f63a9f6fc3f4c628f0b97c822546ac51d0eb6 (diff) | |
download | dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.tar dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.tar.gz dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.tar.bz2 dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.tar.lz dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.tar.xz dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.tar.zst dexon-consensus-b6ca251bcb6e1a19a7276afe68bf37a4372670fa.zip |
core: Add vote filter (#430)
* core: ignore usless vote
* core: export SkipBlockHash and NullBlockHash
* core: add VoteFilter
* Add test
* New VoteFilter for each round
Diffstat (limited to 'core/agreement.go')
-rw-r--r-- | core/agreement.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/core/agreement.go b/core/agreement.go index ebb9b02..c08518a 100644 --- a/core/agreement.go +++ b/core/agreement.go @@ -176,7 +176,7 @@ func (a *agreement) restart( a.data.blocks = make(map[types.NodeID]*types.Block) a.data.requiredVote = len(notarySet)/3*2 + 1 a.data.leader.restart(crs) - a.data.lockValue = nullBlockHash + a.data.lockValue = types.NullBlockHash a.data.lockIter = 0 a.data.isLeader = a.data.ID == leader if a.doneChan != nil { @@ -352,6 +352,17 @@ func (a *agreement) prepareVote(vote *types.Vote) (err error) { return } +func (a *agreement) updateFilter(filter *utils.VoteFilter) { + a.lock.RLock() + defer a.lock.RUnlock() + a.data.lock.RLock() + defer a.data.lock.RUnlock() + filter.Confirm = a.hasOutput + filter.LockIter = a.data.lockIter + filter.Period = a.data.period + filter.Height = a.agreementID().Height +} + // processVote is the entry point for processing Vote. func (a *agreement) processVote(vote *types.Vote) error { a.lock.Lock() @@ -394,13 +405,16 @@ func (a *agreement) processVote(vote *types.Vote) error { if _, exist := a.data.votes[vote.Period]; !exist { a.data.votes[vote.Period] = newVoteListMap() } + if _, exist := a.data.votes[vote.Period][vote.Type][vote.ProposerID]; exist { + return nil + } a.data.votes[vote.Period][vote.Type][vote.ProposerID] = vote if !a.hasOutput && (vote.Type == types.VoteCom || vote.Type == types.VoteFast || vote.Type == types.VoteFastCom) { if hash, ok := a.data.countVoteNoLock(vote.Period, vote.Type); ok && - hash != skipBlockHash { + hash != types.SkipBlockHash { if vote.Type == types.VoteFast { if !a.hasVoteFast { a.data.recv.ProposeVote( @@ -427,8 +441,12 @@ func (a *agreement) processVote(vote *types.Vote) error { return nil } if vote.Type == types.VotePreCom { + if vote.Period < a.data.lockIter { + // This PreCom is useless for us. + return nil + } if hash, ok := a.data.countVoteNoLock(vote.Period, vote.Type); ok && - hash != skipBlockHash { + hash != types.SkipBlockHash { // Condition 1. if a.data.period >= vote.Period && vote.Period > a.data.lockIter && vote.BlockHash != a.data.lockValue { @@ -453,7 +471,8 @@ func (a *agreement) processVote(vote *types.Vote) error { hashes := common.Hashes{} addPullBlocks := func(voteType types.VoteType) { for _, vote := range a.data.votes[vote.Period][voteType] { - if vote.BlockHash == nullBlockHash || vote.BlockHash == skipBlockHash { + if vote.BlockHash == types.NullBlockHash || + vote.BlockHash == types.SkipBlockHash { continue } if _, found := a.findCandidateBlockNoLock(vote.BlockHash); !found { @@ -461,7 +480,6 @@ func (a *agreement) processVote(vote *types.Vote) error { } } } - addPullBlocks(types.VoteInit) addPullBlocks(types.VotePreCom) addPullBlocks(types.VoteCom) if len(hashes) > 0 { |