Skip to content

Commit

Permalink
feat: handle invalid state for duplicate request
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Aug 7, 2024
1 parent c9bca60 commit d3dba9d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { ILogger } from "@ebo-agent/shared";
import { ContractFunctionRevertedError } from "viem";

import { InvalidActorState } from "./exceptions/invalidActorState.exception.js";
import { RequestMismatch } from "./exceptions/requestMismatch.js";
import { EboRegistry } from "./interfaces/eboRegistry.js";
import { ProtocolProvider } from "./protocolProvider.js";
Expand All @@ -27,6 +28,14 @@ export class EboActor {
if (event.metadata.requestId != this.requestId)
throw new RequestMismatch(this.requestId, event.metadata.requestId);

if (this.registry.getRequest(event.metadata.requestId)) {
this.logger.error(
`The request ${event.metadata.requestId} was already being handled by an actor.`,
);

throw new InvalidActorState();
}

this.registry.addRequest(event.metadata.requestId, event.metadata.request);

if (this.anyActiveProposal()) {
Expand Down
1 change: 1 addition & 0 deletions packages/automated-dispute/src/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./rpcUrlsEmpty.exception.js";
export * from "./invalidActorState.exception.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class InvalidActorState extends Error {
constructor() {
// TODO: we'll want to dump the Actor state into stderr at this point
super("The actor is in an invalid state.");

this.name = "InvalidActorState";
}
}
7 changes: 7 additions & 0 deletions packages/automated-dispute/src/interfaces/eboRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export interface EboRegistry {
*/
addRequest(requestId: string, request: Request): void;

/**
* Get a `Request` by ID.
*
* @param requestId request ID
*/
getRequest(requestId: string): Request;

/**
* Return all responses
*
Expand Down

0 comments on commit d3dba9d

Please sign in to comment.