Electra v1.5.0-alpha.3 changes: Move consolidations from beacon block body to the execution payload header. (#14152)

This commit is contained in:
Preston Van Loon
2024-06-27 14:28:30 -05:00
committed by GitHub
parent 6d63dbe1af
commit 7898e65d4e
65 changed files with 1138 additions and 1907 deletions

View File

@@ -14,6 +14,8 @@ import (
"google.golang.org/protobuf/proto"
)
var _ interfaces.ExecutionDataElectra = (*executionPayloadElectra)(nil)
// executionPayload is a convenience wrapper around a beacon block body's execution payload data structure
// This wrapper allows us to conform to a common interface so that beacon
// blocks for future forks can also be applied across Prysm without issues.
@@ -824,26 +826,33 @@ func PayloadToHeaderElectra(payload interfaces.ExecutionDataElectra) (*enginev1.
return nil, err
}
consolidationRequests := payload.ConsolidationRequests()
consolidationRequestsRoot, err := ssz.ConsolidationRequestsSliceRoot(consolidationRequests, fieldparams.MaxConsolidationRequestsPerPayload)
if err != nil {
return nil, err
}
return &enginev1.ExecutionPayloadHeaderElectra{
ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash()),
FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient()),
StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot()),
ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot()),
LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom()),
PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao()),
BlockNumber: payload.BlockNumber(),
GasLimit: payload.GasLimit(),
GasUsed: payload.GasUsed(),
Timestamp: payload.Timestamp(),
ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData()),
BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas()),
BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash()),
TransactionsRoot: txRoot[:],
WithdrawalsRoot: withdrawalsRoot[:],
BlobGasUsed: blobGasUsed,
ExcessBlobGas: excessBlobGas,
DepositRequestsRoot: depositRequestsRoot[:],
WithdrawalRequestsRoot: withdrawalRequestsRoot[:],
ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash()),
FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient()),
StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot()),
ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot()),
LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom()),
PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao()),
BlockNumber: payload.BlockNumber(),
GasLimit: payload.GasLimit(),
GasUsed: payload.GasUsed(),
Timestamp: payload.Timestamp(),
ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData()),
BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas()),
BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash()),
TransactionsRoot: txRoot[:],
WithdrawalsRoot: withdrawalsRoot[:],
BlobGasUsed: blobGasUsed,
ExcessBlobGas: excessBlobGas,
DepositRequestsRoot: depositRequestsRoot[:],
WithdrawalRequestsRoot: withdrawalRequestsRoot[:],
ConsolidationRequestsRoot: consolidationRequestsRoot[:],
}, nil
}
@@ -1243,7 +1252,6 @@ type executionPayloadHeaderElectra struct {
}
var _ interfaces.ExecutionData = &executionPayloadElectra{}
var _ interfaces.ExecutionDataElectra = &executionPayloadElectra{}
// WrappedExecutionPayloadHeaderElectra is a constructor which wraps a protobuf execution header into an interface.
func WrappedExecutionPayloadHeaderElectra(p *enginev1.ExecutionPayloadHeaderElectra) (interfaces.ExecutionData, error) {
@@ -1421,7 +1429,6 @@ func WrappedExecutionPayloadElectra(p *enginev1.ExecutionPayloadElectra) (interf
}
var _ interfaces.ExecutionData = &executionPayloadElectra{}
var _ interfaces.ExecutionDataElectra = &executionPayloadElectra{}
// IsNil checks if the underlying data is nil.
func (e executionPayloadElectra) IsNil() bool {
@@ -1566,6 +1573,11 @@ func (e executionPayloadElectra) WithdrawalRequests() []*enginev1.WithdrawalRequ
return e.p.WithdrawalRequests
}
// ConsolidationRequests --
func (e executionPayloadElectra) ConsolidationRequests() []*enginev1.ConsolidationRequest {
return e.p.ConsolidationRequests
}
// IsBlinded returns true if the underlying data is blinded.
func (e executionPayloadElectra) IsBlinded() bool {
return false

View File

@@ -459,11 +459,6 @@ func BuildSignedBeaconBlockFromExecutionPayload(blk interfaces.ReadOnlySignedBea
if err != nil {
return nil, err
}
electraBody, ok := b.Body().(interfaces.ROBlockBodyElectra)
if !ok {
return nil, errors.Wrapf(interfaces.ErrInvalidCast, "%T does not support electra getters", b.Body())
}
consolidations := electraBody.Consolidations()
var atts []*eth.AttestationElectra
if b.Body().Attestations() != nil {
atts = make([]*eth.AttestationElectra, len(b.Body().Attestations()))
@@ -505,7 +500,6 @@ func BuildSignedBeaconBlockFromExecutionPayload(blk interfaces.ReadOnlySignedBea
ExecutionPayload: p,
BlsToExecutionChanges: blsToExecutionChanges,
BlobKzgCommitments: commitments,
Consolidations: consolidations,
},
},
Signature: sig[:],

View File

@@ -6,7 +6,6 @@ import (
"testing"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -537,26 +536,3 @@ func TestBuildSignedBeaconBlockFromExecutionPayload(t *testing.T) {
require.DeepEqual(t, uint64(321), payload.BlobGasUsed)
})
}
func TestElectraBlockBodyCast(t *testing.T) {
t.Run("deneb cast fails", func(t *testing.T) {
pb := &eth.BeaconBlockBodyDeneb{}
i, err := NewBeaconBlockBody(pb)
require.NoError(t, err)
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Deneb, b.version)
_, err = interfaces.AsROBlockBodyElectra(b)
require.ErrorIs(t, err, interfaces.ErrInvalidCast)
})
t.Run("electra cast succeeds", func(t *testing.T) {
pb := &eth.BeaconBlockBodyElectra{}
i, err := NewBeaconBlockBody(pb)
require.NoError(t, err)
b, ok := i.(*BeaconBlockBody)
require.Equal(t, true, ok)
assert.Equal(t, version.Electra, b.version)
_, err = interfaces.AsROBlockBodyElectra(b)
require.NoError(t, err)
})
}

View File

@@ -277,7 +277,6 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e
ExecutionPayloadHeader: header,
BlsToExecutionChanges: b.block.body.blsToExecutionChanges,
BlobKzgCommitments: b.block.body.blobKzgCommitments,
Consolidations: b.block.body.signedConsolidations,
},
},
Signature: b.signature[:],
@@ -1132,10 +1131,6 @@ func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) {
}
}
func (b *BeaconBlockBody) Consolidations() []*eth.SignedConsolidation {
return b.signedConsolidations
}
// Version returns the version of the beacon block body
func (b *BeaconBlockBody) Version() int {
return b.version

View File

@@ -531,7 +531,6 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
ExecutionPayloadHeader: ph,
BlsToExecutionChanges: b.blsToExecutionChanges,
BlobKzgCommitments: b.blobKzgCommitments,
Consolidations: b.signedConsolidations,
}, nil
}
var p *enginev1.ExecutionPayloadElectra
@@ -555,7 +554,6 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
ExecutionPayload: p,
BlsToExecutionChanges: b.blsToExecutionChanges,
BlobKzgCommitments: b.blobKzgCommitments,
Consolidations: b.signedConsolidations,
}, nil
default:
@@ -1158,7 +1156,6 @@ func initBlockBodyFromProtoElectra(pb *eth.BeaconBlockBodyElectra) (*BeaconBlock
executionPayload: p,
blsToExecutionChanges: pb.BlsToExecutionChanges,
blobKzgCommitments: pb.BlobKzgCommitments,
signedConsolidations: pb.Consolidations,
}
return b, nil
}
@@ -1187,7 +1184,6 @@ func initBlindedBlockBodyFromProtoElectra(pb *eth.BlindedBeaconBlockBodyElectra)
executionPayloadHeader: ph,
blsToExecutionChanges: pb.BlsToExecutionChanges,
blobKzgCommitments: pb.BlobKzgCommitments,
signedConsolidations: pb.Consolidations,
}
return b, nil
}

View File

@@ -54,11 +54,9 @@ type BeaconBlockBody struct {
executionPayloadHeader interfaces.ExecutionData
blsToExecutionChanges []*eth.SignedBLSToExecutionChange
blobKzgCommitments [][]byte
signedConsolidations []*eth.SignedConsolidation
}
var _ interfaces.ReadOnlyBeaconBlockBody = &BeaconBlockBody{}
var _ interfaces.ROBlockBodyElectra = &BeaconBlockBody{}
// BeaconBlock is the main beacon block structure. It can represent any block type.
type BeaconBlock struct {

View File

@@ -4,7 +4,6 @@ go_library(
name = "go_default_library",
srcs = [
"beacon_block.go",
"cast.go",
"error.go",
"utils.go",
"validator.go",

View File

@@ -71,11 +71,6 @@ type ReadOnlyBeaconBlockBody interface {
BlobKzgCommitments() ([][]byte, error)
}
type ROBlockBodyElectra interface {
ReadOnlyBeaconBlockBody
Consolidations() []*ethpb.SignedConsolidation
}
type SignedBeaconBlock interface {
ReadOnlySignedBeaconBlock
SetExecution(ExecutionData) error
@@ -132,4 +127,5 @@ type ExecutionDataElectra interface {
ExecutionData
DepositRequests() []*enginev1.DepositRequest
WithdrawalRequests() []*enginev1.WithdrawalRequest
ConsolidationRequests() []*enginev1.ConsolidationRequest
}

View File

@@ -1,15 +0,0 @@
package interfaces
import "github.com/prysmaticlabs/prysm/v5/runtime/version"
// AsROBlockBodyElectra safely asserts the ReadOnlyBeaconBlockBody to a ROBlockBodyElectra.
// This allows the caller to access methods on the block body which are only available on values after
// the Electra hard fork. If the value is for an earlier fork (based on comparing its Version() to the electra version)
// an error will be returned. Callers that want to conditionally process electra data can check for this condition
// and safely ignore it like `if err != nil && errors.Is(interfaces.ErrInvalidCast) {`
func AsROBlockBodyElectra(in ReadOnlyBeaconBlockBody) (ROBlockBodyElectra, error) {
if in.Version() >= version.Electra {
return in.(ROBlockBodyElectra), nil
}
return nil, NewInvalidCastError(in.Version(), version.Electra)
}

View File

@@ -276,10 +276,6 @@ func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) {
func (b *BeaconBlockBody) Attestations() []eth.Att {
panic("implement me")
}
func (b *BeaconBlockBody) Consolidations() []*eth.SignedConsolidation {
panic("implement me")
}
func (b *BeaconBlockBody) Version() int {
panic("implement me")
}
@@ -287,4 +283,3 @@ func (b *BeaconBlockBody) Version() int {
var _ interfaces.ReadOnlySignedBeaconBlock = &SignedBeaconBlock{}
var _ interfaces.ReadOnlyBeaconBlock = &BeaconBlock{}
var _ interfaces.ReadOnlyBeaconBlockBody = &BeaconBlockBody{}
var _ interfaces.ROBlockBodyElectra = &BeaconBlockBody{}