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: query mainnet block numbers #58

Merged
merged 1 commit into from
Oct 9, 2024
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
11 changes: 8 additions & 3 deletions apps/agent/config.example.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
protocolProvider:
rpcsConfig:
transactionReceiptConfirmations: 1
timeout: 10000
retryInterval: 150
l1:
transactionReceiptConfirmations: 1
timeout: 10000
retryInterval: 150
l2:
transactionReceiptConfirmations: 1
timeout: 10000
retryInterval: 150
contracts:
oracle: "0x1234567890123456789012345678901234567890"
epochManager: "0x1234567890123456789012345678901234567890"
Expand Down
10 changes: 8 additions & 2 deletions apps/agent/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ export const config = {
protocolProvider: {
...configData.protocolProvider,
rpcsConfig: {
...configData.protocolProvider.rpcsConfig,
urls: envData.PROTOCOL_PROVIDER_RPC_URLS,
l1: {
...configData.protocolProvider.rpcsConfig.l1,
urls: envData.PROTOCOL_PROVIDER_L1_RPC_URLS,
},
l2: {
...configData.protocolProvider.rpcsConfig.l2,
urls: envData.PROTOCOL_PROVIDER_L2_RPC_URLS,
},
},
privateKey: envData.PROTOCOL_PROVIDER_PRIVATE_KEY,
},
Expand Down
21 changes: 14 additions & 7 deletions apps/agent/src/config/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,31 @@ const chainRpcUrlSchema = z
.record(chainIdSchema, z.array(z.string().url()))
.transform((records) => new Map(Object.entries(records) as [Caip2ChainId, string[]][]));

const rpcUrlsSchema = z
.string()
.transform((str) => str.split(","))
.refine((arr) => arr.every((url) => z.string().url().safeParse(url).success));

export const envSchema = z.object({
PROTOCOL_PROVIDER_PRIVATE_KEY: z.string().refine((key) => isHex(key)),
PROTOCOL_PROVIDER_RPC_URLS: z
.string()
.transform((str) => str.split(","))
.refine((arr) => arr.every((url) => z.string().url().safeParse(url).success)),
PROTOCOL_PROVIDER_L1_RPC_URLS: rpcUrlsSchema,
PROTOCOL_PROVIDER_L2_RPC_URLS: rpcUrlsSchema,
BLOCK_NUMBER_RPC_URLS_MAP: stringToJSONSchema.pipe(chainRpcUrlSchema),
BLOCK_NUMBER_BLOCKMETA_TOKEN: z.string(),
EBO_AGENT_CONFIG_FILE_PATH: z.string(),
});

const addressSchema = z.string().refine((address) => isAddress(address));
const rpcConfigSchema = z.object({
transactionReceiptConfirmations: z.number().int().positive(),
timeout: z.number().int().positive(),
retryInterval: z.number().int().positive(),
});

const protocolProviderConfigSchema = z.object({
rpcsConfig: z.object({
transactionReceiptConfirmations: z.number().int().positive(),
timeout: z.number().int().positive(),
retryInterval: z.number().int().positive(),
l1: rpcConfigSchema,
l2: rpcConfigSchema,
}),
contracts: z.object({
oracle: addressSchema,
Expand Down
35 changes: 16 additions & 19 deletions packages/automated-dispute/src/exceptions/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
import { Logger } from "@ebo-agent/shared";
import { ILogger } from "@ebo-agent/shared";

import { CustomContractError } from "../exceptions/index.js";
import { ErrorContext } from "../types/index.js";

export class ErrorHandler {
private static logger = Logger.getInstance();

public static async handle(error: CustomContractError): Promise<void> {
public static async handle(error: CustomContractError, logger: ILogger): Promise<void> {
const strategy = error.strategy;
const context = error.getContext();

this.logger.error(`Error occurred: ${error.message}`);

if (strategy.shouldNotify) {
await this.notifyError(error, context);
}
logger.error(`Error occurred: ${error.message}`);

try {
await error.executeCustomAction();
} catch (actionError) {
this.logger.error(`Error executing custom action: ${actionError}`);
// Continue without rethrowing
}

if (strategy.shouldReenqueue && context.reenqueueEvent) {
context.reenqueueEvent();
}

if (strategy.shouldTerminate && context.terminateActor) {
context.terminateActor();
logger.error(`Error executing custom action: ${actionError}`);
} finally {
if (strategy.shouldNotify) {
await this.notifyError(error, context);
}

if (strategy.shouldReenqueue && context.reenqueueEvent) {
context.reenqueueEvent();
}

if (strategy.shouldTerminate && context.terminateActor) {
context.terminateActor();
}
}
}

Expand Down
Loading