snapshot

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNonce                 = errors.New("invalid nonce specified")
	ErrSnapshotNotFound             = errors.New("not found snapshot")
	ErrUnauthorizedProposer         = errors.New("unauthorized proposer")
	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) AddVote

func (s *Snapshot) AddVote(
	voter types.Address,
	candidate validators.Validator,
	authorize bool,
)

AddVote adds a vote to snapshot

func (*Snapshot) Copy

func (s *Snapshot) Copy() *Snapshot

Copy makes a copy of the snapshot

func (*Snapshot) Count

func (s *Snapshot) Count(h func(v *store.Vote) bool) (count int)

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) Equal

func (s *Snapshot) Equal(ss *Snapshot) bool

Equal checks if two snapshots are equal

func (*Snapshot) MarshalJSON

func (s *Snapshot) MarshalJSON() ([]byte, error)

func (*Snapshot) RemoveVotes

func (s *Snapshot) RemoveVotes(shouldRemoveFn func(v *store.Vote) bool)

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

func (s *Snapshot) RemoveVotesByVoter(
	address types.Address,
)

RemoveVotesByVoter is a helper method to remove all votes created by specified address

func (*Snapshot) UnmarshalJSON

func (s *Snapshot) UnmarshalJSON(data []byte) error

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

func (s *SnapshotValidatorStore) ModifyHeader(header *types.Header, proposer types.Address) error

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

func (*SnapshotValidatorStore) Votes

func (s *SnapshotValidatorStore) Votes(height uint64) ([]*store.Vote, error)

Votes returns the votes in the snapshot at the specified height

Jump to

Keyboard shortcuts

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