Skip to content

Commit 732c5a1

Browse files
Mani BrarMani Brar
Mani Brar
authored and
Mani Brar
committed
fix: review fixes(#344)
1 parent ab41a47 commit 732c5a1

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

relayer-cli/src/devnetRelayExample.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export async function start(shutdownManager: ShutdownManager = new ShutdownManag
55
const chainId = parseInt(process.env.VEAOUTBOX_CHAIN_ID);
66
const epochPeriod = 1800; // 30 min
77
const network = "devnet";
8-
await setupExitHandlers(chainId, shutdownManager);
8+
await setupExitHandlers(chainId, shutdownManager, network);
99
while (!shutdownManager.getIsShuttingDown()) {
1010
let nonce = await initialize(chainId, network);
1111
// This is libghtbulb switch address in arbitrum sepolia

relayer-cli/src/testnetRelayer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function start(shutdownManager: ShutdownManager = new ShutdownManag
99
const epochPeriod = getEpochPeriod(chainId);
1010
const batchSize = 10; // 10 messages per batch
1111

12-
await setupExitHandlers(chainId, shutdownManager);
12+
await setupExitHandlers(chainId, shutdownManager, network);
1313

1414
while (!shutdownManager.getIsShuttingDown()) {
1515
let nonce = await initialize(chainId, network);

relayer-cli/src/utils/relay.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ const getCount = async (veaOutbox: VeaOutboxArbToEth | VeaOutboxArbToGnosis, cha
2525
return Number(result["snapshotSaveds"][0].count);
2626
};
2727

28-
const relay = async (chainid: number, nonce: number) => {
29-
const routeParams = getBridgeConfig(chainid);
30-
const veaOutbox = getVeaOutbox(routeParams.veaOutboxAddress, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainid);
31-
const count = await getCount(veaOutbox, chainid);
28+
const relay = async (chainId: number, nonce: number) => {
29+
const routeParams = getBridgeConfig(chainId);
30+
const veaOutbox = getVeaOutbox(routeParams.veaOutboxAddress, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainId);
31+
const count = await getCount(veaOutbox, chainId);
3232

3333
const [proof, [to, data]] = await Promise.all([
34-
getProofAtCount(chainid, nonce, count),
35-
getMessageDataToRelay(chainid, nonce),
34+
getProofAtCount(chainId, nonce, count),
35+
getMessageDataToRelay(chainId, nonce),
3636
]);
3737

3838
const txn = await veaOutbox.sendMessage(proof, nonce, to, data);
3939
await txn.wait();
4040
};
4141

42-
const relayBatch = async (chainid: number, nonce: number, maxBatchSize: number) => {
43-
const routeParams = getBridgeConfig(chainid);
42+
const relayBatch = async (chainId: number, nonce: number, maxBatchSize: number) => {
43+
const routeParams = getBridgeConfig(chainId);
4444
const web3 = new Web3(routeParams.rpcOutbox);
4545
const batchedSend = initializeBatchedSend(web3, routeParams.batcher, process.env.PRIVATE_KEY, 0);
4646
const veaOutboxInstance = new web3.eth.Contract(routeParams.veaOutboxContract.abi, routeParams.veaOutboxAddress);
47-
const veaOutbox = getVeaOutbox(routeParams.veaOutboxAddress, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainid);
48-
const count = await getCount(veaOutbox, chainid);
47+
const veaOutbox = getVeaOutbox(routeParams.veaOutboxAddress, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainId);
48+
const count = await getCount(veaOutbox, chainId);
4949

5050
while (nonce < count) {
5151
let batchMessages = 0;
@@ -57,8 +57,8 @@ const relayBatch = async (chainid: number, nonce: number, maxBatchSize: number)
5757
continue;
5858
}
5959
const [proof, [to, data]] = await Promise.all([
60-
getProofAtCount(chainid, nonce, count),
61-
getMessageDataToRelay(chainid, nonce),
60+
getProofAtCount(chainId, nonce, count),
61+
getMessageDataToRelay(chainId, nonce),
6262
]);
6363
txns.push({
6464
args: [proof, nonce, to, data],
@@ -75,8 +75,8 @@ const relayBatch = async (chainid: number, nonce: number, maxBatchSize: number)
7575
return nonce;
7676
};
7777

78-
const relayAllFrom = async (chainid: number, nonce: number, msgSender: string): Promise<number> => {
79-
const routeParams = getBridgeConfig(chainid);
78+
const relayAllFrom = async (chainId: number, nonce: number, msgSender: string): Promise<number> => {
79+
const routeParams = getBridgeConfig(chainId);
8080

8181
const web3 = new Web3(routeParams.rpcOutbox);
8282
const batchedSend = initializeBatchedSend(
@@ -88,19 +88,19 @@ const relayAllFrom = async (chainid: number, nonce: number, msgSender: string):
8888
);
8989

9090
const contract = new web3.eth.Contract(routeParams.veaOutboxContract.abi, routeParams.veaOutboxAddress);
91-
const veaOutbox = getVeaOutbox(routeParams.veaOutboxAddress, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainid);
92-
const count = await getCount(veaOutbox, chainid);
91+
const veaOutbox = getVeaOutbox(routeParams.veaOutboxAddress, process.env.PRIVATE_KEY, routeParams.rpcOutbox, chainId);
92+
const count = await getCount(veaOutbox, chainId);
9393

9494
if (!count) return null;
9595

9696
let txns = [];
9797

98-
const nonces = await getNonceFrom(chainid, nonce, msgSender);
98+
const nonces = await getNonceFrom(chainId, nonce, msgSender);
9999

100100
for (const x of nonces) {
101101
const [proof, [to, data]] = await Promise.all([
102-
getProofAtCount(chainid, x, count),
103-
getMessageDataToRelay(chainid, x),
102+
getProofAtCount(chainId, x, count),
103+
getMessageDataToRelay(chainId, x),
104104
]);
105105
txns.push({
106106
args: [proof, x, to, data],
@@ -114,9 +114,9 @@ const relayAllFrom = async (chainid: number, nonce: number, msgSender: string):
114114
return nonces[nonces.length - 1];
115115
};
116116

117-
const getNonceFrom = async (chainid: number, nonce: number, msgSender: string) => {
117+
const getNonceFrom = async (chainId: number, nonce: number, msgSender: string) => {
118118
try {
119-
const subgraph = getInboxSubgraph(chainid);
119+
const subgraph = getInboxSubgraph(chainId);
120120

121121
const result = await request(
122122
`https://api.studio.thegraph.com/query/${subgraph}`,

relayer-cli/src/utils/relayerHelpers.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,40 @@ async function updateStateFile(chainId: number, createdTimestamp: number, nonceF
6060
}
6161
}
6262

63-
async function setupExitHandlers(chainId: number, shutdownManager: ShutdownManager) {
63+
async function setupExitHandlers(chainId: number, shutdownManager: ShutdownManager, network: string) {
6464
const cleanup = async () => {
6565
console.log("exit");
66-
const lockFileName = `./state/${chainId}.pid`;
66+
const lockFileName = "./state/" + network + "_" + chainId + ".pid";
6767
if (fs.existsSync(lockFileName)) {
6868
await fs.promises.unlink(lockFileName);
6969
}
7070
};
71-
const handleExit = async () => {
71+
const handleExit = async (exitCode: number = 0) => {
7272
shutdownManager.triggerShutdown();
7373
await cleanup();
7474
process.exit(0);
7575
};
7676

7777
["SIGINT", "SIGTERM", "SIGQUIT"].forEach((signal) =>
7878
process.on(signal, async () => {
79-
await handleExit();
79+
await handleExit(0);
8080
process.exit(0);
8181
})
8282
);
8383

8484
process.on("exit", async () => {
8585
await handleExit();
8686
});
87+
88+
process.on("uncaughtException", async (err) => {
89+
console.error("Uncaught exception:", err);
90+
await handleExit(1);
91+
});
92+
93+
process.on("unhandledRejection", async (reason, promise) => {
94+
console.error("Unhandled promise rejection:", reason, "at", promise);
95+
await handleExit(1);
96+
});
8797
}
8898

8999
function delay(ms: number) {

validator-cli/src/utils/arbMsgExecutor.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ async function messageExecutor(trnxHash: string, childRpc: string, parentRpc: st
1616
const childProvider = new ArbitrumProvider(childJsonRpc);
1717
const parentProvider = new JsonRpcProvider(parentRpc);
1818

19-
let childReceipt: TransactionReceipt | null;
20-
childReceipt = await childProvider.getTransactionReceipt(trnxHash);
19+
const childReceipt: TransactionReceipt = await childProvider.getTransactionReceipt(trnxHash);
2120
if (!childReceipt) {
2221
throw new Error(`Transaction receipt not found for hash: ${trnxHash}`);
2322
}
2423

2524
const messageReceipt = new ChildTransactionReceipt(childReceipt);
2625
const parentSigner: Signer = new Wallet(PRIVATE_KEY, parentProvider);
2726

28-
let childToParentMessage: ChildToParentMessageWriter;
2927
const messages = await messageReceipt.getChildToParentMessages(parentSigner);
30-
childToParentMessage = messages[0];
28+
const childToParentMessage: ChildToParentMessageWriter = messages[0];
3129
if (!childToParentMessage) {
3230
throw new Error("No child-to-parent messages found");
3331
}

0 commit comments

Comments
 (0)