vote

package
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector is an implementation of VotesCollector interface

func (*Collector) AddInvalidProposal added in v3.0.1

func (c *Collector) AddInvalidProposal(proposal *maxbftpb.ProposalData)

AddInvalidProposal adds an invalid proposal to c.invalidProposals if not exists

func (*Collector) AddPendingVote

func (c *Collector) AddPendingVote(vote *maxbftpb.VoteData) error

AddPendingVote add a vote to pending votes cache

func (*Collector) AddVote

func (c *Collector) AddVote(vote *maxbftpb.VoteData) error

AddVote add a vote to votes cache

func (*Collector) GetInvalidProposal added in v3.0.1

func (c *Collector) GetInvalidProposal(blockId string) *maxbftpb.ProposalData

GetInvalidProposal queries invalid proposal from c.invalidProposals and returns it if exists

func (*Collector) GetVotesByView

func (c *Collector) GetVotesByView(view uint64) []*maxbftpb.VoteData

GetVotesByView retrieve votes by view

func (*Collector) PruneView

func (c *Collector) PruneView(view uint64)

PruneView prune votes that before specified view from votes cache and pending votes cache

func (*Collector) SwitchEpoch

func (c *Collector) SwitchEpoch(contract *maxbftpb.GovernanceContract)

SwitchEpoch update the state to a new epoch

func (*Collector) TryBuildQc

func (c *Collector) TryBuildQc(proposal *maxbftpb.ProposalData) (*maxbftpb.QuorumCert, error)

TryBuildQc builds a quorum certification for a proposal when valid votes count reaches the quorum

type Voter

type Voter interface {
	// SwitchEpoch update the state to a new epoch
	SwitchEpoch(contract *maxbft.GovernanceContract, lastFinalView uint64)
	// GenerateVote generate vote for a valid proposal with current view
	GenerateVote(proposal *maxbft.ProposalData, curView uint64, rejectTxIds []string) (*maxbft.VoteData, error)
	// HasVote judges a specified vote by nodeId and view is in voter's cache or not
	HasVote(view uint64) bool
	// AddVote adds a vote to voter's cache
	AddVote(data *maxbft.VoteData)
	// PruneView prunes votes before the specified view (it is usually the final view)
	PruneView(view uint64)
	// GetVote returns votes by a specified view
	GetVote(view uint64) *maxbft.VoteData
}

Voter used to generate vote

func NewVoter

func NewVoter(signer protocol.SigningMember, lastView, epochId uint64, id, hashType string,
	logger protocol.Logger) Voter

NewVoter initial and return the object

type VoterImpl

type VoterImpl struct {
	// contains filtered or unexported fields
}

VoterImpl is an implementation of Voter interface

func (*VoterImpl) AddVote

func (v *VoterImpl) AddVote(vote *maxbft.VoteData)

AddVote adds a vote to voter's cache

func (*VoterImpl) GenerateVote

func (v *VoterImpl) GenerateVote(proposal *maxbft.ProposalData, curView uint64, rejectTxIds []string) (
	*maxbft.VoteData, error)

GenerateVote generate vote for a valid proposal with current view

func (*VoterImpl) GetVote

func (v *VoterImpl) GetVote(view uint64) *maxbft.VoteData

GetVote returns votes by a specified view

func (*VoterImpl) HasVote

func (v *VoterImpl) HasVote(view uint64) bool

HasVote judges a specified vote by view is in voter's cache or not

func (*VoterImpl) PruneView

func (v *VoterImpl) PruneView(view uint64)

PruneView prunes votes before the specified view (it is usually the final view)

func (*VoterImpl) SwitchEpoch

func (v *VoterImpl) SwitchEpoch(contract *maxbft.GovernanceContract, lastView uint64)

SwitchEpoch update the state to a new epoch

type VotesCollector

type VotesCollector interface {
	// PruneView prune votes that before specified view from votes cache and pending votes cache
	PruneView(view uint64)
	// AddVote add a vote to votes cache
	AddVote(vote *maxbftpb.VoteData) error
	// AddPendingVote add a vote to pending votes cache
	AddPendingVote(vote *maxbftpb.VoteData) error
	// SwitchEpoch update the state to a new epoch
	SwitchEpoch(contract *maxbftpb.GovernanceContract)
	// TryBuildQc builds a quorum certification for a proposal when valid votes count reaches the quorum
	TryBuildQc(proposal *maxbftpb.ProposalData) (*maxbftpb.QuorumCert, error)
	// GetVotesByView retrieve votes by view
	GetVotesByView(view uint64) []*maxbftpb.VoteData
	// AddInvalidProposal adds a invalid proposal to the cache
	AddInvalidProposal(proposal *maxbftpb.ProposalData)
	// GetInvalidProposal queries an invalidProposal in the cache by the specified block hash and returns it
	GetInvalidProposal(blockId string) *maxbftpb.ProposalData
}

VotesCollector defines a vote collector to collect and process votes, and build qc

func NewVotesCollector

func NewVotesCollector(verifier verifier.Verifier, quorum, minNodes uint, logger protocol.Logger) VotesCollector

NewVotesCollector initial and return aCollector object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL