Skip to content

Commit

Permalink
feat: handle ProtocolProvider contract revert
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Aug 7, 2024
1 parent be694f1 commit c9bca60
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
56 changes: 50 additions & 6 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BlockNumberService } from "@ebo-agent/blocknumber";
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { ILogger } from "@ebo-agent/shared";
import { ContractFunctionRevertedError } from "viem";

import { RequestMismatch } from "./exceptions/requestMismatch.js";
import { EboRegistry } from "./interfaces/eboRegistry.js";
Expand Down Expand Up @@ -28,6 +29,16 @@ export class EboActor {

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

if (this.anyActiveProposal()) {
// Skipping new proposal until the actor receives a ResponseDisputed event;
// at that moment, it will be possible to re-propose again.
this.logger.info(
`There is an active proposal for request ${this.requestId}. Skipping...`,
);

return;
}

const { chainId } = event.metadata;
const { currentEpoch, currentEpochTimestamp } =
await this.protocolProvider.getCurrentEpoch();
Expand All @@ -39,14 +50,47 @@ export class EboActor {

if (this.alreadyProposed(currentEpoch, chainId, epochBlockNumber)) return;

await this.protocolProvider.proposeResponse(
this.requestId,
currentEpoch,
chainId,
epochBlockNumber,
);
try {
await this.protocolProvider.proposeResponse(
this.requestId,
currentEpoch,
chainId,
epochBlockNumber,
);
} catch (err) {
if (err instanceof ContractFunctionRevertedError) {
this.logger.warn(
`Block ${epochBlockNumber} for epoch ${currentEpoch} and ` +
`chain ${chainId} was not proposed. Skipping proposal...`,
);
} else {
this.logger.error(
`Actor handling request ${this.requestId} is not able to continue.`,
);

throw err;
}
}
}

/**
* Check if there's at least one proposal that has not received any dispute yet.
*
* @returns
*/
private anyActiveProposal() {
// TODO: implement this function
return false;
}

/**
* Check if the same proposal has already been made in the past.
*
* @param epoch epoch of the request
* @param chainId chain id of the request
* @param blockNumber proposed block number
* @returns true if there's a registry of a proposal with the same attributes, false otherwise
*/
private alreadyProposed(epoch: bigint, chainId: Caip2ChainId, blockNumber: bigint) {
const responses = this.registry.getResponses();

Expand Down
1 change: 0 additions & 1 deletion packages/automated-dispute/src/types/prophet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface Request {
disputeModule: Address;
resolutionModule: Address;
finalityModule: Address;
// We might need here modules' data too
}

export interface Response {
Expand Down

0 comments on commit c9bca60

Please sign in to comment.