Skip to content

Commit fd7f009

Browse files
authored
Merge pull request #425 from kleros/fix/validator-arbToGnosis
Fix/validator arb to gnosis
2 parents c0d76cf + 41affd1 commit fd7f009

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

validator-cli/src/consts/bridgeRoutes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const arbToGnosisConfigs: { [key in Network]: RouteConfigs } = {
6666
},
6767
};
6868

69-
const bridges: { [chainId: number]: Bridge } = {
69+
export const bridges: { [chainId: number]: Bridge } = {
7070
11155111: {
7171
chain: "sepolia",
7272
minChallengePeriod: 10800,

validator-cli/src/utils/botConfig.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { InvalidBotPathError, InvalidNetworkError } from "./errors";
2-
import { Network } from "../consts/bridgeRoutes";
1+
import { InvalidBotPathError, InvalidNetworkError, InvalidChainIdError } from "./errors";
2+
import { Network, bridges } from "../consts/bridgeRoutes";
33
require("dotenv").config();
44

55
export enum BotPaths {
@@ -52,6 +52,7 @@ export interface NetworkConfig {
5252
*/
5353
export function getNetworkConfig(): NetworkConfig[] {
5454
const chainIds = process.env.VEAOUTBOX_CHAINS ? process.env.VEAOUTBOX_CHAINS.split(",") : [];
55+
validateChainId(chainIds);
5556
const rawNetwork = process.env.NETWORKS ? process.env.NETWORKS.split(",") : [];
5657
const networks = validateNetworks(rawNetwork);
5758

@@ -74,3 +75,11 @@ function validateNetworks(networks: string[]): Network[] {
7475
}
7576
return networks as unknown as Network[];
7677
}
78+
79+
function validateChainId(chainIds: string[]): void {
80+
for (const chainId of chainIds) {
81+
if (!bridges[chainId]) {
82+
throw new InvalidChainIdError(chainId);
83+
}
84+
}
85+
}

validator-cli/src/utils/epochHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const getLatestChallengeableEpoch = (epochPeriod: number, now: number = Date.now
6464
*/
6565
const getBlockFromEpoch = async (epoch: number, epochPeriod: number, provider: JsonRpcProvider): Promise<number> => {
6666
const epochTimestamp = epoch * epochPeriod;
67-
const latestBlock = await provider.getBlock("final");
67+
const latestBlock = await provider.getBlock("finalized");
6868
const baseBlock = await provider.getBlock(latestBlock.number - 500);
6969
const secPerBlock = (latestBlock.timestamp - baseBlock.timestamp) / (latestBlock.number - baseBlock.number);
7070
const blockFallBack = Math.floor((latestBlock.timestamp - epochTimestamp) / secPerBlock);

validator-cli/src/utils/errors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class InvalidBotPathError extends Error {
3232
}
3333
}
3434

35+
class InvalidChainIdError extends Error {
36+
constructor(chainId: string) {
37+
super();
38+
this.name = "InvalidChainIdError";
39+
const allowed = Object.keys(require("../consts/bridgeRoutes").bridges).join(", ");
40+
this.message = `Invalid chainId: ${chainId}, use from: ${allowed}`;
41+
}
42+
}
43+
3544
class DevnetOwnerNotSetError extends Error {
3645
constructor() {
3746
super();
@@ -64,4 +73,5 @@ export {
6473
DevnetOwnerNotSetError,
6574
InvalidNetworkError,
6675
MissingEnvError,
76+
InvalidChainIdError,
6777
};

validator-cli/src/utils/graphQueries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const getSnapshotSentForEpoch = async (
154154
epoch: number,
155155
veaInbox: string,
156156
chainId: number
157-
): Promise<{ txHash: string }> => {
157+
): Promise<{ txHash: string } | undefined> => {
158158
try {
159159
const subgraph = getInboxSubgraphUrl(chainId);
160160

validator-cli/src/utils/transactionHandlers/arbToGnosisHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ArbToGnosisTransactionHandler extends BaseTransactionHandler<VeaInb
3333
const currentAllowance: bigint = await weth.allowance(signer.address, veaOutbox.address);
3434
if (currentAllowance < deposit) {
3535
const approvalAmount = deposit * BigInt(10); // Approving for 10 claims
36-
const approveTx = await weth.approve(routeConfig[Network.TESTNET].veaOutbox.address, deposit * approvalAmount);
36+
const approveTx = await weth.approve(veaOutbox.address, approvalAmount);
3737
await approveTx.wait();
3838
}
3939
}

validator-cli/src/watcher.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ChallengeAndResolveClaimParams, challengeAndResolveClaim } from "./help
1414
import { saveSnapshot, SaveSnapshotParams } from "./helpers/snapshot";
1515
import { getTransactionHandler } from "./utils/transactionHandlers";
1616

17-
const RPC_BLOCK_LIMIT = 500; // RPC_BLOCK_LIMIT is the limit of blocks that can be queried at once
17+
const RPC_BLOCK_LIMIT = 1000; // RPC_BLOCK_LIMIT is the limit of blocks that can be queried at once
1818

1919
/**
2020
* @file This file contains the logic for watching bridge and validating/resolving for claims.
@@ -35,7 +35,7 @@ export const watch = async (
3535
const { path, toSaveSnapshot } = getBotPath({ cliCommand });
3636
const networkConfigs = getNetworkConfig();
3737
emitter.emit(BotEvents.STARTED, path, networkConfigs[0].networks);
38-
const transactionHandlers: { [epoch: number]: any } = {};
38+
const transactionHandlers: { [key: string]: any } = {};
3939
const toWatch: { [key: string]: { count: number; epochs: number[] } } = {};
4040
while (!shutDownSignal.getIsShutdownSignal()) {
4141
for (const networkConfig of networkConfigs) {
@@ -49,7 +49,7 @@ async function processNetwork(
4949
path: number,
5050
toSaveSnapshot: boolean,
5151
networkConfig: NetworkConfig,
52-
transactionHandlers: { [epoch: number]: any },
52+
transactionHandlers: { [key: string]: any },
5353
toWatch: { [key: string]: { count: number; epochs: number[] } },
5454
emitter: typeof defaultEmitter
5555
): Promise<void> {
@@ -112,7 +112,7 @@ interface ProcessEpochParams {
112112
outboxRPC: string;
113113
routerRPC: string | undefined;
114114
toWatch: { [key: string]: { count: number; epochs: number[] } };
115-
transactionHandlers: { [epoch: number]: any };
115+
transactionHandlers: { [key: string]: any };
116116
emitter: typeof defaultEmitter;
117117
}
118118
async function processEpochsForNetwork({
@@ -141,6 +141,7 @@ async function processEpochsForNetwork({
141141
// Checks and saves the snapshot if needed
142142
if (toSaveSnapshot) {
143143
const TransactionHandler = getTransactionHandler(chainId, network) as any;
144+
const txnHandlerKey = `${routeConfig[network].veaInbox.address}_${currentEpoch}`;
144145
const transactionHandler =
145146
transactionHandlers[currentEpoch] ||
146147
new TransactionHandler({
@@ -163,7 +164,7 @@ async function processEpochsForNetwork({
163164
} as SaveSnapshotParams);
164165
const count = toWatch[networkKey].count;
165166
if (count == -1 || count != latestCount) {
166-
transactionHandlers[currentEpoch] = updatedTransactionHandler;
167+
transactionHandlers[txnHandlerKey] = updatedTransactionHandler;
167168
toWatch[networkKey].count = latestCount;
168169
}
169170
}
@@ -176,7 +177,6 @@ async function processEpochsForNetwork({
176177
if (latestBlock.number - epochBlock > RPC_BLOCK_LIMIT) {
177178
toBlock = epochBlock + RPC_BLOCK_LIMIT;
178179
}
179-
180180
const claim = await getClaim({ chainId, veaOutbox, veaOutboxProvider, epoch, fromBlock: epochBlock, toBlock });
181181

182182
let updatedTransactions;

0 commit comments

Comments
 (0)