Skip to content

Commit fdaf609

Browse files
committed
feat: dockerized the bots and set up the restart policy with pm2-runtime
1 parent 2f37929 commit fdaf609

19 files changed

+219
-7
lines changed

Diff for: .vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"solidity-language-server.trace.server.verbosity": "message",
88
"eslint.packageManager": "yarn",
99
"prettier.useEditorConfig": true,
10-
"prettier.configPath": "prettier-config/.prettierrc.js"
10+
"prettier.configPath": "prettier-config/.prettierrc.js",
11+
"cSpell.words": [
12+
"autorestart"
13+
]
1114
}

Diff for: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

+28
Large diffs are not rendered by default.

Diff for: .yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ plugins:
77
spec: "@yarnpkg/plugin-stage"
88
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
99
spec: "@yarnpkg/plugin-version"
10+
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
11+
spec: "@yarnpkg/plugin-workspace-tools"
1012

1113
yarnPath: .yarn/releases/yarn-3.3.1.cjs

Diff for: contracts/.dockerignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.env
2+
test
3+
lib
4+
cache
5+
cache_hardhat
6+
config
7+
tenderly.yaml
8+
**/.DS_Store
9+
**/*.log

Diff for: contracts/config/DisputeTemplate.simple.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "../NewDisputeTemplate.schema.json",
3+
"title": "Let's do this",
4+
"description": "We want to do this: %s",
5+
"question": "Does it comply with the policy?",
6+
"answers": [
7+
{
8+
"title": "Yes",
9+
"description": "Select this if you agree that it must be done."
10+
},
11+
{
12+
"title": "No",
13+
"description": "Select this if you do not agree that it must be done."
14+
}
15+
],
16+
"policyURI": "/ipfs/Qmdvk...rSD6cE/policy.pdf",
17+
"frontendUrl": "https://kleros-v2.netlify.app/#/cases/%s/overview",
18+
"arbitratorChainID": "421613",
19+
"arbitratorAddress": "0xD08Ab99480d02bf9C092828043f611BcDFEA917b",
20+
"category": "Others",
21+
"specification": "KIP001",
22+
"lang": "en_US"
23+
}

Diff for: contracts/deploy/00-home-chain-arbitrable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";
3+
import disputeTemplate from "../config/DisputeTemplate.simple.json";
44

55
enum HomeChains {
66
ARBITRUM_ONE = 42161,

Diff for: contracts/deploy/03-vea-mock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import getContractAddress from "../deploy-helpers/getContractAddress";
44
import { KlerosCore__factory } from "../typechain-types";
5-
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";
5+
import disputeTemplate from "../config/DisputeTemplate.simple.json";
66

77
const HARDHAT_NETWORK = 31337;
88

Diff for: contracts/deploy/04-foreign-arbitrable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";
3+
import disputeTemplate from "../config/DisputeTemplate.simple.json";
44

55
enum ForeignChains {
66
ETHEREUM_MAINNET = 1,

Diff for: contracts/deploy/04-klerosliquid-to-v2-gnosis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parseUnits, parseEther } from "ethers/lib/utils";
22
import { HardhatRuntimeEnvironment } from "hardhat/types";
33
import { DeployFunction } from "hardhat-deploy/types";
4-
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";
4+
import disputeTemplate from "../config/DisputeTemplate.simple.json";
55

66
enum ForeignChains {
77
GNOSIS_MAINNET = 100,

Diff for: contracts/hardhat.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ const config: HardhatUserConfig = {
5252
foreign: "localhost",
5353
},
5454
},
55+
dockerhost: {
56+
url: `http://host.docker.internal:8545`,
57+
chainId: 31337,
58+
saveDeployments: true,
59+
tags: ["test", "local"],
60+
companionNetworks: {
61+
foreign: "localhost",
62+
},
63+
},
5564
mainnetFork: {
5665
chainId: 1,
5766
url: `http://127.0.0.1:8545`,

Diff for: contracts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"dotenv": "^16.3.1",
5858
"ethereumjs-util": "^7.1.5",
5959
"ethers": "^5.7.2",
60+
"graphql": "^16.7.1",
6061
"graphql-request": "^6.1.0",
6162
"hardhat": "^2.15.0",
6263
"hardhat-contract-sizer": "^2.10.0",

Diff for: contracts/scripts/disputeRelayerBot.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ export default async function main(
8888
);
8989

9090
console.log("Listening for events...");
91-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
92-
await delay(1000000);
91+
const delay = (duration: string) => new Promise((x) => setTimeout(x, duration));
92+
await delay("7 days");
9393
}

Diff for: contracts/scripts/keeperBot.ts

+3
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ async function main() {
381381
return PHASES[await sortition.phase()] === Phase.DRAWING;
382382
};
383383

384+
logger.info("Starting up");
385+
384386
await sendHeartbeat();
385387

386388
logger.info(`Current phase: ${PHASES[await sortition.phase()]}`);
@@ -566,6 +568,7 @@ async function main() {
566568

567569
await sendHeartbeat();
568570

571+
logger.info("Shutting down");
569572
await delay(2000); // Some log messages may be lost otherwise
570573
}
571574

Diff for: cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"commitlint",
1414
"COOLDOWN",
1515
"datetime",
16+
"dockerhost",
1617
"Ethfinex",
1718
"hearbeat",
1819
"IERC",

Diff for: services/keeper-bot/Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM --platform=arm64 node:16-bookworm
2+
3+
WORKDIR /usr/src/app
4+
5+
RUN npm install pm2 -g
6+
7+
USER node
8+
9+
COPY --chown=node:node "./node_modules" "./node_modules"
10+
COPY --chown=node:node "./contracts" "./contracts"
11+
COPY --chown=node:node "./eslint-config" "./eslint-config"
12+
COPY --chown=node:node "./prettier-config" "./prettier-config"
13+
COPY --chown=node:node "./tsconfig" "./tsconfig"
14+
COPY --chown=node:node "./.yarn" "./.yarn"
15+
COPY --chown=node:node [ ".yarnrc.yml", ".nvmrc", ".eslintignore", "package.json", "yarn.lock", "./" ]
16+
17+
RUN yarn set version 3.3.1 && \
18+
yarn --version && \
19+
node --version
20+
21+
WORKDIR /usr/src/app/contracts
22+
23+
RUN yarn workspaces focus && \
24+
yarn build
25+
26+
ENTRYPOINT [ "yarn" ]

Diff for: services/keeper-bot/common.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.3'
2+
services:
3+
bot-base:
4+
build:
5+
context: ../../
6+
dockerfile: ./services/keeper-bot/Dockerfile
7+
image: kleros-v2-bots
8+
command: --help

Diff for: services/keeper-bot/docker-compose.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: '3'
2+
services:
3+
keeper-bot-testnet:
4+
extends:
5+
file: common.yml
6+
service: bot-base
7+
# command: bot:keeper --network arbitrumGoerli
8+
entrypoint:
9+
[
10+
"/bin/bash",
11+
"-c",
12+
"pm2-runtime ecosystem.config.js --only keeper-bot-testnet --no-auto-exit"
13+
]
14+
# entrypoint:
15+
# [
16+
# "/bin/bash",
17+
# "-c",
18+
# "pm2-runtime ecosystem.config.js --only foo --no-auto-exit"
19+
# ]
20+
env_file: .env.testnet
21+
volumes:
22+
- type: bind
23+
source: ./ecosystem.config.js
24+
target: /usr/src/app/contracts/ecosystem.config.js
25+
26+
relayer-bot-from-chiado-testnet:
27+
extends:
28+
file: common.yml
29+
service: bot-base
30+
# command: bot:relayer-from-chiado --network arbitrumGoerli
31+
entrypoint:
32+
[
33+
"/bin/bash",
34+
"-c",
35+
"pm2-runtime ecosystem.config.js --only relayer-bot-from-chiado-testnet --no-auto-exit"
36+
]
37+
volumes:
38+
- type: bind
39+
source: ./ecosystem.config.js
40+
target: /usr/src/app/contracts/ecosystem.config.js
41+
profiles:
42+
- chiado
43+
env_file:
44+
- .env.testnet
45+
46+
relayer-bot-from-goerli-testnet:
47+
extends:
48+
file: common.yml
49+
service: bot-base
50+
command: bot:relayer-from-goerli --network arbitrumGoerli
51+
profiles:
52+
- goerli
53+
env_file:
54+
- .env.testnet
55+
56+
relayer-bot-from-hardhat-host:
57+
extends:
58+
file: common.yml
59+
service: bot-base
60+
command: bot:relayer-from-hardhat --network dockerhost
61+
extra_hosts:
62+
- host.docker.internal:host-gateway
63+
volumes:
64+
- type: bind
65+
source: ../../contracts/deployments/localhost
66+
target: /usr/src/app/contracts/deployments/localhost
67+
profiles:
68+
- hardhat
69+
env_file:
70+
- .env.testnet

Diff for: services/keeper-bot/ecosystem.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
name: "foo",
5+
interpreter: "bash",
6+
script: "yarn",
7+
args: "foo",
8+
restart_delay: 3000,
9+
autorestart: true,
10+
},
11+
{
12+
name: "keeper-bot-testnet",
13+
interpreter: "bash",
14+
script: "yarn",
15+
args: "bot:keeper --network arbitrumGoerli",
16+
restart_delay: 10000,
17+
autorestart: true,
18+
},
19+
{
20+
name: "relayer-bot-from-chiado-testnet",
21+
interpreter: "bash",
22+
script: "yarn",
23+
args: "bot:relayer-from-chiado --network arbitrumGoerli",
24+
restart_delay: 2000,
25+
autorestart: true,
26+
},
27+
],
28+
};

Diff for: yarn.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5170,6 +5170,7 @@ __metadata:
51705170
dotenv: ^16.3.1
51715171
ethereumjs-util: ^7.1.5
51725172
ethers: ^5.7.2
5173+
graphql: ^16.7.1
51735174
graphql-request: ^6.1.0
51745175
hardhat: ^2.15.0
51755176
hardhat-contract-sizer: ^2.10.0

0 commit comments

Comments
 (0)