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

feat: base ebo processor #26

Merged
merged 9 commits into from
Aug 23, 2024
4 changes: 2 additions & 2 deletions packages/automated-dispute/src/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./invalidActorState.exception.js";
export * from "./invalidDisputeStatus.exception.js";
export * from "./requestAlreadyHandled.exception.js";
export * from "./requestMismatch.js";
export * from "./responseAlreadyProposed.js";
export * from "./requestMismatch.exception.js";
export * from "./responseAlreadyProposed.exception.js";
export * from "./rpcUrlsEmpty.exception.js";
4 changes: 4 additions & 0 deletions packages/automated-dispute/src/protocolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class ProtocolProvider {
name: "RequestCreated",
blockNumber: 1n,
logIndex: 1,
requestId: "0x01",
metadata: {
requestId: "0x01",
chainId: "eip155:1",
Expand All @@ -111,6 +112,7 @@ export class ProtocolProvider {
name: "ResponseProposed",
blockNumber: 2n,
logIndex: 1,
requestId: "0x01",
metadata: {
requestId: "0x01",
responseId: "0x02",
Expand All @@ -129,6 +131,7 @@ export class ProtocolProvider {
name: "ResponseDisputed",
blockNumber: 3n,
logIndex: 1,
requestId: "0x01",
metadata: {
requestId: "0x01",
responseId: "0x02",
Expand All @@ -145,6 +148,7 @@ export class ProtocolProvider {
name: "DisputeStatusChanged",
blockNumber: 4n,
logIndex: 20,
requestId: "0x01",
metadata: { disputeId: "0x03", status: "Won", blockNumber: 4n },
} as EboEvent<"DisputeStatusChanged">,
];
Expand Down
40 changes: 40 additions & 0 deletions packages/automated-dispute/src/services/eboProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ILogger } from "@ebo-agent/shared";

import { EboActor } from "../eboActor.js";
import { EboActorsManager } from "../eboActorsManager.js";
import { ProtocolProvider } from "../protocolProvider.js";

const DEFAULT_MS_BETWEEN_CHECKS = 10 * 60 * 1000; // 10 minutes

export class EboProcessor {
private eventsInterval?: NodeJS.Timeout;
private lastCheckedBlock?: bigint;

constructor(
private readonly protocolProvider: ProtocolProvider,
private readonly actorsManager: EboActorsManager,
private readonly logger: ILogger,
) {}

public async start(msBetweenChecks: number = DEFAULT_MS_BETWEEN_CHECKS) {
this.bootstrap(); // Bootstrapping

this.eventsInterval = setInterval(this.eventLoop, msBetweenChecks);
}

private async bootstrap() {
// TODO
}

private async eventLoop() {
// TODO
}

private async onActorError(_actor: EboActor, _error: Error) {
// TODO
}

private async notifyError(_error: Error) {
// TODO
}
}
1 change: 1 addition & 0 deletions packages/automated-dispute/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./eboProcessor.js";
1 change: 1 addition & 0 deletions packages/automated-dispute/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ export type EboEvent<T extends EboEventName> = {
blockNumber: bigint;
logIndex: number;
rawLog?: Log;
requestId: string; // Field to use to route events to actors
metadata: EboEventData<T>;
};
8 changes: 5 additions & 3 deletions packages/automated-dispute/src/types/prophet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { Timestamp } from "@ebo-agent/shared";
import { Address } from "viem";

export type RequestId = string;

export interface Request {
id: string;
id: RequestId;
chainId: Caip2ChainId;
epoch: bigint;
epochTimestamp: Timestamp;
Expand All @@ -25,7 +27,7 @@ export interface Response {

prophetData: Readonly<{
proposer: Address;
requestId: string;
requestId: RequestId;

// To be byte-encode when sending it to Prophet
response: {
Expand All @@ -48,6 +50,6 @@ export interface Dispute {
disputer: Address;
proposer: Address;
responseId: string;
requestId: string;
requestId: RequestId;
};
}
13 changes: 13 additions & 0 deletions packages/automated-dispute/tests/services/eboProcessor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, it } from "vitest";

describe("EboProcessor", () => {
describe.skip("start", () => {
it.skip("bootstraps actors with onchain active requests when starting");
it.skip("fetches events since epoch start when starting");
it.skip("fetches events since last block checked after first events fetch");
it.skip("registers new actor when a new request id is detected on events");
it.skip("forwards events to corresponding actors");
it.skip("notifies if an actor throws while handling events");
it.skip("removes the actor when processing onFinalizeRequest event");
});
});