Documentation ¶
Index ¶
- Variables
- type VersionedUnmarshaler
- func (cf *VersionedUnmarshaler) UnmarshalBeaconBlock(marshaled []byte) (interfaces.SignedBeaconBlock, error)
- func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state.BeaconState, err error)
- func (cf *VersionedUnmarshaler) UnmarshalBlindedBeaconBlock(marshaled []byte) (interfaces.SignedBeaconBlock, error)
Constants ¶
This section is empty.
Variables ¶
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.