Skip to content

Commit

Permalink
refactor: convert execution engine state to a public property
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Jun 29, 2024
1 parent 1f835c8 commit 1f8f8c5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
6 changes: 2 additions & 4 deletions packages/beacon-node/src/execution/engine/disabled.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ExecutionEngineState, IExecutionEngine, PayloadIdCache} from "./interface.js";

export class ExecutionEngineDisabled implements IExecutionEngine {
state = ExecutionEngineState.OFFLINE;

readonly payloadIdCache = new PayloadIdCache();

async notifyNewPayload(): Promise<never> {
Expand All @@ -26,8 +28,4 @@ export class ExecutionEngineDisabled implements IExecutionEngine {
getPayloadBodiesByRange(): Promise<never> {
throw Error("Execution engine disabled");
}

getState(): ExecutionEngineState {
throw Error("Execution engine disabled");
}
}
6 changes: 1 addition & 5 deletions packages/beacon-node/src/execution/engine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
// The default state is ONLINE, it will be updated to SYNCING once we receive the first payload
// This assumption is better than the OFFLINE state, since we can't be sure if the EL is offline and being offline may trigger some notifications
// It's safer to to avoid false positives and assume that the EL is syncing until we receive the first payload
private state: ExecutionEngineState = ExecutionEngineState.ONLINE;
state: ExecutionEngineState = ExecutionEngineState.ONLINE;

readonly payloadIdCache = new PayloadIdCache();
/**
Expand Down Expand Up @@ -417,10 +417,6 @@ export class ExecutionEngineHttp implements IExecutionEngine {
return response.map(deserializeExecutionPayloadBody);
}

getState(): ExecutionEngineState {
return this.state;
}

private updateEngineState(newState: ExecutionEngineState): void {
const oldState = this.state;

Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/execution/engine/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export type VersionedHashes = Uint8Array[];
* - Integrated code into the same binary
*/
export interface IExecutionEngine {
readonly state: ExecutionEngineState;

payloadIdCache: PayloadIdCache;
/**
* A state transition function which applies changes to the self.execution_state.
Expand Down Expand Up @@ -146,6 +148,4 @@ export interface IExecutionEngine {
getPayloadBodiesByHash(blockHash: DATA[]): Promise<(ExecutionPayloadBody | null)[]>;

getPayloadBodiesByRange(start: number, count: number): Promise<(ExecutionPayloadBody | null)[]>;

getState(): ExecutionEngineState;
}
2 changes: 1 addition & 1 deletion packages/beacon-node/src/node/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function runNodeNotifier(modules: NodeNotifierModules): Promise<voi
if (
clockEpoch >= config.BELLATRIX_FORK_EPOCH &&
computeStartSlotAtEpoch(clockEpoch) === clockSlot &&
chain.executionEngine.getState() === ExecutionEngineState.OFFLINE
chain.executionEngine.state === ExecutionEngineState.OFFLINE
) {
logger.warn("Execution client is offline");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class BeaconSync implements IBeaconSync {

getSyncStatus(): SyncingStatus {
const currentSlot = this.chain.clock.currentSlot;
const elOffline = this.chain.executionEngine.getState() === ExecutionEngineState.OFFLINE;
const elOffline = this.chain.executionEngine.state === ExecutionEngineState.OFFLINE;

// If we are pre/at genesis, signal ready
if (currentSlot <= GENESIS_SLOT) {
Expand Down

0 comments on commit 1f8f8c5

Please sign in to comment.