github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/integration/filters_test.go (about) 1 package integration 2 3 import ( 4 "math/rand" 5 6 "github.com/onflow/flow-go/consensus/hotstuff/model" 7 "github.com/onflow/flow-go/model/flow" 8 ) 9 10 // VoteFilter is a filter function for dropping Votes. 11 // Return value `true` implies that the the given Vote should be 12 // dropped, while `false` indicates that the Vote should be received. 13 type VoteFilter func(*model.Vote) bool 14 15 func BlockNoVotes(*model.Vote) bool { 16 return false 17 } 18 19 func BlockAllVotes(*model.Vote) bool { 20 return true 21 } 22 23 // BlockVoteRandomly drops votes randomly with a probability of `dropProbability` ∈ [0,1] 24 func BlockVoteRandomly(dropProbability float64) VoteFilter { 25 return func(*model.Vote) bool { 26 return rand.Float64() < dropProbability 27 } 28 } 29 30 func BlockVotesBy(voterID flow.Identifier) VoteFilter { 31 return func(vote *model.Vote) bool { 32 return vote.SignerID == voterID 33 } 34 } 35 36 // ProposalFilter is a filter function for dropping Proposals. 37 // Return value `true` implies that the the given Proposal should be 38 // dropped, while `false` indicates that the Proposal should be received. 39 type ProposalFilter func(*model.Proposal) bool 40 41 func BlockNoProposals(*model.Proposal) bool { 42 return false 43 } 44 45 func BlockAllProposals(*model.Proposal) bool { 46 return true 47 } 48 49 // BlockProposalRandomly drops proposals randomly with a probability of `dropProbability` ∈ [0,1] 50 func BlockProposalRandomly(dropProbability float64) ProposalFilter { 51 return func(*model.Proposal) bool { 52 return rand.Float64() < dropProbability 53 } 54 } 55 56 // BlockProposalsBy drops all proposals originating from the specified `proposerID` 57 func BlockProposalsBy(proposerID flow.Identifier) ProposalFilter { 58 return func(proposal *model.Proposal) bool { 59 return proposal.Block.ProposerID == proposerID 60 } 61 } 62 63 // TimeoutObjectFilter is a filter function for dropping TimeoutObjects. 64 // Return value `true` implies that the the given TimeoutObject should be 65 // dropped, while `false` indicates that the TimeoutObject should be received. 66 type TimeoutObjectFilter func(*model.TimeoutObject) bool 67 68 // BlockAllTimeoutObjects always returns `true`, i.e. drops all TimeoutObjects 69 func BlockAllTimeoutObjects(*model.TimeoutObject) bool { 70 return true 71 } 72 73 // BlockNoTimeoutObjects always returns `false`, i.e. it lets all TimeoutObjects pass. 74 func BlockNoTimeoutObjects(*model.TimeoutObject) bool { 75 return false 76 }