Removes fork-specific concrete type getters (#13941)

* removing typed pb accessors

* refactor ssz api resp handlers to avoid typed pbs

* json get block handler refactor

* SubmitBlindedBlock to use generic json handling

* update SubmitBlindedBlock

* clear out more usages of PbForkname methods

* remove fork-specific getters from block interface

* remove usages of payload pb methods

* remove pb helpers from execution payload interface

* Update beacon-chain/rpc/eth/beacon/handlers.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/rpc/eth/beacon/handlers.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update api/client/builder/client.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update api/client/builder/client.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update api/client/builder/client.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update api/client/builder/client.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update api/client/builder/client.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Radek review

* fix error message

* deal with wonky builder responses

* ✂️

* gaz

* lint

* tweaks for deep source

---------

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
kasey
2024-05-02 15:52:27 -05:00
committed by GitHub
parent 625818d556
commit c312a88aa3
26 changed files with 553 additions and 1442 deletions

View File

@@ -23,6 +23,23 @@ type executionPayload struct {
p *enginev1.ExecutionPayload
}
// NewWrappedExecutionData creates an appropriate execution payload wrapper based on the incoming type.
func NewWrappedExecutionData(v proto.Message, weiValue math.Wei) (interfaces.ExecutionData, error) {
if weiValue == nil {
weiValue = new(big.Int).SetInt64(0)
}
switch pbStruct := v.(type) {
case *enginev1.ExecutionPayload:
return WrappedExecutionPayload(pbStruct)
case *enginev1.ExecutionPayloadCapella:
return WrappedExecutionPayloadCapella(pbStruct, weiValue)
case *enginev1.ExecutionPayloadDeneb:
return WrappedExecutionPayloadDeneb(pbStruct, weiValue)
default:
return nil, ErrUnsupportedVersion
}
}
// WrappedExecutionPayload is a constructor which wraps a protobuf execution payload into an interface.
func WrappedExecutionPayload(p *enginev1.ExecutionPayload) (interfaces.ExecutionData, error) {
w := executionPayload{p: p}
@@ -172,26 +189,6 @@ func (e executionPayload) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// PbBellatrix --
func (e executionPayload) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return e.p, nil
}
// PbCapella --
func (executionPayload) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayload) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (executionPayload) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (executionPayload) ValueInWei() (math.Wei, error) {
return nil, consensus_types.ErrUnsupportedField
@@ -368,26 +365,6 @@ func (e executionPayloadHeader) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (e executionPayloadHeader) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayloadHeader) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (executionPayloadHeader) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbBellatrix --
func (executionPayloadHeader) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (executionPayloadHeader) ValueInWei() (math.Wei, error) {
return nil, consensus_types.ErrUnsupportedField
@@ -594,26 +571,6 @@ func (e executionPayloadCapella) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (executionPayloadCapella) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayloadCapella) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (e executionPayloadCapella) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return e.p, nil
}
// PbBellatrix --
func (executionPayloadCapella) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (e executionPayloadCapella) ValueInWei() (math.Wei, error) {
return e.weiValue, nil
@@ -792,26 +749,6 @@ func (e executionPayloadHeaderCapella) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (executionPayloadHeaderCapella) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayloadHeaderCapella) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (executionPayloadHeaderCapella) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbBellatrix --
func (executionPayloadHeaderCapella) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (e executionPayloadHeaderCapella) ValueInWei() (math.Wei, error) {
return e.weiValue, nil
@@ -1221,26 +1158,6 @@ func (e executionPayloadHeaderDeneb) ExcessBlobGas() (uint64, error) {
return e.p.ExcessBlobGas, nil
}
// PbElectra --
func (executionPayloadHeaderDeneb) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayloadHeaderDeneb) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbBellatrix --
func (executionPayloadHeaderDeneb) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (executionPayloadHeaderDeneb) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (e executionPayloadHeaderDeneb) ValueInWei() (math.Wei, error) {
return e.weiValue, nil
@@ -1417,26 +1334,6 @@ func (e executionPayloadDeneb) ExcessBlobGas() (uint64, error) {
return e.p.ExcessBlobGas, nil
}
// PbBellatrix --
func (e executionPayloadDeneb) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (e executionPayloadDeneb) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (e executionPayloadDeneb) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return e.p, nil
}
// PbElectra --
func (e executionPayloadDeneb) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (e executionPayloadDeneb) ValueInWei() (math.Wei, error) {
return e.weiValue, nil

View File

@@ -211,44 +211,6 @@ func TestWrapExecutionPayloadHeaderCapella_SSZ(t *testing.T) {
assert.NoError(t, payload.UnmarshalSSZ(encoded))
}
func Test_executionPayload_Pb(t *testing.T) {
payload := createWrappedPayload(t)
pb, err := payload.PbBellatrix()
require.NoError(t, err)
assert.DeepEqual(t, payload.Proto(), pb)
_, err = payload.PbCapella()
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
}
func Test_executionPayloadHeader_Pb(t *testing.T) {
payload := createWrappedPayloadHeader(t)
_, err := payload.PbBellatrix()
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
_, err = payload.PbCapella()
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
}
func Test_executionPayloadCapella_Pb(t *testing.T) {
payload := createWrappedPayloadCapella(t)
pb, err := payload.PbCapella()
require.NoError(t, err)
assert.DeepEqual(t, payload.Proto(), pb)
_, err = payload.PbBellatrix()
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
}
func Test_executionPayloadHeaderCapella_Pb(t *testing.T) {
payload := createWrappedPayloadHeaderCapella(t)
_, err := payload.PbBellatrix()
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
_, err = payload.PbCapella()
require.ErrorIs(t, err, consensus_types.ErrUnsupportedField)
}
func TestWrapExecutionPayloadDeneb(t *testing.T) {
data := &enginev1.ExecutionPayloadDeneb{
ParentHash: []byte("parenthash"),

View File

@@ -150,102 +150,6 @@ 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, consensus_types.ErrNotSupported("PbPhase0Block", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlock), nil
}
// PbAltairBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair, error) {
if b.version != version.Altair {
return nil, consensus_types.ErrNotSupported("PbAltairBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlockAltair), nil
}
// PbBellatrixBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBellatrixBlock() (*eth.SignedBeaconBlockBellatrix, error) {
if b.version != version.Bellatrix || b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbBellatrixBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlockBellatrix), nil
}
// PbBlindedBellatrixBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeaconBlockBellatrix, error) {
if b.version != version.Bellatrix || !b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbBlindedBellatrixBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBlindedBeaconBlockBellatrix), nil
}
// PbCapellaBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbCapellaBlock() (*eth.SignedBeaconBlockCapella, error) {
if b.version != version.Capella || b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbCapellaBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlockCapella), nil
}
// PbBlindedCapellaBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedCapellaBlock() (*eth.SignedBlindedBeaconBlockCapella, error) {
if b.version != version.Capella || !b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbBlindedCapellaBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBlindedBeaconBlockCapella), nil
}
// PbDenebBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbDenebBlock() (*eth.SignedBeaconBlockDeneb, error) {
if b.version != version.Deneb || b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbDenebBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlockDeneb), nil
}
// PbBlindedDenebBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedDenebBlock() (*eth.SignedBlindedBeaconBlockDeneb, error) {
if b.version != version.Deneb || !b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbBlindedDenebBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBlindedBeaconBlockDeneb), nil
}
// ToBlinded converts a non-blinded block to its blinded equivalent.
func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, error) {
if b.version < version.Bellatrix {

View File

@@ -14,7 +14,6 @@ go_library(
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)

View File

@@ -5,7 +5,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
type blockMutator struct {
@@ -16,38 +15,23 @@ type blockMutator struct {
}
func (m blockMutator) apply(b interfaces.SignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
switch b.Version() {
case version.Phase0:
bb, err := b.PbPhase0Block()
if err != nil {
return nil, err
}
m.Phase0(bb)
return blocks.NewSignedBeaconBlock(bb)
case version.Altair:
bb, err := b.PbAltairBlock()
if err != nil {
return nil, err
}
m.Altair(bb)
return blocks.NewSignedBeaconBlock(bb)
case version.Bellatrix:
bb, err := b.PbBellatrixBlock()
if err != nil {
return nil, err
}
m.Bellatrix(bb)
return blocks.NewSignedBeaconBlock(bb)
case version.Capella:
bb, err := b.PbCapellaBlock()
if err != nil {
return nil, err
}
m.Capella(bb)
return blocks.NewSignedBeaconBlock(bb)
pb, err := b.Proto()
if err != nil {
return nil, err
}
switch pbStruct := pb.(type) {
case *eth.SignedBeaconBlock:
m.Phase0(pbStruct)
case *eth.SignedBeaconBlockAltair:
m.Altair(pbStruct)
case *eth.SignedBeaconBlockBellatrix:
m.Bellatrix(pbStruct)
case *eth.SignedBeaconBlockCapella:
m.Capella(pbStruct)
default:
return nil, blocks.ErrUnsupportedSignedBeaconBlock
}
return blocks.NewSignedBeaconBlock(pb)
}
// SetBlockStateRoot modifies the block's state root.

View File

@@ -21,15 +21,7 @@ type ReadOnlySignedBeaconBlock interface {
Copy() (SignedBeaconBlock, error)
Proto() (proto.Message, error)
PbGenericBlock() (*ethpb.GenericSignedBeaconBlock, error)
PbPhase0Block() (*ethpb.SignedBeaconBlock, error)
PbAltairBlock() (*ethpb.SignedBeaconBlockAltair, error)
ToBlinded() (ReadOnlySignedBeaconBlock, error)
PbBellatrixBlock() (*ethpb.SignedBeaconBlockBellatrix, error)
PbBlindedBellatrixBlock() (*ethpb.SignedBlindedBeaconBlockBellatrix, error)
PbCapellaBlock() (*ethpb.SignedBeaconBlockCapella, error)
PbDenebBlock() (*ethpb.SignedBeaconBlockDeneb, error)
PbBlindedCapellaBlock() (*ethpb.SignedBlindedBeaconBlockCapella, error)
PbBlindedDenebBlock() (*ethpb.SignedBlindedBeaconBlockDeneb, error)
ssz.Marshaler
ssz.Unmarshaler
Version() int
@@ -131,10 +123,6 @@ type ExecutionData interface {
TransactionsRoot() ([]byte, error)
Withdrawals() ([]*enginev1.Withdrawal, error)
WithdrawalsRoot() ([]byte, error)
PbCapella() (*enginev1.ExecutionPayloadCapella, error)
PbBellatrix() (*enginev1.ExecutionPayload, error)
PbDeneb() (*enginev1.ExecutionPayloadDeneb, error)
PbElectra() (*enginev1.ExecutionPayloadElectra, error)
ValueInWei() (math.Wei, error)
ValueInGwei() (uint64, error)
DepositReceipts() ([]*enginev1.DepositReceipt, error)

View File

@@ -43,38 +43,6 @@ func (SignedBeaconBlock) Proto() (proto.Message, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbPhase0Block() (*eth.SignedBeaconBlock, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbAltairBlock() (*eth.SignedBeaconBlockAltair, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbBellatrixBlock() (*eth.SignedBeaconBlockBellatrix, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbBlindedBellatrixBlock() (*eth.SignedBlindedBeaconBlockBellatrix, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbCapellaBlock() (*eth.SignedBeaconBlockCapella, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbBlindedCapellaBlock() (*eth.SignedBlindedBeaconBlockCapella, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbDenebBlock() (*eth.SignedBeaconBlockDeneb, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbBlindedDenebBlock() (*eth.SignedBlindedBeaconBlockDeneb, error) {
panic("implement me")
}
func (SignedBeaconBlock) MarshalSSZTo(_ []byte) ([]byte, error) {
panic("implement me")
}