Skip to content

Commit

Permalink
Add blob getters (#13170)
Browse files Browse the repository at this point in the history
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
terencechain and prylabs-bulldozer[bot] authored Nov 4, 2023
1 parent 12f7143 commit f663f60
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
22 changes: 22 additions & 0 deletions consensus-types/blocks/roblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
57 changes: 57 additions & 0 deletions consensus-types/blocks/roblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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: &ethpb.BlobSidecar{
SignedBlockHeader: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
Slot: slot,
},
},
},
}
assert.Equal(t, slot, blob.Slot())
}

func TestParentRoot(t *testing.T) {
root := [32]byte{1}
blob := &ROBlob{
BlobSidecar: &ethpb.BlobSidecar{
SignedBlockHeader: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
ParentRoot: root[:],
},
},
},
}
assert.Equal(t, root, blob.ParentRoot())
}

func TestBodyRoot(t *testing.T) {
root := [32]byte{1}
blob := &ROBlob{
BlobSidecar: &ethpb.BlobSidecar{
SignedBlockHeader: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
BodyRoot: root[:],
},
},
},
}
assert.Equal(t, root, blob.BodyRoot())
}

func TestProposeIndex(t *testing.T) {
index := primitives.ValidatorIndex(1)
blob := &ROBlob{
BlobSidecar: &ethpb.BlobSidecar{
SignedBlockHeader: &ethpb.SignedBeaconBlockHeader{
Header: &ethpb.BeaconBlockHeader{
ProposerIndex: index,
},
},
},
}
assert.Equal(t, index, blob.ProposerIndex())
}

0 comments on commit f663f60

Please sign in to comment.