github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/integration/filters_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"math/rand"
     5  
     6  	"github.com/koko1123/flow-go-1/consensus/hotstuff/model"
     7  	"github.com/koko1123/flow-go-1/model/flow"
     8  )
     9  
    10  type VoteFilter func(*model.Vote) bool
    11  
    12  func BlockNoVotes(*model.Vote) bool {
    13  	return false
    14  }
    15  
    16  func BlockAllVotes(*model.Vote) bool {
    17  	return true
    18  }
    19  
    20  func BlockVoteRatio(ratio float64) VoteFilter {
    21  	return func(*model.Vote) bool {
    22  		return rand.Float64() <= ratio
    23  	}
    24  }
    25  
    26  func BlockVotesBy(voterID flow.Identifier) VoteFilter {
    27  	return func(vote *model.Vote) bool {
    28  		return vote.SignerID == voterID
    29  	}
    30  }
    31  
    32  type ProposalFilter func(*model.Proposal) bool
    33  
    34  func BlockNoProposals(*model.Proposal) bool {
    35  	return false
    36  }
    37  
    38  func BlockAllProposals(*model.Proposal) bool {
    39  	return true
    40  }
    41  
    42  func BlockProposalRatio(ratio float64) ProposalFilter {
    43  	return func(*model.Proposal) bool {
    44  		return rand.Float64() <= ratio
    45  	}
    46  }
    47  
    48  func BlockProposalsBy(proposerID flow.Identifier) ProposalFilter {
    49  	return func(proposal *model.Proposal) bool {
    50  		return proposal.Block.ProposerID == proposerID
    51  	}
    52  }