Compare commits

...

24 Commits

Author SHA1 Message Date
james-prysm
c9445cec5c wip attester slashing to interface, need to update corresponding functions in service.go etc 2024-04-28 21:05:07 -05:00
james-prysm
7b75fc9157 Merge branch 'develop' into eletra-devnet-0-block-n-state 2024-04-26 15:58:14 -05:00
james-prysm
0a2acdabb8 wip attester slashing still broken 2024-04-26 15:17:43 -05:00
james-prysm
1f80b6f538 updating more block changes 2024-04-26 13:17:49 -05:00
james-prysm
215714ec37 Merge branch 'develop' into eletra-devnet-0-block-n-state 2024-04-26 13:12:50 -05:00
james-prysm
40ae89a3f1 Merge branch 'develop' into eletra-devnet-0-block-n-state 2024-04-26 11:26:37 -05:00
james-prysm
8ef6b6e79c wip block changes for attestations 2024-04-25 23:08:43 -05:00
james-prysm
8769fe8c97 Merge branch 'develop' into eletra-devnet-0-block-n-state 2024-04-25 10:33:42 -05:00
james-prysm
ece3d1842e reverting some conflict resolution issues 2024-04-24 17:14:33 -05:00
james-prysm
f65ff0e805 Merge branch 'develop' into eletra-devnet-0-block-n-state 2024-04-24 17:12:24 -05:00
james-prysm
55bc68f929 wip attestation changes, proto.go still broken, tests still broken, and attesterslashing not handled 2024-04-24 17:08:53 -05:00
james-prysm
1ddd487630 wip adding electra block and state changes 2024-04-24 15:53:57 -05:00
james-prysm
2a096fd583 update block & state wip 2024-04-24 15:53:57 -05:00
terence tsao
b1d0c9647a Fix minimal test. Skip beacon state test 2024-04-24 13:49:40 -07:00
james-prysm
a0202ba792 fixing eletra state to use electra payload 2024-04-24 13:49:40 -07:00
terence tsao
b7ae6b4355 Everything passing except for beacon state hash tree root 2024-04-24 13:49:40 -07:00
james-prysm
c21a3eb22a including changes from eip7002 2024-04-24 13:49:40 -07:00
terence tsao
13e3ec576d All EIP7251 containers passing 2024-04-24 13:49:40 -07:00
terence tsao
35022096b3 All EIP7549 containers are passing 2024-04-24 13:49:40 -07:00
terence tsao
cf909246dc Pull in EIP-7251 protobuf changes
From: https://github.com/prysmaticlabs/prysm/pull/13903
2024-04-24 13:49:40 -07:00
terence tsao
f33670c513 Enable Electra spec test 2024-04-24 13:49:40 -07:00
rkapka
504e45fde7 stubs 2024-04-24 13:49:40 -07:00
rkapka
92b90d7945 proto and ssz 2024-04-24 13:49:40 -07:00
rkapka
06e57af08b block protos 2024-04-24 13:49:40 -07:00
47 changed files with 1797 additions and 182 deletions

View File

@@ -401,7 +401,7 @@ func (s *Service) saveOrphanedOperations(ctx context.Context, orphanedRoot [32]b
}
for _, a := range orphanedBlk.Block().Body().Attestations() {
// if the attestation is one epoch older, it wouldn't been useful to save it.
if a.Data.Slot+params.BeaconConfig().SlotsPerEpoch < s.CurrentSlot() {
if a.GetData().Slot+params.BeaconConfig().SlotsPerEpoch < s.CurrentSlot() {
continue
}
if helpers.IsAggregated(a) {

View File

@@ -366,17 +366,17 @@ func (s *Service) handleEpochBoundary(ctx context.Context, slot primitives.Slot,
func (s *Service) handleBlockAttestations(ctx context.Context, blk interfaces.ReadOnlyBeaconBlock, st state.BeaconState) error {
// Feed in block's attestations to fork choice store.
for _, a := range blk.Body().Attestations() {
committee, err := helpers.BeaconCommitteeFromState(ctx, st, a.Data.Slot, a.Data.CommitteeIndex)
committee, err := helpers.BeaconCommitteeFromState(ctx, st, a.GetData().Slot, a.GetData().CommitteeIndex)
if err != nil {
return err
}
indices, err := attestation.AttestingIndices(a.AggregationBits, committee)
indices, err := attestation.AttestingIndices(a.GetAggregationBits(), committee)
if err != nil {
return err
}
r := bytesutil.ToBytes32(a.Data.BeaconBlockRoot)
r := bytesutil.ToBytes32(a.GetData().BeaconBlockRoot)
if s.cfg.ForkChoiceStore.HasNode(r) {
s.cfg.ForkChoiceStore.ProcessAttestation(ctx, indices, r, a.Data.Target.Epoch)
s.cfg.ForkChoiceStore.ProcessAttestation(ctx, indices, r, a.GetData().Target.Epoch)
} else if err := s.cfg.AttPool.SaveBlockAttestation(a); err != nil {
return err
}

View File

@@ -48,7 +48,7 @@ func ProcessAttestationsNoVerifySignature(
func ProcessAttestationNoVerifySignature(
ctx context.Context,
beaconState state.BeaconState,
att *ethpb.Attestation,
att interfaces.Attestation,
totalBalance uint64,
) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "altair.ProcessAttestationNoVerifySignature")
@@ -58,24 +58,24 @@ func ProcessAttestationNoVerifySignature(
return nil, err
}
delay, err := beaconState.Slot().SafeSubSlot(att.Data.Slot)
delay, err := beaconState.Slot().SafeSubSlot(att.GetData().Slot)
if err != nil {
return nil, fmt.Errorf("att slot %d can't be greater than state slot %d", att.Data.Slot, beaconState.Slot())
return nil, fmt.Errorf("att slot %d can't be greater than state slot %d", att.GetData().Slot, beaconState.Slot())
}
participatedFlags, err := AttestationParticipationFlagIndices(beaconState, att.Data, delay)
participatedFlags, err := AttestationParticipationFlagIndices(beaconState, att.GetData(), delay)
if err != nil {
return nil, err
}
committee, err := helpers.BeaconCommitteeFromState(ctx, beaconState, att.Data.Slot, att.Data.CommitteeIndex)
committee, err := helpers.BeaconCommitteeFromState(ctx, beaconState, att.GetData().Slot, att.GetData().CommitteeIndex)
if err != nil {
return nil, err
}
indices, err := attestation.AttestingIndices(att.AggregationBits, committee)
indices, err := attestation.AttestingIndices(att.GetAggregationBits(), committee)
if err != nil {
return nil, err
}
return SetParticipationAndRewardProposer(ctx, beaconState, att.Data.Target.Epoch, indices, participatedFlags, totalBalance)
return SetParticipationAndRewardProposer(ctx, beaconState, att.GetData().Target.Epoch, indices, participatedFlags, totalBalance)
}
// SetParticipationAndRewardProposer retrieves and sets the epoch participation bits in state. Based on the epoch participation, it rewards

View File

@@ -46,7 +46,7 @@ func ProcessAttestationsNoVerifySignature(
func VerifyAttestationNoVerifySignature(
ctx context.Context,
beaconState state.ReadOnlyBeaconState,
att *ethpb.Attestation,
att interfaces.Attestation,
) error {
ctx, span := trace.StartSpan(ctx, "core.VerifyAttestationNoVerifySignature")
defer span.End()
@@ -56,7 +56,7 @@ func VerifyAttestationNoVerifySignature(
}
currEpoch := time.CurrentEpoch(beaconState)
prevEpoch := time.PrevEpoch(beaconState)
data := att.Data
data := att.GetData()
if data.Target.Epoch != prevEpoch && data.Target.Epoch != currEpoch {
return fmt.Errorf(
"expected target epoch (%d) to be the previous epoch (%d) or the current epoch (%d)",
@@ -76,11 +76,11 @@ func VerifyAttestationNoVerifySignature(
}
}
if err := helpers.ValidateSlotTargetEpoch(att.Data); err != nil {
if err := helpers.ValidateSlotTargetEpoch(att.GetData()); err != nil {
return err
}
s := att.Data.Slot
s := att.GetData().Slot
minInclusionCheck := s+params.BeaconConfig().MinAttestationInclusionDelay <= beaconState.Slot()
if !minInclusionCheck {
return fmt.Errorf(
@@ -102,13 +102,13 @@ func VerifyAttestationNoVerifySignature(
)
}
}
activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, beaconState, att.Data.Target.Epoch)
activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, beaconState, att.GetData().Target.Epoch)
if err != nil {
return err
}
c := helpers.SlotCommitteeCount(activeValidatorCount)
if uint64(att.Data.CommitteeIndex) >= c {
return fmt.Errorf("committee index %d >= committee count %d", att.Data.CommitteeIndex, c)
if uint64(att.GetData().CommitteeIndex) >= c {
return fmt.Errorf("committee index %d >= committee count %d", att.GetData().CommitteeIndex, c)
}
if err := helpers.VerifyAttestationBitfieldLengths(ctx, beaconState, att); err != nil {
@@ -116,7 +116,7 @@ func VerifyAttestationNoVerifySignature(
}
// Verify attesting indices are correct.
committee, err := helpers.BeaconCommitteeFromState(ctx, beaconState, att.Data.Slot, att.Data.CommitteeIndex)
committee, err := helpers.BeaconCommitteeFromState(ctx, beaconState, att.GetData().Slot, att.GetData().CommitteeIndex)
if err != nil {
return err
}
@@ -133,7 +133,7 @@ func VerifyAttestationNoVerifySignature(
func ProcessAttestationNoVerifySignature(
ctx context.Context,
beaconState state.BeaconState,
att *ethpb.Attestation,
att interfaces.Attestation,
) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerifySignature")
defer span.End()
@@ -143,15 +143,15 @@ func ProcessAttestationNoVerifySignature(
}
currEpoch := time.CurrentEpoch(beaconState)
data := att.Data
s := att.Data.Slot
data := att.GetData()
s := att.GetData().Slot
proposerIndex, err := helpers.BeaconProposerIndex(ctx, beaconState)
if err != nil {
return nil, err
}
pendingAtt := &ethpb.PendingAttestation{
Data: data,
AggregationBits: att.AggregationBits,
AggregationBits: att.GetAggregationBits(),
InclusionDelay: beaconState.Slot() - s,
ProposerIndex: proposerIndex,
}

View File

@@ -179,7 +179,7 @@ func randaoSigningData(ctx context.Context, beaconState state.ReadOnlyBeaconStat
func createAttestationSignatureBatch(
ctx context.Context,
beaconState state.ReadOnlyBeaconState,
atts []*ethpb.Attestation,
atts []interfaces.Attestation,
domain []byte,
) (*bls.SignatureBatch, error) {
if len(atts) == 0 {
@@ -191,8 +191,8 @@ func createAttestationSignatureBatch(
msgs := make([][32]byte, len(atts))
descs := make([]string, len(atts))
for i, a := range atts {
sigs[i] = a.Signature
c, err := helpers.BeaconCommitteeFromState(ctx, beaconState, a.Data.Slot, a.Data.CommitteeIndex)
sigs[i] = a.GetSignature()
c, err := helpers.BeaconCommitteeFromState(ctx, beaconState, a.GetData().Slot, a.GetData().CommitteeIndex)
if err != nil {
return nil, err
}
@@ -233,7 +233,7 @@ func createAttestationSignatureBatch(
// AttestationSignatureBatch retrieves all the related attestation signature data such as the relevant public keys,
// signatures and attestation signing data and collate it into a signature batch object.
func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, atts []*ethpb.Attestation) (*bls.SignatureBatch, error) {
func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBeaconState, atts []interfaces.Attestation) (*bls.SignatureBatch, error) {
if len(atts) == 0 {
return bls.NewSet(), nil
}
@@ -243,10 +243,10 @@ func AttestationSignatureBatch(ctx context.Context, beaconState state.ReadOnlyBe
dt := params.BeaconConfig().DomainBeaconAttester
// Split attestations by fork. Note: the signature domain will differ based on the fork.
var preForkAtts []*ethpb.Attestation
var postForkAtts []*ethpb.Attestation
var preForkAtts []interfaces.Attestation
var postForkAtts []interfaces.Attestation
for _, a := range atts {
if slots.ToEpoch(a.Data.Slot) < fork.Epoch {
if slots.ToEpoch(a.GetData().Slot) < fork.Epoch {
preForkAtts = append(preForkAtts, a)
} else {
postForkAtts = append(postForkAtts, a)

View File

@@ -25,6 +25,7 @@ go_library(
"//beacon-chain/state:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//container/slice:go_default_library",
"//container/trie:go_default_library",

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -21,20 +22,20 @@ var (
// ValidateNilAttestation checks if any composite field of input attestation is nil.
// Access to these nil fields will result in run time panic,
// it is recommended to run these checks as first line of defense.
func ValidateNilAttestation(attestation *ethpb.Attestation) error {
func ValidateNilAttestation(attestation interfaces.Attestation) error {
if attestation == nil {
return errors.New("attestation can't be nil")
}
if attestation.Data == nil {
if attestation.GetData() == nil {
return errors.New("attestation's data can't be nil")
}
if attestation.Data.Source == nil {
if attestation.GetData().Source == nil {
return errors.New("attestation's source can't be nil")
}
if attestation.Data.Target == nil {
if attestation.GetData().Target == nil {
return errors.New("attestation's target can't be nil")
}
if attestation.AggregationBits == nil {
if attestation.GetAggregationBits() == nil {
return errors.New("attestation's bitfield can't be nil")
}
return nil
@@ -71,8 +72,8 @@ func IsAggregator(committeeCount uint64, slotSig []byte) (bool, error) {
// IsAggregated returns true if the attestation is an aggregated attestation,
// false otherwise.
func IsAggregated(attestation *ethpb.Attestation) bool {
return attestation.AggregationBits.Count() > 1
func IsAggregated(attestation interfaces.Attestation) bool {
return attestation.GetAggregationBits().Count() > 1
}
// ComputeSubnetForAttestation returns the subnet for which the provided attestation will be broadcasted to.

View File

@@ -15,12 +15,12 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/container/slice"
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/math"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)
@@ -257,8 +257,8 @@ func VerifyBitfieldLength(bf bitfield.Bitfield, committeeSize uint64) error {
// VerifyAttestationBitfieldLengths verifies that an attestations aggregation bitfields is
// a valid length matching the size of the committee.
func VerifyAttestationBitfieldLengths(ctx context.Context, state state.ReadOnlyBeaconState, att *ethpb.Attestation) error {
committee, err := BeaconCommitteeFromState(ctx, state, att.Data.Slot, att.Data.CommitteeIndex)
func VerifyAttestationBitfieldLengths(ctx context.Context, state state.ReadOnlyBeaconState, att interfaces.Attestation) error {
committee, err := BeaconCommitteeFromState(ctx, state, att.GetData().Slot, att.GetData().CommitteeIndex)
if err != nil {
return errors.Wrap(err, "could not retrieve beacon committees")
}
@@ -267,7 +267,7 @@ func VerifyAttestationBitfieldLengths(ctx context.Context, state state.ReadOnlyB
return errors.New("no committee exist for this attestation")
}
if err := VerifyBitfieldLength(att.AggregationBits, uint64(len(committee))); err != nil {
if err := VerifyBitfieldLength(att.GetAggregationBits(), uint64(len(committee))); err != nil {
return errors.Wrap(err, "failed to verify aggregation bitfield")
}
return nil

View File

@@ -20,9 +20,9 @@ go_library(
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/params:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/hash:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/attestation/aggregation/attestations:go_default_library",
"//time:go_default_library",
"//time/slots:go_default_library",

View File

@@ -15,6 +15,7 @@ go_library(
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//config/params:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/hash:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -7,8 +7,8 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
attaggregation "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations"
log "github.com/sirupsen/logrus"
"go.opencensus.io/trace"
@@ -28,13 +28,13 @@ func (c *AttCaches) AggregateUnaggregatedAttestations(ctx context.Context) error
return c.aggregateUnaggregatedAtts(ctx, unaggregatedAtts)
}
func (c *AttCaches) aggregateUnaggregatedAtts(ctx context.Context, unaggregatedAtts []*ethpb.Attestation) error {
func (c *AttCaches) aggregateUnaggregatedAtts(ctx context.Context, unaggregatedAtts []interfaces.Attestation) error {
_, span := trace.StartSpan(ctx, "operations.attestations.kv.aggregateUnaggregatedAtts")
defer span.End()
attsByDataRoot := make(map[[32]byte][]*ethpb.Attestation, len(unaggregatedAtts))
attsByDataRoot := make(map[[32]byte][]interfaces.Attestation, len(unaggregatedAtts))
for _, att := range unaggregatedAtts {
attDataRoot, err := att.Data.HashTreeRoot()
attDataRoot, err := att.GetData().HashTreeRoot()
if err != nil {
return err
}
@@ -66,12 +66,12 @@ func (c *AttCaches) aggregateUnaggregatedAtts(ctx context.Context, unaggregatedA
// aggregateParallel aggregates attestations in parallel for `atts` and saves them in the pool,
// returns the unaggregated attestations that weren't able to aggregate.
// Given `n` CPU cores, it creates a channel of size `n` and spawns `n` goroutines to aggregate attestations
func (c *AttCaches) aggregateParallel(atts map[[32]byte][]*ethpb.Attestation, leftOver map[[32]byte]bool) map[[32]byte]bool {
func (c *AttCaches) aggregateParallel(atts map[[32]byte][]interfaces.Attestation, leftOver map[[32]byte]bool) map[[32]byte]bool {
var leftoverLock sync.Mutex
wg := sync.WaitGroup{}
n := runtime.GOMAXPROCS(0) // defaults to the value of runtime.NumCPU
ch := make(chan []*ethpb.Attestation, n)
ch := make(chan []interfaces.Attestation, n)
wg.Add(n)
for i := 0; i < n; i++ {
go func() {
@@ -87,7 +87,7 @@ func (c *AttCaches) aggregateParallel(atts map[[32]byte][]*ethpb.Attestation, le
continue
}
if helpers.IsAggregated(aggregated) {
if err := c.SaveAggregatedAttestations([]*ethpb.Attestation{aggregated}); err != nil {
if err := c.SaveAggregatedAttestations([]interfaces.Attestation{aggregated}); err != nil {
log.WithError(err).Error("could not save aggregated attestation")
continue
}
@@ -116,7 +116,7 @@ func (c *AttCaches) aggregateParallel(atts map[[32]byte][]*ethpb.Attestation, le
}
// SaveAggregatedAttestation saves an aggregated attestation in cache.
func (c *AttCaches) SaveAggregatedAttestation(att *ethpb.Attestation) error {
func (c *AttCaches) SaveAggregatedAttestation(att interfaces.Attestation) error {
if err := helpers.ValidateNilAttestation(att); err != nil {
return err
}
@@ -139,16 +139,16 @@ func (c *AttCaches) SaveAggregatedAttestation(att *ethpb.Attestation) error {
return nil
}
r, err := hashFn(att.Data)
r, err := hashFn(att.GetData())
if err != nil {
return errors.Wrap(err, "could not tree hash attestation")
}
copiedAtt := ethpb.CopyAttestation(att)
copiedAtt := interfaces.CopyAttestation(att)
c.aggregatedAttLock.Lock()
defer c.aggregatedAttLock.Unlock()
atts, ok := c.aggregatedAtt[r]
if !ok {
atts := []*ethpb.Attestation{copiedAtt}
atts := []interfaces.Attestation{copiedAtt}
c.aggregatedAtt[r] = atts
return nil
}
@@ -163,7 +163,7 @@ func (c *AttCaches) SaveAggregatedAttestation(att *ethpb.Attestation) error {
}
// SaveAggregatedAttestations saves a list of aggregated attestations in cache.
func (c *AttCaches) SaveAggregatedAttestations(atts []*ethpb.Attestation) error {
func (c *AttCaches) SaveAggregatedAttestations(atts []interfaces.Attestation) error {
for _, att := range atts {
if err := c.SaveAggregatedAttestation(att); err != nil {
log.WithError(err).Debug("Could not save aggregated attestation")
@@ -176,11 +176,11 @@ func (c *AttCaches) SaveAggregatedAttestations(atts []*ethpb.Attestation) error
}
// AggregatedAttestations returns the aggregated attestations in cache.
func (c *AttCaches) AggregatedAttestations() []*ethpb.Attestation {
func (c *AttCaches) AggregatedAttestations() []interfaces.Attestation {
c.aggregatedAttLock.RLock()
defer c.aggregatedAttLock.RUnlock()
atts := make([]*ethpb.Attestation, 0)
atts := make([]interfaces.Attestation, 0)
for _, a := range c.aggregatedAtt {
atts = append(atts, a...)
@@ -191,16 +191,16 @@ func (c *AttCaches) AggregatedAttestations() []*ethpb.Attestation {
// AggregatedAttestationsBySlotIndex returns the aggregated attestations in cache,
// filtered by committee index and slot.
func (c *AttCaches) AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []*ethpb.Attestation {
func (c *AttCaches) AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation {
_, span := trace.StartSpan(ctx, "operations.attestations.kv.AggregatedAttestationsBySlotIndex")
defer span.End()
atts := make([]*ethpb.Attestation, 0)
atts := make([]interfaces.Attestation, 0)
c.aggregatedAttLock.RLock()
defer c.aggregatedAttLock.RUnlock()
for _, a := range c.aggregatedAtt {
if slot == a[0].Data.Slot && committeeIndex == a[0].Data.CommitteeIndex {
if slot == a[0].GetData().Slot && committeeIndex == a[0].GetData().CommitteeIndex {
atts = append(atts, a...)
}
}
@@ -209,14 +209,14 @@ func (c *AttCaches) AggregatedAttestationsBySlotIndex(ctx context.Context, slot
}
// DeleteAggregatedAttestation deletes the aggregated attestations in cache.
func (c *AttCaches) DeleteAggregatedAttestation(att *ethpb.Attestation) error {
func (c *AttCaches) DeleteAggregatedAttestation(att interfaces.Attestation) error {
if err := helpers.ValidateNilAttestation(att); err != nil {
return err
}
if !helpers.IsAggregated(att) {
return errors.New("attestation is not aggregated")
}
r, err := hashFn(att.Data)
r, err := hashFn(att.GetData())
if err != nil {
return errors.Wrap(err, "could not tree hash attestation data")
}
@@ -232,9 +232,9 @@ func (c *AttCaches) DeleteAggregatedAttestation(att *ethpb.Attestation) error {
return nil
}
filtered := make([]*ethpb.Attestation, 0)
filtered := make([]interfaces.Attestation, 0)
for _, a := range attList {
if c, err := att.AggregationBits.Contains(a.AggregationBits); err != nil {
if c, err := att.GetAggregationBits().Contains(a.GetAggregationBits()); err != nil {
return err
} else if !c {
filtered = append(filtered, a)
@@ -250,11 +250,11 @@ func (c *AttCaches) DeleteAggregatedAttestation(att *ethpb.Attestation) error {
}
// HasAggregatedAttestation checks if the input attestations has already existed in cache.
func (c *AttCaches) HasAggregatedAttestation(att *ethpb.Attestation) (bool, error) {
func (c *AttCaches) HasAggregatedAttestation(att interfaces.Attestation) (bool, error) {
if err := helpers.ValidateNilAttestation(att); err != nil {
return false, err
}
r, err := hashFn(att.Data)
r, err := hashFn(att.GetData())
if err != nil {
return false, errors.Wrap(err, "could not tree hash attestation")
}
@@ -263,7 +263,7 @@ func (c *AttCaches) HasAggregatedAttestation(att *ethpb.Attestation) (bool, erro
defer c.aggregatedAttLock.RUnlock()
if atts, ok := c.aggregatedAtt[r]; ok {
for _, a := range atts {
if c, err := a.AggregationBits.Contains(att.AggregationBits); err != nil {
if c, err := a.GetAggregationBits().Contains(att.GetAggregationBits()); err != nil {
return false, err
} else if c {
return true, nil
@@ -275,7 +275,7 @@ func (c *AttCaches) HasAggregatedAttestation(att *ethpb.Attestation) (bool, erro
defer c.blockAttLock.RUnlock()
if atts, ok := c.blockAtt[r]; ok {
for _, a := range atts {
if c, err := a.AggregationBits.Contains(att.AggregationBits); err != nil {
if c, err := a.GetAggregationBits().Contains(att.GetAggregationBits()); err != nil {
return false, err
} else if c {
return true, nil

View File

@@ -2,6 +2,7 @@ package kv
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)
@@ -35,13 +36,13 @@ func (c *AttCaches) SaveForkchoiceAttestations(atts []*ethpb.Attestation) error
}
// ForkchoiceAttestations returns the forkchoice attestations in cache.
func (c *AttCaches) ForkchoiceAttestations() []*ethpb.Attestation {
func (c *AttCaches) ForkchoiceAttestations() []interfaces.Attestation {
c.forkchoiceAttLock.RLock()
defer c.forkchoiceAttLock.RUnlock()
atts := make([]*ethpb.Attestation, 0, len(c.forkchoiceAtt))
atts := make([]interfaces.Attestation, 0, len(c.forkchoiceAtt))
for _, att := range c.forkchoiceAtt {
atts = append(atts, ethpb.CopyAttestation(att) /* Copied */)
atts = append(atts, interfaces.CopyAttestation(att) /* Copied */)
}
return atts

View File

@@ -9,8 +9,8 @@ import (
"github.com/patrickmn/go-cache"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)
var hashFn = hash.Proto
@@ -20,13 +20,13 @@ var hashFn = hash.Proto
// such are unaggregated, aggregated or attestations within a block.
type AttCaches struct {
aggregatedAttLock sync.RWMutex
aggregatedAtt map[[32]byte][]*ethpb.Attestation
aggregatedAtt map[[32]byte][]interfaces.Attestation
unAggregateAttLock sync.RWMutex
unAggregatedAtt map[[32]byte]*ethpb.Attestation
unAggregatedAtt map[[32]byte]interfaces.Attestation
forkchoiceAttLock sync.RWMutex
forkchoiceAtt map[[32]byte]*ethpb.Attestation
forkchoiceAtt map[[32]byte]interfaces.Attestation
blockAttLock sync.RWMutex
blockAtt map[[32]byte][]*ethpb.Attestation
blockAtt map[[32]byte][]interfaces.Attestation
seenAtt *cache.Cache
}
@@ -36,10 +36,10 @@ func NewAttCaches() *AttCaches {
secsInEpoch := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
c := cache.New(secsInEpoch*time.Second, 2*secsInEpoch*time.Second)
pool := &AttCaches{
unAggregatedAtt: make(map[[32]byte]*ethpb.Attestation),
aggregatedAtt: make(map[[32]byte][]*ethpb.Attestation),
forkchoiceAtt: make(map[[32]byte]*ethpb.Attestation),
blockAtt: make(map[[32]byte][]*ethpb.Attestation),
unAggregatedAtt: make(map[[32]byte]interfaces.Attestation),
aggregatedAtt: make(map[[32]byte][]interfaces.Attestation),
forkchoiceAtt: make(map[[32]byte]interfaces.Attestation),
blockAtt: make(map[[32]byte][]interfaces.Attestation),
seenAtt: c,
}

View File

@@ -4,11 +4,11 @@ import (
"github.com/patrickmn/go-cache"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
)
func (c *AttCaches) insertSeenBit(att *ethpb.Attestation) error {
r, err := hashFn(att.Data)
func (c *AttCaches) insertSeenBit(att interfaces.Attestation) error {
r, err := hashFn(att.GetData())
if err != nil {
return err
}
@@ -21,7 +21,7 @@ func (c *AttCaches) insertSeenBit(att *ethpb.Attestation) error {
}
alreadyExists := false
for _, bit := range seenBits {
if c, err := bit.Contains(att.AggregationBits); err != nil {
if c, err := bit.Contains(att.GetAggregationBits()); err != nil {
return err
} else if c {
alreadyExists = true
@@ -29,18 +29,18 @@ func (c *AttCaches) insertSeenBit(att *ethpb.Attestation) error {
}
}
if !alreadyExists {
seenBits = append(seenBits, att.AggregationBits)
seenBits = append(seenBits, att.GetAggregationBits())
}
c.seenAtt.Set(string(r[:]), seenBits, cache.DefaultExpiration /* one epoch */)
return nil
}
c.seenAtt.Set(string(r[:]), []bitfield.Bitlist{att.AggregationBits}, cache.DefaultExpiration /* one epoch */)
c.seenAtt.Set(string(r[:]), []bitfield.Bitlist{att.GetAggregationBits()}, cache.DefaultExpiration /* one epoch */)
return nil
}
func (c *AttCaches) hasSeenBit(att *ethpb.Attestation) (bool, error) {
r, err := hashFn(att.Data)
func (c *AttCaches) hasSeenBit(att interfaces.Attestation) (bool, error) {
r, err := hashFn(att.GetData())
if err != nil {
return false, err
}
@@ -52,7 +52,7 @@ func (c *AttCaches) hasSeenBit(att *ethpb.Attestation) (bool, error) {
return false, errors.New("could not convert to bitlist type")
}
for _, bit := range seenBits {
if c, err := bit.Contains(att.AggregationBits); err != nil {
if c, err := bit.Contains(att.GetAggregationBits()); err != nil {
return false, err
} else if c {
return true, nil

View File

@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"go.opencensus.io/trace"
@@ -51,18 +52,18 @@ func (c *AttCaches) SaveUnaggregatedAttestations(atts []*ethpb.Attestation) erro
}
// UnaggregatedAttestations returns all the unaggregated attestations in cache.
func (c *AttCaches) UnaggregatedAttestations() ([]*ethpb.Attestation, error) {
func (c *AttCaches) UnaggregatedAttestations() ([]interfaces.Attestation, error) {
c.unAggregateAttLock.RLock()
defer c.unAggregateAttLock.RUnlock()
unAggregatedAtts := c.unAggregatedAtt
atts := make([]*ethpb.Attestation, 0, len(unAggregatedAtts))
atts := make([]interfaces.Attestation, 0, len(unAggregatedAtts))
for _, att := range unAggregatedAtts {
seen, err := c.hasSeenBit(att)
if err != nil {
return nil, err
}
if !seen {
atts = append(atts, ethpb.CopyAttestation(att) /* Copied */)
atts = append(atts, interfaces.CopyAttestation(att) /* Copied */)
}
}
return atts, nil
@@ -70,18 +71,18 @@ func (c *AttCaches) UnaggregatedAttestations() ([]*ethpb.Attestation, error) {
// UnaggregatedAttestationsBySlotIndex returns the unaggregated attestations in cache,
// filtered by committee index and slot.
func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []*ethpb.Attestation {
func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation {
_, span := trace.StartSpan(ctx, "operations.attestations.kv.UnaggregatedAttestationsBySlotIndex")
defer span.End()
atts := make([]*ethpb.Attestation, 0)
atts := make([]interfaces.Attestation, 0)
c.unAggregateAttLock.RLock()
defer c.unAggregateAttLock.RUnlock()
unAggregatedAtts := c.unAggregatedAtt
for _, a := range unAggregatedAtts {
if slot == a.Data.Slot && committeeIndex == a.Data.CommitteeIndex {
if slot == a.GetData().Slot && committeeIndex == a.GetData().CommitteeIndex {
atts = append(atts, a)
}
}
@@ -90,7 +91,7 @@ func (c *AttCaches) UnaggregatedAttestationsBySlotIndex(ctx context.Context, slo
}
// DeleteUnaggregatedAttestation deletes the unaggregated attestations in cache.
func (c *AttCaches) DeleteUnaggregatedAttestation(att *ethpb.Attestation) error {
func (c *AttCaches) DeleteUnaggregatedAttestation(att interfaces.Attestation) error {
if att == nil {
return nil
}

View File

@@ -4,8 +4,8 @@ import (
"context"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations/kv"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)
// Pool defines the necessary methods for Prysm attestations pool to serve
@@ -15,30 +15,30 @@ import (
type Pool interface {
// For Aggregated attestations
AggregateUnaggregatedAttestations(ctx context.Context) error
SaveAggregatedAttestation(att *ethpb.Attestation) error
SaveAggregatedAttestations(atts []*ethpb.Attestation) error
AggregatedAttestations() []*ethpb.Attestation
AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []*ethpb.Attestation
DeleteAggregatedAttestation(att *ethpb.Attestation) error
HasAggregatedAttestation(att *ethpb.Attestation) (bool, error)
SaveAggregatedAttestation(att interfaces.Attestation) error
SaveAggregatedAttestations(atts []interfaces.Attestation) error
AggregatedAttestations() []interfaces.Attestation
AggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation
DeleteAggregatedAttestation(att interfaces.Attestation) error
HasAggregatedAttestation(att interfaces.Attestation) (bool, error)
AggregatedAttestationCount() int
// For unaggregated attestations.
SaveUnaggregatedAttestation(att *ethpb.Attestation) error
SaveUnaggregatedAttestations(atts []*ethpb.Attestation) error
UnaggregatedAttestations() ([]*ethpb.Attestation, error)
UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []*ethpb.Attestation
DeleteUnaggregatedAttestation(att *ethpb.Attestation) error
SaveUnaggregatedAttestation(att interfaces.Attestation) error
SaveUnaggregatedAttestations(atts []interfaces.Attestation) error
UnaggregatedAttestations() ([]interfaces.Attestation, error)
UnaggregatedAttestationsBySlotIndex(ctx context.Context, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []interfaces.Attestation
DeleteUnaggregatedAttestation(att interfaces.Attestation) error
DeleteSeenUnaggregatedAttestations() (int, error)
UnaggregatedAttestationCount() int
// For attestations that were included in the block.
SaveBlockAttestation(att *ethpb.Attestation) error
BlockAttestations() []*ethpb.Attestation
DeleteBlockAttestation(att *ethpb.Attestation) error
SaveBlockAttestation(att interfaces.Attestation) error
BlockAttestations() []interfaces.Attestation
DeleteBlockAttestation(att interfaces.Attestation) error
// For attestations to be passed to fork choice.
SaveForkchoiceAttestation(att *ethpb.Attestation) error
SaveForkchoiceAttestations(atts []*ethpb.Attestation) error
ForkchoiceAttestations() []*ethpb.Attestation
DeleteForkchoiceAttestation(att *ethpb.Attestation) error
SaveForkchoiceAttestation(att interfaces.Attestation) error
SaveForkchoiceAttestations(atts []interfaces.Attestation) error
ForkchoiceAttestations() []interfaces.Attestation
DeleteForkchoiceAttestation(att interfaces.Attestation) error
ForkchoiceAttestationCount() int
}

View File

@@ -9,8 +9,8 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/config/features"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
attaggregation "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations"
"github.com/prysmaticlabs/prysm/v5/time/slots"
"go.opencensus.io/trace"
@@ -67,7 +67,7 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error {
atts := append(s.cfg.Pool.AggregatedAttestations(), s.cfg.Pool.BlockAttestations()...)
atts = append(atts, s.cfg.Pool.ForkchoiceAttestations()...)
attsByDataRoot := make(map[[32]byte][]*ethpb.Attestation, len(atts))
attsByDataRoot := make(map[[32]byte][]interfaces.Attestation, len(atts))
// Consolidate attestations by aggregating them by similar data root.
for _, att := range atts {
@@ -79,7 +79,7 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error {
continue
}
attDataRoot, err := att.Data.HashTreeRoot()
attDataRoot, err := att.GetData().HashTreeRoot()
if err != nil {
return err
}
@@ -103,10 +103,10 @@ func (s *Service) batchForkChoiceAtts(ctx context.Context) error {
// This aggregates a list of attestations using the aggregation algorithm defined in AggregateAttestations
// and saves the attestations for fork choice.
func (s *Service) aggregateAndSaveForkChoiceAtts(atts []*ethpb.Attestation) error {
clonedAtts := make([]*ethpb.Attestation, len(atts))
func (s *Service) aggregateAndSaveForkChoiceAtts(atts []interfaces.Attestation) error {
clonedAtts := make([]interfaces.Attestation, len(atts))
for i, a := range atts {
clonedAtts[i] = ethpb.CopyAttestation(a)
clonedAtts[i] = interfaces.CopyAttestation(a)
}
aggregatedAtts, err := attaggregation.Aggregate(clonedAtts)
if err != nil {
@@ -118,12 +118,12 @@ func (s *Service) aggregateAndSaveForkChoiceAtts(atts []*ethpb.Attestation) erro
// This checks if the attestation has previously been aggregated for fork choice
// return true if yes, false if no.
func (s *Service) seen(att *ethpb.Attestation) (bool, error) {
attRoot, err := hash.Proto(att.Data)
func (s *Service) seen(att interfaces.Attestation) (bool, error) {
attRoot, err := hash.Proto(att.GetData())
if err != nil {
return false, err
}
incomingBits := att.AggregationBits
incomingBits := att.GetAggregationBits()
savedBits, ok := s.forkChoiceProcessedRoots.Get(attRoot)
if ok {
savedBitlist, ok := savedBits.(bitfield.Bitlist)

View File

@@ -29,7 +29,7 @@ func (s *Service) pruneAttsPool() {
func (s *Service) pruneExpiredAtts() {
aggregatedAtts := s.cfg.Pool.AggregatedAttestations()
for _, att := range aggregatedAtts {
if s.expired(att.Data.Slot) {
if s.expired(att.GetData().Slot) {
if err := s.cfg.Pool.DeleteAggregatedAttestation(att); err != nil {
log.WithError(err).Error("Could not delete expired aggregated attestation")
}
@@ -46,7 +46,7 @@ func (s *Service) pruneExpiredAtts() {
return
}
for _, att := range unAggregatedAtts {
if s.expired(att.Data.Slot) {
if s.expired(att.GetData().Slot) {
if err := s.cfg.Pool.DeleteUnaggregatedAttestation(att); err != nil {
log.WithError(err).Error("Could not delete expired unaggregated attestation")
}
@@ -56,7 +56,7 @@ func (s *Service) pruneExpiredAtts() {
blockAtts := s.cfg.Pool.BlockAttestations()
for _, att := range blockAtts {
if s.expired(att.Data.Slot) {
if s.expired(att.GetData().Slot) {
if err := s.cfg.Pool.DeleteBlockAttestation(att); err != nil {
log.WithError(err).Error("Could not delete expired block attestation")
}

View File

@@ -11,6 +11,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/container/slice"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -118,7 +119,7 @@ func (p *Pool) PendingProposerSlashings(ctx context.Context, state state.ReadOnl
func (p *Pool) InsertAttesterSlashing(
ctx context.Context,
state state.ReadOnlyBeaconState,
slashing *ethpb.AttesterSlashing,
slashing interfaces.AttesterSlashing,
) error {
p.lock.Lock()
defer p.lock.Unlock()
@@ -129,7 +130,7 @@ func (p *Pool) InsertAttesterSlashing(
return errors.Wrap(err, "could not verify attester slashing")
}
slashedVal := slice.IntersectionUint64(slashing.Attestation_1.AttestingIndices, slashing.Attestation_2.AttestingIndices)
slashedVal := slice.IntersectionUint64(slashing.GetAttestationOne().GetAttestingIndicesVal(), slashing.GetAttestationTwo().GetAttestingIndicesVal())
cantSlash := make([]uint64, 0, len(slashedVal))
slashingReason := ""
for _, val := range slashedVal {

View File

@@ -5,6 +5,7 @@ import (
"sync"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)
@@ -14,7 +15,7 @@ type PoolInserter interface {
InsertAttesterSlashing(
ctx context.Context,
state state.ReadOnlyBeaconState,
slashing *ethpb.AttesterSlashing,
slashing interfaces.AttesterSlashing,
) error
InsertProposerSlashing(
ctx context.Context,

View File

@@ -57,6 +57,7 @@ type BeaconState struct {
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader
latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella
latestExecutionPayloadHeaderDeneb *enginev1.ExecutionPayloadHeaderDeneb
latestExecutionPayloadHeaderElectra *enginev1.ExecutionPayloadHeaderElectra
nextWithdrawalIndex uint64
nextWithdrawalValidatorIndex primitives.ValidatorIndex

View File

@@ -27,7 +27,11 @@ func (b *BeaconState) LatestExecutionPayloadHeader() (interfaces.ExecutionData,
return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapellaVal(), big.NewInt(0))
}
return blocks.WrappedExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDenebVal(), big.NewInt(0))
if b.version == version.Deneb {
return blocks.WrappedExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDenebVal(), big.NewInt(0))
}
return blocks.WrappedExecutionPayloadHeaderElectra(b.latestExecutionPayloadHeaderElectraVal(), big.NewInt(0))
}
// latestExecutionPayloadHeaderVal of the beacon state.
@@ -45,3 +49,7 @@ func (b *BeaconState) latestExecutionPayloadHeaderCapellaVal() *enginev1.Executi
func (b *BeaconState) latestExecutionPayloadHeaderDenebVal() *enginev1.ExecutionPayloadHeaderDeneb {
return ethpb.CopyExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDeneb)
}
func (b *BeaconState) latestExecutionPayloadHeaderElectraVal() *enginev1.ExecutionPayloadHeaderElectra {
return ethpb.CopyExecutionPayloadHeaderElectra(b.latestExecutionPayloadHeaderElectra)
}

View File

@@ -172,6 +172,46 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex,
HistoricalSummaries: b.historicalSummaries,
}
case version.Electra:
return &ethpb.BeaconStateElectra{
GenesisTime: b.genesisTime,
GenesisValidatorsRoot: gvrCopy[:],
Slot: b.slot,
Fork: b.fork,
LatestBlockHeader: b.latestBlockHeader,
BlockRoots: br,
StateRoots: sr,
HistoricalRoots: b.historicalRoots.Slice(),
Eth1Data: b.eth1Data,
Eth1DataVotes: b.eth1DataVotes,
Eth1DepositIndex: b.eth1DepositIndex,
Validators: vals,
Balances: bals,
RandaoMixes: rm,
Slashings: b.slashings,
PreviousEpochParticipation: b.previousEpochParticipation,
CurrentEpochParticipation: b.currentEpochParticipation,
JustificationBits: b.justificationBits,
PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint,
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint,
FinalizedCheckpoint: b.finalizedCheckpoint,
InactivityScores: b.inactivityScoresVal(),
CurrentSyncCommittee: b.currentSyncCommittee,
NextSyncCommittee: b.nextSyncCommittee,
LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderElectra,
NextWithdrawalIndex: b.nextWithdrawalIndex,
NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex,
HistoricalSummaries: b.historicalSummaries,
// DepositReceiptsStartIndex:
// DepositBalanceToConsume:
// ExitBalanceToConsume:
// EarliestExitEpoch:
// ConsolidationBalanceToConsume:
// EarliestConsolidationEpoch:
// PendingBalanceDeposits:
// PendingPartialWithdrawals:
// PendingConsolidations:
}
default:
return nil
}

View File

@@ -56,6 +56,10 @@ func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionDa
b.latestExecutionPayloadHeaderDeneb = header
b.markFieldAsDirty(types.LatestExecutionPayloadHeaderDeneb)
return nil
case *enginev1.ExecutionPayloadHeaderElectra:
b.latestExecutionPayloadHeaderElectra = header
b.markFieldAsDirty(types.LatestExecutionPayloadHeaderElectra)
return nil
default:
return errors.New("value must be an execution payload header")
}

View File

@@ -131,6 +131,11 @@ func InitializeFromProtoDeneb(st *ethpb.BeaconStateDeneb) (state.BeaconState, er
return InitializeFromProtoUnsafeDeneb(proto.Clone(st).(*ethpb.BeaconStateDeneb))
}
// InitializeFromProtoElectra the beacon state from a protobuf representation.
func InitializeFromProtoElectra(st *ethpb.BeaconStateElectra) (state.BeaconState, error) {
return InitializeFromProtoUnsafeElectra(proto.Clone(st).(*ethpb.BeaconStateElectra))
}
// InitializeFromProtoUnsafePhase0 directly uses the beacon state protobuf fields
// and sets them as fields of the BeaconState type.
func InitializeFromProtoUnsafePhase0(st *ethpb.BeaconState) (state.BeaconState, error) {
@@ -683,6 +688,119 @@ func InitializeFromProtoUnsafeDeneb(st *ethpb.BeaconStateDeneb) (state.BeaconSta
return b, nil
}
// InitializeFromProtoUnsafeElectra directly uses the beacon state protobuf fields
// and sets them as fields of the BeaconState type.
func InitializeFromProtoUnsafeElectra(st *ethpb.BeaconStateElectra) (state.BeaconState, error) {
if st == nil {
return nil, errors.New("received nil state")
}
hRoots := customtypes.HistoricalRoots(make([][32]byte, len(st.HistoricalRoots)))
for i, r := range st.HistoricalRoots {
hRoots[i] = bytesutil.ToBytes32(r)
}
fieldCount := params.BeaconConfig().BeaconStateDenebFieldCount
b := &BeaconState{
version: version.Deneb,
genesisTime: st.GenesisTime,
genesisValidatorsRoot: bytesutil.ToBytes32(st.GenesisValidatorsRoot),
slot: st.Slot,
fork: st.Fork,
latestBlockHeader: st.LatestBlockHeader,
historicalRoots: hRoots,
eth1Data: st.Eth1Data,
eth1DataVotes: st.Eth1DataVotes,
eth1DepositIndex: st.Eth1DepositIndex,
slashings: st.Slashings,
previousEpochParticipation: st.PreviousEpochParticipation,
currentEpochParticipation: st.CurrentEpochParticipation,
justificationBits: st.JustificationBits,
previousJustifiedCheckpoint: st.PreviousJustifiedCheckpoint,
currentJustifiedCheckpoint: st.CurrentJustifiedCheckpoint,
finalizedCheckpoint: st.FinalizedCheckpoint,
currentSyncCommittee: st.CurrentSyncCommittee,
nextSyncCommittee: st.NextSyncCommittee,
latestExecutionPayloadHeaderElectra: st.LatestExecutionPayloadHeader,
nextWithdrawalIndex: st.NextWithdrawalIndex,
nextWithdrawalValidatorIndex: st.NextWithdrawalValidatorIndex,
historicalSummaries: st.HistoricalSummaries,
dirtyFields: make(map[types.FieldIndex]bool, fieldCount),
dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount),
stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount),
rebuildTrie: make(map[types.FieldIndex]bool, fieldCount),
valMapHandler: stateutil.NewValMapHandler(st.Validators),
}
if features.Get().EnableExperimentalState {
b.blockRootsMultiValue = NewMultiValueBlockRoots(st.BlockRoots)
b.stateRootsMultiValue = NewMultiValueStateRoots(st.StateRoots)
b.randaoMixesMultiValue = NewMultiValueRandaoMixes(st.RandaoMixes)
b.balancesMultiValue = NewMultiValueBalances(st.Balances)
b.validatorsMultiValue = NewMultiValueValidators(st.Validators)
b.inactivityScoresMultiValue = NewMultiValueInactivityScores(st.InactivityScores)
b.sharedFieldReferences = make(map[types.FieldIndex]*stateutil.Reference, experimentalStateDenebSharedFieldRefCount)
} else {
bRoots := make([][32]byte, fieldparams.BlockRootsLength)
for i, r := range st.BlockRoots {
bRoots[i] = bytesutil.ToBytes32(r)
}
b.blockRoots = bRoots
sRoots := make([][32]byte, fieldparams.StateRootsLength)
for i, r := range st.StateRoots {
sRoots[i] = bytesutil.ToBytes32(r)
}
b.stateRoots = sRoots
mixes := make([][32]byte, fieldparams.RandaoMixesLength)
for i, m := range st.RandaoMixes {
mixes[i] = bytesutil.ToBytes32(m)
}
b.randaoMixes = mixes
b.balances = st.Balances
b.validators = st.Validators
b.inactivityScores = st.InactivityScores
b.sharedFieldReferences = make(map[types.FieldIndex]*stateutil.Reference, denebSharedFieldRefCount)
}
for _, f := range denebFields {
b.dirtyFields[f] = true
b.rebuildTrie[f] = true
b.dirtyIndices[f] = []uint64{}
trie, err := fieldtrie.NewFieldTrie(f, types.BasicArray, nil, 0)
if err != nil {
return nil, err
}
b.stateFieldLeaves[f] = trie
}
// Initialize field reference tracking for shared data.
b.sharedFieldReferences[types.HistoricalRoots] = stateutil.NewRef(1)
b.sharedFieldReferences[types.Eth1DataVotes] = stateutil.NewRef(1)
b.sharedFieldReferences[types.Slashings] = stateutil.NewRef(1)
b.sharedFieldReferences[types.PreviousEpochParticipationBits] = stateutil.NewRef(1)
b.sharedFieldReferences[types.CurrentEpochParticipationBits] = stateutil.NewRef(1)
b.sharedFieldReferences[types.LatestExecutionPayloadHeaderDeneb] = stateutil.NewRef(1) // New in Deneb.
b.sharedFieldReferences[types.HistoricalSummaries] = stateutil.NewRef(1) // New in Capella.
if !features.Get().EnableExperimentalState {
b.sharedFieldReferences[types.BlockRoots] = stateutil.NewRef(1)
b.sharedFieldReferences[types.StateRoots] = stateutil.NewRef(1)
b.sharedFieldReferences[types.RandaoMixes] = stateutil.NewRef(1)
b.sharedFieldReferences[types.Balances] = stateutil.NewRef(1)
b.sharedFieldReferences[types.Validators] = stateutil.NewRef(1)
b.sharedFieldReferences[types.InactivityScores] = stateutil.NewRef(1)
}
state.Count.Inc()
// Finalizer runs when dst is being destroyed in garbage collection.
runtime.SetFinalizer(b, finalizerCleanup)
return b, nil
}
// Copy returns a deep copy of the beacon state.
func (b *BeaconState) Copy() state.BeaconState {
b.lock.RLock()
@@ -750,6 +868,7 @@ func (b *BeaconState) Copy() state.BeaconState {
latestExecutionPayloadHeader: b.latestExecutionPayloadHeaderVal(),
latestExecutionPayloadHeaderCapella: b.latestExecutionPayloadHeaderCapellaVal(),
latestExecutionPayloadHeaderDeneb: b.latestExecutionPayloadHeaderDenebVal(),
latestExecutionPayloadHeaderElectra: b.latestExecutionPayloadHeaderElectraVal(),
id: types.Enumerator.Inc(),

View File

@@ -207,6 +207,7 @@ const (
LatestExecutionPayloadHeader
LatestExecutionPayloadHeaderCapella
LatestExecutionPayloadHeaderDeneb
LatestExecutionPayloadHeaderElectra
NextWithdrawalIndex
NextWithdrawalValidatorIndex
HistoricalSummaries

View File

@@ -172,6 +172,26 @@ func (e executionPayload) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// DepositReceipts --
func (executionPayload) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (executionPayload) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (executionPayload) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayload) WithdrawalRequestsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbBellatrix --
func (e executionPayload) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return e.p, nil
@@ -187,6 +207,11 @@ 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
@@ -353,6 +378,31 @@ func (e executionPayloadHeader) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// DepositReceipts --
func (executionPayloadHeader) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (executionPayloadHeader) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (executionPayloadHeader) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayloadHeader) WithdrawalRequestsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (executionPayloadHeader) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayloadHeader) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
@@ -564,6 +614,31 @@ func (e executionPayloadCapella) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// DepositReceipts --
func (executionPayloadCapella) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (executionPayloadCapella) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (executionPayloadCapella) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayloadCapella) WithdrawalRequestsRoot() ([]byte, error) {
return nil, 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
@@ -747,6 +822,31 @@ func (e executionPayloadHeaderCapella) ExcessBlobGas() (uint64, error) {
return 0, consensus_types.ErrUnsupportedField
}
// DepositReceipts --
func (executionPayloadHeaderCapella) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (executionPayloadHeaderCapella) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (executionPayloadHeaderCapella) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayloadHeaderCapella) WithdrawalRequestsRoot() ([]byte, error) {
return nil, 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
@@ -858,6 +958,73 @@ func PayloadToHeaderDeneb(payload interfaces.ExecutionData) (*enginev1.Execution
}, nil
}
// PayloadToHeaderElectra converts `payload` into execution payload header format.
func PayloadToHeaderElectra(payload interfaces.ExecutionData) (*enginev1.ExecutionPayloadHeaderElectra, error) {
txs, err := payload.Transactions()
if err != nil {
return nil, err
}
txRoot, err := ssz.TransactionsRoot(txs)
if err != nil {
return nil, err
}
withdrawals, err := payload.Withdrawals()
if err != nil {
return nil, err
}
withdrawalsRoot, err := ssz.WithdrawalSliceRoot(withdrawals, fieldparams.MaxWithdrawalsPerPayload)
if err != nil {
return nil, err
}
blobGasUsed, err := payload.BlobGasUsed()
if err != nil {
return nil, err
}
excessBlobGas, err := payload.ExcessBlobGas()
if err != nil {
return nil, err
}
depositReceipts, err := payload.DepositReceipts()
if err != nil {
return nil, err
}
depositReceiptsRoot, err := ssz.DepositReceiptSliceRoot(depositReceipts, fieldparams.MaxDepositReceiptsPerPayload)
if err != nil {
return nil, err
}
withdrawalRequests, err := payload.WithdrawalRequests()
if err != nil {
return nil, err
}
withdrawalRequestsRoot, err := ssz.WithdrawalRequestSliceRoot(withdrawalRequests, fieldparams.MaxWithdrawalRequestsPerPayload)
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,
DepositReceiptsRoot: depositReceiptsRoot[:],
WithdrawalRequestsRoot: withdrawalRequestsRoot[:],
}, nil
}
// IsEmptyExecutionData checks if an execution data is empty underneath. If a single field has
// a non-zero value, this function will return false.
func IsEmptyExecutionData(data interfaces.ExecutionData) (bool, error) {
@@ -1071,6 +1238,31 @@ func (e executionPayloadHeaderDeneb) ExcessBlobGas() (uint64, error) {
return e.p.ExcessBlobGas, nil
}
// DepositReceipts --
func (executionPayloadHeaderDeneb) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (executionPayloadHeaderDeneb) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (executionPayloadHeaderDeneb) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayloadHeaderDeneb) WithdrawalRequestsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (executionPayloadHeaderDeneb) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (executionPayloadHeaderDeneb) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
@@ -1252,6 +1444,31 @@ func (e executionPayloadDeneb) ExcessBlobGas() (uint64, error) {
return e.p.ExcessBlobGas, nil
}
// DepositReceipts --
func (executionPayloadDeneb) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (executionPayloadDeneb) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (executionPayloadDeneb) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayloadDeneb) WithdrawalRequestsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (executionPayloadDeneb) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbBellatrix --
func (e executionPayloadDeneb) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
@@ -1294,3 +1511,415 @@ func PayloadValueToGwei(value []byte) math.Gwei {
v := big.NewInt(0).SetBytes(bytesutil.ReverseByteOrder(value))
return math.WeiToGwei(v)
}
// executionPayloadElectra 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.
type executionPayloadElectra struct {
p *enginev1.ExecutionPayloadElectra
weiValue math.Wei
gweiValue uint64
}
// WrappedExecutionPayloadElectra is a constructor which wraps a protobuf execution payload into an interface.
func WrappedExecutionPayloadElectra(p *enginev1.ExecutionPayloadElectra, value math.Wei) (interfaces.ExecutionData, error) {
w := executionPayloadElectra{p: p, weiValue: value, gweiValue: uint64(math.WeiToGwei(value))}
if w.IsNil() {
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}
// IsNil checks if the underlying data is nil.
func (e executionPayloadElectra) IsNil() bool {
return e.p == nil
}
// MarshalSSZ --
func (e executionPayloadElectra) MarshalSSZ() ([]byte, error) {
return e.p.MarshalSSZ()
}
// MarshalSSZTo --
func (e executionPayloadElectra) MarshalSSZTo(dst []byte) ([]byte, error) {
return e.p.MarshalSSZTo(dst)
}
// SizeSSZ --
func (e executionPayloadElectra) SizeSSZ() int {
return e.p.SizeSSZ()
}
// UnmarshalSSZ --
func (e executionPayloadElectra) UnmarshalSSZ(buf []byte) error {
return e.p.UnmarshalSSZ(buf)
}
// HashTreeRoot --
func (e executionPayloadElectra) HashTreeRoot() ([32]byte, error) {
return e.p.HashTreeRoot()
}
// HashTreeRootWith --
func (e executionPayloadElectra) HashTreeRootWith(hh *fastssz.Hasher) error {
return e.p.HashTreeRootWith(hh)
}
// Proto --
func (e executionPayloadElectra) Proto() proto.Message {
return e.p
}
// ParentHash --
func (e executionPayloadElectra) ParentHash() []byte {
return e.p.ParentHash
}
// FeeRecipient --
func (e executionPayloadElectra) FeeRecipient() []byte {
return e.p.FeeRecipient
}
// StateRoot --
func (e executionPayloadElectra) StateRoot() []byte {
return e.p.StateRoot
}
// ReceiptsRoot --
func (e executionPayloadElectra) ReceiptsRoot() []byte {
return e.p.ReceiptsRoot
}
// LogsBloom --
func (e executionPayloadElectra) LogsBloom() []byte {
return e.p.LogsBloom
}
// PrevRandao --
func (e executionPayloadElectra) PrevRandao() []byte {
return e.p.PrevRandao
}
// BlockNumber --
func (e executionPayloadElectra) BlockNumber() uint64 {
return e.p.BlockNumber
}
// GasLimit --
func (e executionPayloadElectra) GasLimit() uint64 {
return e.p.GasLimit
}
// GasUsed --
func (e executionPayloadElectra) GasUsed() uint64 {
return e.p.GasUsed
}
// Timestamp --
func (e executionPayloadElectra) Timestamp() uint64 {
return e.p.Timestamp
}
// ExtraData --
func (e executionPayloadElectra) ExtraData() []byte {
return e.p.ExtraData
}
// BaseFeePerGas --
func (e executionPayloadElectra) BaseFeePerGas() []byte {
return e.p.BaseFeePerGas
}
// BlockHash --
func (e executionPayloadElectra) BlockHash() []byte {
return e.p.BlockHash
}
// Transactions --
func (e executionPayloadElectra) Transactions() ([][]byte, error) {
return e.p.Transactions, nil
}
// TransactionsRoot --
func (e executionPayloadElectra) TransactionsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// Withdrawals --
func (e executionPayloadElectra) Withdrawals() ([]*enginev1.Withdrawal, error) {
return e.p.Withdrawals, nil
}
// WithdrawalsRoot --
func (e executionPayloadElectra) WithdrawalsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
func (e executionPayloadElectra) BlobGasUsed() (uint64, error) {
return e.p.BlobGasUsed, nil
}
func (e executionPayloadElectra) ExcessBlobGas() (uint64, error) {
return e.p.ExcessBlobGas, nil
}
// DepositReceipts --
func (e executionPayloadElectra) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return e.p.DepositReceipts, nil
}
// DepositReceiptsRoot --
func (executionPayloadElectra) DepositReceiptsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequests --
func (e executionPayloadElectra) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (executionPayloadElectra) WithdrawalRequestsRoot() ([]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (e executionPayloadElectra) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return e.p, nil
}
// PbBellatrix --
func (e executionPayloadElectra) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (e executionPayloadElectra) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (e executionPayloadElectra) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (e executionPayloadElectra) ValueInWei() (math.Wei, error) {
return e.weiValue, nil
}
// ValueInGwei --
func (e executionPayloadElectra) ValueInGwei() (uint64, error) {
return e.gweiValue, nil
}
// IsBlinded returns true if the underlying data is blinded.
func (e executionPayloadElectra) IsBlinded() bool {
return false
}
// executionPayloadHeaderElectra is a convenience wrapper around a blinded beacon block body's execution header 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.
type executionPayloadHeaderElectra struct {
p *enginev1.ExecutionPayloadHeaderElectra
weiValue math.Wei
gweiValue uint64
}
// WrappedExecutionPayloadHeaderElectra is a constructor which wraps a protobuf execution header into an interface.
func WrappedExecutionPayloadHeaderElectra(p *enginev1.ExecutionPayloadHeaderElectra, value math.Wei) (interfaces.ExecutionData, error) {
w := executionPayloadHeaderElectra{p: p, weiValue: value, gweiValue: uint64(math.WeiToGwei(value))}
if w.IsNil() {
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}
// IsNil checks if the underlying data is nil.
func (e executionPayloadHeaderElectra) IsNil() bool {
return e.p == nil
}
// MarshalSSZ --
func (e executionPayloadHeaderElectra) MarshalSSZ() ([]byte, error) {
return e.p.MarshalSSZ()
}
// MarshalSSZTo --
func (e executionPayloadHeaderElectra) MarshalSSZTo(dst []byte) ([]byte, error) {
return e.p.MarshalSSZTo(dst)
}
// SizeSSZ --
func (e executionPayloadHeaderElectra) SizeSSZ() int {
return e.p.SizeSSZ()
}
// UnmarshalSSZ --
func (e executionPayloadHeaderElectra) UnmarshalSSZ(buf []byte) error {
return e.p.UnmarshalSSZ(buf)
}
// HashTreeRoot --
func (e executionPayloadHeaderElectra) HashTreeRoot() ([32]byte, error) {
return e.p.HashTreeRoot()
}
// HashTreeRootWith --
func (e executionPayloadHeaderElectra) HashTreeRootWith(hh *fastssz.Hasher) error {
return e.p.HashTreeRootWith(hh)
}
// Proto --
func (e executionPayloadHeaderElectra) Proto() proto.Message {
return e.p
}
// ParentHash --
func (e executionPayloadHeaderElectra) ParentHash() []byte {
return e.p.ParentHash
}
// FeeRecipient --
func (e executionPayloadHeaderElectra) FeeRecipient() []byte {
return e.p.FeeRecipient
}
// StateRoot --
func (e executionPayloadHeaderElectra) StateRoot() []byte {
return e.p.StateRoot
}
// ReceiptsRoot --
func (e executionPayloadHeaderElectra) ReceiptsRoot() []byte {
return e.p.ReceiptsRoot
}
// LogsBloom --
func (e executionPayloadHeaderElectra) LogsBloom() []byte {
return e.p.LogsBloom
}
// PrevRandao --
func (e executionPayloadHeaderElectra) PrevRandao() []byte {
return e.p.PrevRandao
}
// BlockNumber --
func (e executionPayloadHeaderElectra) BlockNumber() uint64 {
return e.p.BlockNumber
}
// GasLimit --
func (e executionPayloadHeaderElectra) GasLimit() uint64 {
return e.p.GasLimit
}
// GasUsed --
func (e executionPayloadHeaderElectra) GasUsed() uint64 {
return e.p.GasUsed
}
// Timestamp --
func (e executionPayloadHeaderElectra) Timestamp() uint64 {
return e.p.Timestamp
}
// ExtraData --
func (e executionPayloadHeaderElectra) ExtraData() []byte {
return e.p.ExtraData
}
// BaseFeePerGas --
func (e executionPayloadHeaderElectra) BaseFeePerGas() []byte {
return e.p.BaseFeePerGas
}
// BlockHash --
func (e executionPayloadHeaderElectra) BlockHash() []byte {
return e.p.BlockHash
}
// Transactions --
func (e executionPayloadHeaderElectra) Transactions() ([][]byte, error) {
return nil, consensus_types.ErrUnsupportedField
}
// TransactionsRoot --
func (e executionPayloadHeaderElectra) TransactionsRoot() ([]byte, error) {
return e.p.TransactionsRoot, nil
}
// Withdrawals --
func (e executionPayloadHeaderElectra) Withdrawals() ([]*enginev1.Withdrawal, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalsRoot --
func (e executionPayloadHeaderElectra) WithdrawalsRoot() ([]byte, error) {
return e.p.WithdrawalsRoot, nil
}
func (e executionPayloadHeaderElectra) BlobGasUsed() (uint64, error) {
return e.p.BlobGasUsed, nil
}
func (e executionPayloadHeaderElectra) ExcessBlobGas() (uint64, error) {
return e.p.ExcessBlobGas, nil
}
// DepositReceipts --
func (executionPayloadHeaderElectra) DepositReceipts() ([]*enginev1.DepositReceipt, error) {
return nil, consensus_types.ErrUnsupportedField
}
// DepositReceiptsRoot --
func (e executionPayloadHeaderElectra) DepositReceiptsRoot() ([]byte, error) {
return e.p.ReceiptsRoot, nil
}
// WithdrawalRequests --
func (executionPayloadHeaderElectra) WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error) {
return nil, consensus_types.ErrUnsupportedField
}
// WithdrawalRequestsRoot --
func (e executionPayloadHeaderElectra) WithdrawalRequestsRoot() ([]byte, error) {
return e.p.WithdrawalRequestsRoot, nil
}
// PbBellatrix --
func (e executionPayloadHeaderElectra) PbBellatrix() (*enginev1.ExecutionPayload, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbCapella --
func (e executionPayloadHeaderElectra) PbCapella() (*enginev1.ExecutionPayloadCapella, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbDeneb --
func (e executionPayloadHeaderElectra) PbDeneb() (*enginev1.ExecutionPayloadDeneb, error) {
return nil, consensus_types.ErrUnsupportedField
}
// PbElectra --
func (e executionPayloadHeaderElectra) PbElectra() (*enginev1.ExecutionPayloadElectra, error) {
return nil, consensus_types.ErrUnsupportedField
}
// ValueInWei --
func (e executionPayloadHeaderElectra) ValueInWei() (math.Wei, error) {
return e.weiValue, nil
}
// ValueInGwei --
func (e executionPayloadHeaderElectra) ValueInGwei() (uint64, error) {
return e.gweiValue, nil
}
// IsBlinded returns true if the underlying data is blinded.
func (e executionPayloadHeaderElectra) IsBlinded() bool {
return true
}

View File

@@ -67,6 +67,14 @@ func NewSignedBeaconBlock(i interface{}) (interfaces.SignedBeaconBlock, error) {
return initBlindedSignedBlockFromProtoDeneb(b)
case *eth.GenericSignedBeaconBlock_BlindedDeneb:
return initBlindedSignedBlockFromProtoDeneb(b.BlindedDeneb)
case *eth.GenericSignedBeaconBlock_Electra:
return initSignedBlockFromProtoElectra(b.Electra.Block)
case *eth.SignedBeaconBlockElectra:
return initSignedBlockFromProtoElectra(b)
case *eth.SignedBlindedBeaconBlockElectra:
return initBlindedSignedBlockFromProtoElectra(b)
case *eth.GenericSignedBeaconBlock_BlindedElectra:
return initBlindedSignedBlockFromProtoElectra(b.BlindedElectra)
default:
return nil, errors.Wrapf(ErrUnsupportedSignedBeaconBlock, "unable to create block from type %T", i)
}
@@ -109,6 +117,14 @@ func NewBeaconBlock(i interface{}) (interfaces.ReadOnlyBeaconBlock, error) {
return initBlindedBlockFromProtoDeneb(b)
case *eth.GenericBeaconBlock_BlindedDeneb:
return initBlindedBlockFromProtoDeneb(b.BlindedDeneb)
case *eth.GenericBeaconBlock_Electra:
return initBlockFromProtoElectra(b.Electra.Block)
case *eth.BeaconBlockElectra:
return initBlockFromProtoElectra(b)
case *eth.BlindedBeaconBlockElectra:
return initBlindedBlockFromProtoElectra(b)
case *eth.GenericBeaconBlock_BlindedElectra:
return initBlindedBlockFromProtoElectra(b.BlindedElectra)
default:
return nil, errors.Wrapf(errUnsupportedBeaconBlock, "unable to create block from type %T", i)
}
@@ -135,6 +151,10 @@ func NewBeaconBlockBody(i interface{}) (interfaces.ReadOnlyBeaconBlockBody, erro
return initBlockBodyFromProtoDeneb(b)
case *eth.BlindedBeaconBlockBodyDeneb:
return initBlindedBlockBodyFromProtoDeneb(b)
case *eth.BeaconBlockBodyElectra:
return initBlockBodyFromProtoElectra(b)
case *eth.BlindedBeaconBlockBodyElectra:
return initBlindedBlockBodyFromProtoElectra(b)
default:
return nil, errors.Wrapf(errUnsupportedBeaconBlockBody, "unable to create block body from type %T", i)
}
@@ -201,6 +221,19 @@ func BuildSignedBeaconBlock(blk interfaces.ReadOnlyBeaconBlock, signature []byte
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBeaconBlockDeneb{Block: pb, Signature: signature})
case version.Electra:
if blk.IsBlinded() {
pb, ok := pb.(*eth.BlindedBeaconBlockElectra)
if !ok {
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBlindedBeaconBlockElectra{Message: pb, Signature: signature})
}
pb, ok := pb.(*eth.BeaconBlockElectra)
if !ok {
return nil, errIncorrectBlockVersion
}
return NewSignedBeaconBlock(&eth.SignedBeaconBlockElectra{Block: pb, Signature: signature})
default:
return nil, errUnsupportedBeaconBlock
}

View File

@@ -81,6 +81,13 @@ func (b *SignedBeaconBlock) Copy() (interfaces.SignedBeaconBlock, error) {
}
cp := eth.CopySignedBeaconBlockDeneb(pb.(*eth.SignedBeaconBlockDeneb))
return initSignedBlockFromProtoDeneb(cp)
case version.Electra:
if b.IsBlinded() {
cp := eth.CopySignedBlindedBeaconBlockElectra(pb.(*eth.SignedBlindedBeaconBlockElectra))
return initBlindedSignedBlockFromProtoElectra(cp)
}
cp := eth.CopySignedBeaconBlockElectra(pb.(*eth.SignedBeaconBlockElectra))
return initSignedBlockFromProtoElectra(cp)
default:
return nil, errIncorrectBlockVersion
}
@@ -128,6 +135,15 @@ func (b *SignedBeaconBlock) PbGenericBlock() (*eth.GenericSignedBeaconBlock, err
return &eth.GenericSignedBeaconBlock{
Block: &eth.GenericSignedBeaconBlock_Deneb{Deneb: pb.(*eth.SignedBeaconBlockContentsDeneb)},
}, nil
case version.Electra:
if b.IsBlinded() {
return &eth.GenericSignedBeaconBlock{
Block: &eth.GenericSignedBeaconBlock_BlindedElectra{BlindedElectra: pb.(*eth.SignedBlindedBeaconBlockElectra)},
}, nil
}
return &eth.GenericSignedBeaconBlock{
Block: &eth.GenericSignedBeaconBlock_Electra{Electra: pb.(*eth.SignedBeaconBlockContentsElectra)},
}, nil
default:
return nil, errIncorrectBlockVersion
}
@@ -229,6 +245,30 @@ func (b *SignedBeaconBlock) PbBlindedDenebBlock() (*eth.SignedBlindedBeaconBlock
return pb.(*eth.SignedBlindedBeaconBlockDeneb), nil
}
// PbElectraBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbElectraBlock() (*eth.SignedBeaconBlockElectra, error) {
if b.version != version.Electra || b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbElectraBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBeaconBlockElectra), nil
}
// PbBlindedElectraBlock returns the underlying protobuf object.
func (b *SignedBeaconBlock) PbBlindedElectraBlock() (*eth.SignedBlindedBeaconBlockElectra, error) {
if b.version != version.Electra || !b.IsBlinded() {
return nil, consensus_types.ErrNotSupported("PbBlindedElectraBlock", b.version)
}
pb, err := b.Proto()
if err != nil {
return nil, err
}
return pb.(*eth.SignedBlindedBeaconBlockElectra), nil
}
// ToBlinded converts a non-blinded block to its blinded equivalent.
func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, error) {
if b.version < version.Bellatrix {
@@ -330,6 +370,36 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e
},
Signature: b.signature[:],
})
case *enginev1.ExecutionPayloadElectra:
header, err := PayloadToHeaderElectra(payload)
if err != nil {
return nil, err
}
return initBlindedSignedBlockFromProtoElectra(
&eth.SignedBlindedBeaconBlockElectra{
Message: &eth.BlindedBeaconBlockElectra{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyElectra{
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashingsElectra,
Attestations: b.block.body.attestationsElectra,
Deposits: b.block.body.deposits,
VoluntaryExits: b.block.body.voluntaryExits,
SyncAggregate: b.block.body.syncAggregate,
ExecutionPayloadHeader: header,
BlsToExecutionChanges: b.block.body.blsToExecutionChanges,
BlobKzgCommitments: b.block.body.blobKzgCommitments,
Consolidations: b.block.body.signedConsolidations,
},
},
Signature: b.signature[:],
})
default:
return nil, fmt.Errorf("%T is not an execution payload header", p)
}
@@ -459,6 +529,11 @@ func (b *SignedBeaconBlock) MarshalSSZ() ([]byte, error) {
return pb.(*eth.SignedBlindedBeaconBlockDeneb).MarshalSSZ()
}
return pb.(*eth.SignedBeaconBlockDeneb).MarshalSSZ()
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.SignedBlindedBeaconBlockElectra).MarshalSSZ()
}
return pb.(*eth.SignedBeaconBlockElectra).MarshalSSZ()
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -491,6 +566,11 @@ func (b *SignedBeaconBlock) MarshalSSZTo(dst []byte) ([]byte, error) {
return pb.(*eth.SignedBlindedBeaconBlockDeneb).MarshalSSZTo(dst)
}
return pb.(*eth.SignedBeaconBlockDeneb).MarshalSSZTo(dst)
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.SignedBlindedBeaconBlockElectra).MarshalSSZTo(dst)
}
return pb.(*eth.SignedBeaconBlockElectra).MarshalSSZTo(dst)
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -527,6 +607,11 @@ func (b *SignedBeaconBlock) SizeSSZ() int {
return pb.(*eth.SignedBlindedBeaconBlockDeneb).SizeSSZ()
}
return pb.(*eth.SignedBeaconBlockDeneb).SizeSSZ()
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.SignedBlindedBeaconBlockElectra).SizeSSZ()
}
return pb.(*eth.SignedBeaconBlockElectra).SizeSSZ()
default:
panic(incorrectBlockVersion)
}
@@ -622,6 +707,28 @@ func (b *SignedBeaconBlock) UnmarshalSSZ(buf []byte) error {
return err
}
}
case version.Electra:
if b.IsBlinded() {
pb := &eth.SignedBlindedBeaconBlockElectra{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initBlindedSignedBlockFromProtoElectra(pb)
if err != nil {
return err
}
} else {
pb := &eth.SignedBeaconBlockElectra{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initSignedBlockFromProtoElectra(pb)
if err != nil {
return err
}
}
default:
return errIncorrectBlockVersion
}
@@ -695,6 +802,11 @@ func (b *BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
return pb.(*eth.BlindedBeaconBlockDeneb).HashTreeRoot()
}
return pb.(*eth.BeaconBlockDeneb).HashTreeRoot()
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockElectra).HashTreeRoot()
}
return pb.(*eth.BeaconBlockElectra).HashTreeRoot()
default:
return [field_params.RootLength]byte{}, errIncorrectBlockVersion
}
@@ -726,6 +838,11 @@ func (b *BeaconBlock) HashTreeRootWith(h *ssz.Hasher) error {
return pb.(*eth.BlindedBeaconBlockDeneb).HashTreeRootWith(h)
}
return pb.(*eth.BeaconBlockDeneb).HashTreeRootWith(h)
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockElectra).HashTreeRootWith(h)
}
return pb.(*eth.BeaconBlockElectra).HashTreeRootWith(h)
default:
return errIncorrectBlockVersion
}
@@ -758,6 +875,11 @@ func (b *BeaconBlock) MarshalSSZ() ([]byte, error) {
return pb.(*eth.BlindedBeaconBlockDeneb).MarshalSSZ()
}
return pb.(*eth.BeaconBlockDeneb).MarshalSSZ()
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockElectra).MarshalSSZ()
}
return pb.(*eth.BeaconBlockElectra).MarshalSSZ()
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -790,6 +912,11 @@ func (b *BeaconBlock) MarshalSSZTo(dst []byte) ([]byte, error) {
return pb.(*eth.BlindedBeaconBlockDeneb).MarshalSSZTo(dst)
}
return pb.(*eth.BeaconBlockDeneb).MarshalSSZTo(dst)
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockElectra).MarshalSSZTo(dst)
}
return pb.(*eth.BeaconBlockElectra).MarshalSSZTo(dst)
default:
return []byte{}, errIncorrectBlockVersion
}
@@ -826,6 +953,11 @@ func (b *BeaconBlock) SizeSSZ() int {
return pb.(*eth.BlindedBeaconBlockDeneb).SizeSSZ()
}
return pb.(*eth.BeaconBlockDeneb).SizeSSZ()
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockElectra).SizeSSZ()
}
return pb.(*eth.BeaconBlockElectra).SizeSSZ()
default:
panic(incorrectBodyVersion)
}
@@ -921,6 +1053,28 @@ func (b *BeaconBlock) UnmarshalSSZ(buf []byte) error {
return err
}
}
case version.Electra:
if b.IsBlinded() {
pb := &eth.BlindedBeaconBlockElectra{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initBlindedBlockFromProtoElectra(pb)
if err != nil {
return err
}
} else {
pb := &eth.BeaconBlockElectra{}
if err := pb.UnmarshalSSZ(buf); err != nil {
return err
}
var err error
newBlock, err = initBlockFromProtoElectra(pb)
if err != nil {
return err
}
}
default:
return errIncorrectBlockVersion
}
@@ -954,6 +1108,11 @@ func (b *BeaconBlock) AsSignRequestObject() (validatorpb.SignRequestObject, erro
return &validatorpb.SignRequest_BlindedBlockDeneb{BlindedBlockDeneb: pb.(*eth.BlindedBeaconBlockDeneb)}, nil
}
return &validatorpb.SignRequest_BlockDeneb{BlockDeneb: pb.(*eth.BeaconBlockDeneb)}, nil
case version.Electra:
if b.IsBlinded() {
return &validatorpb.SignRequest_BlindedBlockElectra{BlindedBlockElectra: pb.(*eth.BlindedBeaconBlockElectra)}, nil
}
return &validatorpb.SignRequest_BlockElectra{BlockElectra: pb.(*eth.BeaconBlockElectra)}, nil
default:
return nil, errIncorrectBlockVersion
}
@@ -996,6 +1155,13 @@ func (b *BeaconBlock) Copy() (interfaces.ReadOnlyBeaconBlock, error) {
}
cp := eth.CopyBeaconBlockDeneb(pb.(*eth.BeaconBlockDeneb))
return initBlockFromProtoDeneb(cp)
case version.Electra:
if b.IsBlinded() {
cp := eth.CopyBlindedBeaconBlockElectra(pb.(*eth.BlindedBeaconBlockElectra))
return initBlindedBlockFromProtoElectra(cp)
}
cp := eth.CopyBeaconBlockElectra(pb.(*eth.BeaconBlockElectra))
return initBlockFromProtoElectra(cp)
default:
return nil, errIncorrectBlockVersion
}
@@ -1027,13 +1193,42 @@ func (b *BeaconBlockBody) ProposerSlashings() []*eth.ProposerSlashing {
}
// AttesterSlashings returns the attester slashings in the block.
func (b *BeaconBlockBody) AttesterSlashings() []*eth.AttesterSlashing {
return b.attesterSlashings
func (b *BeaconBlockBody) AttesterSlashings() []interfaces.AttesterSlashing {
var attestations []interfaces.AttesterSlashing
if b.version >= version.Electra {
attestations = make([]interfaces.AttesterSlashing, len(b.attesterSlashingsElectra))
for i, att := range b.attesterSlashingsElectra {
attestations[i] = att
}
return attestations
}
attestations = make([]interfaces.AttesterSlashing, len(b.attesterSlashings))
for i, att := range b.attesterSlashings {
attestations[i] = att
}
return attestations
}
// AttesterSlashingsElectra returns the attester slashings in the block.
func (b *BeaconBlockBody) AttesterSlashingsElectra() []*eth.AttesterSlashingElectra {
return b.attesterSlashingsElectra
}
// Attestations returns the stored attestations in the block.
func (b *BeaconBlockBody) Attestations() []*eth.Attestation {
return b.attestations
func (b *BeaconBlockBody) Attestations() []interfaces.Attestation {
var attestations []interfaces.Attestation
if b.version >= version.Electra {
attestations = make([]interfaces.Attestation, len(b.attestationsElectra))
for i, att := range b.attestationsElectra {
attestations[i] = att
}
return attestations
}
attestations = make([]interfaces.Attestation, len(b.attestations))
for i, att := range b.attestations {
attestations[i] = att
}
return attestations
}
// Deposits returns the stored deposits in the block.
@@ -1079,13 +1274,20 @@ func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) {
switch b.version {
case version.Phase0, version.Altair, version.Bellatrix, version.Capella:
return nil, consensus_types.ErrNotSupported("BlobKzgCommitments", b.version)
case version.Deneb:
case version.Deneb, version.Electra:
return b.blobKzgCommitments, nil
default:
return nil, errIncorrectBlockVersion
}
}
func (b *BeaconBlockBody) Consolidations() ([]*eth.SignedConsolidation, error) {
if b.version < version.Electra {
return nil, consensus_types.ErrNotSupported("Consolidations", b.version)
}
return b.signedConsolidations, nil
}
// Version returns the version of the beacon block body
func (b *BeaconBlockBody) Version() int {
return b.version
@@ -1117,6 +1319,11 @@ func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error)
return pb.(*eth.BlindedBeaconBlockBodyDeneb).HashTreeRoot()
}
return pb.(*eth.BeaconBlockBodyDeneb).HashTreeRoot()
case version.Electra:
if b.IsBlinded() {
return pb.(*eth.BlindedBeaconBlockElectra).HashTreeRoot()
}
return pb.(*eth.BeaconBlockElectra).HashTreeRoot()
default:
return [field_params.RootLength]byte{}, errIncorrectBodyVersion
}

View File

@@ -449,6 +449,53 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
BlsToExecutionChanges: b.blsToExecutionChanges,
BlobKzgCommitments: b.blobKzgCommitments,
}, nil
case version.Electra:
if b.IsBlinded() {
var ph *enginev1.ExecutionPayloadHeaderElectra
var ok bool
if b.executionPayloadHeader != nil {
ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderElectra)
if !ok {
return nil, errPayloadHeaderWrongType
}
}
return &eth.BlindedBeaconBlockBodyElectra{
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashingsElectra,
Attestations: b.attestationsElectra,
Deposits: b.deposits,
VoluntaryExits: b.voluntaryExits,
SyncAggregate: b.syncAggregate,
ExecutionPayloadHeader: ph,
BlsToExecutionChanges: b.blsToExecutionChanges,
BlobKzgCommitments: b.blobKzgCommitments,
}, nil
}
var p *enginev1.ExecutionPayloadElectra
var ok bool
if b.executionPayload != nil {
p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadElectra)
if !ok {
return nil, errPayloadWrongType
}
}
return &eth.BeaconBlockBodyElectra{
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashingsElectra,
Attestations: b.attestationsElectra,
Deposits: b.deposits,
VoluntaryExits: b.voluntaryExits,
SyncAggregate: b.syncAggregate,
ExecutionPayload: p,
BlsToExecutionChanges: b.blsToExecutionChanges,
BlobKzgCommitments: b.blobKzgCommitments,
}, nil
default:
return nil, errors.New("unsupported beacon block body version")
}
@@ -539,6 +586,23 @@ func initSignedBlockFromProtoDeneb(pb *eth.SignedBeaconBlockDeneb) (*SignedBeaco
return b, nil
}
func initSignedBlockFromProtoElectra(pb *eth.SignedBeaconBlockElectra) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
block, err := initBlockFromProtoElectra(pb.Block)
if err != nil {
return nil, err
}
b := &SignedBeaconBlock{
version: version.Electra,
block: block,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBellatrix) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
@@ -590,6 +654,23 @@ func initBlindedSignedBlockFromProtoDeneb(pb *eth.SignedBlindedBeaconBlockDeneb)
return b, nil
}
func initBlindedSignedBlockFromProtoElectra(pb *eth.SignedBlindedBeaconBlockElectra) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
block, err := initBlindedBlockFromProtoElectra(pb.Message)
if err != nil {
return nil, err
}
b := &SignedBeaconBlock{
version: version.Electra,
block: block,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
@@ -710,6 +791,26 @@ func initBlockFromProtoDeneb(pb *eth.BeaconBlockDeneb) (*BeaconBlock, error) {
return b, nil
}
func initBlockFromProtoElectra(pb *eth.BeaconBlockElectra) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
body, err := initBlockBodyFromProtoElectra(pb.Body)
if err != nil {
return nil, err
}
b := &BeaconBlock{
version: version.Electra,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
}
func initBlindedBlockFromProtoCapella(pb *eth.BlindedBeaconBlockCapella) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
@@ -750,11 +851,30 @@ func initBlindedBlockFromProtoDeneb(pb *eth.BlindedBeaconBlockDeneb) (*BeaconBlo
return b, nil
}
func initBlindedBlockFromProtoElectra(pb *eth.BlindedBeaconBlockElectra) (*BeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
}
body, err := initBlindedBlockBodyFromProtoElectra(pb.Body)
if err != nil {
return nil, err
}
b := &BeaconBlock{
version: version.Electra,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
}
func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
}
b := &BeaconBlockBody{
version: version.Phase0,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
@@ -773,7 +893,6 @@ func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBo
if pb == nil {
return nil, errNilBlockBody
}
b := &BeaconBlockBody{
version: version.Altair,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
@@ -950,3 +1069,60 @@ func initBlindedBlockBodyFromProtoDeneb(pb *eth.BlindedBeaconBlockBodyDeneb) (*B
}
return b, nil
}
func initBlockBodyFromProtoElectra(pb *eth.BeaconBlockBodyElectra) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
}
p, err := WrappedExecutionPayloadElectra(pb.ExecutionPayload, big.NewInt(0))
// We allow the payload to be nil
if err != nil && err != consensus_types.ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
version: version.Electra,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashingsElectra: pb.AttesterSlashings,
attestationsElectra: pb.Attestations,
deposits: pb.Deposits,
voluntaryExits: pb.VoluntaryExits,
syncAggregate: pb.SyncAggregate,
executionPayload: p,
blsToExecutionChanges: pb.BlsToExecutionChanges,
blobKzgCommitments: pb.BlobKzgCommitments,
}
return b, nil
}
func initBlindedBlockBodyFromProtoElectra(pb *eth.BlindedBeaconBlockBodyElectra) (*BeaconBlockBody, error) {
if pb == nil {
return nil, errNilBlockBody
}
ph, err := WrappedExecutionPayloadHeaderElectra(pb.ExecutionPayloadHeader, big.NewInt(0))
// We allow the payload to be nil
if err != nil && err != consensus_types.ErrNilObjectWrapped {
return nil, err
}
b := &BeaconBlockBody{
version: version.Electra,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashingsElectra: pb.AttesterSlashings,
attestationsElectra: pb.Attestations,
deposits: pb.Deposits,
voluntaryExits: pb.VoluntaryExits,
syncAggregate: pb.SyncAggregate,
executionPayloadHeader: ph,
blsToExecutionChanges: pb.BlsToExecutionChanges,
blobKzgCommitments: pb.BlobKzgCommitments,
signedConsolidations: pb.Consolidations,
}
return b, nil
}

View File

@@ -68,12 +68,24 @@ func (b *SignedBeaconBlock) SetAttesterSlashings(a []*eth.AttesterSlashing) {
b.block.body.attesterSlashings = a
}
// SetAttesterSlashingsElectra sets the attester slashings in the block.
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetAttesterSlashingsElectra(a []*eth.AttesterSlashingElectra) {
b.block.body.attesterSlashingsElectra = a
}
// SetAttestations sets the attestations in the block.
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetAttestations(a []*eth.Attestation) {
b.block.body.attestations = a
}
// SetAttestationsElectra sets the attestations in the block.
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetAttestationsElectra(a []*eth.AttestationElectra) {
b.block.body.attestationsElectra = a
}
// SetDeposits sets the deposits in the block.
// This function is not thread safe, it is only used during block creation.
func (b *SignedBeaconBlock) SetDeposits(d []*eth.Deposit) {
@@ -125,10 +137,19 @@ func (b *SignedBeaconBlock) SetBlobKzgCommitments(c [][]byte) error {
switch b.version {
case version.Phase0, version.Altair, version.Bellatrix, version.Capella:
return consensus_types.ErrNotSupported("SetBlobKzgCommitments", b.version)
case version.Deneb:
case version.Deneb, version.Electra:
b.block.body.blobKzgCommitments = c
return nil
default:
return errIncorrectBlockVersion
}
}
// SetConsolidations sets the signed consolidations in the block. eip7521
func (b *SignedBeaconBlock) SetConsolidations(consolidations []*eth.SignedConsolidation) error {
if b.version < version.Electra {
return consensus_types.ErrNotSupported("Consolidations", b.version)
}
b.block.body.signedConsolidations = consolidations
return nil
}

View File

@@ -38,20 +38,23 @@ var (
// BeaconBlockBody is the main beacon block body structure. It can represent any block type.
type BeaconBlockBody struct {
version int
randaoReveal [field_params.BLSSignatureLength]byte
eth1Data *eth.Eth1Data
graffiti [field_params.RootLength]byte
proposerSlashings []*eth.ProposerSlashing
attesterSlashings []*eth.AttesterSlashing
attestations []*eth.Attestation
deposits []*eth.Deposit
voluntaryExits []*eth.SignedVoluntaryExit
syncAggregate *eth.SyncAggregate
executionPayload interfaces.ExecutionData
executionPayloadHeader interfaces.ExecutionData
blsToExecutionChanges []*eth.SignedBLSToExecutionChange
blobKzgCommitments [][]byte
version int
randaoReveal [field_params.BLSSignatureLength]byte
eth1Data *eth.Eth1Data
graffiti [field_params.RootLength]byte
proposerSlashings []*eth.ProposerSlashing
attesterSlashings []*eth.AttesterSlashing
attesterSlashingsElectra []*eth.AttesterSlashingElectra
attestations []*eth.Attestation
attestationsElectra []*eth.AttestationElectra
deposits []*eth.Deposit
voluntaryExits []*eth.SignedVoluntaryExit
syncAggregate *eth.SyncAggregate
executionPayload interfaces.ExecutionData
executionPayloadHeader interfaces.ExecutionData
blsToExecutionChanges []*eth.SignedBLSToExecutionChange
blobKzgCommitments [][]byte
signedConsolidations []*eth.SignedConsolidation
}
// BeaconBlock is the main beacon block structure. It can represent any block type.

View File

@@ -17,6 +17,7 @@ go_library(
"//proto/prysm/v1alpha1/validator-client:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_fastssz//:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

View File

@@ -2,6 +2,7 @@ package interfaces
import (
ssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/go-bitfield"
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/math"
@@ -27,8 +28,10 @@ type ReadOnlySignedBeaconBlock interface {
PbBlindedBellatrixBlock() (*ethpb.SignedBlindedBeaconBlockBellatrix, error)
PbCapellaBlock() (*ethpb.SignedBeaconBlockCapella, error)
PbDenebBlock() (*ethpb.SignedBeaconBlockDeneb, error)
PbElectraBlock() (*ethpb.SignedBeaconBlockElectra, error)
PbBlindedCapellaBlock() (*ethpb.SignedBlindedBeaconBlockCapella, error)
PbBlindedDenebBlock() (*ethpb.SignedBlindedBeaconBlockDeneb, error)
PbBlindedElectraBlock() (*ethpb.SignedBlindedBeaconBlockElectra, error)
ssz.Marshaler
ssz.Unmarshaler
Version() int
@@ -66,8 +69,8 @@ type ReadOnlyBeaconBlockBody interface {
Eth1Data() *ethpb.Eth1Data
Graffiti() [field_params.RootLength]byte
ProposerSlashings() []*ethpb.ProposerSlashing
AttesterSlashings() []*ethpb.AttesterSlashing
Attestations() []*ethpb.Attestation
AttesterSlashings() []AttesterSlashing
Attestations() []Attestation
Deposits() []*ethpb.Deposit
VoluntaryExits() []*ethpb.SignedVoluntaryExit
SyncAggregate() (*ethpb.SyncAggregate, error)
@@ -77,6 +80,7 @@ type ReadOnlyBeaconBlockBody interface {
Execution() (ExecutionData, error)
BLSToExecutionChanges() ([]*ethpb.SignedBLSToExecutionChange, error)
BlobKzgCommitments() ([][]byte, error)
Consolidations() ([]*ethpb.SignedConsolidation, error)
}
type SignedBeaconBlock interface {
@@ -84,11 +88,14 @@ type SignedBeaconBlock interface {
SetExecution(ExecutionData) error
SetBLSToExecutionChanges([]*ethpb.SignedBLSToExecutionChange) error
SetBlobKzgCommitments(c [][]byte) error
SetConsolidations([]*ethpb.SignedConsolidation) error
SetSyncAggregate(*ethpb.SyncAggregate) error
SetVoluntaryExits([]*ethpb.SignedVoluntaryExit)
SetDeposits([]*ethpb.Deposit)
SetAttestations([]*ethpb.Attestation)
SetAttestationsElectra([]*ethpb.AttestationElectra)
SetAttesterSlashings([]*ethpb.AttesterSlashing)
SetAttesterSlashingsElectra([]*ethpb.AttesterSlashingElectra)
SetProposerSlashings([]*ethpb.ProposerSlashing)
SetGraffiti([]byte)
SetEth1Data(*ethpb.Eth1Data)
@@ -132,6 +139,76 @@ type ExecutionData interface {
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)
DepositReceiptsRoot() ([]byte, error)
WithdrawalRequests() ([]*enginev1.ExecutionLayerWithdrawalRequest, error)
WithdrawalRequestsRoot() ([]byte, error)
}
type Attestation interface {
proto.Message
ssz.Marshaler
ssz.Unmarshaler
ssz.HashRoot
Version() int
GetAggregationBits() bitfield.Bitlist
SetAggregationBits(bits bitfield.Bitlist)
GetData() *ethpb.AttestationData
SetData(data *ethpb.AttestationData)
GetCommitteeBitsVal() bitfield.Bitfield
SetCommitteeBitsVal(bits bitfield.Bitfield)
GetSignature() []byte
SetSignature(sig []byte)
}
type AttesterSlashing interface {
proto.Message
ssz.Marshaler
ssz.Unmarshaler
ssz.HashRoot
GetAttestationOne() ethpb.GeneralIndexedAttestation
SetAttestationOne(ethpb.GeneralIndexedAttestation)
GetAttestationTwo() ethpb.GeneralIndexedAttestation
SetAttestationTwo(ethpb.GeneralIndexedAttestation)
}
type AggregateAttestationAndProof interface {
proto.Message
ssz.Marshaler
ssz.Unmarshaler
ssz.HashRoot
GetAggregatorIndex() primitives.ValidatorIndex
SetAggregatorIndex(index primitives.ValidatorIndex)
GetAttestation() Attestation
SetAttestation(att Attestation)
GetSelectionProof() []byte
SetSelectionProof(proof []byte)
}
type SignedAggregateAttestationAndProof interface {
proto.Message
ssz.Marshaler
ssz.Unmarshaler
ssz.HashRoot
GetAggregateAttestationAndProof() AggregateAttestationAndProof
SetAggregateAttestationAndProof(agg AggregateAttestationAndProof)
GetSignature() []byte
SetSignature(sig []byte)
}
// TODO: this is ugly. The proper way to do this is to create a Copy() function on the interface and implement it. But this results in a circular dependency.
// CopyAttestation copies the provided attestation object.
func CopyAttestation(att Attestation) Attestation {
a, ok := att.(*ethpb.Attestation)
if ok {
return ethpb.CopyAttestation(a)
}
ae, ok := att.(*ethpb.AttestationElectra)
if ok {
return ethpb.CopyAttestationElectra(ae)
}
return nil
}

View File

@@ -75,6 +75,14 @@ func (SignedBeaconBlock) PbBlindedDenebBlock() (*eth.SignedBlindedBeaconBlockDen
panic("implement me")
}
func (SignedBeaconBlock) PbElectraBlock() (*eth.SignedBeaconBlockElectra, error) {
panic("implement me")
}
func (SignedBeaconBlock) PbBlindedElectraBlock() (*eth.SignedBlindedBeaconBlockElectra, error) {
panic("implement me")
}
func (SignedBeaconBlock) MarshalSSZTo(_ []byte) ([]byte, error) {
panic("implement me")
}
@@ -224,7 +232,7 @@ func (BeaconBlockBody) ProposerSlashings() []*eth.ProposerSlashing {
panic("implement me")
}
func (BeaconBlockBody) AttesterSlashings() []*eth.AttesterSlashing {
func (BeaconBlockBody) AttesterSlashings() []interfaces.AttesterSlashing {
panic("implement me")
}
@@ -284,10 +292,18 @@ func (b *BeaconBlockBody) SetAttesterSlashings([]*eth.AttesterSlashing) {
panic("implement me")
}
func (b *BeaconBlockBody) SetAttesterSlashingsElectra([]*eth.AttesterSlashingElectra) {
panic("implement me")
}
func (b *BeaconBlockBody) SetAttestations([]*eth.Attestation) {
panic("implement me")
}
func (b *BeaconBlockBody) SetAttestationsElectra([]*eth.AttestationElectra) {
panic("implement me")
}
func (b *BeaconBlockBody) SetDeposits([]*eth.Deposit) {
panic("implement me")
}
@@ -313,7 +329,15 @@ func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) {
panic("implement me")
}
func (b *BeaconBlockBody) Attestations() []*eth.Attestation {
func (b *BeaconBlockBody) Attestations() []interfaces.Attestation {
panic("implement me")
}
func (b *BeaconBlockBody) Consolidations() ([]*eth.SignedConsolidation, error) {
panic("implement me")
}
func (b *BeaconBlockBody) SetConsolidations([]*eth.SignedConsolidation) error {
panic("implement me")
}

View File

@@ -205,6 +205,8 @@ go_proto_library(
go_library(
name = "go_default_library",
srcs = [
"attestation.go",
"beacon_block.go",
"cloners.go",
"eip_7251.go",
"sync_committee_mainnet.go",
@@ -220,6 +222,7 @@ go_library(
"//encoding/bytesutil:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/ext:go_default_library",
"//runtime/version:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_grpc_ecosystem_grpc_gateway_v2//protoc-gen-openapiv2/options:options_go_proto",
"@com_github_grpc_ecosystem_grpc_gateway_v2//runtime:go_default_library",

View File

@@ -1 +1,83 @@
package eth
import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
func (a *Attestation) Version() int {
return version.Phase0
}
func (a *Attestation) GetCommitteeBitsVal() bitfield.Bitfield {
return nil
}
func (a *Attestation) SetAggregationBits(bits bitfield.Bitlist) {
a.AggregationBits = bits
}
func (a *Attestation) SetData(data *AttestationData) {
a.Data = data
}
func (a *Attestation) SetCommitteeBitsVal(bits bitfield.Bitfield) {
return
}
func (a *Attestation) SetSignature(sig []byte) {
a.Signature = sig
}
func (a *PendingAttestation) Version() int {
return version.Phase0
}
func (a *PendingAttestation) GetCommitteeBitsVal() bitfield.Bitfield {
return nil
}
func (a *PendingAttestation) SetAggregationBits(bits bitfield.Bitlist) {
a.AggregationBits = bits
}
func (a *PendingAttestation) SetData(data *AttestationData) {
a.Data = data
}
func (a *PendingAttestation) SetCommitteeBitsVal(bits bitfield.Bitfield) {
return
}
func (a *PendingAttestation) SetSignature(sig []byte) {
return
}
func (a *PendingAttestation) GetSignature() []byte {
return nil
}
func (a *AttestationElectra) Version() int {
return version.Electra
}
func (a *AttestationElectra) SetAggregationBits(bits bitfield.Bitlist) {
a.AggregationBits = bits
}
func (a *AttestationElectra) SetData(data *AttestationData) {
a.Data = data
}
func (a *AttestationElectra) GetCommitteeBitsVal() bitfield.Bitfield {
return a.CommitteeBits
}
func (a *AttestationElectra) SetCommitteeBitsVal(bits bitfield.Bitfield) {
//TODO: process this based on mainnet vs minimal spec
//a.CommitteeBits = bits
}
func (a *AttestationElectra) SetSignature(sig []byte) {
a.Signature = sig
}

View File

@@ -8,6 +8,7 @@ go_library(
deps = [
"//beacon-chain/core/signing:go_default_library",
"//config/params:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations",
visibility = ["//visibility:public"],
deps = [
"//consensus-types/interfaces:go_default_library",
"//crypto/bls:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/attestation/aggregation:go_default_library",

View File

@@ -2,6 +2,7 @@ package attestations
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation"
@@ -9,7 +10,7 @@ import (
)
// attList represents list of attestations, defined for easier en masse operations (filtering, sorting).
type attList []*ethpb.Attestation
type attList []interfaces.Attestation
// BLS aggregate signature aliases for testing / benchmark substitution. These methods are
// significantly more expensive than the inner logic of AggregateAttestations so they must be
@@ -32,25 +33,25 @@ var ErrInvalidAttestationCount = errors.New("invalid number of attestations")
// clonedAtts[i] = stateTrie.CopyAttestation(a)
// }
// aggregatedAtts, err := attaggregation.Aggregate(clonedAtts)
func Aggregate(atts []*ethpb.Attestation) ([]*ethpb.Attestation, error) {
func Aggregate(atts []interfaces.Attestation) ([]interfaces.Attestation, error) {
return MaxCoverAttestationAggregation(atts)
}
// AggregateDisjointOneBitAtts aggregates unaggregated attestations with the
// exact same attestation data.
func AggregateDisjointOneBitAtts(atts []*ethpb.Attestation) (*ethpb.Attestation, error) {
func AggregateDisjointOneBitAtts(atts []interfaces.Attestation) (interfaces.Attestation, error) {
if len(atts) == 0 {
return nil, nil
}
if len(atts) == 1 {
return atts[0], nil
}
coverage, err := atts[0].AggregationBits.ToBitlist64()
coverage, err := atts[0].GetAggregationBits().ToBitlist64()
if err != nil {
return nil, errors.Wrap(err, "could not get aggregation bits")
}
for _, att := range atts[1:] {
bits, err := att.AggregationBits.ToBitlist64()
bits, err := att.GetAggregationBits().ToBitlist64()
if err != nil {
return nil, errors.Wrap(err, "could not get aggregation bits")
}

View File

@@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation"
@@ -14,7 +15,7 @@ import (
// Aggregation occurs in many rounds, up until no more aggregation is possible (all attestations
// are overlapping).
// See https://hackmd.io/@farazdagi/in-place-attagg for design and rationale.
func MaxCoverAttestationAggregation(atts []*ethpb.Attestation) ([]*ethpb.Attestation, error) {
func MaxCoverAttestationAggregation(atts []interfaces.Attestation) ([]interfaces.Attestation, error) {
if len(atts) < 2 {
return atts, nil
}
@@ -28,7 +29,7 @@ func MaxCoverAttestationAggregation(atts []*ethpb.Attestation) ([]*ethpb.Attesta
candidates := make([]*bitfield.Bitlist64, len(atts))
for i := 0; i < len(atts); i++ {
var err error
candidates[i], err = atts[i].AggregationBits.ToBitlist64()
candidates[i], err = atts[i].GetAggregationBits().ToBitlist64()
if err != nil {
return nil, err
}
@@ -119,6 +120,7 @@ func NewMaxCover(atts []*ethpb.Attestation) *aggregation.MaxCoverProblem {
return &aggregation.MaxCoverProblem{Candidates: candidates}
}
// TODO: review if this needs to be updated
// aggregate returns list as an aggregated attestation.
func (al attList) aggregate(coverage bitfield.Bitlist) (*ethpb.Attestation, error) {
if len(al) < 2 {
@@ -126,7 +128,7 @@ func (al attList) aggregate(coverage bitfield.Bitlist) (*ethpb.Attestation, erro
}
signs := make([]bls.Signature, len(al))
for i := 0; i < len(al); i++ {
sig, err := signatureFromBytes(al[i].Signature)
sig, err := signatureFromBytes(al[i].GetSignature())
if err != nil {
return nil, err
}
@@ -134,7 +136,7 @@ func (al attList) aggregate(coverage bitfield.Bitlist) (*ethpb.Attestation, erro
}
return &ethpb.Attestation{
AggregationBits: coverage,
Data: ethpb.CopyAttestationData(al[0].Data),
Data: ethpb.CopyAttestationData(al[0].GetData()),
Signature: aggregateSignatures(signs).Marshal(),
}, nil
}
@@ -149,7 +151,7 @@ func padSelectedKeys(keys []int, pad int) []int {
// aggregateAttestations combines signatures of selected attestations into a single aggregate attestation, and
// pushes that aggregated attestation into the position of the first of selected attestations.
func aggregateAttestations(atts []*ethpb.Attestation, keys []int, coverage *bitfield.Bitlist64) (targetIdx int, err error) {
func aggregateAttestations(atts []interfaces.Attestation, keys []int, coverage *bitfield.Bitlist64) (targetIdx int, err error) {
if len(keys) < 2 || atts == nil || len(atts) < 2 {
return targetIdx, errors.Wrap(ErrInvalidAttestationCount, "cannot aggregate")
}
@@ -160,13 +162,13 @@ func aggregateAttestations(atts []*ethpb.Attestation, keys []int, coverage *bitf
var data *ethpb.AttestationData
signs := make([]bls.Signature, 0, len(keys))
for i, idx := range keys {
sig, err := signatureFromBytes(atts[idx].Signature)
sig, err := signatureFromBytes(atts[idx].GetSignature())
if err != nil {
return targetIdx, err
}
signs = append(signs, sig)
if i == 0 {
data = ethpb.CopyAttestationData(atts[idx].Data)
data = ethpb.CopyAttestationData(atts[idx].GetData())
targetIdx = idx
}
}
@@ -183,7 +185,7 @@ func aggregateAttestations(atts []*ethpb.Attestation, keys []int, coverage *bitf
// rearrangeProcessedAttestations pushes processed attestations to the end of the slice, returning
// the number of items re-arranged (so that caller can cut the slice, and allow processed items to be
// garbage collected).
func rearrangeProcessedAttestations(atts []*ethpb.Attestation, candidates []*bitfield.Bitlist64, processedKeys []int) {
func rearrangeProcessedAttestations(atts []interfaces.Attestation, candidates []*bitfield.Bitlist64, processedKeys []int) {
if atts == nil || candidates == nil || processedKeys == nil {
return
}
@@ -215,7 +217,7 @@ func (al attList) merge(al1 attList) attList {
// selectUsingKeys returns only items with specified keys.
func (al attList) selectUsingKeys(keys []int) attList {
filtered := make([]*ethpb.Attestation, len(keys))
filtered := make([]interfaces.Attestation, len(keys))
for i, key := range keys {
filtered[i] = al[key]
}
@@ -246,7 +248,7 @@ func (al attList) selectComplementUsingKeys(keys []int) attList {
// hasCoverage returns true if a given coverage is found in attestations list.
func (al attList) hasCoverage(coverage bitfield.Bitlist) (bool, error) {
for _, att := range al {
x, err := att.AggregationBits.Xor(coverage)
x, err := att.GetAggregationBits().Xor(coverage)
if err != nil {
return false, err
}
@@ -263,12 +265,12 @@ func (al attList) filterContained() (attList, error) {
return al, nil
}
sort.Slice(al, func(i, j int) bool {
return al[i].AggregationBits.Count() > al[j].AggregationBits.Count()
return al[i].GetAggregationBits().Count() > al[j].GetAggregationBits().Count()
})
filtered := al[:0]
filtered = append(filtered, al[0])
for i := 1; i < len(al); i++ {
c, err := filtered[len(filtered)-1].AggregationBits.Contains(al[i].AggregationBits)
c, err := filtered[len(filtered)-1].GetAggregationBits().Contains(al[i].GetAggregationBits())
if err != nil {
return nil, err
}
@@ -288,11 +290,11 @@ func (al attList) validate() error {
if len(al) == 0 {
return errors.Wrap(aggregation.ErrInvalidMaxCoverProblem, "empty list")
}
if al[0].AggregationBits == nil || al[0].AggregationBits.Len() == 0 {
if al[0].GetAggregationBits() == nil || al[0].GetAggregationBits().Len() == 0 {
return errors.Wrap(aggregation.ErrInvalidMaxCoverProblem, "bitlist cannot be nil or empty")
}
for i := 1; i < len(al); i++ {
if al[i].AggregationBits == nil || al[i].AggregationBits.Len() == 0 {
if al[i].GetAggregationBits() == nil || al[i].GetAggregationBits().Len() == 0 {
return errors.Wrap(aggregation.ErrInvalidMaxCoverProblem, "bitlist cannot be nil or empty")
}
}

View File

@@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -37,8 +38,8 @@ import (
// data=attestation.data,
// signature=attestation.signature,
// )
func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, committee []primitives.ValidatorIndex) (*ethpb.IndexedAttestation, error) {
attIndices, err := AttestingIndices(attestation.AggregationBits, committee)
func ConvertToIndexed(ctx context.Context, attestation interfaces.Attestation, committee []primitives.ValidatorIndex) (*ethpb.IndexedAttestation, error) {
attIndices, err := AttestingIndices(attestation.GetAggregationBits(), committee)
if err != nil {
return nil, err
}
@@ -47,8 +48,8 @@ func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, commi
return attIndices[i] < attIndices[j]
})
inAtt := &ethpb.IndexedAttestation{
Data: attestation.Data,
Signature: attestation.Signature,
Data: attestation.GetData(),
Signature: attestation.GetSignature(),
AttestingIndices: attIndices,
}
return inAtt, err

View File

@@ -0,0 +1,93 @@
package eth
import (
ssz "github.com/prysmaticlabs/fastssz"
"google.golang.org/protobuf/proto"
)
type GeneralIndexedAttestation interface {
proto.Message
ssz.Marshaler
ssz.Unmarshaler
ssz.HashRoot
GetAttestingIndicesVal() []uint64
SetAttestingIndicesVal([]uint64)
GetData() *AttestationData
SetData(*AttestationData)
GetSignature() []byte
SetSignature(sig []byte)
}
//TODO: consider replacing this entirely... indexattestation doesn't need to be a protobuf
func (a *AttesterSlashing) GetAttestationOne() GeneralIndexedAttestation {
return a.Attestation_1
}
func (a *AttesterSlashing) SetAttestationOne(att GeneralIndexedAttestation) {
at, ok := att.(*IndexedAttestation)
//TODO: should this error?
if ok {
a.Attestation_1 = at
}
}
func (a *AttesterSlashing) GetAttestationTwo() GeneralIndexedAttestation {
return a.Attestation_2
}
func (a *AttesterSlashing) SetAttestationTwo(att GeneralIndexedAttestation) {
at, ok := att.(*IndexedAttestation)
//TODO: should this error?
if ok {
a.Attestation_2 = at
}
}
func (a *IndexedAttestation) GetAttestingIndicesVal() []uint64 {
return a.AttestingIndices
}
func (a *IndexedAttestation) SetAttestingIndicesVal(indices []uint64) {
a.AttestingIndices = indices
}
func (a *IndexedAttestation) SetData(data *AttestationData) {
a.Data = data
}
func (a *IndexedAttestation) SetSignature(sig []byte) {
a.Signature = sig
}
func (a *AttesterSlashingElectra) GetAttestationOne() GeneralIndexedAttestation {
return a.Attestation_1
}
func (a *AttesterSlashingElectra) SetAttestationOne(att GeneralIndexedAttestation) {
at, ok := att.(*IndexedAttestationElectra)
//TODO: should this error?
if ok {
a.Attestation_1 = at
}
}
func (a *AttesterSlashingElectra) GetAttestationTwo() GeneralIndexedAttestation {
return a.Attestation_2
}
func (a *AttesterSlashingElectra) SetAttestationTwo(att GeneralIndexedAttestation) {
at, ok := att.(*IndexedAttestationElectra)
//TODO: should this error?
if ok {
a.Attestation_2 = at
}
}
func (a *IndexedAttestationElectra) GetAttestingIndicesVal() []uint64 {
return a.AttestingIndices
}
func (a *IndexedAttestationElectra) SetAttestingIndicesVal(indices []uint64) {
a.AttestingIndices = indices
}
func (a *IndexedAttestationElectra) SetData(data *AttestationData) {
a.Data = data
}
func (a *IndexedAttestationElectra) SetSignature(sig []byte) {
a.Signature = sig
}

View File

@@ -1107,8 +1107,8 @@ func CopyExecutionPayloadHeaderElectra(payload *enginev1.ExecutionPayloadHeaderE
WithdrawalsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalsRoot),
BlobGasUsed: payload.BlobGasUsed,
ExcessBlobGas: payload.ExcessBlobGas,
DepositReceiptsRoot: bytesutil.SafeCopyBytes(payload.DepositReceiptsRoot),
WithdrawalRequestsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalRequestsRoot),
DepositReceiptsRoot: bytesutil.SafeCopyBytes(payload.DepositReceiptsRoot), // new in electra eip 6110
WithdrawalRequestsRoot: bytesutil.SafeCopyBytes(payload.WithdrawalRequestsRoot), // new in electra eip7521,7002
}
}

View File

@@ -8,6 +8,7 @@ const (
Bellatrix
Capella
Deneb
Electra
)
var versionToString = map[int]string{
@@ -16,6 +17,7 @@ var versionToString = map[int]string{
Bellatrix: "bellatrix",
Capella: "capella",
Deneb: "deneb",
Electra: "electra",
}
// stringToVersion and allVersions are populated in init()

View File

@@ -1408,3 +1408,76 @@ func HydrateV2BlindedBeaconBlockBodyDeneb(b *v2.BlindedBeaconBlockBodyDeneb) *v2
}
return b
}
// HydrateSignedBeaconBlockElectra hydrates a signed beacon block with correct field length sizes
// to comply with fssz marshalling and unmarshalling rules.
func HydrateSignedBeaconBlockElectra(b *ethpb.SignedBeaconBlockElectra) *ethpb.SignedBeaconBlockElectra {
if b == nil {
b = &ethpb.SignedBeaconBlockElectra{}
}
if b.Signature == nil {
b.Signature = make([]byte, fieldparams.BLSSignatureLength)
}
b.Block = HydrateBeaconBlockElectra(b.Block)
return b
}
// HydrateBeaconBlockElectra hydrates a beacon block with correct field length sizes
// to comply with fssz marshalling and unmarshalling rules.
func HydrateBeaconBlockElectra(b *ethpb.BeaconBlockElectra) *ethpb.BeaconBlockElectra {
if b == nil {
b = &ethpb.BeaconBlockElectra{}
}
if b.ParentRoot == nil {
b.ParentRoot = make([]byte, fieldparams.RootLength)
}
if b.StateRoot == nil {
b.StateRoot = make([]byte, fieldparams.RootLength)
}
b.Body = HydrateBeaconBlockBodyElectra(b.Body)
return b
}
// HydrateBeaconBlockBodyElectra hydrates a beacon block body with correct field length sizes
// to comply with fssz marshalling and unmarshalling rules.
func HydrateBeaconBlockBodyElectra(b *ethpb.BeaconBlockBodyElectra) *ethpb.BeaconBlockBodyElectra {
if b == nil {
b = &ethpb.BeaconBlockBodyElectra{}
}
if b.RandaoReveal == nil {
b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength)
}
if b.Graffiti == nil {
b.Graffiti = make([]byte, fieldparams.RootLength)
}
if b.Eth1Data == nil {
b.Eth1Data = &ethpb.Eth1Data{
DepositRoot: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
}
}
if b.SyncAggregate == nil {
b.SyncAggregate = &ethpb.SyncAggregate{
SyncCommitteeBits: make([]byte, fieldparams.SyncAggregateSyncCommitteeBytesLength),
SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength),
}
}
if b.ExecutionPayload == nil {
b.ExecutionPayload = &enginev1.ExecutionPayloadElectra{
ParentHash: make([]byte, fieldparams.RootLength),
FeeRecipient: make([]byte, 20),
StateRoot: make([]byte, fieldparams.RootLength),
ReceiptsRoot: make([]byte, fieldparams.RootLength),
LogsBloom: make([]byte, 256),
PrevRandao: make([]byte, fieldparams.RootLength),
ExtraData: make([]byte, 0),
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
Transactions: make([][]byte, 0),
Withdrawals: make([]*enginev1.Withdrawal, 0),
DepositReceipts: make([]*enginev1.DepositReceipt, 0),
WithdrawalRequests: make([]*enginev1.ExecutionLayerWithdrawalRequest, 0),
}
}
return b
}

View File

@@ -49,3 +49,8 @@ func NewBlindedBeaconBlockDeneb() *ethpb.SignedBlindedBeaconBlockDeneb {
func NewBlindedBeaconBlockCapellaV2() *v2.SignedBlindedBeaconBlockCapella {
return HydrateV2SignedBlindedBeaconBlockCapella(&v2.SignedBlindedBeaconBlockCapella{})
}
// NewBeaconBlockElectra creates a beacon block with minimum marshalable fields.
func NewBeaconBlockElectra() *ethpb.SignedBeaconBlockElectra {
return HydrateSignedBeaconBlockElectra(&ethpb.SignedBeaconBlockElectra{})
}