Skip to content

Commit

Permalink
fix: query mainnet block numbers (#58)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Closes GRT-190

## Description
Uses L1 block numbers for epoch blocks.
  • Loading branch information
0xyaco authored Oct 9, 2024
1 parent 8c4a702 commit 18683d5
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 169 deletions.
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

0 comments on commit 18683d5

Please sign in to comment.