Skip to content

Commit

Permalink
Use ExecutionEngineHttp in BeaconNode
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Sep 27, 2021
1 parent b878b6c commit 89895ae
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/lodestar/src/eth1/provider/jsonRpcHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class JsonRpcHttpClient {
private readonly urls: string[],
private readonly opts: {
signal: AbortSignal;
timeout?: number;
/** If returns true, do not fallback to other urls and throw early */
shouldNotFallback?: (error: Error) => boolean;
}
Expand Down Expand Up @@ -105,7 +106,7 @@ export class JsonRpcHttpClient {
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, opts?.timeout ?? REQUEST_TIMEOUT);
}, opts?.timeout ?? this.opts.timeout ?? REQUEST_TIMEOUT);

const onParentSignalAbort = (): void => controller.abort();

Expand Down
25 changes: 22 additions & 3 deletions packages/lodestar/src/executionEngine/http.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import {AbortSignal} from "@chainsafe/abort-controller";
import {Bytes32, merge, Root, ExecutionAddress, PayloadId, RootHex} from "@chainsafe/lodestar-types";
import {fromHexString, toHexString} from "@chainsafe/ssz";
import {JsonRpcHttpClient} from "../eth1/provider/jsonRpcHttpClient";
import {hexToNumber, numberToHex} from "../eth1/provider/utils";
import {IExecutionEngine} from "./interface";

/**
export type ExecutionEngineHttpOpts = {
urls: string[];
timeout?: number;
};

export const defaultExecutionEngineHttpOpts: ExecutionEngineHttpOpts = {
urls: ["http://localhost:8550"],
};

export /**
* based on Ethereum JSON-RPC API and inherits the following properties of this standard:
* - Supported communication protocols (HTTP and WebSocket)
* - Message format and encoding notation
Expand All @@ -13,8 +23,17 @@ import {IExecutionEngine} from "./interface";
* Client software MUST expose Engine API at a port independent from JSON-RPC API. The default port for the Engine API is 8550 for HTTP and 8551 for WebSocket.
* https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.1/src/engine/interop/specification.md
*/
export class ExecutionEngineHttp implements IExecutionEngine {
constructor(private readonly rpc: JsonRpcHttpClient) {}
class ExecutionEngineHttp implements IExecutionEngine {
private readonly rpc: JsonRpcHttpClient;

constructor(opts: ExecutionEngineHttpOpts, signal: AbortSignal, rpc?: JsonRpcHttpClient) {
this.rpc =
rpc ??
new JsonRpcHttpClient(opts.urls, {
signal,
timeout: opts.timeout,
});
}

/**
* `engine_executePayload`
Expand Down
8 changes: 4 additions & 4 deletions packages/lodestar/src/node/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import {AbortController} from "@chainsafe/abort-controller";
import LibP2p from "libp2p";
import {Registry} from "prom-client";

import {TreeBacked} from "@chainsafe/ssz";
import {IBeaconConfig} from "@chainsafe/lodestar-config";
Expand All @@ -17,11 +18,10 @@ import {BeaconSync, IBeaconSync} from "../sync";
import {BeaconChain, IBeaconChain, initBeaconMetrics} from "../chain";
import {createMetrics, IMetrics, HttpMetricsServer} from "../metrics";
import {getApi, RestApi} from "../api";
import {IBeaconNodeOptions} from "./options";
import {ExecutionEngineHttp} from "../executionEngine";
import {initializeEth1ForBlockProduction} from "../eth1";
import {IBeaconNodeOptions} from "./options";
import {runNodeNotifier} from "./notifier";
import {Registry} from "prom-client";
import {ExecutionEngineDisabled} from "../executionEngine";

export * from "./options";

Expand Down Expand Up @@ -137,7 +137,7 @@ export class BeaconNode {
{config, db, logger: logger.child(opts.logger.eth1), signal},
anchorState
),
executionEngine: new ExecutionEngineDisabled(),
executionEngine: new ExecutionEngineHttp(opts.executionEngine, signal),
});

// Load persisted data from disk to in-memory caches
Expand Down
3 changes: 3 additions & 0 deletions packages/lodestar/src/node/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {defaultLoggerOptions, IBeaconLoggerOptions} from "./loggerOptions";
import {defaultMetricsOptions, IMetricsOptions} from "../metrics/options";
import {defaultNetworkOptions, INetworkOptions} from "../network/options";
import {defaultSyncOptions, SyncOptions} from "../sync/options";
import {defaultExecutionEngineHttpOpts, ExecutionEngineHttpOpts} from "../executionEngine/http";
// Re-export so the CLI doesn't need to depend on lodestar-api
export {allNamespaces} from "../api/rest/index";

Expand All @@ -18,6 +19,7 @@ export interface IBeaconNodeOptions {
chain: IChainOptions;
db: IDatabaseOptions;
eth1: Eth1Options;
executionEngine: ExecutionEngineHttpOpts;
logger: IBeaconLoggerOptions;
metrics: IMetricsOptions;
network: INetworkOptions;
Expand All @@ -29,6 +31,7 @@ export const defaultOptions: IBeaconNodeOptions = {
chain: defaultChainOptions,
db: defaultDbOptions,
eth1: defaultEth1Options,
executionEngine: defaultExecutionEngineHttpOpts,
logger: defaultLoggerOptions,
metrics: defaultMetricsOptions,
network: defaultNetworkOptions,
Expand Down

0 comments on commit 89895ae

Please sign in to comment.