Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Nov 19, 2024
1 parent 6039f58 commit 0c34c20
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ 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 ? 0 : undefined;

const logCtx = {slot: block.message.slot, executionBlock: executionPayloadEnabled.blockNumber};
chain.logger.debug("Call engine api newPayload", logCtx);
Expand All @@ -312,7 +314,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
Expand Up @@ -586,6 +586,11 @@ function preparePayloadAttributes(
(payloadAttributes as deneb.SSEPayloadAttributes["payloadAttributes"]).parentBeaconBlockRoot = parentBlockRoot;
}

if (ForkSeq[fork] >= ForkSeq.electra) {
(payloadAttributes as electra.SSEPayloadAttributes["payloadAttributes"]).targetBlobsPerBlock = 0;
(payloadAttributes as electra.SSEPayloadAttributes["payloadAttributes"]).maxBlobsPerBlock = 0;
}

return payloadAttributes;
}

Expand Down
17 changes: 13 additions & 4 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,
): 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,14 @@ 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
ForkSeq[fork] >= ForkSeq.electra
? "engine_forkchoiceUpdatedV4"
:
ForkSeq[fork] >= ForkSeq.deneb
? "engine_forkchoiceUpdatedV3"
: ForkSeq[fork] >= ForkSeq.capella
: ForkSeq[fork] >= ForkSeq.capella
? "engine_forkchoiceUpdatedV2"
: "engine_forkchoiceUpdatedV1";
: "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
18 changes: 17 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,9 @@ export type PayloadAttributesRpc = {
withdrawals?: WithdrawalRpc[];
/** DATA, 32 Bytes - value for the parentBeaconBlockRoot to be used for building block */
parentBeaconBlockRoot?: DATA;
// TODO
targetBlobsPerBlock?: QUANTITY;
maxBlobsPerBlock?: QUANTITY;
};

export type ClientVersionRpc = {
Expand Down Expand Up @@ -348,6 +360,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 +378,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

0 comments on commit 0c34c20

Please sign in to comment.