-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat/arb-sep-to-sep-testnet #344
base: dev
Are you sure you want to change the base?
Changes from all commits
4936cf2
4aeed81
14a7d10
9a28c64
30b0b61
63c93b0
f313f3a
b8e556f
a4b6a90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,9 +1,13 @@ | ||||||
import { relayAllFrom } from "./utils/relay"; | ||||||
import * as fs from "fs"; | ||||||
import { initialize, updateStateFile } from "./utils/relayerHelpers"; | ||||||
|
||||||
// let chain_ids = [5, 10200]; | ||||||
let chain_ids = [11155111]; | ||||||
const epochPeriod = 1800; // 30 min | ||||||
const _contract = require("@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthDevnet.json"); | ||||||
const network = "devnet"; | ||||||
|
||||||
["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) => | ||||||
process.on(signal, async () => { | ||||||
console.log("exit"); | ||||||
|
@@ -20,11 +24,11 @@ const epochPeriod = 1800; // 30 min | |||||
(async () => { | ||||||
while (1) { | ||||||
for (const chain_id of chain_ids) { | ||||||
let nonce = await initialize(chain_id); | ||||||
let nonce = await initialize(chain_id, network); | ||||||
// This is libghtbulb switch address in arbitrum sepolia | ||||||
const sender = "0x28d6D503F4c5734cD926E96b63C61527d975B382"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Externalize the hardcoded sender address Hardcoding the Apply this diff to externalize the - const sender = "0x28d6D503F4c5734cD926E96b63C61527d975B382";
+ const sender = process.env.SENDER_ADDRESS || "0x28d6D503F4c5734cD926E96b63C61527d975B382"; Note: You'll need to set the 📝 Committable suggestion
Suggested change
|
||||||
nonce = await relayAllFrom(chain_id, nonce, sender); | ||||||
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce); | ||||||
nonce = await relayAllFrom(chain_id, nonce, sender, _contract); | ||||||
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce, network); | ||||||
} | ||||||
const currentTS = Math.floor(Date.now() / 1000); | ||||||
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000; | ||||||
|
@@ -33,53 +37,6 @@ const epochPeriod = 1800; // 30 min | |||||
} | ||||||
})(); | ||||||
|
||||||
async function initialize(chain_id: number): Promise<number> { | ||||||
if (chain_id !== 11155111) throw new Error("Invalid chainid"); | ||||||
|
||||||
const lock_file_name = "./src/state/" + chain_id + ".pid"; | ||||||
|
||||||
if (fs.existsSync(lock_file_name)) { | ||||||
console.log("Skipping chain with process already running, delete pid file to force", chain_id); | ||||||
throw new Error("Already running"); | ||||||
} | ||||||
fs.writeFileSync(lock_file_name, process.pid.toString(), { encoding: "utf8" }); | ||||||
|
||||||
// STATE_DIR is absolute path of the directory where the state files are stored | ||||||
// STATE_DIR must have trailing slash | ||||||
const state_file = process.env.STATE_DIR + chain_id + ".json"; | ||||||
if (!fs.existsSync(state_file)) { | ||||||
// No state file so initialize starting now | ||||||
const tsnow = Math.floor(Date.now() / 1000); | ||||||
await updateStateFile(chain_id, tsnow, 0); | ||||||
} | ||||||
|
||||||
// print pwd for debugging | ||||||
console.log(process.cwd()); | ||||||
var chain_state = require(state_file); | ||||||
|
||||||
let nonce = 0; | ||||||
if ("nonce" in chain_state) { | ||||||
nonce = chain_state["nonce"]; | ||||||
} | ||||||
|
||||||
return nonce; | ||||||
} | ||||||
|
||||||
async function updateStateFile(chain_id: number, createdTimestamp: number, nonceFrom: number) { | ||||||
const chain_state_file = "./src/state/" + chain_id + ".json"; | ||||||
const json = { | ||||||
ts: createdTimestamp, | ||||||
nonce: nonceFrom, | ||||||
}; | ||||||
fs.writeFileSync(chain_state_file, JSON.stringify(json), { encoding: "utf8" }); | ||||||
for (const chain_id of chain_ids) { | ||||||
const lock_file_name = "./src/state/" + chain_id + ".pid"; | ||||||
if (fs.existsSync(lock_file_name)) { | ||||||
fs.unlinkSync(lock_file_name); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
function delay(ms: number) { | ||||||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import * as fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
require("dotenv").config(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { relayBatch } from "utils/relay"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { initialize, updateStateFile } from "utils/relayerHelpers"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const _contract = require("@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisTestnet.json"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
let chain_id = 10200; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const epochPeriod = 7200; // 3 hrs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const batchSize = 10; // 10 messages per batch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const network = "testnet"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process.on(signal, async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log("exit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const lock_file_name = "./src/state/" + chain_id + ".pid"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (fs.existsSync(lock_file_name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
fs.unlinkSync(lock_file_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
process.exit(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+12
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove invalid signal 'MODULE_NOT_FOUND' from signal handlers "MODULE_NOT_FOUND" is not a valid signal or event that can be caught using Apply this diff to remove the invalid signal: -["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) =>
+["SIGINT", "SIGTERM", "SIGQUIT", "EXIT"].forEach((signal) => 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
while (1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 'while (true)' instead of 'while (1)' for infinite loop Using Apply this diff to fix the issue: - while (1) {
+ while (true) { 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
let nonce = await initialize(chain_id, network); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log("chain_id", chain_id, "nonce", nonce); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
nonce = await relayBatch(chain_id, nonce, batchSize, _contract); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce, network); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
const currentTS = Math.floor(Date.now() / 1000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
await delay(delayAmount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+24
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling inside the main loop to prevent crashes Currently, any unhandled exceptions within the loop will cause the relayer to crash and exit. Wrapping the contents of the loop in a Apply this diff to add error handling: (async () => {
while (true) {
+ try {
let nonce = await initialize(chain_id, network);
console.log("chain_id", chain_id, "nonce", nonce);
nonce = await relayBatch(chain_id, nonce, batchSize, _contract);
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce, network);
const currentTS = Math.floor(Date.now() / 1000);
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000;
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds");
await delay(delayAmount);
+ } catch (error) {
+ console.error("An error occurred in the main loop:", error);
+ }
}
})(); 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
})(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
function delay(ms: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Extract 'delay' function into a shared utility module The Move the +// In utils/delay.ts
+export function delay(ms: number) {
+ return new Promise((resolve) => setTimeout(resolve, ms));
+}
-// In arbSepToChiadoRelayer.ts
-function delay(ms: number) {
- return new Promise((resolve) => setTimeout(resolve, ms));
-}
+// Replace with import statement
+import { delay } from "utils/delay";
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import * as fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
require("dotenv").config(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { relayBatch } from "utils/relay"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import { initialize, updateStateFile } from "utils/relayerHelpers"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
const _contract = require("@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthTestnet.json"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const network = "testnet"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
let chain_id = 11155111; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use camelCase and It's recommended to use camelCase for variable names in JavaScript/TypeScript. Also, since Apply this diff: -let chain_id = 11155111;
+const chainId = 11155111; Ensure you update all occurrences of 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
const epochPeriod = 7200; // 3 hrs | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const batchSize = 10; // 10 messages per batch | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||
process.on(signal, async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log("exit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const lock_file_name = "./src/state/" + chain_id + ".pid"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (fs.existsSync(lock_file_name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
fs.unlinkSync(lock_file_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
process.exit(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+13
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the list of signals in the signal handler The signals Consider modifying the signal handling as follows: -["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) =>
+["SIGINT", "SIGTERM", "SIGQUIT"].forEach((signal) =>
process.on(signal, async () => {
console.log("exit");
const lock_file_name = "./src/state/" + chainId + ".pid";
if (fs.existsSync(lock_file_name)) {
fs.unlinkSync(lock_file_name);
}
process.exit(0);
})
); If you need to handle the process.on('exit', () => {
console.log("Process exiting");
const lockFileName = "./src/state/" + chainId + ".pid";
if (fs.existsSync(lockFileName)) {
fs.unlinkSync(lockFileName);
}
}); Please note that asynchronous code inside an |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
while (1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace constant condition Using Apply this diff: -(async () => {
- while (1) {
+(async () => {
+ while (true) { 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
let nonce = await initialize(chain_id, network); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
nonce = await relayBatch(chain_id, nonce, batchSize, _contract); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce, network); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const currentTS = Math.floor(Date.now() / 1000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
await delay(delayAmount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
})(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+25
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling in the main loop If an error occurs during Apply this diff: while (true) {
+ try {
let nonce = await initialize(chainId, network);
nonce = await relayBatch(chainId, nonce, batchSize, _contract);
if (nonce != null) await updateStateFile(chainId, Math.floor(Date.now() / 1000), nonce, network);
const currentTS = Math.floor(Date.now() / 1000);
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000;
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds");
await delay(delayAmount);
+ } catch (error) {
+ console.error("An error occurred during the relay loop:", error);
+ // Optionally, handle the error, retry, or perform cleanup
+ }
} This will log the error and allow the loop to continue running. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
function delay(ms: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor The Create a export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
} Then import it where needed: +import { delay } from "utils/delay"; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,8 +3,9 @@ import { JsonRpcProvider } from "@ethersproject/providers"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VeaOutboxArbToEth__factory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VeaOutboxArbToEthDevnet__factory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VeaOutboxArbToGnosisDevnet__factory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VeaInboxArbToEth__factory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VeaInboxArbToGnosis__factory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VeaOutboxArbToGnosis__factory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} from "@kleros/vea-contracts/typechain-types"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getWallet(privateKey: string, web3ProviderURL: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -15,20 +16,37 @@ function getWalletRPC(privateKey: string, rpc: JsonRpcProvider) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new Wallet(privateKey, rpc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaInboxArbToEth(veaInboxAddress: string, privateKey: string, web3ProviderURL: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Using destination chainId as identifier, Ex: Arbitrum One (42161) -> Ethereum Mainnet (1): Use "1" as chainId | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaInbox(veaInboxAddress: string, privateKey: string, web3ProviderURL: string, chainId: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (chainId == 11155111) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (chainId == 10200) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+19
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle unexpected The Consider adding an } else if (chainId == 10200) {
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
+ } else {
+ throw new Error(`Unsupported chainId: ${chainId}`);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaInboxArbToEthProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaInboxProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider, chainId: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (chainId == 11155111) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (chainId == 10200) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+28
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure Similar to Add an } else if (chainId == 10200) {
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
+ } else {
+ throw new Error(`Unsupported chainId: ${chainId}`);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutboxArbToEthProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutbox(veaInboxAddress: string, privateKey: string, web3ProviderURL: string, chainId: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (chainId == 11155111) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (chainId == 10200) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct parameter name to The parameter Apply this diff to correct the parameter name: -function getVeaOutbox(veaInboxAddress: string, privateKey: string, web3ProviderURL: string, chainId: number) {
+function getVeaOutbox(veaOutboxAddress: string, privateKey: string, web3ProviderURL: string, chainId: number) {
if (chainId == 11155111) {
- return VeaOutboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
+ return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL));
} else if (chainId == 10200) {
- return VeaOutboxArbToGnosis__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
+ return VeaOutboxArbToGnosis__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL));
} else {
throw new Error(`Unsupported chainId: ${chainId}`);
}
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutboxArbToEth(veaOutboxAddress: string, privateKey: string, web3ProviderURL: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutboxProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider, chainId: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (chainId == 11155111) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (chainId == 10200) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+44
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct parameter name to The parameter Apply this diff: -function getVeaOutboxProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider, chainId: number) {
+function getVeaOutboxProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider, chainId: number) {
if (chainId == 11155111) {
- return VeaOutboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
+ return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
} else if (chainId == 10200) {
- return VeaOutboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
+ return VeaOutboxArbToGnosis__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
} else {
throw new Error(`Unsupported chainId: ${chainId}`);
}
} 📝 Committable suggestion
Suggested change
Handle unexpected The Add an } else if (chainId == 10200) {
return VeaOutboxArbToGnosis__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
+ } else {
+ throw new Error(`Unsupported chainId: ${chainId}`);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutboxArbToEthDevnetProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -39,19 +57,12 @@ function getVeaOutboxArbToEthDevnet(veaOutboxAddress: string, privateKey: string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToEthDevnet__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutboxArbToGnosisProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToGnosisDevnet__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
function getVeaOutboxArbToGnosis(veaOutboxAddress: string, privateKey: string, web3ProviderURL: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return VeaOutboxArbToGnosisDevnet__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaOutboxArbToEth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getWalletRPC, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaOutboxArbToEthDevnetProvider, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaInboxArbToEth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaInboxArbToEthProvider, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaOutboxArbToEthProvider, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaOutbox, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaInbox, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaOutboxProvider, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaInboxProvider, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
getVeaOutboxArbToEthDevnet, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { getProofAtCount, getMessageDataToRelay } from "./proof"; | ||
import { getVeaOutboxArbToEth } from "./ethers"; | ||
import { getVeaOutbox } from "./ethers"; | ||
import request from "graphql-request"; | ||
import { VeaOutboxArbToEth } from "@kleros/vea-contracts/typechain-types"; | ||
import { VeaOutboxArbToEth, VeaOutboxArbToGnosis } from "@kleros/vea-contracts/typechain-types"; | ||
import { getBridgeConfig, getInboxSubgraph } from "../consts/bridgeRoutes"; | ||
const fs = require("fs"); | ||
|
||
require("dotenv").config(); | ||
|
||
const Web3 = require("web3"); | ||
const _batchedSend = require("web3-batched-send"); | ||
const _contract = require("@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthDevnet.json"); | ||
|
||
const getCount = async (veaOutbox: VeaOutboxArbToEth, chainid: number): Promise<number> => { | ||
const getCount = async (veaOutbox: VeaOutboxArbToEth | VeaOutboxArbToGnosis, chainid: number): Promise<number> => { | ||
const subgraph = getInboxSubgraph(chainid); | ||
const stateRoot = await veaOutbox.stateRoot(); | ||
|
||
|
@@ -31,8 +30,7 @@ const getCount = async (veaOutbox: VeaOutboxArbToEth, chainid: number): Promise< | |
|
||
const relay = async (chainid: number, nonce: number) => { | ||
const routeParams = getBridgeConfig(chainid); | ||
|
||
const veaOutbox = getVeaOutboxArbToEth(routeParams.veaOutbox, process.env.PRIVATE_KEY, routeParams.rpcOutbox); | ||
const veaOutbox = getVeaOutbox(routeParams.veaOutbox, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainid); | ||
const count = await getCount(veaOutbox, chainid); | ||
|
||
const proof = await getProofAtCount(chainid, nonce, count); | ||
|
@@ -42,32 +40,41 @@ const relay = async (chainid: number, nonce: number) => { | |
await txn.wait(); | ||
}; | ||
|
||
const relayBatch = async (chainid: number, nonce: number, iterations: number) => { | ||
const relayBatch = async (chainid: number, nonce: number, maxBatchSize: number, _contract: any) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update all calls to The |
||
const routeParams = getBridgeConfig(chainid); | ||
|
||
const web3 = new Web3(routeParams.rpcOutbox); | ||
const batchedSend = _batchedSend(web3, routeParams.rpcOutbox, process.env.PRIVATE_KEY, 0); | ||
|
||
const batchedSend = _batchedSend(web3, routeParams.batcher, process.env.PRIVATE_KEY, 0); | ||
const contract = new web3.eth.Contract(_contract.abi, routeParams.veaOutbox); | ||
const veaOutbox = getVeaOutboxArbToEth(routeParams.veaOutbox, process.env.PRIVATE_KEY, routeParams.rpcOutbox); | ||
const veaOutbox = getVeaOutbox(routeParams.veaOutbox, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainid); | ||
const count = await getCount(veaOutbox, chainid); | ||
|
||
let txns = []; | ||
|
||
for (let i = 0; i < iterations; i++) { | ||
const proof = await getProofAtCount(chainid, nonce + i, count); | ||
const [to, data] = await getMessageDataToRelay(chainid, nonce + i); | ||
txns.push({ | ||
args: [proof, nonce + i, to, data], | ||
method: contract.methods.sendMessage, | ||
to: contract.options.address, | ||
}); | ||
while (nonce <= count) { | ||
let batchMessages = 0; | ||
let txns = []; | ||
for (let i = 0; batchMessages < maxBatchSize && nonce + i < count; i++) { | ||
const isMsgRelayed = await veaOutbox.isMsgRelayed(nonce + i); | ||
if (isMsgRelayed) continue; | ||
const proof = await getProofAtCount(chainid, nonce + i, count); | ||
const [to, data] = await getMessageDataToRelay(chainid, nonce + i); | ||
txns.push({ | ||
args: [proof, nonce + i, to, data], | ||
method: contract.methods.sendMessage, | ||
to: contract.options.address, | ||
}); | ||
batchMessages += 1; | ||
} | ||
try { | ||
await batchedSend(txns); | ||
// Updating nonce to the next message to be sent | ||
nonce += batchMessages + 1; | ||
} catch (error) { | ||
console.error(`Unable to execute messgae batch(${batchMessages} msgs) from nonce:${nonce} `, error); | ||
} | ||
} | ||
|
||
await batchedSend(txns); | ||
return nonce; | ||
}; | ||
|
||
const relayAllFrom = async (chainid: number, nonce: number, msgSender: string): Promise<number> => { | ||
const relayAllFrom = async (chainid: number, nonce: number, msgSender: string, _contract: any): Promise<number> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synchronize function signature changes for The |
||
const routeParams = getBridgeConfig(chainid); | ||
|
||
const web3 = new Web3(routeParams.rpcOutbox); | ||
|
@@ -80,7 +87,7 @@ const relayAllFrom = async (chainid: number, nonce: number, msgSender: string): | |
); | ||
|
||
const contract = new web3.eth.Contract(_contract.abi, routeParams.veaOutbox); | ||
const veaOutbox = getVeaOutboxArbToEth(routeParams.veaOutbox, process.env.PRIVATE_KEY, routeParams.rpcOutbox); | ||
const veaOutbox = getVeaOutbox(routeParams.veaOutbox, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainid); | ||
const count = await getCount(veaOutbox, chainid); | ||
|
||
if (!count) return null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use consistent module import syntax
You are mixing ES module
import
statements with CommonJSrequire
statements. For consistency and to avoid potential issues, it's recommended to useimport
statements throughout the code.Apply this diff to change the
require
statement to animport
statement:Note: Ensure that your TypeScript configuration (
tsconfig.json
) has"resolveJsonModule": true
and"esModuleInterop": true
to support importing JSON files.📝 Committable suggestion