Skip to content

Commit d6c5692

Browse files
authored
Execution API Electra: requests as a sidecar (#14492)
* wip * gaz * rename field * sammy review * updating execution api request and reverting response back * fixing linting * changelog * changelog * adding in serialization of requests * code cleanup * adding some happy path tests and fixing mock * mock still broken * fixing linting * updating name on proto * missed naming * placeholder fix for TestClient_HTTP * removing duplicate change log * adding in test for get payloadv4 as well as some tests * added tests for execution client testing, fixed encode type * adding comment for placeholder test * fixing test and addressing feedback * feedback * flipping the test names, was used in reverse * feedback from kasey * reverting switch back to if statements to fix bug * lint
1 parent 1086bdf commit d6c5692

File tree

19 files changed

+946
-104
lines changed

19 files changed

+946
-104
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Updating to this release is recommended at your convenience.
6565
- GetBeaconStateV2: add Electra case.
6666
- Implement [consensus-specs/3875](https://github.com/ethereum/consensus-specs/pull/3875).
6767
- Tests to ensure sepolia config matches the official upstream yaml.
68+
- `engine_newPayloadV4`,`engine_getPayloadV4` used for electra payload communication with execution client. [pr](https://github.com/prysmaticlabs/prysm/pull/14492)
6869
- HTTP endpoint for PublishBlobs.
6970
- GetBlockV2, GetBlindedBlock, ProduceBlockV2, ProduceBlockV3: add Electra case.
7071
- Add Electra support and tests for light client functions.

beacon-chain/blockchain/execution_engine.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,25 @@ func (s *Service) notifyNewPayload(ctx context.Context, preStateVersion int,
216216
}
217217

218218
var lastValidHash []byte
219+
var parentRoot *common.Hash
220+
var versionedHashes []common.Hash
221+
var requests *enginev1.ExecutionRequests
219222
if blk.Version() >= version.Deneb {
220-
var versionedHashes []common.Hash
221223
versionedHashes, err = kzgCommitmentsToVersionedHashes(blk.Block().Body())
222224
if err != nil {
223225
return false, errors.Wrap(err, "could not get versioned hashes to feed the engine")
224226
}
225-
pr := common.Hash(blk.Block().ParentRoot())
226-
lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, versionedHashes, &pr)
227-
} else {
228-
lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, []common.Hash{}, &common.Hash{} /*empty version hashes and root before Deneb*/)
227+
prh := common.Hash(blk.Block().ParentRoot())
228+
parentRoot = &prh
229229
}
230+
if blk.Version() >= version.Electra {
231+
requests, err = blk.Block().Body().ExecutionRequests()
232+
if err != nil {
233+
return false, errors.Wrap(err, "could not get execution requests")
234+
}
235+
}
236+
lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, versionedHashes, parentRoot, requests)
237+
230238
switch {
231239
case err == nil:
232240
newPayloadValidNodeCount.Inc()

beacon-chain/execution/engine_client.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type PayloadReconstructor interface {
108108
// EngineCaller defines a client that can interact with an Ethereum
109109
// execution node's engine service via JSON-RPC.
110110
type EngineCaller interface {
111-
NewPayload(ctx context.Context, payload interfaces.ExecutionData, versionedHashes []common.Hash, parentBlockRoot *common.Hash) ([]byte, error)
111+
NewPayload(ctx context.Context, payload interfaces.ExecutionData, versionedHashes []common.Hash, parentBlockRoot *common.Hash, executionRequests *pb.ExecutionRequests) ([]byte, error)
112112
ForkchoiceUpdated(
113113
ctx context.Context, state *pb.ForkchoiceState, attrs payloadattribute.Attributer,
114114
) (*pb.PayloadIDBytes, []byte, error)
@@ -119,8 +119,8 @@ type EngineCaller interface {
119119

120120
var ErrEmptyBlockHash = errors.New("Block hash is empty 0x0000...")
121121

122-
// NewPayload calls the engine_newPayloadVX method via JSON-RPC.
123-
func (s *Service) NewPayload(ctx context.Context, payload interfaces.ExecutionData, versionedHashes []common.Hash, parentBlockRoot *common.Hash) ([]byte, error) {
122+
// NewPayload request calls the engine_newPayloadVX method via JSON-RPC.
123+
func (s *Service) NewPayload(ctx context.Context, payload interfaces.ExecutionData, versionedHashes []common.Hash, parentBlockRoot *common.Hash, executionRequests *pb.ExecutionRequests) ([]byte, error) {
124124
ctx, span := trace.StartSpan(ctx, "powchain.engine-api-client.NewPayload")
125125
defer span.End()
126126
start := time.Now()
@@ -157,9 +157,20 @@ func (s *Service) NewPayload(ctx context.Context, payload interfaces.ExecutionDa
157157
if !ok {
158158
return nil, errors.New("execution data must be a Deneb execution payload")
159159
}
160-
err := s.rpcClient.CallContext(ctx, result, NewPayloadMethodV3, payloadPb, versionedHashes, parentBlockRoot)
161-
if err != nil {
162-
return nil, handleRPCError(err)
160+
if executionRequests == nil {
161+
err := s.rpcClient.CallContext(ctx, result, NewPayloadMethodV3, payloadPb, versionedHashes, parentBlockRoot)
162+
if err != nil {
163+
return nil, handleRPCError(err)
164+
}
165+
} else {
166+
flattenedRequests, err := pb.EncodeExecutionRequests(executionRequests)
167+
if err != nil {
168+
return nil, errors.Wrap(err, "failed to encode execution requests")
169+
}
170+
err = s.rpcClient.CallContext(ctx, result, NewPayloadMethodV4, payloadPb, versionedHashes, parentBlockRoot, flattenedRequests)
171+
if err != nil {
172+
return nil, handleRPCError(err)
173+
}
163174
}
164175
default:
165176
return nil, errors.New("unknown execution data type")
@@ -253,6 +264,9 @@ func (s *Service) ForkchoiceUpdated(
253264

254265
func getPayloadMethodAndMessage(slot primitives.Slot) (string, proto.Message) {
255266
pe := slots.ToEpoch(slot)
267+
if pe >= params.BeaconConfig().ElectraForkEpoch {
268+
return GetPayloadMethodV4, &pb.ExecutionBundleElectra{}
269+
}
256270
if pe >= params.BeaconConfig().DenebForkEpoch {
257271
return GetPayloadMethodV3, &pb.ExecutionPayloadDenebWithValueAndBlobsBundle{}
258272
}

0 commit comments

Comments
 (0)