Skip to content

Commit ad4ec77

Browse files
authored
feat: move requests from execution payload to beacon block body (#7094)
* Move requests from payload to block body * Lint * Add execution requests to engine api * Remove engine_getPayloadBodies*V2 * Update spec test version * Lint * Fix unit test and polish * Remove todo
1 parent d0ba6bc commit ad4ec77

File tree

20 files changed

+160
-229
lines changed

20 files changed

+160
-229
lines changed

packages/beacon-node/src/chain/blocks/verifyBlocksExecutionPayloads.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
isMergeTransitionBlock as isMergeTransitionBlockFn,
66
isExecutionEnabled,
77
} from "@lodestar/state-transition";
8-
import {bellatrix, Slot, deneb, SignedBeaconBlock} from "@lodestar/types";
8+
import {bellatrix, Slot, deneb, SignedBeaconBlock, electra} from "@lodestar/types";
99
import {
1010
IForkChoice,
1111
assertValidTerminalPowBlock,
@@ -302,14 +302,17 @@ export async function verifyBlockExecutionPayload(
302302
? (block.message.body as deneb.BeaconBlockBody).blobKzgCommitments.map(kzgCommitmentToVersionedHash)
303303
: undefined;
304304
const parentBlockRoot = ForkSeq[fork] >= ForkSeq.deneb ? block.message.parentRoot : undefined;
305+
const executionRequests =
306+
ForkSeq[fork] >= ForkSeq.electra ? (block.message.body as electra.BeaconBlockBody).executionRequests : undefined;
305307

306308
const logCtx = {slot: block.message.slot, executionBlock: executionPayloadEnabled.blockNumber};
307309
chain.logger.debug("Call engine api newPayload", logCtx);
308310
const execResult = await chain.executionEngine.notifyNewPayload(
309311
fork,
310312
executionPayloadEnabled,
311313
versionedHashes,
312-
parentBlockRoot
314+
parentBlockRoot,
315+
executionRequests
313316
);
314317
chain.logger.debug("Receive engine api newPayload result", {...logCtx, status: execResult.status});
315318

packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
BlindedBeaconBlockBody,
1818
BlindedBeaconBlock,
1919
sszTypesFor,
20+
electra,
2021
} from "@lodestar/types";
2122
import {
2223
CachedBeaconStateAllForks,
@@ -258,7 +259,7 @@ export async function produceBlockBody<T extends BlockType>(
258259
}
259260

260261
const engineRes = await this.executionEngine.getPayload(fork, payloadId);
261-
const {executionPayload, blobsBundle} = engineRes;
262+
const {executionPayload, blobsBundle, executionRequests} = engineRes;
262263
shouldOverrideBuilder = engineRes.shouldOverrideBuilder;
263264

264265
(blockBody as BeaconBlockBody<ForkExecution>).executionPayload = executionPayload;
@@ -298,6 +299,13 @@ export async function produceBlockBody<T extends BlockType>(
298299
} else {
299300
blobsResult = {type: BlobsResultType.preDeneb};
300301
}
302+
303+
if (ForkSeq[fork] >= ForkSeq.electra) {
304+
if (executionRequests === undefined) {
305+
throw Error(`Missing executionRequests response from getPayload at fork=${fork}`);
306+
}
307+
(blockBody as electra.BeaconBlockBody).executionRequests = executionRequests;
308+
}
301309
}
302310
} catch (e) {
303311
this.metrics?.blockPayload.payloadFetchErrors.inc();

packages/beacon-node/src/execution/engine/http.ts

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ExecutionPayload, Root, RootHex, Wei} from "@lodestar/types";
1+
import {ExecutionPayload, ExecutionRequests, Root, RootHex, Wei} from "@lodestar/types";
22
import {SLOTS_PER_EPOCH, ForkName, ForkSeq} from "@lodestar/params";
33
import {Logger} from "@lodestar/logger";
44
import {
@@ -37,6 +37,7 @@ import {
3737
ExecutionPayloadBody,
3838
assertReqSizeLimit,
3939
deserializeExecutionPayloadBody,
40+
serializeExecutionRequests,
4041
} from "./types.js";
4142
import {getExecutionEngineState} from "./utils.js";
4243

@@ -195,7 +196,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
195196
fork: ForkName,
196197
executionPayload: ExecutionPayload,
197198
versionedHashes?: VersionedHashes,
198-
parentBlockRoot?: Root
199+
parentBlockRoot?: Root,
200+
executionRequests?: ExecutionRequests
199201
): Promise<ExecutePayloadResponse> {
200202
const method =
201203
ForkSeq[fork] >= ForkSeq.electra
@@ -220,12 +222,28 @@ export class ExecutionEngineHttp implements IExecutionEngine {
220222
const serializedVersionedHashes = serializeVersionedHashes(versionedHashes);
221223
const parentBeaconBlockRoot = serializeBeaconBlockRoot(parentBlockRoot);
222224

223-
const method = ForkSeq[fork] >= ForkSeq.electra ? "engine_newPayloadV4" : "engine_newPayloadV3";
224-
engineRequest = {
225-
method,
226-
params: [serializedExecutionPayload, serializedVersionedHashes, parentBeaconBlockRoot],
227-
methodOpts: notifyNewPayloadOpts,
228-
};
225+
if (ForkSeq[fork] >= ForkSeq.electra) {
226+
if (executionRequests === undefined) {
227+
throw Error(`executionRequests required in notifyNewPayload for fork=${fork}`);
228+
}
229+
const serializedExecutionRequests = serializeExecutionRequests(executionRequests);
230+
engineRequest = {
231+
method: "engine_newPayloadV4",
232+
params: [
233+
serializedExecutionPayload,
234+
serializedVersionedHashes,
235+
parentBeaconBlockRoot,
236+
serializedExecutionRequests,
237+
],
238+
methodOpts: notifyNewPayloadOpts,
239+
};
240+
} else {
241+
engineRequest = {
242+
method: "engine_newPayloadV3",
243+
params: [serializedExecutionPayload, serializedVersionedHashes, parentBeaconBlockRoot],
244+
methodOpts: notifyNewPayloadOpts,
245+
};
246+
}
229247
} else {
230248
const method = ForkSeq[fork] >= ForkSeq.capella ? "engine_newPayloadV2" : "engine_newPayloadV1";
231249
engineRequest = {
@@ -391,6 +409,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
391409
executionPayload: ExecutionPayload;
392410
executionPayloadValue: Wei;
393411
blobsBundle?: BlobsBundle;
412+
executionRequests?: ExecutionRequests;
394413
shouldOverrideBuilder?: boolean;
395414
}> {
396415
const method =
@@ -419,8 +438,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
419438
}
420439

421440
async getPayloadBodiesByHash(fork: ForkName, blockHashes: RootHex[]): Promise<(ExecutionPayloadBody | null)[]> {
422-
const method =
423-
ForkSeq[fork] >= ForkSeq.electra ? "engine_getPayloadBodiesByHashV2" : "engine_getPayloadBodiesByHashV1";
441+
const method = "engine_getPayloadBodiesByHashV1";
424442
assertReqSizeLimit(blockHashes.length, 32);
425443
const response = await this.rpc.fetchWithRetries<
426444
EngineApiRpcReturnTypes[typeof method],
@@ -434,8 +452,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
434452
startBlockNumber: number,
435453
blockCount: number
436454
): Promise<(ExecutionPayloadBody | null)[]> {
437-
const method =
438-
ForkSeq[fork] >= ForkSeq.electra ? "engine_getPayloadBodiesByRangeV2" : "engine_getPayloadBodiesByRangeV1";
455+
const method = "engine_getPayloadBodiesByRangeV1";
439456
assertReqSizeLimit(blockCount, 32);
440457
const start = numToQuantity(startBlockNumber);
441458
const count = numToQuantity(blockCount);

packages/beacon-node/src/execution/engine/interface.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {ForkName} from "@lodestar/params";
22
import {KZGCommitment, Blob, KZGProof} from "@lodestar/types/deneb";
3-
import {Root, RootHex, capella, Wei, ExecutionPayload} from "@lodestar/types";
3+
import {Root, RootHex, capella, Wei, ExecutionPayload, ExecutionRequests} from "@lodestar/types";
44

55
import {DATA} from "../../eth1/provider/utils.js";
6-
import {PayloadIdCache, PayloadId, WithdrawalV1, DepositRequestV1} from "./payloadIdCache.js";
6+
import {PayloadIdCache, PayloadId, WithdrawalV1} from "./payloadIdCache.js";
77
import {ExecutionPayloadBody} from "./types.js";
88

9-
export {PayloadIdCache, type PayloadId, type WithdrawalV1, type DepositRequestV1};
9+
export {PayloadIdCache, type PayloadId, type WithdrawalV1};
1010

1111
export enum ExecutionPayloadStatus {
1212
/** given payload is valid */
@@ -134,7 +134,8 @@ export interface IExecutionEngine {
134134
fork: ForkName,
135135
executionPayload: ExecutionPayload,
136136
versionedHashes?: VersionedHashes,
137-
parentBeaconBlockRoot?: Root
137+
parentBeaconBlockRoot?: Root,
138+
executionRequests?: ExecutionRequests
138139
): Promise<ExecutePayloadResponse>;
139140

140141
/**
@@ -171,6 +172,7 @@ export interface IExecutionEngine {
171172
executionPayload: ExecutionPayload;
172173
executionPayloadValue: Wei;
173174
blobsBundle?: BlobsBundle;
175+
executionRequests?: ExecutionRequests;
174176
shouldOverrideBuilder?: boolean;
175177
}>;
176178

packages/beacon-node/src/execution/engine/mock.ts

-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
9898
engine_getPayloadV3: this.getPayload.bind(this),
9999
engine_getPayloadV4: this.getPayload.bind(this),
100100
engine_getPayloadBodiesByHashV1: this.getPayloadBodiesByHash.bind(this),
101-
engine_getPayloadBodiesByHashV2: this.getPayloadBodiesByHash.bind(this),
102101
engine_getPayloadBodiesByRangeV1: this.getPayloadBodiesByRange.bind(this),
103102
engine_getClientVersionV1: this.getClientVersionV1.bind(this),
104-
engine_getPayloadBodiesByRangeV2: this.getPayloadBodiesByRange.bind(this),
105103
};
106104
}
107105

packages/beacon-node/src/execution/engine/payloadIdCache.ts

-20
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@ export type WithdrawalV1 = {
1818
amount: QUANTITY;
1919
};
2020

21-
export type DepositRequestV1 = {
22-
pubkey: DATA;
23-
withdrawalCredentials: DATA;
24-
amount: QUANTITY;
25-
signature: DATA;
26-
index: QUANTITY;
27-
};
28-
29-
export type WithdrawalRequestV1 = {
30-
sourceAddress: DATA;
31-
validatorPubkey: DATA;
32-
amount: QUANTITY;
33-
};
34-
35-
export type ConsolidationRequestV1 = {
36-
sourceAddress: DATA;
37-
sourcePubkey: DATA;
38-
targetPubkey: DATA;
39-
};
40-
4121
type FcuAttributes = {headBlockHash: DATA; finalizedBlockHash: DATA} & Omit<PayloadAttributesRpc, "withdrawals">;
4222

4323
export class PayloadIdCache {

0 commit comments

Comments
 (0)