Skip to content

Commit

Permalink
Add engine API
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Jan 9, 2025
1 parent 93e5525 commit 75bb159
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/beacon-node/src/execution/engine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ExecutionEngineState,
ExecutionPayloadStatus,
IExecutionEngine,
InclusionList,
PayloadAttributes,
PayloadId,
VersionedHashes,
Expand Down Expand Up @@ -202,10 +203,13 @@ export class ExecutionEngineHttp implements IExecutionEngine {
executionPayload: ExecutionPayload,
versionedHashes?: VersionedHashes,
parentBlockRoot?: Root,
executionRequests?: ExecutionRequests
executionRequests?: ExecutionRequests,
inclusionList?: InclusionList, // TODO FOCIL: figure out how to get IL when process_execution_payload
): Promise<ExecutePayloadResponse> {
const method =
ForkSeq[fork] >= ForkSeq.electra
ForkSeq[fork] >= ForkSeq.focil
? "engine_newPayloadV5"
: ForkSeq[fork] >= ForkSeq.electra
? "engine_newPayloadV4"
: ForkSeq[fork] >= ForkSeq.deneb
? "engine_newPayloadV3"
Expand All @@ -215,6 +219,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {

const serializedExecutionPayload = serializeExecutionPayload(fork, executionPayload);

// TODO FOCIL: Add V5. Current code is ugly with all the nested if
let engineRequest: EngineRequest;
if (ForkSeq[fork] >= ForkSeq.deneb) {
if (versionedHashes === undefined) {
Expand Down
7 changes: 6 additions & 1 deletion packages/beacon-node/src/execution/engine/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export type ClientVersion = {

export type VersionedHashes = Uint8Array[];

export type InclusionList = {
transactions: Uint8Array[];
}

/**
* Execution engine represents an abstract protocol to interact with execution clients. Potential transports include:
* - JSON RPC over network
Expand All @@ -135,7 +139,8 @@ export interface IExecutionEngine {
executionPayload: ExecutionPayload,
versionedHashes?: VersionedHashes,
parentBeaconBlockRoot?: Root,
executionRequests?: ExecutionRequests
executionRequests?: ExecutionRequests,
inclusionList?: InclusionList,
): Promise<ExecutePayloadResponse>;

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/beacon-node/src/execution/engine/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
engine_newPayloadV2: this.notifyNewPayload.bind(this),
engine_newPayloadV3: this.notifyNewPayload.bind(this),
engine_newPayloadV4: this.notifyNewPayload.bind(this),
engine_newPayloadV5: this.notifyNewPayload.bind(this),
engine_forkchoiceUpdatedV1: this.notifyForkchoiceUpdate.bind(this),
engine_forkchoiceUpdatedV2: this.notifyForkchoiceUpdate.bind(this),
engine_forkchoiceUpdatedV3: this.notifyForkchoiceUpdate.bind(this),
Expand All @@ -100,6 +101,8 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
engine_getPayloadBodiesByRangeV1: this.getPayloadBodiesByRange.bind(this),
engine_getClientVersionV1: this.getClientVersionV1.bind(this),
engine_getBlobsV1: this.getBlobs.bind(this),
engine_getInclusionListV1: () => ({transactions: []}),
engine_updatePayloadWithInclusionListV1: () => ({payloadId: ""})
};
}

Expand Down
27 changes: 27 additions & 0 deletions packages/beacon-node/src/execution/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type EngineApiRpcParamTypes = {
engine_newPayloadV2: [ExecutionPayloadRpc];
engine_newPayloadV3: [ExecutionPayloadRpc, VersionedHashesRpc, DATA];
engine_newPayloadV4: [ExecutionPayloadRpc, VersionedHashesRpc, DATA, ExecutionRequestsRpc];
engine_newPayloadV5: [ExecutionPayloadRpc, VersionedHashesRpc, DATA, ExecutionRequestsRpc, InclusionListRpc];
/**
* 1. Object - Payload validity status with respect to the consensus rules:
* - blockHash: DATA, 32 Bytes - block hash value of the payload
Expand Down Expand Up @@ -70,6 +71,17 @@ export type EngineApiRpcParamTypes = {
engine_getClientVersionV1: [ClientVersionRpc];

engine_getBlobsV1: [DATA[]];

/**
* 1. DATA - 32 bytes - parent hash which returned inclusion list should be built upon
*/
engine_getInclusionListV1: [DATA];

/**
* 1. DATA - 8 bytes - Identifier of the payload build process
* 2. DATA[] aka InclusionListV1
*/
engine_updatePayloadWithInclusionListV1: [QUANTITY, InclusionListRpc];
};

export type PayloadStatus = {
Expand All @@ -87,6 +99,7 @@ export type EngineApiRpcReturnTypes = {
engine_newPayloadV2: PayloadStatus;
engine_newPayloadV3: PayloadStatus;
engine_newPayloadV4: PayloadStatus;
engine_newPayloadV5: PayloadStatus;
engine_forkchoiceUpdatedV1: {
payloadStatus: PayloadStatus;
payloadId: QUANTITY | null;
Expand Down Expand Up @@ -114,6 +127,10 @@ export type EngineApiRpcReturnTypes = {
engine_getClientVersionV1: ClientVersionRpc[];

engine_getBlobsV1: (BlobAndProofRpc | null)[];

engine_getInclusionListV1: InclusionListRpc;

engine_updatePayloadWithInclusionListV1: UpdateInclusionListResponse;
};

type ExecutionPayloadRpcWithValue = {
Expand Down Expand Up @@ -212,6 +229,16 @@ export interface BlobsBundleRpc {
proofs: DATA[]; // some ELs could also provide proofs, each 48 bytes
}

type InclusionListRpc = {
/** Array of DATA - Array of transaction objects */
transactions: DATA[];
}

type UpdateInclusionListResponse = {
/** DATA, 8 Bytes - Identifier of the payload build process */
payloadId: QUANTITY;
}

export function serializeExecutionPayload(fork: ForkName, data: ExecutionPayload): ExecutionPayloadRpc {
const payload: ExecutionPayloadRpc = {
parentHash: bytesToData(data.parentHash),
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {ts as bellatrix} from "./bellatrix/index.js";
import {ts as capella} from "./capella/index.js";
import {ts as deneb} from "./deneb/index.js";
import {ts as electra} from "./electra/index.js";
import {ts as focil} from "./focil/index.js";
import {ts as phase0} from "./phase0/index.js";
import {Slot} from "./primitive/types.js";

Expand All @@ -22,6 +23,7 @@ export {ts as bellatrix} from "./bellatrix/index.js";
export {ts as capella} from "./capella/index.js";
export {ts as deneb} from "./deneb/index.js";
export {ts as electra} from "./electra/index.js";
export {ts as focil} from "./focil/index.js";

/** Common non-spec type to represent roots as strings */
export type RootHex = string;
Expand Down

0 comments on commit 75bb159

Please sign in to comment.