voter

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateVote

func CreateVote(privKey crypto.PrivKey, block xchain.Block) (*types.Vote, error)

CreateVote creates a vote for the given block.

func GenEmptyStateFile

func GenEmptyStateFile(path string) error

GenEmptyStateFile generates an empty attester state file at the given path. This must be called before LoadVoter.

Types

type IsValDetector added in v0.1.4

type IsValDetector func(valset []abci.ValidatorUpdate) (isValidator bool, statusChanged bool)

IsValDetector is a function that detects if the "IsValidator" status changes for subsequent validator updates.

func NewIsValDetector added in v0.1.4

func NewIsValDetector(localAddr common.Address) IsValDetector

type Voter

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

Voter implements the types.Voter interface. It is responsible for creating and persisting votes. The goal is to ensure "all blocks are votes for".

Note Start must be called only once on startup. GetAvailable, SetProposed, and SetCommitted are thread safe, but must be called after Start.

func LoadVoter

func LoadVoter(privKey crypto.PrivKey, path string, provider xchain.Provider, deps types.VoterDeps,
	network netconf.Network,
) (*Voter, error)

LoadVoter returns a new attester with state loaded from disk.

func (*Voter) AvailableCount added in v0.1.3

func (v *Voter) AvailableCount() int

AvailableCount returns the number of available votes.

func (*Voter) GetAvailable

func (v *Voter) GetAvailable() []*types.Vote

GetAvailable returns a copy of all the available votes.

func (*Voter) LocalAddress

func (v *Voter) LocalAddress() common.Address

func (*Voter) SetCommitted

func (v *Voter) SetCommitted(headers []*types.BlockHeader) error

SetCommitted sets the votes as committed. Persisting the result to disk.

func (*Voter) SetProposed

func (v *Voter) SetProposed(headers []*types.BlockHeader) error

SetProposed sets the votes as proposed.

func (*Voter) Start

func (v *Voter) Start(ctx context.Context)

Start starts runners that attest to each source chain. It does not block, it returns immediately.

func (*Voter) TrimBehind

func (v *Voter) TrimBehind(minsByChain map[types.ChainVersion]uint64) int

TrimBehind trims all available and proposed votes that are behind the vote window thresholds (map[chainID]offset) and returns the number that was deleted.

func (*Voter) UpdateValidators added in v0.1.4

func (v *Voter) UpdateValidators(valset []abci.ValidatorUpdate)

UpdateValidators caches whether this voter is a validator in the provided set.

func (*Voter) Vote

func (v *Voter) Vote(block xchain.Block, allowSkip bool) error

Vote creates a vote for the given block and adds it to the internal state.

func (*Voter) WaitDone

func (v *Voter) WaitDone()

WaitDone waits for all runners to exit. Note the original Start context must be canceled to exit.

Jump to

Keyboard shortcuts

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