Move some errors to separate consensus-types package (#12329)

* move `ErrNilObjectWrapped` to separate package

* build fix

* move not supported

---------

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka
2023-04-25 17:07:24 +02:00
committed by GitHub
parent 9e3598334d
commit 328e6fb074
22 changed files with 137 additions and 101 deletions

View File

@@ -0,0 +1,12 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["types.go"],
importpath = "github.com/prysmaticlabs/prysm/v4/consensus-types",
visibility = ["//visibility:public"],
deps = [
"//runtime/version:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)

View File

@@ -14,6 +14,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",
@@ -39,6 +40,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",

View File

@@ -6,6 +6,7 @@ import (
fastssz "github.com/prysmaticlabs/fastssz"
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
@@ -24,7 +25,7 @@ type executionPayload struct {
func WrappedExecutionPayload(p *enginev1.ExecutionPayload) (interfaces.ExecutionData, error) {
w := executionPayload{p: p}
if w.IsNil() {
return nil, ErrNilObjectWrapped
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}
@@ -146,17 +147,17 @@ func (e executionPayload) Transactions() ([][]byte, error) {
// TransactionsRoot --
func (e executionPayload) TransactionsRoot() ([]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// Withdrawals --
func (e executionPayload) Withdrawals() ([]*enginev1.Withdrawal, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// WithdrawalsRoot --
func (e executionPayload) WithdrawalsRoot() ([]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// PbBellatrix --
@@ -166,12 +167,12 @@ func (e executionPayload) PbBellatrix() (*enginev1.ExecutionPayload, error) {
// PbCapella --
func (executionPayload) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// ValueInGwei --
func (executionPayload) ValueInGwei() (uint64, error) {
return 0, ErrUnsupportedGetter
return 0, consensus_types.ErrUnsupportedGetter
}
// executionPayloadHeader is a convenience wrapper around a blinded beacon block body's execution header data structure
@@ -185,7 +186,7 @@ type executionPayloadHeader struct {
func WrappedExecutionPayloadHeader(p *enginev1.ExecutionPayloadHeader) (interfaces.ExecutionData, error) {
w := executionPayloadHeader{p: p}
if w.IsNil() {
return nil, ErrNilObjectWrapped
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}
@@ -302,7 +303,7 @@ func (e executionPayloadHeader) BlockHash() []byte {
// Transactions --
func (executionPayloadHeader) Transactions() ([][]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// TransactionsRoot --
@@ -312,27 +313,27 @@ func (e executionPayloadHeader) TransactionsRoot() ([]byte, error) {
// Withdrawals --
func (e executionPayloadHeader) Withdrawals() ([]*enginev1.Withdrawal, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// WithdrawalsRoot --
func (e executionPayloadHeader) WithdrawalsRoot() ([]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// PbCapella --
func (executionPayloadHeader) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// PbBellatrix --
func (executionPayloadHeader) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// ValueInGwei --
func (executionPayloadHeader) ValueInGwei() (uint64, error) {
return 0, ErrUnsupportedGetter
return 0, consensus_types.ErrUnsupportedGetter
}
// PayloadToHeader converts `payload` into execution payload header format.
@@ -375,7 +376,7 @@ type executionPayloadCapella struct {
func WrappedExecutionPayloadCapella(p *enginev1.ExecutionPayloadCapella, value uint64) (interfaces.ExecutionData, error) {
w := executionPayloadCapella{p: p, value: value}
if w.IsNil() {
return nil, ErrNilObjectWrapped
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}
@@ -497,7 +498,7 @@ func (e executionPayloadCapella) Transactions() ([][]byte, error) {
// TransactionsRoot --
func (e executionPayloadCapella) TransactionsRoot() ([]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// Withdrawals --
@@ -507,7 +508,7 @@ func (e executionPayloadCapella) Withdrawals() ([]*enginev1.Withdrawal, error) {
// WithdrawalsRoot --
func (e executionPayloadCapella) WithdrawalsRoot() ([]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// PbCapella --
@@ -517,7 +518,7 @@ func (e executionPayloadCapella) PbCapella() (*enginev1.ExecutionPayloadCapella,
// PbBellatrix --
func (executionPayloadCapella) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// ValueInGwei --
@@ -537,7 +538,7 @@ type executionPayloadHeaderCapella struct {
func WrappedExecutionPayloadHeaderCapella(p *enginev1.ExecutionPayloadHeaderCapella, value uint64) (interfaces.ExecutionData, error) {
w := executionPayloadHeaderCapella{p: p, value: value}
if w.IsNil() {
return nil, ErrNilObjectWrapped
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}
@@ -654,7 +655,7 @@ func (e executionPayloadHeaderCapella) BlockHash() []byte {
// Transactions --
func (executionPayloadHeaderCapella) Transactions() ([][]byte, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// TransactionsRoot --
@@ -664,7 +665,7 @@ func (e executionPayloadHeaderCapella) TransactionsRoot() ([]byte, error) {
// Withdrawals --
func (e executionPayloadHeaderCapella) Withdrawals() ([]*enginev1.Withdrawal, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// WithdrawalsRoot --
@@ -674,12 +675,12 @@ func (e executionPayloadHeaderCapella) WithdrawalsRoot() ([]byte, error) {
// PbCapella --
func (executionPayloadHeaderCapella) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// PbBellatrix --
func (executionPayloadHeaderCapella) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, ErrUnsupportedGetter
return nil, consensus_types.ErrUnsupportedGetter
}
// ValueInGwei --
@@ -755,7 +756,7 @@ func IsEmptyExecutionData(data interfaces.ExecutionData) (bool, error) {
txs, err := data.Transactions()
switch {
case errors.Is(err, ErrUnsupportedGetter):
case errors.Is(err, consensus_types.ErrUnsupportedGetter):
case err != nil:
return false, err
default:

View File

@@ -4,6 +4,7 @@ import (
"testing"
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
@@ -29,7 +30,7 @@ func TestWrapExecutionPayloadHeader(t *testing.T) {
func TestWrapExecutionPayload_IsNil(t *testing.T) {
_, err := blocks.WrappedExecutionPayload(nil)
require.Equal(t, blocks.ErrNilObjectWrapped, err)
require.Equal(t, consensus_types.ErrNilObjectWrapped, err)
data := &enginev1.ExecutionPayload{GasUsed: 54}
wsb, err := blocks.WrappedExecutionPayload(data)
@@ -40,7 +41,7 @@ func TestWrapExecutionPayload_IsNil(t *testing.T) {
func TestWrapExecutionPayloadHeader_IsNil(t *testing.T) {
_, err := blocks.WrappedExecutionPayloadHeader(nil)
require.Equal(t, blocks.ErrNilObjectWrapped, err)
require.Equal(t, consensus_types.ErrNilObjectWrapped, err)
data := &enginev1.ExecutionPayloadHeader{GasUsed: 54}
wsb, err := blocks.WrappedExecutionPayloadHeader(data)
@@ -151,7 +152,7 @@ func TestWrapExecutionPayloadHeaderCapella(t *testing.T) {
func TestWrapExecutionPayloadCapella_IsNil(t *testing.T) {
_, err := blocks.WrappedExecutionPayloadCapella(nil, 0)
require.Equal(t, blocks.ErrNilObjectWrapped, err)
require.Equal(t, consensus_types.ErrNilObjectWrapped, err)
data := &enginev1.ExecutionPayloadCapella{GasUsed: 54}
payload, err := blocks.WrappedExecutionPayloadCapella(data, 0)
@@ -162,7 +163,7 @@ func TestWrapExecutionPayloadCapella_IsNil(t *testing.T) {
func TestWrapExecutionPayloadHeaderCapella_IsNil(t *testing.T) {
_, err := blocks.WrappedExecutionPayloadHeaderCapella(nil, 0)
require.Equal(t, blocks.ErrNilObjectWrapped, err)
require.Equal(t, consensus_types.ErrNilObjectWrapped, err)
data := &enginev1.ExecutionPayloadHeaderCapella{GasUsed: 54}
payload, err := blocks.WrappedExecutionPayloadHeaderCapella(data, 0)
@@ -210,16 +211,16 @@ func Test_executionPayload_Pb(t *testing.T) {
assert.DeepEqual(t, payload.Proto(), pb)
_, err = payload.PbCapella()
require.ErrorIs(t, err, blocks.ErrUnsupportedGetter)
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
}
func Test_executionPayloadHeader_Pb(t *testing.T) {
payload := createWrappedPayloadHeader(t)
_, err := payload.PbBellatrix()
require.ErrorIs(t, err, blocks.ErrUnsupportedGetter)
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
_, err = payload.PbCapella()
require.ErrorIs(t, err, blocks.ErrUnsupportedGetter)
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
}
func Test_executionPayloadCapella_Pb(t *testing.T) {
@@ -229,16 +230,16 @@ func Test_executionPayloadCapella_Pb(t *testing.T) {
assert.DeepEqual(t, payload.Proto(), pb)
_, err = payload.PbBellatrix()
require.ErrorIs(t, err, blocks.ErrUnsupportedGetter)
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
}
func Test_executionPayloadHeaderCapella_Pb(t *testing.T) {
payload := createWrappedPayloadHeaderCapella(t)
_, err := payload.PbBellatrix()
require.ErrorIs(t, err, blocks.ErrUnsupportedGetter)
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
_, err = payload.PbCapella()
require.ErrorIs(t, err, blocks.ErrUnsupportedGetter)
require.ErrorIs(t, err, consensus_types.ErrUnsupportedGetter)
}
func createWrappedPayload(t testing.TB) interfaces.ExecutionData {

View File

@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
@@ -116,7 +117,7 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
// PbPhase0Block returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbPhase0Block() (*eth.SignedBeaconBlock, error) {
if b.version != version.Phase0 {
return nil, ErrNotSupported("PbPhase0Block", b.version)
return nil, consensus_types.ErrNotSupported("PbPhase0Block", b.version)
}
pb, err := b.Proto()
if err != nil {
@@ -128,7 +129,7 @@ func (b *SignedBeaconBlock) PbPhase0Block() (*eth.SignedBeaconBlock, error) {
// PbAltairBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair, error) {
if b.version != version.Altair {
return nil, ErrNotSupported("PbAltairBlock", b.version)
return nil, consensus_types.ErrNotSupported("PbAltairBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
@@ -140,7 +141,7 @@ func (b *SignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair, error
// PbBellatrixBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBellatrixBlock() (*eth.SignedBeaconBlockBellatrix, error) {
if b.version != version.Bellatrix || b.IsBlinded() {
return nil, ErrNotSupported("PbBellatrixBlock", b.version)
return nil, consensus_types.ErrNotSupported("PbBellatrixBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
@@ -152,7 +153,7 @@ func (b *SignedBeaconBlock) PbBellatrixBlock() (*eth.SignedBeaconBlockBellatrix,
// PbBlindedBellatrixBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeaconBlockBellatrix, error) {
if b.version != version.Bellatrix || !b.IsBlinded() {
return nil, ErrNotSupported("PbBlindedBellatrixBlock", b.version)
return nil, consensus_types.ErrNotSupported("PbBlindedBellatrixBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
@@ -164,7 +165,7 @@ func (b *SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeaconB
// PbCapellaBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbCapellaBlock() (*eth.SignedBeaconBlockCapella, error) {
if b.version != version.Capella || b.IsBlinded() {
return nil, ErrNotSupported("PbCapellaBlock", b.version)
return nil, consensus_types.ErrNotSupported("PbCapellaBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
@@ -176,7 +177,7 @@ func (b *SignedBeaconBlock) PbCapellaBlock() (*eth.SignedBeaconBlockCapella, err
// PbBlindedCapellaBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedCapellaBlock() (*eth.SignedBlindedBeaconBlockCapella, error) {
if b.version != version.Capella || !b.IsBlinded() {
return nil, ErrNotSupported("PbBlindedCapellaBlock", b.version)
return nil, consensus_types.ErrNotSupported("PbBlindedCapellaBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
@@ -813,7 +814,7 @@ func (b *BeaconBlockBody) VoluntaryExits() []*eth.SignedVoluntaryExit {
// SyncAggregate returns the sync aggregate in the block.
func (b *BeaconBlockBody) SyncAggregate() (*eth.SyncAggregate, error) {
if b.version == version.Phase0 {
return nil, ErrNotSupported("SyncAggregate", b.version)
return nil, consensus_types.ErrNotSupported("SyncAggregate", b.version)
}
return b.syncAggregate, nil
}
@@ -822,7 +823,7 @@ func (b *BeaconBlockBody) SyncAggregate() (*eth.SyncAggregate, error) {
func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
switch b.version {
case version.Phase0, version.Altair:
return nil, ErrNotSupported("Execution", b.version)
return nil, consensus_types.ErrNotSupported("Execution", b.version)
case version.Bellatrix:
if b.isBlinded {
var ph *enginev1.ExecutionPayloadHeader
@@ -872,7 +873,7 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
func (b *BeaconBlockBody) BLSToExecutionChanges() ([]*eth.SignedBLSToExecutionChange, error) {
if b.version < version.Capella {
return nil, ErrNotSupported("BLSToExecutionChanges", b.version)
return nil, consensus_types.ErrNotSupported("BLSToExecutionChanges", b.version)
}
return b.blsToExecutionChanges, nil
}

View File

@@ -2,6 +2,7 @@ package blocks
import (
"github.com/pkg/errors"
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
@@ -614,7 +615,7 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB
p, err := WrappedExecutionPayload(pb.ExecutionPayload)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
if err != nil && err != consensus_types.ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
@@ -641,7 +642,7 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat
ph, err := WrappedExecutionPayloadHeader(pb.ExecutionPayloadHeader)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
if err != nil && err != consensus_types.ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
@@ -668,7 +669,7 @@ func initBlockBodyFromProtoCapella(pb *eth.BeaconBlockBodyCapella) (*BeaconBlock
p, err := WrappedExecutionPayloadCapella(pb.ExecutionPayload, 0)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
if err != nil && err != consensus_types.ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
@@ -696,7 +697,7 @@ func initBlindedBlockBodyFromProtoCapella(pb *eth.BlindedBeaconBlockBodyCapella)
ph, err := WrappedExecutionPayloadHeaderCapella(pb.ExecutionPayloadHeader, 0)
// We allow the payload to be nil
if err != nil && err != ErrNilObjectWrapped {
if err != nil && err != consensus_types.ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{

View File

@@ -1,6 +1,7 @@
package blocks
import (
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
@@ -95,7 +96,7 @@ func (b *SignedBeaconBlock) SetVoluntaryExits(v []*eth.SignedVoluntaryExit) {
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetSyncAggregate(s *eth.SyncAggregate) error {
if b.version == version.Phase0 {
return ErrNotSupported("SyncAggregate", b.version)
return consensus_types.ErrNotSupported("SyncAggregate", b.version)
}
b.block.body.syncAggregate = s
return nil
@@ -105,7 +106,7 @@ func (b *SignedBeaconBlock) SetSyncAggregate(s *eth.SyncAggregate) error {
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetExecution(e interfaces.ExecutionData) error {
if b.version == version.Phase0 || b.version == version.Altair {
return ErrNotSupported("Execution", b.version)
return consensus_types.ErrNotSupported("Execution", b.version)
}
if b.block.body.isBlinded {
b.block.body.executionPayloadHeader = e
@@ -119,7 +120,7 @@ func (b *SignedBeaconBlock) SetExecution(e interfaces.ExecutionData) error {
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetBLSToExecutionChanges(blsToExecutionChanges []*eth.SignedBLSToExecutionChange) error {
if b.version < version.Capella {
return ErrNotSupported("BLSToExecutionChanges", b.version)
return consensus_types.ErrNotSupported("BLSToExecutionChanges", b.version)
}
b.block.body.blsToExecutionChanges = blsToExecutionChanges
return nil

View File

@@ -1,14 +1,11 @@
package blocks
import (
"fmt"
"github.com/pkg/errors"
field_params "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
)
var (
@@ -28,12 +25,8 @@ const (
)
var (
// ErrUnsupportedGetter is returned when a getter access is not supported for a specific beacon block version.
ErrUnsupportedGetter = errors.New("unsupported getter")
// ErrUnsupportedVersion for beacon block methods.
ErrUnsupportedVersion = errors.New("unsupported beacon block version")
// ErrNilObjectWrapped is returned in a constructor when the underlying object is nil.
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
ErrUnsupportedVersion = errors.New("unsupported beacon block version")
errNilBlock = errors.New("received nil beacon block")
errNilBlockBody = errors.New("received nil beacon block body")
errIncorrectBlockVersion = errors.New(incorrectBlockVersion)
@@ -74,7 +67,3 @@ type SignedBeaconBlock struct {
block *BeaconBlock
signature [field_params.BLSSignatureLength]byte
}
func ErrNotSupported(funcName string, ver int) error {
return errors.Wrap(ErrUnsupportedGetter, fmt.Sprintf("%s is not supported for %s", funcName, version.String(ver)))
}

View File

@@ -10,6 +10,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v4/consensus-types/payload-attribute",
visibility = ["//visibility:public"],
deps = [
"//consensus-types:go_default_library",
"//consensus-types/blocks:go_default_library",
"//proto/engine/v1:go_default_library",
"//runtime/version:go_default_library",

View File

@@ -1,7 +1,7 @@
package payloadattribute
import (
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
consensus_types "github.com/prysmaticlabs/prysm/v4/consensus-types"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
)
@@ -33,7 +33,7 @@ func (a *data) Withdrawals() ([]*enginev1.Withdrawal, error) {
return nil, errNilPayloadAttribute
}
if a.version < version.Capella {
return nil, blocks.ErrNotSupported("Withdrawals", a.version)
return nil, consensus_types.ErrNotSupported("Withdrawals", a.version)
}
return a.withdrawals, nil
}
@@ -44,7 +44,7 @@ func (a *data) PbV1() (*enginev1.PayloadAttributes, error) {
return nil, errNilPayloadAttribute
}
if a.version != version.Bellatrix {
return nil, blocks.ErrNotSupported("PayloadAttributePbV1", a.version)
return nil, consensus_types.ErrNotSupported("PayloadAttributePbV1", a.version)
}
if a.timeStamp == 0 && len(a.prevRandao) == 0 {
return nil, nil
@@ -62,7 +62,7 @@ func (a *data) PbV2() (*enginev1.PayloadAttributesV2, error) {
return nil, errNilPayloadAttribute
}
if a.version != version.Capella {
return nil, blocks.ErrNotSupported("PayloadAttributePbV2", a.version)
return nil, consensus_types.ErrNotSupported("PayloadAttributePbV2", a.version)
}
if a.timeStamp == 0 && len(a.prevRandao) == 0 {
return nil, nil

20
consensus-types/types.go Normal file
View File

@@ -0,0 +1,20 @@
package consensus_types
import (
"errors"
"fmt"
errors2 "github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
)
var (
// ErrNilObjectWrapped is returned in a constructor when the underlying object is nil.
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
// ErrUnsupportedGetter is returned when a getter access is not supported for a specific beacon block version.
ErrUnsupportedGetter = errors.New("unsupported getter")
)
func ErrNotSupported(funcName string, ver int) error {
return errors2.Wrap(ErrUnsupportedGetter, fmt.Sprintf("%s is not supported for %s", funcName, version.String(ver)))
}