Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement EIP-7742 #7232

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ProtoBlock,
assertValidTerminalPowBlock,
} from "@lodestar/fork-choice";
import {ForkSeq, SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params";
import {ForkSeq, MAX_BLOBS_PER_BLOCK, SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params";
import {
CachedBeaconStateAllForks,
isExecutionBlockBodyType,
Expand Down Expand Up @@ -304,6 +304,7 @@ export async function verifyBlockExecutionPayload(
const parentBlockRoot = ForkSeq[fork] >= ForkSeq.deneb ? block.message.parentRoot : undefined;
const executionRequests =
ForkSeq[fork] >= ForkSeq.electra ? (block.message.body as electra.BeaconBlockBody).executionRequests : undefined;
const targetBlobsPerBlock = ForkSeq[fork] >= ForkSeq.electra ? Math.floor(MAX_BLOBS_PER_BLOCK / 2) : undefined;

const logCtx = {slot: block.message.slot, executionBlock: executionPayloadEnabled.blockNumber};
chain.logger.debug("Call engine api newPayload", logCtx);
Expand All @@ -312,7 +313,8 @@ export async function verifyBlockExecutionPayload(
executionPayloadEnabled,
versionedHashes,
parentBlockRoot,
executionRequests
executionRequests,
targetBlobsPerBlock
);
chain.logger.debug("Receive engine api newPayload result", {...logCtx, status: execResult.status});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ChainForkConfig} from "@lodestar/config";
import {ForkExecution, ForkSeq, isForkExecution} from "@lodestar/params";
import {ForkExecution, ForkSeq, MAX_BLOBS_PER_BLOCK, isForkExecution} from "@lodestar/params";
import {
CachedBeaconStateAllForks,
CachedBeaconStateBellatrix,
Expand Down Expand Up @@ -586,6 +586,13 @@ function preparePayloadAttributes(
(payloadAttributes as deneb.SSEPayloadAttributes["payloadAttributes"]).parentBeaconBlockRoot = parentBlockRoot;
}

if (ForkSeq[fork] >= ForkSeq.electra) {
(payloadAttributes as electra.SSEPayloadAttributes["payloadAttributes"]).targetBlobsPerBlock = Math.floor(
MAX_BLOBS_PER_BLOCK / 2
);
(payloadAttributes as electra.SSEPayloadAttributes["payloadAttributes"]).maxBlobsPerBlock = MAX_BLOBS_PER_BLOCK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast to electra.SSEPayloadAttributes once

}

return payloadAttributes;
}

Expand Down
20 changes: 14 additions & 6 deletions packages/beacon-node/src/execution/engine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
executionPayload: ExecutionPayload,
versionedHashes?: VersionedHashes,
parentBlockRoot?: Root,
executionRequests?: ExecutionRequests
executionRequests?: ExecutionRequests,
maxBlobsPerBlock?: number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verifyBlocksExecutionPayload passed in targetBlobsPerBlock which is correct as in the api but here it's maxBlobsPerBlock

): Promise<ExecutePayloadResponse> {
const method =
ForkSeq[fork] >= ForkSeq.electra
Expand Down Expand Up @@ -230,14 +231,19 @@ export class ExecutionEngineHttp implements IExecutionEngine {
if (executionRequests === undefined) {
throw Error(`executionRequests required in notifyNewPayload for fork=${fork}`);
}
if (maxBlobsPerBlock === undefined) {
throw Error(`maxBlobsPerBlock required in notifyNewPayload for fork=${fork}`);
}
const serializedExecutionRequests = serializeExecutionRequests(executionRequests);

engineRequest = {
method: "engine_newPayloadV4",
params: [
serializedExecutionPayload,
serializedVersionedHashes,
parentBeaconBlockRoot,
serializedExecutionRequests,
numToQuantity(maxBlobsPerBlock),
],
methodOpts: notifyNewPayloadOpts,
};
Expand Down Expand Up @@ -341,11 +347,13 @@ export class ExecutionEngineHttp implements IExecutionEngine {
// Once on capella, should this need to be permanently switched to v2 when payload attrs
// not provided
const method =
ForkSeq[fork] >= ForkSeq.deneb
? "engine_forkchoiceUpdatedV3"
: ForkSeq[fork] >= ForkSeq.capella
? "engine_forkchoiceUpdatedV2"
: "engine_forkchoiceUpdatedV1";
ForkSeq[fork] >= ForkSeq.electra
? "engine_forkchoiceUpdatedV4"
: ForkSeq[fork] >= ForkSeq.deneb
? "engine_forkchoiceUpdatedV3"
: ForkSeq[fork] >= ForkSeq.capella
? "engine_forkchoiceUpdatedV2"
: "engine_forkchoiceUpdatedV1";
const payloadAttributesRpc = payloadAttributes ? serializePayloadAttributes(payloadAttributes) : undefined;
// If we are just fcUing and not asking execution for payload, retry is not required
// and we can move on, as the next fcU will be issued soon on the new slot
Expand Down
5 changes: 4 additions & 1 deletion packages/beacon-node/src/execution/engine/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export type PayloadAttributes = {
suggestedFeeRecipient: string;
withdrawals?: capella.Withdrawal[];
parentBeaconBlockRoot?: Uint8Array;
targetBlobsPerBlock?: number;
maxBlobsPerBlock?: number;
};

export type BlobsBundle = {
Expand Down Expand Up @@ -135,7 +137,8 @@ export interface IExecutionEngine {
executionPayload: ExecutionPayload,
versionedHashes?: VersionedHashes,
parentBeaconBlockRoot?: Root,
executionRequests?: ExecutionRequests
executionRequests?: ExecutionRequests,
targetBlobsPerBlock?: number
): Promise<ExecutePayloadResponse>;

/**
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/src/execution/engine/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
engine_forkchoiceUpdatedV1: this.notifyForkchoiceUpdate.bind(this),
engine_forkchoiceUpdatedV2: this.notifyForkchoiceUpdate.bind(this),
engine_forkchoiceUpdatedV3: this.notifyForkchoiceUpdate.bind(this),
engine_forkchoiceUpdatedV4: this.notifyForkchoiceUpdate.bind(this),
engine_getPayloadV1: this.getPayload.bind(this),
engine_getPayloadV2: this.getPayload.bind(this),
engine_getPayloadV3: this.getPayload.bind(this),
Expand Down
19 changes: 18 additions & 1 deletion packages/beacon-node/src/execution/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type EngineApiRpcParamTypes = {
engine_newPayloadV1: [ExecutionPayloadRpc];
engine_newPayloadV2: [ExecutionPayloadRpc];
engine_newPayloadV3: [ExecutionPayloadRpc, VersionedHashesRpc, DATA];
engine_newPayloadV4: [ExecutionPayloadRpc, VersionedHashesRpc, DATA, ExecutionRequestsRpc];
engine_newPayloadV4: [ExecutionPayloadRpc, VersionedHashesRpc, DATA, ExecutionRequestsRpc, QUANTITY];
/**
* 1. Object - Payload validity status with respect to the consensus rules:
* - blockHash: DATA, 32 Bytes - block hash value of the payload
Expand All @@ -45,6 +45,10 @@ export type EngineApiRpcParamTypes = {
forkChoiceData: {headBlockHash: DATA; safeBlockHash: DATA; finalizedBlockHash: DATA},
payloadAttributes?: PayloadAttributesRpc,
];
engine_forkchoiceUpdatedV4: [
forkChoiceData: {headBlockHash: DATA; safeBlockHash: DATA; finalizedBlockHash: DATA},
payloadAttributes?: PayloadAttributesRpc,
];
/**
* 1. payloadId: QUANTITY, 64 Bits - Identifier of the payload building process
*/
Expand Down Expand Up @@ -99,6 +103,10 @@ export type EngineApiRpcReturnTypes = {
payloadStatus: PayloadStatus;
payloadId: QUANTITY | null;
};
engine_forkchoiceUpdatedV4: {
payloadStatus: PayloadStatus;
payloadId: QUANTITY | null;
};
/**
* payloadId | Error: QUANTITY, 64 Bits - Identifier of the payload building process
*/
Expand Down Expand Up @@ -155,6 +163,7 @@ export type ExecutionPayloadRpc = {
blobGasUsed?: QUANTITY; // DENEB
excessBlobGas?: QUANTITY; // DENEB
parentBeaconBlockRoot?: QUANTITY; // DENEB
targetBlobsPerBlock?: QUANTITY; // ELECTRA
};

export type WithdrawalRpc = {
Expand Down Expand Up @@ -193,6 +202,10 @@ export type PayloadAttributesRpc = {
withdrawals?: WithdrawalRpc[];
/** DATA, 32 Bytes - value for the parentBeaconBlockRoot to be used for building block */
parentBeaconBlockRoot?: DATA;
/** QUANTITY, 64 Bits - Average number of blobs to include per payload. */
targetBlobsPerBlock?: QUANTITY;
/** QUANTITY, 64 Bits - Maximum number of blobs allowed per payload. */
maxBlobsPerBlock?: QUANTITY;
};

export type ClientVersionRpc = {
Expand Down Expand Up @@ -348,6 +361,8 @@ export function serializePayloadAttributes(data: PayloadAttributes): PayloadAttr
suggestedFeeRecipient: data.suggestedFeeRecipient,
withdrawals: data.withdrawals?.map(serializeWithdrawal),
parentBeaconBlockRoot: data.parentBeaconBlockRoot ? bytesToData(data.parentBeaconBlockRoot) : undefined,
targetBlobsPerBlock: data.targetBlobsPerBlock ? numToQuantity(data.targetBlobsPerBlock) : undefined,
maxBlobsPerBlock: data.maxBlobsPerBlock ? numToQuantity(data.maxBlobsPerBlock) : undefined,
};
}

Expand All @@ -364,6 +379,8 @@ export function deserializePayloadAttributes(data: PayloadAttributesRpc): Payloa
suggestedFeeRecipient: data.suggestedFeeRecipient,
withdrawals: data.withdrawals?.map((withdrawal) => deserializeWithdrawal(withdrawal)),
parentBeaconBlockRoot: data.parentBeaconBlockRoot ? dataToBytes(data.parentBeaconBlockRoot, 32) : undefined,
targetBlobsPerBlock: data.targetBlobsPerBlock ? quantityToNum(data.targetBlobsPerBlock) : undefined,
maxBlobsPerBlock: data.maxBlobsPerBlock ? quantityToNum(data.maxBlobsPerBlock) : undefined,
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/electra/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ export const LightClientStore = new ContainerType(
// PayloadAttributes primarily for SSE event
export const PayloadAttributes = new ContainerType(
{
...capellaSsz.PayloadAttributes.fields,
parentBeaconBlockRoot: Root,
...denebSsz.PayloadAttributes.fields,
targetBlobsPerBlock: UintNum64,
maxBlobsPerBlock: UintNum64,
},
{typeName: "PayloadAttributes", jsonCase: "eth2"}
);
Expand Down
Loading