detect

package
v5.1.3-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForkNotFound = errors.New("version found in fork schedule but can't be matched to a named fork")

Functions

This section is empty.

Types

type VersionedUnmarshaler

type VersionedUnmarshaler struct {
	Config *params.BeaconChainConfig
	// Fork aligns with the fork names in config/params/values.go
	Fork int
	// Version corresponds to the Version type defined in the beacon-chain spec, aka a "fork version number":
	// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#custom-types
	Version [fieldparams.VersionLength]byte
}

VersionedUnmarshaler represents the intersection of Configuration (eg mainnet, testnet) and Fork (eg phase0, altair). Using a detected VersionedUnmarshaler, a BeaconState or ReadOnlySignedBeaconBlock can be correctly unmarshaled without the need to hard code a concrete type in paths where only the marshaled bytes, or marshaled bytes and a version, are available.

func FromBlock

func FromBlock(marshaled []byte) (*VersionedUnmarshaler, error)

FromBlock uses the known size of an offset and signature to determine the slot of a block without unmarshalling it. The slot is used to determine the version along with the respective config.

func FromForkVersion

func FromForkVersion(cv [fieldparams.VersionLength]byte) (*VersionedUnmarshaler, error)

FromForkVersion uses a lookup table to resolve a Version (from a beacon node api for instance, or obtained by peeking at the bytes of a marshaled BeaconState) to a VersionedUnmarshaler.

func FromState

func FromState(marshaled []byte) (*VersionedUnmarshaler, error)

FromState exploits the fixed-size lower-order bytes in a BeaconState as a heuristic to obtain the value of the state.version field without first unmarshaling the BeaconState. The Version is then internally used to lookup the correct ConfigVersion.

func (*VersionedUnmarshaler) UnmarshalBeaconBlock

func (cf *VersionedUnmarshaler) UnmarshalBeaconBlock(marshaled []byte) (interfaces.SignedBeaconBlock, error)

UnmarshalBeaconBlock uses internal knowledge in the VersionedUnmarshaler to pick the right concrete ReadOnlySignedBeaconBlock type, then Unmarshal()s the type and returns an instance of block.ReadOnlySignedBeaconBlock if successful.

func (*VersionedUnmarshaler) UnmarshalBeaconState

func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state.BeaconState, err error)

UnmarshalBeaconState uses internal knowledge in the VersionedUnmarshaler to pick the right concrete BeaconState type, then Unmarshal()s the type and returns an instance of state.BeaconState if successful.

func (*VersionedUnmarshaler) UnmarshalBlindedBeaconBlock

func (cf *VersionedUnmarshaler) UnmarshalBlindedBeaconBlock(marshaled []byte) (interfaces.SignedBeaconBlock, error)

UnmarshalBlindedBeaconBlock uses internal knowledge in the VersionedUnmarshaler to pick the right concrete blinded ReadOnlySignedBeaconBlock type, then Unmarshal()s the type and returns an instance of block.ReadOnlySignedBeaconBlock if successful. For Phase0 and Altair it works exactly line UnmarshalBeaconBlock.

Jump to

Keyboard shortcuts

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