forks

package
v5.0.4-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 13 Imported by: 3

Documentation

Overview

Package forks contains useful helpers for Ethereum consensus fork-related functionality.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPreviousVersion = errors.New("no previous version")

ErrNoPreviousVersion indicates that a version prior to the given version could not be found, because the given version is the first one in the list

View Source
var ErrVersionNotFound = errors.New("could not find an entry in the fork schedule")

ErrVersionNotFound indicates the config package couldn't determine the version for an epoch using the fork schedule.

Functions

func CreateForkDigest

func CreateForkDigest(
	genesisTime time.Time,
	genesisValidatorsRoot []byte,
) ([4]byte, error)

CreateForkDigest creates a fork digest from a genesis time and genesis validators root, utilizing the current slot to determine the active fork version in the node.

func Fork

func Fork(
	targetEpoch primitives.Epoch,
) (*ethpb.Fork, error)

Fork given a target epoch, returns the active fork version during this epoch.

func ForkDigestFromEpoch

func ForkDigestFromEpoch(currentEpoch primitives.Epoch, genesisValidatorsRoot []byte) ([4]byte, error)

ForkDigestFromEpoch retrieves the fork digest from the current schedule determined by the provided epoch.

func IsForkNextEpoch

func IsForkNextEpoch(genesisTime time.Time, genesisValidatorsRoot []byte) (bool, error)

IsForkNextEpoch checks if an allotted fork is in the following epoch.

func LastForkEpoch

func LastForkEpoch() primitives.Epoch

LastForkEpoch returns the last valid fork epoch that exists in our fork schedule.

func NextForkData

func NextForkData(currEpoch primitives.Epoch) ([4]byte, primitives.Epoch, error)

NextForkData retrieves the next fork data according to the provided current epoch.

func RetrieveForkDataFromDigest

func RetrieveForkDataFromDigest(digest [4]byte, genesisValidatorsRoot []byte) ([4]byte, primitives.Epoch, error)

RetrieveForkDataFromDigest performs the inverse, where it tries to determine the fork version and epoch from a provided digest by looping through our current fork schedule.

func SortedForkVersions

func SortedForkVersions(forkSchedule map[[4]byte]primitives.Epoch) [][4]byte

SortedForkVersions sorts the provided fork schedule in ascending order by epoch.

Types

type ForkScheduleEntry

type ForkScheduleEntry struct {
	Version [fieldparams.VersionLength]byte
	Epoch   primitives.Epoch
	Name    string
}

ForkScheduleEntry is a Version+Epoch tuple for sorted storage in an OrderedSchedule

type OrderedSchedule

type OrderedSchedule []ForkScheduleEntry

OrderedSchedule provides a type that can be used to sort the fork schedule and find the Version the chain should be at for a given epoch (via VersionForEpoch) or name (via VersionForName).

func NewOrderedSchedule

func NewOrderedSchedule(b *params.BeaconChainConfig) OrderedSchedule

NewOrderedSchedule Converts fork version maps into a list of Version+Epoch+Name values, ordered by Epoch from lowest to highest. See docs for OrderedSchedule for more detail on what you can do with this type.

func (OrderedSchedule) ForkFromVersion

func (o OrderedSchedule) ForkFromVersion(version [fieldparams.VersionLength]byte) (*ethpb.Fork, error)

func (OrderedSchedule) Len

func (o OrderedSchedule) Len() int

Len implements the Len method of sort.Interface

func (OrderedSchedule) Less

func (o OrderedSchedule) Less(i, j int) bool

Less implements the Less method of sort.Interface

func (OrderedSchedule) Previous

func (OrderedSchedule) Swap

func (o OrderedSchedule) Swap(i, j int)

Swap implements the Swap method of sort.Interface

func (OrderedSchedule) VersionForEpoch

func (o OrderedSchedule) VersionForEpoch(epoch primitives.Epoch) ([fieldparams.VersionLength]byte, error)

VersionForEpoch finds the Version with the highest epoch <= the given epoch

func (OrderedSchedule) VersionForName

func (o OrderedSchedule) VersionForName(name string) ([fieldparams.VersionLength]byte, error)

VersionForName finds the Version corresponding to the lowercase version of the provided name.

Jump to

Keyboard shortcuts

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