Skip to content

Commit 5c7c017

Browse files
Mani BrarMani Brar
authored andcommitted
fix: relayer & validator
1 parent 14a5228 commit 5c7c017

File tree

13 files changed

+222
-230
lines changed

13 files changed

+222
-230
lines changed

relayer-cli/.env.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
PRIVATE_KEY=
22

3+
# Devnet Sender Address
4+
DEVNET_SENDER=0x906dE43dBef27639b1688Ac46532a16dc07Ce410
5+
36
RPC_CHIADO=https://rpc.chiadochain.net
47
RPC_SEPOLIA=
58

9+
VEAOUTBOX_CHAIN_ID=1115111
10+
11+
612
VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS=0x906dE43dBef27639b1688Ac46532a16dc07Ce410
713
VEAINBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS=0xAb53e341121448Ae259Da8fa17f216Cb0e21199C
814
VEAOUTBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS=0x906dE43dBef27639b1688Ac46532a16dc07Ce410

relayer-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"start-devnet-relayer": "npx ts-node ./src/devnetRelayExample.ts",
14-
"start-testnet-sepolia": "npx ts-node ./src/testnet/arbSepToSepRelayer.ts"
14+
"start-testnet-relayer": "npx ts-node ./src/testnetRelayer.ts"
1515
},
1616
"dependencies": {
1717
"@kleros/vea-contracts": "workspace:^",
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,61 @@
11
// File for handling contants and configurations
22
require("dotenv").config();
3+
import veaOutboxArbToEthContract from "@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthTestnet.json";
4+
import veaOutboxArbToGnosisContract from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisTestnet.json";
35

46
interface IBridge {
57
chainId: number;
6-
veaInbox: string;
7-
veaOutbox: string;
8+
chain: string;
9+
epochPeriod: number;
10+
veaInboxAddress: string;
11+
veaOutboxAddress: string;
812
batcher: string;
913
rpcOutbox: string;
14+
veaOutboxContract: any;
1015
}
1116

1217
// Using destination chainId to get the route configuration.
1318
const bridges: { [chainId: number]: IBridge } = {
1419
11155111: {
1520
chainId: 11155111,
16-
veaInbox: process.env.VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS,
17-
veaOutbox: process.env.VEAOUTBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS,
21+
chain: "sepolia",
22+
epochPeriod: 7200,
23+
veaInboxAddress: process.env.VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS,
24+
veaOutboxAddress: process.env.VEAOUTBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS,
1825
batcher: process.env.TRANSACTION_BATCHER_CONTRACT_ADDRESS_SEPOLIA,
1926
rpcOutbox: process.env.RPC_SEPOLIA,
27+
veaOutboxContract: veaOutboxArbToEthContract,
2028
},
2129
10200: {
2230
chainId: 10200,
23-
veaInbox: process.env.VEAINBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS,
24-
veaOutbox: process.env.VEAOUTBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS,
31+
chain: "chiado",
32+
epochPeriod: 3600,
33+
veaInboxAddress: process.env.VEAINBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS,
34+
veaOutboxAddress: process.env.VEAOUTBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS,
2535
batcher: process.env.TRANSACTION_BATCHER_CONTRACT_ADDRESS_CHIADO,
2636
rpcOutbox: process.env.RPC_CHIADO,
37+
veaOutboxContract: veaOutboxArbToGnosisContract,
2738
},
2839
};
2940

41+
// Getters
3042
const getBridgeConfig = (chainId: number): IBridge | undefined => {
3143
return bridges[chainId];
3244
};
3345

46+
const getEpochPeriod = (chainId: number): number => {
47+
return bridges[chainId].epochPeriod;
48+
};
49+
3450
const getInboxSubgraph = (chainId: number): string => {
3551
switch (chainId) {
3652
case 11155111:
3753
return process.env.VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_SUBGRAPH;
3854
case 10200:
3955
return process.env.VEAINBOX_ARBSEPOLIA_TO_CHIADO_SUBGRAPH;
4056
default:
41-
throw new Error("Invalid chainid");
57+
throw new Error("Invalid chainId");
4258
}
4359
};
4460

45-
export { getBridgeConfig, getInboxSubgraph };
61+
export { getBridgeConfig, getInboxSubgraph, getEpochPeriod };
Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
import { relayAllFrom } from "./utils/relay";
2-
import * as fs from "fs";
3-
import { initialize, updateStateFile } from "./utils/relayerHelpers";
2+
import { initialize, ShutdownManager, updateStateFile, setupExitHandlers, delay } from "./utils/relayerHelpers";
43

5-
// let chain_ids = [5, 10200];
6-
let chain_ids = [11155111];
7-
const epochPeriod = 1800; // 30 min
8-
const _contract = require("@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthDevnet.json");
9-
const network = "devnet";
4+
export async function start(shutdownManager: ShutdownManager = new ShutdownManager()) {
5+
const chainId = parseInt(process.env.VEAOUTBOX_CHAIN_ID);
6+
const epochPeriod = 1800; // 30 min
7+
const network = "devnet";
8+
await setupExitHandlers(chainId, shutdownManager);
9+
while (!shutdownManager.getIsShuttingDown()) {
10+
let nonce = await initialize(chainId, network);
11+
// This is libghtbulb switch address in arbitrum sepolia
12+
const sender = process.env.DEVNET_SENDER;
13+
nonce = await relayAllFrom(chainId, nonce, sender);
14+
if (nonce != null) await updateStateFile(chainId, Math.floor(Date.now() / 1000), nonce, network);
1015

11-
["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) =>
12-
process.on(signal, async () => {
13-
console.log("exit");
14-
for (const chain_id of chain_ids) {
15-
const lock_file_name = "./src/state/" + chain_id + ".pid";
16-
if (fs.existsSync(lock_file_name)) {
17-
fs.unlinkSync(lock_file_name);
18-
}
19-
}
20-
process.exit(0);
21-
})
22-
);
23-
24-
(async () => {
25-
while (1) {
26-
for (const chain_id of chain_ids) {
27-
let nonce = await initialize(chain_id, network);
28-
// This is libghtbulb switch address in arbitrum sepolia
29-
const sender = "0x28d6D503F4c5734cD926E96b63C61527d975B382";
30-
nonce = await relayAllFrom(chain_id, nonce, sender, _contract);
31-
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce, network);
32-
}
3316
const currentTS = Math.floor(Date.now() / 1000);
3417
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000;
3518
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds");
3619
await delay(delayAmount);
3720
}
38-
})();
21+
}
3922

40-
function delay(ms: number) {
41-
return new Promise((resolve) => setTimeout(resolve, ms));
23+
if (require.main === module) {
24+
const shutdownManager = new ShutdownManager(false);
25+
start(shutdownManager);
4226
}

relayer-cli/src/state/11155111.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

relayer-cli/src/testnet/arbSepToChiadoRelayer.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

relayer-cli/src/testnet/arbSepToSepRelayer.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

relayer-cli/src/testnetRelayer.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require("dotenv").config();
2+
import { relayBatch } from "utils/relay";
3+
import { initialize, updateStateFile, delay, setupExitHandlers, ShutdownManager } from "utils/relayerHelpers";
4+
import { getEpochPeriod } from "consts/bridgeRoutes";
5+
6+
export async function start(shutdownManager: ShutdownManager = new ShutdownManager()) {
7+
const network = "testnet";
8+
const chainId = parseInt(process.env.VEAOUTBOX_CHAIN_ID);
9+
const epochPeriod = getEpochPeriod(chainId);
10+
const batchSize = 10; // 10 messages per batch
11+
12+
await setupExitHandlers(chainId, shutdownManager);
13+
14+
while (!shutdownManager.getIsShuttingDown()) {
15+
let nonce = await initialize(chainId, network);
16+
nonce = await relayBatch(chainId, nonce, batchSize);
17+
if (nonce != null) await updateStateFile(chainId, Math.floor(Date.now() / 1000), nonce, network);
18+
const currentTS = Math.floor(Date.now() / 1000);
19+
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000;
20+
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds");
21+
await delay(delayAmount);
22+
}
23+
}
24+
25+
if (require.main === module) {
26+
const shutdownManager = new ShutdownManager(false);
27+
start(shutdownManager);
28+
}

relayer-cli/src/utils/ethers.ts

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
VeaInboxArbToGnosis__factory,
88
VeaOutboxArbToGnosis__factory,
99
} from "@kleros/vea-contracts/typechain-types";
10+
import { getBridgeConfig } from "consts/bridgeRoutes";
1011

1112
function getWallet(privateKey: string, web3ProviderURL: string) {
1213
return new Wallet(privateKey, new JsonRpcProvider(web3ProviderURL));
@@ -18,40 +19,58 @@ function getWalletRPC(privateKey: string, rpc: JsonRpcProvider) {
1819

1920
// Using destination chainId as identifier, Ex: Arbitrum One (42161) -> Ethereum Mainnet (1): Use "1" as chainId
2021
function getVeaInbox(veaInboxAddress: string, privateKey: string, web3ProviderURL: string, chainId: number) {
21-
if (chainId == 11155111) {
22-
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
23-
} else if (chainId == 10200) {
24-
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
25-
} else {
26-
throw new Error(`Unsupported chainId: ${chainId}`);
22+
const bridge = getBridgeConfig(chainId);
23+
switch (bridge.chain) {
24+
case "sepolia":
25+
case "mainnet":
26+
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
27+
case "chiado":
28+
case "gnosis":
29+
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
30+
default:
31+
throw new Error(`Unsupported chainId: ${chainId}`);
2732
}
2833
}
2934

3035
function getVeaInboxProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider, chainId: number) {
31-
if (chainId == 11155111) {
32-
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
33-
} else if (chainId == 10200) {
34-
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
36+
const bridges = getBridgeConfig(chainId);
37+
switch (bridges.chain) {
38+
case "sepolia":
39+
case "mainnet":
40+
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
41+
case "chiado":
42+
case "gnosis":
43+
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
44+
default:
45+
throw new Error(`Unsupported chainId: ${chainId}`);
3546
}
3647
}
3748

3849
function getVeaOutbox(veaInboxAddress: string, privateKey: string, web3ProviderURL: string, chainId: number) {
39-
if (chainId == 11155111) {
40-
return VeaOutboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
41-
} else if (chainId == 10200) {
42-
return VeaOutboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
43-
} else {
44-
throw new Error(`Unsupported chainId: ${chainId}`);
50+
const bridges = getBridgeConfig(chainId);
51+
switch (bridges.chain) {
52+
case "sepolia":
53+
case "mainnet":
54+
return VeaOutboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
55+
case "chiado":
56+
case "gnosis":
57+
return VeaOutboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
58+
default:
59+
throw new Error(`Unsupported chainId: ${chainId}`);
4560
}
4661
}
4762

4863
function getVeaOutboxProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider, chainId: number) {
49-
if (chainId == 11155111) {
50-
return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
51-
} else if (chainId == 10200) {
52-
return VeaOutboxArbToGnosis__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
53-
} else {
54-
throw new Error(`Unsupported chainId: ${chainId}`);
64+
const bridges = getBridgeConfig(chainId);
65+
switch (bridges.chain) {
66+
case "sepolia":
67+
case "mainnet":
68+
return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
69+
case "chiado":
70+
case "gnosis":
71+
return VeaOutboxArbToGnosis__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
72+
default:
73+
throw new Error(`Unsupported chainId: ${chainId}`);
5574
}
5675
}
5776

0 commit comments

Comments
 (0)