From 2e1c3c9c3033fefe38ee9651b771c8717887c9d7 Mon Sep 17 00:00:00 2001 From: Cal Bera Date: Wed, 14 Aug 2024 15:27:36 -0400 Subject: [PATCH] Experimental --- mod/consensus-types/pkg/types/block.go | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/mod/consensus-types/pkg/types/block.go b/mod/consensus-types/pkg/types/block.go index 5a6b10131e..d937e24ac9 100644 --- a/mod/consensus-types/pkg/types/block.go +++ b/mod/consensus-types/pkg/types/block.go @@ -24,6 +24,7 @@ import ( "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" "github.com/berachain/beacon-kit/mod/primitives/pkg/version" + "github.com/davecgh/go-spew/spew" fastssz "github.com/ferranbt/fastssz" "github.com/karalabe/ssz" ) @@ -46,7 +47,12 @@ type BeaconBlock struct { // Empty creates an empty beacon block. func (*BeaconBlock) Empty() *BeaconBlock { - return &BeaconBlock{} + return &BeaconBlock{ + Body: &BeaconBlockBody{ + Eth1Data: &Eth1Data{}, + ExecutionPayload: &ExecutionPayload{}, + }, + } } // NewWithVersion assembles a new beacon block from the given. @@ -56,21 +62,16 @@ func (b *BeaconBlock) NewWithVersion( parentBlockRoot common.Root, forkVersion uint32, ) (*BeaconBlock, error) { - var ( - block *BeaconBlock - ) + var block *BeaconBlock switch forkVersion { case version.Deneb: - block = &BeaconBlock{ - Slot: slot, - ProposerIndex: proposerIndex, - ParentRoot: parentBlockRoot, - StateRoot: common.Root{}, - Body: &BeaconBlockBody{}, - } + block = new(BeaconBlock).Empty() + block.Slot = slot + block.ProposerIndex = proposerIndex + block.ParentRoot = parentBlockRoot default: - return &BeaconBlock{}, ErrForkVersionNotSupported + return block, ErrForkVersionNotSupported } return block, nil @@ -81,10 +82,10 @@ func (b *BeaconBlock) NewFromSSZ( bz []byte, forkVersion uint32, ) (*BeaconBlock, error) { - var block = new(BeaconBlock) + var block *BeaconBlock switch forkVersion { case version.Deneb: - block = &BeaconBlock{} + block = new(BeaconBlock).Empty() case version.DenebPlus: panic("unsupported fork version") default: @@ -111,6 +112,9 @@ func (b *BeaconBlock) SizeSSZ(fixed bool) uint32 { // DefineSSZ defines the SSZ encoding for the BeaconBlock object. func (b *BeaconBlock) DefineSSZ(codec *ssz.Codec) { + spew.Dump(b) + spew.Dump(codec) + // Define the static data (fields and dynamic offsets) ssz.DefineUint64(codec, &b.Slot) ssz.DefineUint64(codec, &b.ProposerIndex)