Skip to content

Commit

Permalink
Interop
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Nov 7, 2024
1 parent b22febf commit d862393
Show file tree
Hide file tree
Showing 23 changed files with 2,051 additions and 1,333 deletions.
7 changes: 7 additions & 0 deletions beacon-chain/blockchain/receive_execution_payload_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func (s *Service) ReceiveExecutionPayloadEnvelope(ctx context.Context, signed in
}
timeWithoutDaWait := time.Since(receivedTime) - daWaitedTime
executionEngineProcessingTime.Observe(float64(timeWithoutDaWait.Milliseconds()))

log.WithFields(logrus.Fields{
"blockRoot": fmt.Sprintf("%#x", root),
"stateRoot": fmt.Sprintf("%#x", envelope.StateRoot()),
"builder": envelope.BuilderIndex(),
}).Info("Successfully processed execution payload envelope")

return nil
}

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/core/epbs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go_library(
"//runtime/version:go_default_library",
"//time/slots:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/core/time/slot_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ func CanUpgradeToElectra(slot primitives.Slot) bool {
func CanProcessEpoch(state state.ReadOnlyBeaconState) bool {
return (state.Slot()+1)%params.BeaconConfig().SlotsPerEpoch == 0
}

func CanUpgradeToEpbs(slot primitives.Slot) bool {
epochStart := slots.IsEpochStart(slot)
epbsEpoch := slots.ToEpoch(slot) == params.BeaconConfig().EPBSForkEpoch
return epochStart && epbsEpoch
}
117 changes: 117 additions & 0 deletions beacon-chain/core/transition/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/execution"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
"github.com/prysmaticlabs/prysm/v5/config/features"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing"
prysmTrace "github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
v1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -369,6 +372,15 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta
upgraded = true
}

if time.CanUpgradeToEpbs(state.Slot()) {
state, err = UpgradeToEpbs(state)
if err != nil {
tracing.AnnotateError(span, err)
return nil, err
}
upgraded = true
}

if upgraded {
log.Debugf("upgraded state to %s", version.String(state.Version()))
}
Expand Down Expand Up @@ -487,3 +499,108 @@ func ProcessEpochPrecompute(ctx context.Context, state state.BeaconState) (state
}
return state, nil
}

func UpgradeToEpbs(beaconState state.BeaconState) (state.BeaconState, error) {
currentSyncCommittee, err := beaconState.CurrentSyncCommittee()
if err != nil {
return nil, err
}
nextSyncCommittee, err := beaconState.NextSyncCommittee()
if err != nil {
return nil, err
}
prevEpochParticipation, err := beaconState.PreviousEpochParticipation()
if err != nil {
return nil, err
}
currentEpochParticipation, err := beaconState.CurrentEpochParticipation()
if err != nil {
return nil, err
}
inactivityScores, err := beaconState.InactivityScores()
if err != nil {
return nil, err
}
wi, err := beaconState.NextWithdrawalIndex()
if err != nil {
return nil, err
}
vi, err := beaconState.NextWithdrawalValidatorIndex()
if err != nil {
return nil, err
}
summaries, err := beaconState.HistoricalSummaries()
if err != nil {
return nil, err
}
historicalRoots, err := beaconState.HistoricalRoots()
if err != nil {
return nil, err
}

latestHeader, err := beaconState.LatestExecutionPayloadHeader()
if err != nil {
return nil, err
}

s := &ethpb.BeaconStateEPBS{
GenesisTime: beaconState.GenesisTime(),
GenesisValidatorsRoot: beaconState.GenesisValidatorsRoot(),
Slot: beaconState.Slot(),
Fork: &ethpb.Fork{
PreviousVersion: beaconState.Fork().CurrentVersion,
CurrentVersion: params.BeaconConfig().EPBSForkVersion,
Epoch: time.CurrentEpoch(beaconState),
},
LatestBlockHeader: beaconState.LatestBlockHeader(),
BlockRoots: beaconState.BlockRoots(),
StateRoots: beaconState.StateRoots(),
HistoricalRoots: historicalRoots,
Eth1Data: beaconState.Eth1Data(),
Eth1DataVotes: beaconState.Eth1DataVotes(),
Eth1DepositIndex: beaconState.Eth1DepositIndex(),
Validators: beaconState.Validators(),
Balances: beaconState.Balances(),
RandaoMixes: beaconState.RandaoMixes(),
Slashings: beaconState.Slashings(),
PreviousEpochParticipation: prevEpochParticipation,
CurrentEpochParticipation: currentEpochParticipation,
JustificationBits: beaconState.JustificationBits(),
PreviousJustifiedCheckpoint: beaconState.PreviousJustifiedCheckpoint(),
CurrentJustifiedCheckpoint: beaconState.CurrentJustifiedCheckpoint(),
FinalizedCheckpoint: beaconState.FinalizedCheckpoint(),
InactivityScores: inactivityScores,
CurrentSyncCommittee: currentSyncCommittee,
NextSyncCommittee: nextSyncCommittee,
NextWithdrawalIndex: wi,
NextWithdrawalValidatorIndex: vi,
HistoricalSummaries: summaries,

// TODO: fix this
DepositRequestsStartIndex: 0,
DepositBalanceToConsume: 0,
ExitBalanceToConsume: 0,
EarliestExitEpoch: 0,
ConsolidationBalanceToConsume: 0,
EarliestConsolidationEpoch: 0,
PendingDeposits: make([]*ethpb.PendingDeposit, 0),
PendingPartialWithdrawals: make([]*ethpb.PendingPartialWithdrawal, 0),
PendingConsolidations: make([]*ethpb.PendingConsolidation, 0),
LatestExecutionPayloadHeader: &v1.ExecutionPayloadHeaderEPBS{
ParentBlockHash: make([]byte, 32),
ParentBlockRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
BlobKzgCommitmentsRoot: make([]byte, 32),
},
LatestBlockHash: latestHeader.BlockHash(),
LatestFullSlot: beaconState.Slot(),
LastWithdrawalsRoot: make([]byte, 32),
}

post, err := state_native.InitializeFromProtoUnsafeEpbs(s)
if err != nil {
return nil, errors.Wrap(err, "failed to initialize post electra beaconState")
}

return post, nil
}
1 change: 1 addition & 0 deletions beacon-chain/p2p/gossip_topic_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func init() {
GossipTypeMapping[reflect.TypeOf(&ethpb.SignedBeaconBlockCapella{})] = BlockSubnetTopicFormat
// Specially handle Deneb objects.
GossipTypeMapping[reflect.TypeOf(&ethpb.SignedBeaconBlockDeneb{})] = BlockSubnetTopicFormat
GossipTypeMapping[reflect.TypeOf(&ethpb.SignedBeaconBlockEpbs{})] = BlockSubnetTopicFormat
// Specially handle Electra objects.
GossipTypeMapping[reflect.TypeOf(&ethpb.SignedBeaconBlockElectra{})] = BlockSubnetTopicFormat
GossipTypeMapping[reflect.TypeOf(&ethpb.AttestationElectra{})] = AttestationSubnetTopicFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (vs *Server) constructGenericBeaconBlock(sBlk interfaces.SignedBeaconBlock,
bidStr := primitives.WeiToBigInt(winningBid).String()

switch sBlk.Version() {
case version.EPBS:
return &ethpb.GenericBeaconBlock{Block: &ethpb.GenericBeaconBlock_Epbs{Epbs: blockProto.(*ethpb.BeaconBlockEpbs)}}, nil
case version.Electra:
return vs.constructElectraBlock(blockProto, isBlinded, bidStr, blobsBundle), nil
case version.Deneb:
Expand Down
26 changes: 24 additions & 2 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (
if err != nil {
return nil, errors.Wrap(err, "could not build block in parallel")
}

if sBlk.Version() >= version.EPBS {
beaconBlockRoot, err := sBlk.Block().HashTreeRoot()
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not hash tree root: %v", err)
}
vs.payloadEnvelope.BeaconBlockRoot = beaconBlockRoot[:]
}

return resp, nil
}

Expand Down Expand Up @@ -223,11 +232,24 @@ func (vs *Server) BuildBlockParallel(ctx context.Context, sBlk interfaces.Signed

// Set bls to execution change. New in Capella.
vs.setBlsToExecData(sBlk, head)

// Set payload attestations to block. New in ePBS
if err := vs.setPayloadAttestations(sBlk, head); err != nil {
log.WithError(err).Error("Could not set payload attestations on block")
}
}()

winningBid := primitives.ZeroWei()
var bundle *enginev1.BlobsBundle
if sBlk.Version() >= version.Bellatrix {
if sBlk.Version() >= version.EPBS {
if vs.signedExecutionPayloadHeader == nil {
log.Warn("Failed to retrieve the signed execution payload header, proposing a block without it")
} else {
if err := sBlk.SetSignedExecutionPayloadHeader(vs.signedExecutionPayloadHeader); err != nil {
log.Warn("Failed to set the signed execution payload header, proposing a block without it")
}
}
} else if sBlk.Version() >= version.Bellatrix {
local, err := vs.getLocalPayload(ctx, sBlk.Block(), head)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get local payload: %v", err)
Expand Down Expand Up @@ -277,7 +299,7 @@ func (vs *Server) ProposeBeaconBlock(ctx context.Context, req *ethpb.GenericSign
var sidecars []*ethpb.BlobSidecar
if block.IsBlinded() {
block, sidecars, err = vs.handleBlindedBlock(ctx, block)
} else if block.Version() >= version.Deneb {
} else if block.Version() >= version.Deneb && block.Version() < version.EPBS {
sidecars, err = vs.blobSidecarsFromUnblindedBlock(block, req)
}
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func getEmptyBlock(slot primitives.Slot) (interfaces.SignedBeaconBlock, error) {
var err error
epoch := slots.ToEpoch(slot)
switch {
case epoch >= params.BeaconConfig().EPBSForkEpoch:
sBlk, err = blocks.NewSignedBeaconBlock(&ethpb.SignedBeaconBlockEpbs{Block: &ethpb.BeaconBlockEpbs{Body: &ethpb.BeaconBlockBodyEpbs{}}})
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not initialize block for proposal: %v", err)
}
case epoch >= params.BeaconConfig().ElectraForkEpoch:
sBlk, err = blocks.NewSignedBeaconBlock(&ethpb.SignedBeaconBlockElectra{Block: &ethpb.BeaconBlockElectra{Body: &ethpb.BeaconBlockBodyElectra{}}})
if err != nil {
Expand Down
Loading

0 comments on commit d862393

Please sign in to comment.