From f663f605d24c09513d8c6ff48235d04143171b10 Mon Sep 17 00:00:00 2001 From: terence Date: Sat, 4 Nov 2023 07:35:56 -0700 Subject: [PATCH] Add blob getters (#13170) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- consensus-types/blocks/roblob.go | 22 +++++++++++ consensus-types/blocks/roblob_test.go | 57 +++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/consensus-types/blocks/roblob.go b/consensus-types/blocks/roblob.go index db95fab8a44f..d7a6aa37ae5a 100644 --- a/consensus-types/blocks/roblob.go +++ b/consensus-types/blocks/roblob.go @@ -2,6 +2,8 @@ package blocks import ( "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) @@ -40,3 +42,23 @@ func NewROBlob(b *ethpb.BlobSidecar) (ROBlob, error) { func (b *ROBlob) BlockRoot() [32]byte { return b.root } + +// Slot returns the slot of the blob sidecar. +func (b *ROBlob) Slot() primitives.Slot { + return b.SignedBlockHeader.Header.Slot +} + +// ParentRoot returns the parent root of the blob sidecar. +func (b *ROBlob) ParentRoot() [32]byte { + return bytesutil.ToBytes32(b.SignedBlockHeader.Header.ParentRoot) +} + +// BodyRoot returns the body root of the blob sidecar. +func (b *ROBlob) BodyRoot() [32]byte { + return bytesutil.ToBytes32(b.SignedBlockHeader.Header.BodyRoot) +} + +// ProposerIndex returns the proposer index of the blob sidecar. +func (b *ROBlob) ProposerIndex() primitives.ValidatorIndex { + return b.SignedBlockHeader.Header.ProposerIndex +} diff --git a/consensus-types/blocks/roblob_test.go b/consensus-types/blocks/roblob_test.go index 168ede003f28..af18e6f3971a 100644 --- a/consensus-types/blocks/roblob_test.go +++ b/consensus-types/blocks/roblob_test.go @@ -4,6 +4,7 @@ import ( "testing" fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" + "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" ) @@ -57,3 +58,59 @@ func TestBlockRoot(t *testing.T) { } assert.Equal(t, root, blob.BlockRoot()) } + +func TestSlot(t *testing.T) { + slot := primitives.Slot(1) + blob := &ROBlob{ + BlobSidecar: ðpb.BlobSidecar{ + SignedBlockHeader: ðpb.SignedBeaconBlockHeader{ + Header: ðpb.BeaconBlockHeader{ + Slot: slot, + }, + }, + }, + } + assert.Equal(t, slot, blob.Slot()) +} + +func TestParentRoot(t *testing.T) { + root := [32]byte{1} + blob := &ROBlob{ + BlobSidecar: ðpb.BlobSidecar{ + SignedBlockHeader: ðpb.SignedBeaconBlockHeader{ + Header: ðpb.BeaconBlockHeader{ + ParentRoot: root[:], + }, + }, + }, + } + assert.Equal(t, root, blob.ParentRoot()) +} + +func TestBodyRoot(t *testing.T) { + root := [32]byte{1} + blob := &ROBlob{ + BlobSidecar: ðpb.BlobSidecar{ + SignedBlockHeader: ðpb.SignedBeaconBlockHeader{ + Header: ðpb.BeaconBlockHeader{ + BodyRoot: root[:], + }, + }, + }, + } + assert.Equal(t, root, blob.BodyRoot()) +} + +func TestProposeIndex(t *testing.T) { + index := primitives.ValidatorIndex(1) + blob := &ROBlob{ + BlobSidecar: ðpb.BlobSidecar{ + SignedBlockHeader: ðpb.SignedBeaconBlockHeader{ + Header: ðpb.BeaconBlockHeader{ + ProposerIndex: index, + }, + }, + }, + } + assert.Equal(t, index, blob.ProposerIndex()) +}