diff --git a/bots/.envrc_sample b/bots/.envrc_sample index b499ee89..e6608428 100644 --- a/bots/.envrc_sample +++ b/bots/.envrc_sample @@ -1,8 +1,8 @@ export TYPEORM_CONNECTION=postgres export TYPEORM_HOST=localhost -export TYPEORM_USERNAME=jungsuhan -export TYPEORM_PASSWORD=jungsuhan -export TYPEORM_DATABASE=challenger +export TYPEORM_USERNAME=user +export TYPEORM_PASSWORD=password +export TYPEORM_DATABASE=rollup export TYPEORM_PORT=5432 export TYPEORM_SYNCHRONIZE=true export TYPEORM_LOGGING=false @@ -12,22 +12,20 @@ export USE_LOG_FILE=false export EXECUTOR_PORT=3000 export BATCH_PORT=3001 -export L1_LCD_URI=https://next-stone-rest.initia.tech -export L1_RPC_URI=https://next-stone-rpc.initia.tech +export L1_LCD_URI=http://localhost:1317 +export L1_RPC_URI=http://localhost:26657 export L2_LCD_URI=http://localhost:1318 -export L2_RPC_URI=http://localhost:26658 +export L2_RPC_URI=http://localhost:26667 export BRIDGE_ID=1 - # executor config -export EXECUTOR_MNEMONIC='recycle sight world spoon leopard shine dizzy before public use jungle either arctic detail hawk output option august hedgehog menu keen night work become' +export EXECUTOR_MNEMONIC='' # batch submitter config -export BATCH_SUBMITTER_MNEMONIC='broken umbrella tent include pet simple amount renew insect page sound whip shock dynamic deputy left outside churn lounge raise mirror toss annual fat' +export BATCH_SUBMITTER_MNEMONIC='' # challenger config -export CHALLENGER_MNEMONIC='purity yard brush wagon note forest athlete seek offer clown surround cover present ski bargain obvious cute admit gloom text shaft super impose rubber' +export CHALLENGER_MNEMONIC='' # output submitter config -export OUTPUT_SUBMITTER_MNEMONIC='airport hidden cake dry bleak alcohol enough tower charge cash modify feature analyst suffer bus oyster initial coffee wine plug paper damp sock afraid' -export EXECUTOR_URI=http://localhost:3000 \ No newline at end of file +export OUTPUT_SUBMITTER_MNEMONIC='' diff --git a/bots/README.md b/bots/README.md index 7efaae99..ab8d876e 100644 --- a/bots/README.md +++ b/bots/README.md @@ -1,4 +1,4 @@ -# Initia Rollup JS +# OPinit Bots Initia Optimistic Rollup Bots. @@ -9,116 +9,86 @@ Initia Optimistic Rollup Bots. ## How to use -## Setup L2 +## Create Bridge -Initializes the L2 id and op-bridge/output contracts. -You should set `submissionInterval`, `finalizedTime` and `l2StartBlockHeight` before initializing. +Before running rollup bots, you should create bridge between L1 and L2. If you use `initia.js`, you can create bridge using `MsgCreateBridge` message as follows. -```bash -export SUB_INTV=10 -export FIN_TIME=10 -export L2_HEIGHT=1 -npm run l2setup +```typescript +import { MsgCreateBridge, BridgeConfig, Duration } from '@initia/initia.js'; + +const bridgeConfig = new BridgeConfig( + challenger.key.accAddress, + outputSubmitter.key.accAddress, + Duration.fromString(submissionInterval.toString()), + Duration.fromString(finalizedTime.toString()), + new Date(), + this.metadata +); +const msg = new MsgCreateBridge(executor.key.accAddress, bridgeConfig); ``` +## Configuration + +| Name | Description | Default | +| ------------------------- | ------------------------------------------------------ | -------------------------------- | +| L1_LCD_URI | L1 node LCD URI | | +| L1_RPC_URI | L1 node RPC URI | | +| L2_LCD_URI | L2 node LCD URI | | +| L2_RPC_URI | L2 node RPC URI | | +| BRIDGE_ID | Bridge ID | '' | +| EXECUTOR_PORT | Executor port | 3000 | +| BATCH_PORT | Batch submitter port | 3001 | +| EXECUTOR_MNEMONIC | Mnemonic seed for executor | '' | +| BATCH_SUBMITTER_MNEMONIC | Mnemonic seed for submitter | '' | +| OUTPUT_SUBMITTER_MNEMONIC | Mnemonic seed for output submitter | '' | +| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' | + +> In OPinit bots, we use [direnv](https://direnv.net) for managing environment variable for development. See [sample of .envrc](.envrc_sample) + ## Bridge Executor Bridge executor is a bot that monitor L1, L2 node and execute bridge transaction. It will execute following steps. -1. Publish L2 ID to L1 - - L2 ID should be published under executor account -2. Initialize bridge contract on L1 with L2 ID - - Execute `initialize` entry function in `bridge.move` +1. Set bridge executor mnemonic on `.envrc`. +2. Set DB configurations using `ormconfig.json` or `.envrc`. 3. Run executor bot - Execute L1, L2 monitor in bridge executor - ```bash npm run executor ``` - - If you use pm2, you can run executor with following command. - - ```bash - pm2 start pm2.json --only executor - ``` - -4. Register coin to bridge store and prepare deposit store - - Execute `register_token` -5. Now you can deposit after registering coin is done - ## Batch Submitter Batch submitter is a background process that submits transaction batches to the BatchInbox module of L1. -You can run with following command. - -```bash -npm run batch -``` - -If you use pm2, -```bash -pm2 start pm2.json --only batch -``` +1. Set batch submitter mnemonic on `.envrc`. +2. Set DB configurations using `ormconfig.json` or `.envrc`. +3. Run batch submitter bot + - Execute batch submitter + ```bash + npm run batch + ``` ## Output Submitter Output submitter is the component to store the L2 output root for block finalization. -Output submitter will get the L2 output results from executor and submit it to L1 using `propose_l2_output` in `output.move`. - -```bash -npm run output -``` - -If you use pm2, +Output submitter will get the L2 output results from executor and submit it to L1. -```bash -pm2 start pm2.json --only output -``` +1. Set output submitter mnemonic on `.envrc`. +2. Run output submitter bot + - Execute output submitter + ```bash + npm run output + ``` ## Challenger Challenger is an entity capable of deleting invalid output proposals from the output oracle. -```bash -npm run challenger -``` - -If you use pm2, - -```bash -pm2 start pm2.json --only challenger -``` - -## Configuration - -| Name | Description | Default | -| ------------------------- | ------------------------------------------------------ | -------------------------------- | -| L1_LCD_URI | L1 node LCD URI | ' | -| L1_RPC_URI | L1 node RPC URI | ' | -| L2_LCD_URI | L2 node LCD URI | | -| L2_RPC_URI | L2 node RPC URI | | -| L2ID | L2ID | '' | -| BATCH_PORT | Batch submitter port | 3000 | -| EXECUTOR_PORT | Executor port | 3001 | -| EXECUTOR_URI | Executor URI (for output submitter) | | -| EXECUTOR_MNEMONIC | Mnemonic seed for executor | '' | -| BATCH_SUBMITTER_MNEMONIC | Mnemonic seed for submitter | '' | -| OUTPUT_SUBMITTER_MNEMONIC | Mnemonic seed for output submitter | '' | -| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' | - -> In Batch Submitter, we use [direnv](https://direnv.net) for managing environment variable for development. See [sample of .envrc](.envrc_sample) - -## Test - -Docker and docker-compose are required to run integration test. - -```bash -npm run test:integration -``` - -If you want to reset docker container, run following command. - -```bash -./docker-compose-reset -``` +1. Set challenger mnemonic on `.envrc`. +2. Set DB configurations using `ormconfig.json` or `.envrc`. +3. Run challenger bot + - Execute challenger + ```bash + npm run challenger + ``` \ No newline at end of file diff --git a/bots/src/config.ts b/bots/src/config.ts index d6dfe75e..96992230 100644 --- a/bots/src/config.ts +++ b/bots/src/config.ts @@ -7,8 +7,7 @@ interface ConfigInterface { L1_RPC_URI: string; L2_LCD_URI: string; L2_RPC_URI: string; - EXECUTOR_URI: string; - L1_DENOM: string; + EXECUTOR_URI: string; // only for test BRIDGE_ID: number; OUTPUT_SUBMITTER_MNEMONIC: string; EXECUTOR_MNEMONIC: string; @@ -28,8 +27,7 @@ const defaultConfig = { L1_RPC_URI: 'https://stone-rpc.initia.tech', L2_LCD_URI: 'https://minitia-rest.initia.tech', L2_RPC_URI: 'https://minitia-rpc.initia.tech', - EXECUTOR_URI: 'https://minitia-executor.initia.tech', - L1_DENOM: 'uinit', + EXECUTOR_URI: 'https://minitia-executor.initia.tech', BRIDGE_ID: '', OUTPUT_SUBMITTER_MNEMONIC: '', EXECUTOR_ADDR: '', @@ -49,7 +47,6 @@ export class Config implements ConfigInterface { L2_LCD_URI: string; L2_RPC_URI: string; EXECUTOR_URI: string; - L1_DENOM: string; BRIDGE_ID: number; OUTPUT_SUBMITTER_MNEMONIC: string; EXECUTOR_ADDR: string; @@ -70,7 +67,6 @@ export class Config implements ConfigInterface { L2_LCD_URI, L2_RPC_URI, EXECUTOR_URI, - L1_DENOM, BRIDGE_ID, OUTPUT_SUBMITTER_MNEMONIC, EXECUTOR_ADDR, @@ -87,7 +83,6 @@ export class Config implements ConfigInterface { this.L2_LCD_URI = L2_LCD_URI; this.L2_RPC_URI = L2_RPC_URI; this.EXECUTOR_URI = EXECUTOR_URI; - this.L1_DENOM = L1_DENOM; this.BRIDGE_ID = parseInt(BRIDGE_ID); this.OUTPUT_SUBMITTER_MNEMONIC = OUTPUT_SUBMITTER_MNEMONIC; this.EXECUTOR_ADDR = EXECUTOR_ADDR; diff --git a/bots/src/test/utils/TxBot.ts b/bots/src/test/utils/TxBot.ts index 3a90b4bb..306fbf7b 100644 --- a/bots/src/test/utils/TxBot.ts +++ b/bots/src/test/utils/TxBot.ts @@ -17,6 +17,7 @@ export class TxBot { config.l1lcd, new MnemonicKey({ mnemonic: + // init1wzenw7r2t2ra39k4l9yqq95pw55ap4sm4vsa9g 'diamond donkey opinion claw cool harbor tree elegant outer mother claw amount message result leave tank plunge harbor garment purity arrest humble figure endless' }) ); @@ -25,6 +26,7 @@ export class TxBot { config.l1lcd, new MnemonicKey({ mnemonic: + // init174knscjg688ddtxj8smyjz073r3w5mmsp3m0m2 'cheap start amused certain dune unique diet enemy surround total grab item reduce engage office brain border liar eagle random unknown avoid chapter report' }) ); diff --git a/bots/src/worker/bridgeExecutor/Monitor.ts b/bots/src/worker/bridgeExecutor/Monitor.ts index 33dc50ec..df418a54 100644 --- a/bots/src/worker/bridgeExecutor/Monitor.ts +++ b/bots/src/worker/bridgeExecutor/Monitor.ts @@ -13,12 +13,10 @@ export abstract class Monitor { protected db: DataSource; protected isRunning = false; protected bridgeId: number; - protected l1Denom: string; helper: MonitorHelper = new MonitorHelper(); constructor(public socket: RPCSocket, public logger: winston.Logger) { this.bridgeId = config.BRIDGE_ID; - this.l1Denom = config.L1_DENOM; } public async run(): Promise {