Add blob getters (#13170)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terence 2023-11-04 07:35:56 -07:00 committed by GitHub
parent 12f7143c4f
commit f663f605d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 0 deletions

View File

@ -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
}

View File

@ -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: &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())
}