proposals

package
v0.2.15-beta.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const NewProposalProtocol = "newProposal"

NewProposalProtocol is the protocol indicator for gossip Proposals.

Variables

View Source
var (
	// ErrZeroTotalWeight is returned when zero total epoch weight is used when calculating eligible slots.
	ErrZeroTotalWeight = errors.New("zero total weight not allowed")
)

Functions

func CalcEligibleLayer

func CalcEligibleLayer(epochNumber types.EpochID, layersPerEpoch uint32, vrfSig []byte) types.LayerID

CalcEligibleLayer calculates the eligible layer from the VRF signature.

func ComputeWeightPerEligibility

func ComputeWeightPerEligibility(
	atxdb atxDB,
	mdb ballotDB,
	ballot *types.Ballot,
	layerSize,
	layersPerEpoch uint32,
) (util.Weight, error)

ComputeWeightPerEligibility computes the ballot weight per eligibility w.r.t the active set recorded in its reference ballot.

func GetNumEligibleSlots

func GetNumEligibleSlots(weight, totalWeight uint64, committeeSize uint32, layersPerEpoch uint32) (uint32, error)

GetNumEligibleSlots calculates the number of eligible slots for a smesher in an epoch.

func SerializeVRFMessage

func SerializeVRFMessage(beacon types.Beacon, epoch types.EpochID, counter uint32) ([]byte, error)

SerializeVRFMessage serializes a message for generating/verifying a VRF signature.

Types

type Config

type Config struct {
	LayerSize      uint32
	LayersPerEpoch uint32
	GoldenATXID    types.ATXID
	MaxExceptions  int
	Hdist          uint32
}

Config defines configuration for the handler.

type DB

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

DB holds all data for proposals.

func NewProposalDB

func NewProposalDB(sqlDB *sql.Database, logger log.Log) (*DB, error)

NewProposalDB returns a new DB for proposals.

func (*DB) AddProposal

func (db *DB) AddProposal(ctx context.Context, p *types.Proposal) error

AddProposal adds a proposal to the database.

func (*DB) Get

func (db *DB) Get(hash []byte) ([]byte, error)

Get Proposal encoded in byte using ProposalID hash.

func (*DB) GetProposal

func (db *DB) GetProposal(id types.ProposalID) (*types.Proposal, error)

GetProposal retrieves a proposal from the database.

func (*DB) GetProposals

func (db *DB) GetProposals(pids []types.ProposalID) ([]*types.Proposal, error)

GetProposals retrieves multiple proposals from the database.

func (*DB) HasProposal

func (db *DB) HasProposal(id types.ProposalID) bool

HasProposal returns true if the database has the Proposal specified by the ProposalID and false otherwise.

func (*DB) LayerProposalIDs

func (db *DB) LayerProposalIDs(lid types.LayerID) ([]types.ProposalID, error)

LayerProposalIDs retrieves all proposal IDs from the layer specified by layer ID.

func (*DB) LayerProposals

func (db *DB) LayerProposals(lid types.LayerID) ([]*types.Proposal, error)

LayerProposals retrieves all proposals from the layer specified by layer ID.

type Handler

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

Handler processes Proposal from gossip and, if deems it valid, propagates it to peers.

func NewHandler

func NewHandler(f system.Fetcher, bc system.BeaconCollector, db atxDB, m meshDB, p proposalDB, opts ...Opt) *Handler

NewHandler creates new Handler.

func (*Handler) HandleBallotData

func (h *Handler) HandleBallotData(ctx context.Context, data []byte) error

HandleBallotData handles Ballot data from sync.

func (*Handler) HandleProposal

func (h *Handler) HandleProposal(ctx context.Context, _ p2p.Peer, msg []byte) pubsub.ValidationResult

HandleProposal is the gossip receiver for Proposal.

func (*Handler) HandleProposalData

func (h *Handler) HandleProposalData(ctx context.Context, data []byte) error

HandleProposalData handles Proposal data from sync.

type Opt

type Opt func(h *Handler)

Opt for configuring Handler.

func WithConfig

func WithConfig(cfg Config) Opt

WithConfig defines protocol parameters.

func WithLogger

func WithLogger(logger log.Log) Opt

WithLogger defines logger for Handler.

type Validator

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

Validator validates the eligibility of a Ballot. the validation focuses on eligibility only and assumes the Ballot to be valid otherwise.

func NewEligibilityValidator

func NewEligibilityValidator(
	avgLayerSize, layersPerEpoch uint32, db atxDB, bc system.BeaconCollector, m meshDB, lg log.Log,
) *Validator

NewEligibilityValidator returns a new EligibilityValidator.

func (*Validator) CheckEligibility

func (v *Validator) CheckEligibility(ctx context.Context, ballot *types.Ballot) (bool, error)

CheckEligibility checks that a ballot is eligible in the layer that it specifies.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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