Skip to content

Commit 5dca90c

Browse files
committed
feat: added instrumentation for heartbeat and logging to the dispute relayer bot
1 parent e87dffc commit 5dca90c

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

contracts/scripts/disputeRelayerBot.ts

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { ethers } from "hardhat";
1+
import env from "./utils/env";
2+
import loggerFactory from "./utils/logger";
3+
import { BigNumber } from "ethers";
24
import hre = require("hardhat");
35
import {
46
KlerosCore,
@@ -11,6 +13,20 @@ import { DisputeRequestEventObject } from "../typechain-types/src/arbitration/in
1113
import { HttpNetworkConfig } from "hardhat/types";
1214
import { DeploymentsExtension } from "hardhat-deploy/types";
1315

16+
const { ethers } = hre;
17+
const HEARTBEAT_URL = env.optionalNoDefault("HEARTBEAT_URL_RELAYER_BOT");
18+
19+
const loggerOptions = env.optionalNoDefault("LOGTAIL_TOKEN_RELAYER_BOT")
20+
? {
21+
transportTargetOptions: {
22+
target: "@logtail/pino",
23+
options: { sourceToken: env.require("LOGTAIL_TOKEN_RELAYER_BOT") },
24+
level: env.optional("LOG_LEVEL", "info"),
25+
},
26+
level: env.optional("LOG_LEVEL", "info"), // for pino-pretty
27+
}
28+
: {};
29+
1430
export default async function main(
1531
foreignNetwork: HttpNetworkConfig,
1632
foreignDeployments: DeploymentsExtension,
@@ -28,21 +44,26 @@ export default async function main(
2844
const foreignChainId = await foreignChainProvider.getNetwork().then((network) => network.chainId);
2945
const arbitrableInterface = IArbitrableV2__factory.createInterface();
3046

47+
const logger = loggerFactory.createLogger(loggerOptions).child({ foreignChainId: foreignChainId });
48+
logger.info(`Listening for events from ${foreignGatewayArtifact}...`);
49+
50+
if (HEARTBEAT_URL) {
51+
logger.debug("Sending heartbeat");
52+
fetch(HEARTBEAT_URL);
53+
} else {
54+
logger.debug("Heartbeat not set up, skipping");
55+
}
56+
3157
// Event subscription
3258
// WARNING: The callback might run more than once if the script is restarted in the same block
3359
// type Listener = [ eventArg1, ...eventArgN, transactionReceipt ]
3460
foreignGateway.on(
3561
"CrossChainDisputeOutgoing",
3662
async (foreignBlockHash, foreignArbitrable, foreignDisputeID, choices, extraData, txReceipt) => {
37-
console.log(
38-
"CrossChainDisputeOutgoing: %s %s %s %s %s",
39-
foreignBlockHash,
40-
foreignArbitrable,
41-
foreignDisputeID,
42-
choices,
43-
extraData
63+
logger.info(
64+
`CrossChainDisputeOutgoing: ${foreignBlockHash} ${foreignArbitrable} ${foreignDisputeID} ${choices} ${extraData}`
4465
);
45-
// console.log("tx receipt: %O", txReceipt);
66+
// logger.info(`tx receipt: ${JSON.stringify(txReceipt)}`);
4667

4768
// txReceipt is missing the full logs for this tx so we need to request it here
4869
const fullTxReceipt = await foreignChainProvider.getTransactionReceipt(txReceipt.transactionHash);
@@ -51,7 +72,7 @@ export default async function main(
5172
const disputeRequest = fullTxReceipt.logs
5273
.filter((log) => log.topics[0] === arbitrableInterface.getEventTopic("DisputeRequest"))
5374
.map((log) => arbitrableInterface.parseLog(log).args as unknown as DisputeRequestEventObject)[0];
54-
console.log("tx events DisputeRequest: %O", disputeRequest);
75+
logger.info(`tx events DisputeRequest: ${JSON.stringify(disputeRequest)}`);
5576
// TODO: log a warning if there are multiple DisputeRequest events
5677

5778
const relayCreateDisputeParams = {
@@ -65,7 +86,7 @@ export default async function main(
6586
choices: choices,
6687
extraData: extraData,
6788
};
68-
console.log("Relaying dispute to home chain... %O", relayCreateDisputeParams);
89+
logger.info(`Relaying dispute to home chain... ${JSON.stringify(relayCreateDisputeParams)}`);
6990

7091
let tx;
7192
if (feeToken === undefined) {
@@ -83,11 +104,10 @@ export default async function main(
83104
](relayCreateDisputeParams, cost);
84105
}
85106
tx = tx.wait();
86-
console.log("relayCreateDispute txId: %O", tx.transactionHash);
107+
logger.info(`relayCreateDispute txId: ${tx.transactionHash}`);
87108
}
88109
);
89110

90-
console.log("Listening for events...");
91111
const delay = (ms) => new Promise((x) => setTimeout(x, ms));
92-
await delay(24 * 60 * 60 * 1000); // 24 hours
112+
await delay(60 * 60 * 1000); // 1 hour
93113
}

services/bots/.env.testnet.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ SUBGRAPH_URL=https://api.thegraph.com/subgraphs/name/alcercu/kleroscoretest
66

77
# Logging
88
LOG_LEVEL=debug
9-
LOGTAIL_TOKEN=<optional token>
9+
LOGTAIL_TOKEN_KEEPER_BOT=<optional token>
10+
LOGTAIL_TOKEN_RELAYER_BOT=<optional token>
1011

1112
# Heartbeat
1213
HEARTBEAT_URL_KEEPER_BOT=<optional url>
14+
HEARTBEAT_URL_RELAYER_BOT=<optional url>
15+
16+
DISPUTES_TO_SKIP=

services/bots/ecosystem.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
interpreter: "sh",
2222
script: "yarn",
2323
args: "bot:relayer-from-chiado --network arbitrumGoerli",
24-
restart_delay: 2000,
24+
restart_delay: 5000,
2525
autorestart: true,
2626
},
2727
],

0 commit comments

Comments
 (0)