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

fix: move and fix execution engine state update checks for online state #5862

Merged
merged 2 commits into from
Aug 8, 2023
Merged
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
2 changes: 1 addition & 1 deletion packages/beacon-node/src/execution/engine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
protected async fetchWithRetries<R, P = IJson[]>(payload: RpcPayload<P>, opts?: ReqOpts): Promise<R> {
try {
const res = await this.rpc.fetchWithRetries<R, P>(payload, opts);
this.updateEngineState(ExecutionEngineState.ONLINE);
this.updateEngineState(getExecutionEngineState({targetState: ExecutionEngineState.ONLINE, oldState: this.state}));
return res;
} catch (err) {
this.updateEngineState(getExecutionEngineState({payloadError: err, oldState: this.state}));
Expand Down
15 changes: 12 additions & 3 deletions packages/beacon-node/src/execution/engine/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,21 @@ function getExecutionEngineStateForPayloadError(
export function getExecutionEngineState<S extends ExecutionPayloadStatus | undefined, E extends unknown | undefined>({
payloadError,
payloadStatus,
targetState,
oldState,
}:
| {payloadStatus: S; payloadError?: never; oldState: ExecutionEngineState}
| {payloadStatus?: never; payloadError: E; oldState: ExecutionEngineState}): ExecutionEngineState {
| {payloadStatus: S; payloadError?: never; targetState?: never; oldState: ExecutionEngineState}
| {payloadStatus?: never; payloadError: E; targetState?: never; oldState: ExecutionEngineState}
| {
payloadStatus?: never;
payloadError?: never;
targetState: ExecutionEngineState;
oldState: ExecutionEngineState;
}): ExecutionEngineState {
const newState =
payloadStatus === undefined
targetState !== undefined
? targetState
: payloadStatus === undefined
? getExecutionEngineStateForPayloadError(payloadError, oldState)
: getExecutionEngineStateForPayloadStatus(payloadStatus);

Expand Down
51 changes: 51 additions & 0 deletions packages/beacon-node/test/unit/execution/engine/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,49 @@ describe("execution / engine / utils", () => {
],
];

const testCasesTargetState: Record<
ExecutionEngineState,
[oldState: ExecutionEngineState, newState: ExecutionEngineState][]
> = {
[ExecutionEngineState.ONLINE]: [
[ExecutionEngineState.ONLINE, ExecutionEngineState.ONLINE],
[ExecutionEngineState.AUTH_FAILED, ExecutionEngineState.ONLINE],
[ExecutionEngineState.OFFLINE, ExecutionEngineState.ONLINE],
// Once start syncing it should not go back to online state
// Online is an initial state when execution engine is created
[ExecutionEngineState.SYNCED, ExecutionEngineState.SYNCED],
[ExecutionEngineState.SYNCING, ExecutionEngineState.SYNCING],
],
[ExecutionEngineState.AUTH_FAILED]: [
[ExecutionEngineState.ONLINE, ExecutionEngineState.AUTH_FAILED],
[ExecutionEngineState.AUTH_FAILED, ExecutionEngineState.AUTH_FAILED],
[ExecutionEngineState.OFFLINE, ExecutionEngineState.AUTH_FAILED],
[ExecutionEngineState.SYNCED, ExecutionEngineState.AUTH_FAILED],
[ExecutionEngineState.SYNCING, ExecutionEngineState.AUTH_FAILED],
],
[ExecutionEngineState.OFFLINE]: [
[ExecutionEngineState.ONLINE, ExecutionEngineState.OFFLINE],
[ExecutionEngineState.AUTH_FAILED, ExecutionEngineState.OFFLINE],
[ExecutionEngineState.OFFLINE, ExecutionEngineState.OFFLINE],
[ExecutionEngineState.SYNCED, ExecutionEngineState.OFFLINE],
[ExecutionEngineState.SYNCING, ExecutionEngineState.OFFLINE],
],
[ExecutionEngineState.SYNCED]: [
[ExecutionEngineState.ONLINE, ExecutionEngineState.SYNCED],
[ExecutionEngineState.AUTH_FAILED, ExecutionEngineState.SYNCED],
[ExecutionEngineState.OFFLINE, ExecutionEngineState.SYNCED],
[ExecutionEngineState.SYNCED, ExecutionEngineState.SYNCED],
[ExecutionEngineState.SYNCING, ExecutionEngineState.SYNCED],
],
[ExecutionEngineState.SYNCING]: [
[ExecutionEngineState.ONLINE, ExecutionEngineState.SYNCING],
[ExecutionEngineState.AUTH_FAILED, ExecutionEngineState.SYNCING],
[ExecutionEngineState.OFFLINE, ExecutionEngineState.SYNCING],
[ExecutionEngineState.SYNCED, ExecutionEngineState.SYNCING],
[ExecutionEngineState.SYNCING, ExecutionEngineState.SYNCING],
],
};

for (const payloadStatus of Object.keys(testCasesPayload) as ExecutionPayloadStatus[]) {
for (const [oldState, newState] of testCasesPayload[payloadStatus]) {
it(`should transition from "${oldState}" to "${newState}" on payload status "${payloadStatus}"`, () => {
Expand All @@ -188,5 +231,13 @@ describe("execution / engine / utils", () => {
});
}
}

for (const targetState of Object.keys(testCasesTargetState) as ExecutionEngineState[]) {
for (const [oldState, newState] of testCasesTargetState[targetState]) {
it(`should transition from "${oldState}" to "${newState}" on when targeting "${targetState}"`, () => {
expect(getExecutionEngineState({targetState, oldState})).to.equal(newState);
});
}
}
});
});
Loading