voting

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RejectReason added in v0.0.19

func RejectReason(err error) string

RejectReason maps an AddVote error to a bounded label for instructions_rejected_total; unmatched errors return "other". The label set is mirrored by the metrics pre-init (metrics.New) — keep the two in sync.

Types

type Round

type Round struct {
	Voting votingSync // instructionID -> instructionHash -> VoteBox
	// contains filtered or unexported fields
}

Round holds all voting activity that belongs to one signing policy (reward epoch).

func (*Round) MaxVotingWeightBips added in v0.0.21

func (r *Round) MaxVotingWeightBips() float64

MaxVotingWeightBips returns the highest provider weight accumulated by any single voting this epoch, in BIPS of the policy's total voter weight.

func (*Round) ProposerCount added in v0.0.19

func (r *Round) ProposerCount() int

ProposerCount returns the number of distinct initiators (proposers) seen this epoch.

func (*Round) ProviderVoterCount added in v0.0.19

func (r *Round) ProviderVoterCount() int

ProviderVoterCount returns the number of distinct data-provider voters seen this epoch.

func (*Round) ThresholdBips added in v0.0.21

func (r *Round) ThresholdBips() float64

ThresholdBips returns the policy's finalization threshold in BIPS of its total voter weight. Policy-derived, so it is independent of participation.

func (*Round) TopPendingProposals added in v0.0.19

func (r *Round) TopPendingProposals(n int) []limiter.VoterPending

TopPendingProposals returns up to n voters with the most unfinalised proposals this epoch, highest first, excluding voters with none.

func (*Round) VotedWeightBips added in v0.0.21

func (r *Round) VotedWeightBips() float64

VotedWeightBips returns the combined signing-policy weight of this epoch's data-provider voters, in BIPS of the policy's total voter weight.

type Storage

type Storage struct {
	*storage.Cyclic[uint32, *Round]

	// Channel for actions created by voting.
	Out chan *types.Action
	// contains filtered or unexported fields
}

Storage holds one voting Round per signing policy in a cyclic buffer; storing a new round at ID%size overwrites the previous occupant.

func NewStorage

func NewStorage(ctx context.Context, config *config.Voting, meta meta.Meta, m *metrics.Metrics) *Storage

NewStorage creates a voting Storage backed by a cyclic buffer sized by config.HistorySize. ctx is the service-lifetime context that bounds per-box goroutines created during AddVote. m may be nil or disabled.

func (*Storage) AddVote

func (s *Storage) AddVote(data *instruction.Data, signer common.Address, signature []byte) (*voting.Receipt, error)

AddVote records a vote in the appropriate box and returns a signed receipt. Returns an error if the round is missing; opens a new VoteBox for an unseen instruction hash when the proposer is within the limiter's per-voter cap.

func (*Storage) CurrentMaxVotingWeightBips added in v0.0.21

func (s *Storage) CurrentMaxVotingWeightBips() float64

CurrentMaxVotingWeightBips returns the highest provider weight any single voting accumulated in the reported reward epoch, in BIPS of the policy total, or 0 if no round is stored. Round selection matches CurrentVotedWeightBips. Read at scrape time.

func (*Storage) CurrentRoundInitiatorCount added in v0.0.19

func (s *Storage) CurrentRoundInitiatorCount() int

CurrentRoundInitiatorCount returns the distinct initiator count for the reported reward epoch, or 0 if no round is stored. Reports the current reward epoch's round, falling back to its predecessor only while the current round has no accepted provider votes. Read at scrape time.

func (*Storage) CurrentRoundProviderVoterCount added in v0.0.19

func (s *Storage) CurrentRoundProviderVoterCount() int

CurrentRoundProviderVoterCount returns the distinct data-provider-voter count for the reported reward epoch, or 0 if no round is stored. Reports the current reward epoch's round, falling back to its predecessor only while the current round has no accepted provider votes. Read at scrape time.

func (*Storage) CurrentRoundTopPending added in v0.0.19

func (s *Storage) CurrentRoundTopPending(n int) []limiter.VoterPending

CurrentRoundTopPending returns up to n voters with the most unfinalised proposals in the latest reward epoch, or nil if no round is stored. During an epoch-announcement overlap it merges the newest resident round and its predecessor, taking the max pending per provider (not the sum, so a provider present in both rounds is not double-counted). Read at scrape time.

func (*Storage) CurrentVotedWeightBips added in v0.0.21

func (s *Storage) CurrentVotedWeightBips() float64

CurrentVotedWeightBips returns the combined weight of the reported reward epoch's data-provider voters in BIPS of the policy total, or 0 if no round is stored. Reports the current reward epoch's round, falling back to its predecessor only while the current round has no accepted provider votes. Read at scrape time.

func (*Storage) CurrentVotingThresholdBips added in v0.0.21

func (s *Storage) CurrentVotingThresholdBips() float64

CurrentVotingThresholdBips returns the reported reward epoch's finalization threshold in BIPS of its policy total voter weight, or 0 if no round is stored. Round selection matches CurrentVotedWeightBips, so the three weight gauges are comparable. Read at scrape time.

func (*Storage) MaxConsensusEpoch added in v0.0.20

func (s *Storage) MaxConsensusEpoch() uint32

MaxConsensusEpoch returns the highest reward epoch reached by consensus, or 0 if none yet.

func (*Storage) OldestStoredEpoch added in v0.0.19

func (s *Storage) OldestStoredEpoch() (uint32, bool)

OldestStoredEpoch returns the oldest reward epoch with a round still resident in the cyclic buffer, with ok=false when none is stored. The newest resident epoch is the active one, already exposed as policy_active_reward_epoch. Read at scrape time.

func (*Storage) StoreNewRound

func (s *Storage) StoreNewRound(policy *policy.SigningPolicy)

StoreNewRound creates and stores a round for the policy, overwriting the previous occupant at the same cyclic slot. A no-op if a round for this policy already exists.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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