Documentation ¶
Index ¶
- Variables
- type SignerInterface
- type Snapshot
- func (s *Snapshot) AddVote(voter types.Address, candidate validators.Validator, authorize bool)
- func (s *Snapshot) Copy() *Snapshot
- func (s *Snapshot) Count(h func(v *store.Vote) bool) (count int)
- func (s *Snapshot) CountByCandidate(candidate validators.Validator) int
- func (s *Snapshot) CountByVoterAndCandidate(voter types.Address, candidate validators.Validator) int
- func (s *Snapshot) Equal(ss *Snapshot) bool
- func (s *Snapshot) MarshalJSON() ([]byte, error)
- func (s *Snapshot) RemoveVotes(shouldRemoveFn func(v *store.Vote) bool)
- func (s *Snapshot) RemoveVotesByCandidate(candidate validators.Validator)
- func (s *Snapshot) RemoveVotesByVoter(address types.Address)
- func (s *Snapshot) UnmarshalJSON(data []byte) error
- type SnapshotMetadata
- type SnapshotValidatorStore
- func (s *SnapshotValidatorStore) Candidates() []*store.Candidate
- func (s *SnapshotValidatorStore) GetSnapshotMetadata() *SnapshotMetadata
- func (s *SnapshotValidatorStore) GetSnapshots() []*Snapshot
- func (s *SnapshotValidatorStore) GetValidatorsByHeight(height uint64) (validators.Validators, error)
- func (s *SnapshotValidatorStore) ModifyHeader(header *types.Header, proposer types.Address) error
- func (s *SnapshotValidatorStore) ProcessHeader(header *types.Header) error
- func (s *SnapshotValidatorStore) ProcessHeadersInRange(from, to uint64) error
- func (s *SnapshotValidatorStore) Propose(candidate validators.Validator, auth bool, proposer types.Address) error
- func (s *SnapshotValidatorStore) SourceType() store.SourceType
- func (s *SnapshotValidatorStore) UpdateValidatorSet(newValidators validators.Validators, fromHeight uint64) error
- func (s *SnapshotValidatorStore) VerifyHeader(header *types.Header) error
- func (s *SnapshotValidatorStore) Votes(height uint64) ([]*store.Vote, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidNonce = errors.New("invalid nonce specified") ErrSnapshotNotFound = errors.New("not found snapshot") ErrIncorrectNonce = errors.New("incorrect vote nonce") ErrAlreadyCandidate = errors.New("already a candidate") ErrCandidateIsValidator = errors.New("the candidate is already a validator") ErrCandidateNotExistInSet = errors.New("cannot remove a validator if they're not in the snapshot") ErrAlreadyVoted = errors.New("already voted for this address") ErrMultipleVotesBySameValidator = errors.New("more than one proposal per validator per address found") )
Functions ¶
This section is empty.
Types ¶
type SignerInterface ¶
type SignerInterface interface { Type() validators.ValidatorType EcrecoverFromHeader(*types.Header) (types.Address, error) GetValidators(*types.Header) (validators.Validators, error) }
SignerInterface is an interface of the Signer SnapshotValidatorStore calls
type Snapshot ¶
type Snapshot struct { // block number when the snapshot was created Number uint64 // block hash when the snapshot was created Hash string // votes casted in chronological order Votes []*store.Vote // current set of validators Set validators.Validators }
Snapshot is the current state at a given point in time for validators and votes
func (*Snapshot) Count ¶
Count returns the vote tally. The count increases if the callback function returns true
func (*Snapshot) CountByCandidate ¶
func (s *Snapshot) CountByCandidate( candidate validators.Validator, ) int
CountByCandidateAndVoter is a helper method to count votes by candidate
func (*Snapshot) CountByVoterAndCandidate ¶
func (s *Snapshot) CountByVoterAndCandidate( voter types.Address, candidate validators.Validator, ) int
CountByCandidateAndVoter is a helper method to count votes by voter address and candidate
func (*Snapshot) MarshalJSON ¶
func (*Snapshot) RemoveVotes ¶
RemoveVotes removes the Votes that meet condition defined in the given function
func (*Snapshot) RemoveVotesByCandidate ¶
func (s *Snapshot) RemoveVotesByCandidate( candidate validators.Validator, )
RemoveVotesByCandidate is a helper method to remove all votes to specified candidate
func (*Snapshot) RemoveVotesByVoter ¶
RemoveVotesByVoter is a helper method to remove all votes created by specified address
func (*Snapshot) UnmarshalJSON ¶
type SnapshotMetadata ¶
type SnapshotMetadata struct { // LastBlock represents the latest block in the snapshot LastBlock uint64 }
snapshotMetadata defines the metadata for the snapshot
type SnapshotValidatorStore ¶
type SnapshotValidatorStore struct {
// contains filtered or unexported fields
}
func NewSnapshotValidatorStore ¶
func NewSnapshotValidatorStore( logger hclog.Logger, blockchain store.HeaderGetter, getSigner func(uint64) (SignerInterface, error), epochSize uint64, metadata *SnapshotMetadata, snapshots []*Snapshot, ) (*SnapshotValidatorStore, error)
NewSnapshotValidatorStore creates and initializes *SnapshotValidatorStore
func (*SnapshotValidatorStore) Candidates ¶
func (s *SnapshotValidatorStore) Candidates() []*store.Candidate
Candidates returns the current candidates
func (*SnapshotValidatorStore) GetSnapshotMetadata ¶
func (s *SnapshotValidatorStore) GetSnapshotMetadata() *SnapshotMetadata
GetSnapshotMetadata returns metadata
func (*SnapshotValidatorStore) GetSnapshots ¶
func (s *SnapshotValidatorStore) GetSnapshots() []*Snapshot
GetSnapshots returns all Snapshots
func (*SnapshotValidatorStore) GetValidatorsByHeight ¶
func (s *SnapshotValidatorStore) GetValidatorsByHeight(height uint64) (validators.Validators, error)
GetValidators returns the validator set in the Snapshot for the given height
func (*SnapshotValidatorStore) ModifyHeader ¶
ModifyHeader updates Header to vote
func (*SnapshotValidatorStore) ProcessHeader ¶
func (s *SnapshotValidatorStore) ProcessHeader( header *types.Header, ) error
ProcessHeader processes the header and updates snapshots
func (*SnapshotValidatorStore) ProcessHeadersInRange ¶
func (s *SnapshotValidatorStore) ProcessHeadersInRange( from, to uint64, ) error
ProcessHeadersInRange is a helper function process headers in the given range
func (*SnapshotValidatorStore) Propose ¶
func (s *SnapshotValidatorStore) Propose(candidate validators.Validator, auth bool, proposer types.Address) error
Propose adds new candidate for vote
func (*SnapshotValidatorStore) SourceType ¶
func (s *SnapshotValidatorStore) SourceType() store.SourceType
SourceType returns validator store type
func (*SnapshotValidatorStore) UpdateValidatorSet ¶
func (s *SnapshotValidatorStore) UpdateValidatorSet( newValidators validators.Validators, fromHeight uint64, ) error
UpdateValidatorSet resets Snapshot with given validators at specified height
func (*SnapshotValidatorStore) VerifyHeader ¶
func (s *SnapshotValidatorStore) VerifyHeader(header *types.Header) error
VerifyHeader verifies the fields of Header which are modified in ModifyHeader