github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/votecollector/common.go (about) 1 package votecollector 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/koko1123/flow-go-1/consensus/hotstuff" 8 "github.com/koko1123/flow-go-1/consensus/hotstuff/model" 9 ) 10 11 var ( 12 VoteForIncompatibleViewError = errors.New("vote for incompatible view") 13 VoteForIncompatibleBlockError = errors.New("vote for incompatible block") 14 ) 15 16 /******************************* NoopProcessor *******************************/ 17 18 // NoopProcessor implements hotstuff.VoteProcessor. It drops all votes. 19 type NoopProcessor struct { 20 status hotstuff.VoteCollectorStatus 21 } 22 23 func NewNoopCollector(status hotstuff.VoteCollectorStatus) *NoopProcessor { 24 return &NoopProcessor{status} 25 } 26 27 func (c *NoopProcessor) Process(*model.Vote) error { return nil } 28 func (c *NoopProcessor) Status() hotstuff.VoteCollectorStatus { return c.status } 29 30 /************************ enforcing vote is for block ************************/ 31 32 // EnsureVoteForBlock verifies that the vote is for the given block. 33 // Returns nil on success and sentinel errors: 34 // - model.VoteForIncompatibleViewError if the vote is from a different view than block 35 // - model.VoteForIncompatibleBlockError if the vote is from the same view as block 36 // but for a different blockID 37 func EnsureVoteForBlock(vote *model.Vote, block *model.Block) error { 38 if vote.View != block.View { 39 return fmt.Errorf("vote %v has view %d while block's view is %d: %w ", vote.ID(), vote.View, block.View, VoteForIncompatibleViewError) 40 } 41 if vote.BlockID != block.BlockID { 42 return fmt.Errorf("expecting only votes for block %v, but vote %v is for block %v: %w ", block.BlockID, vote.ID(), vote.BlockID, VoteForIncompatibleBlockError) 43 } 44 return nil 45 }