Skip to content

Commit

Permalink
drop BeaconBlockHeader from beacon state
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Dec 10, 2024
1 parent 0c07e10 commit cf18b5a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 33 deletions.
2 changes: 0 additions & 2 deletions cmd/beacond/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,10 @@ type (

// BeaconStateMarshallable is a type alias for the BeaconState.
BeaconStateMarshallable = types.BeaconState[
*BeaconBlockHeader,
*Eth1Data,
*ExecutionPayloadHeader,
*Fork,
*Validator,
BeaconBlockHeader,
Eth1Data,
ExecutionPayloadHeader,
Fork,
Expand Down
33 changes: 14 additions & 19 deletions consensus-types/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (

// BeaconState represents the entire state of the beacon chain.
type BeaconState[
BeaconBlockHeaderT constraints.
StaticSSZField[BeaconBlockHeaderT, B],
Eth1DataT constraints.
StaticSSZField[Eth1DataT, E],
ExecutionPayloadHeaderT constraints.
Expand All @@ -40,15 +38,15 @@ type BeaconState[
StaticSSZField[ForkT, F],
ValidatorT constraints.
StaticSSZField[ValidatorT, V],
B, E, P, F, V any,
E, P, F, V any,
] struct {
// Versioning
GenesisValidatorsRoot common.Root
Slot math.Slot
Fork ForkT

// History
LatestBlockHeader BeaconBlockHeaderT
LatestBlockHeader *BeaconBlockHeader
BlockRoots []common.Root
StateRoots []common.Root

Expand All @@ -75,18 +73,17 @@ type BeaconState[

// New creates a new BeaconState.
func (st *BeaconState[
BeaconBlockHeaderT,
Eth1DataT,
ExecutionPayloadHeaderT,
ForkT,
ValidatorT,
B, E, P, F, V,
E, P, F, V,
]) New(
_ uint32,
genesisValidatorsRoot common.Root,
slot math.Slot,
fork ForkT,
latestBlockHeader BeaconBlockHeaderT,
latestBlockHeader *BeaconBlockHeader,
blockRoots []common.Root,
stateRoots []common.Root,
eth1Data Eth1DataT,
Expand All @@ -100,20 +97,18 @@ func (st *BeaconState[
slashings []math.Gwei,
totalSlashing math.Gwei,
) (*BeaconState[
BeaconBlockHeaderT,
Eth1DataT,
ExecutionPayloadHeaderT,
ForkT,
ValidatorT,
B, E, P, F, V,
E, P, F, V,
], error) {
return &BeaconState[
BeaconBlockHeaderT,
Eth1DataT,
ExecutionPayloadHeaderT,
ForkT,
ValidatorT,
B, E, P, F, V,
E, P, F, V,
]{
Slot: slot,
GenesisValidatorsRoot: genesisValidatorsRoot,
Expand All @@ -140,7 +135,7 @@ func (st *BeaconState[

// SizeSSZ returns the ssz encoded size in bytes for the BeaconState object.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) SizeSSZ(siz *ssz.Sizer, fixed bool) uint32 {
var size uint32 = 300

Expand All @@ -164,7 +159,7 @@ func (st *BeaconState[
//
//nolint:mnd // todo fix.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) DefineSSZ(codec *ssz.Codec) {
// Versioning
ssz.DefineStaticBytes(codec, &st.GenesisValidatorsRoot)
Expand Down Expand Up @@ -208,22 +203,22 @@ func (st *BeaconState[

// MarshalSSZ marshals the BeaconState into SSZ format.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) MarshalSSZ() ([]byte, error) {
buf := make([]byte, ssz.Size(st))
return buf, ssz.EncodeToBytes(buf, st)
}

// UnmarshalSSZ unmarshals the BeaconState from SSZ format.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) UnmarshalSSZ(buf []byte) error {
return ssz.DecodeFromBytes(buf, st)
}

// HashTreeRoot computes the Merkleization of the BeaconState.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) HashTreeRoot() common.Root {
return ssz.HashConcurrent(st)
}
Expand All @@ -233,7 +228,7 @@ func (st *BeaconState[
/* -------------------------------------------------------------------------- */

func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) MarshalSSZTo(
dst []byte,
) ([]byte, error) {
Expand All @@ -249,7 +244,7 @@ func (st *BeaconState[
//
//nolint:mnd,funlen,gocognit // todo fix.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) HashTreeRootWith(
hh fastssz.HashWalker,
) error {
Expand Down Expand Up @@ -397,7 +392,7 @@ func (st *BeaconState[

// GetTree ssz hashes the BeaconState object.
func (st *BeaconState[
_, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _,
]) GetTree() (*fastssz.Node, error) {
return fastssz.ProofTree(st)
}
8 changes: 0 additions & 8 deletions consensus-types/types/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,20 @@ import (

// generateValidBeaconState generates a valid beacon state for the types.
func generateValidBeaconState() *types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
types.Validator,
] {
return &types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
Expand Down Expand Up @@ -157,12 +153,10 @@ func TestBeaconStateMarshalUnmarshalSSZ(t *testing.T) {
require.NotNil(t, data)

newState := &types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
Expand Down Expand Up @@ -193,12 +187,10 @@ func TestGetTree(t *testing.T) {

func TestBeaconState_UnmarshalSSZ_Error(t *testing.T) {
state := &types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
Expand Down
2 changes: 0 additions & 2 deletions node-api/handlers/proof/merkle/mock/beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ var _ ptypes.BeaconState[
// using the default BeaconState type that is marshallable.
type (
BeaconStateMarshallable = types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
Expand Down
2 changes: 0 additions & 2 deletions state-transition/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ import (

type (
TestBeaconStateMarshallableT = types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
Expand Down

0 comments on commit cf18b5a

Please sign in to comment.