Skip to content
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: OPinit bot #10

Merged
merged 38 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7006080
remove docker setup
JSHan94 Nov 10, 2023
b23952c
add consts for testing
JSHan94 Dec 14, 2023
4f34728
remove blockSDK empty tx
JSHan94 Dec 14, 2023
45296c1
fix as review
JSHan94 Dec 15, 2023
6f64a06
change check order
JSHan94 Dec 15, 2023
22b87a1
convert .envrc to .env
JSHan94 Dec 15, 2023
4974623
add link
JSHan94 Dec 15, 2023
81b56d2
use .env.WORKER_NAME as default
JSHan94 Dec 15, 2023
42d3440
fix gas prices
JSHan94 Dec 15, 2023
e7d7d5c
add DELETE_OUTPUT_PROPOSAL on readme
JSHan94 Dec 18, 2023
23d6562
add notify on slack in challenger
JSHan94 Dec 18, 2023
c26be80
trace error by info
JSHan94 Dec 19, 2023
0dac345
colorize
JSHan94 Dec 19, 2023
6519049
add L2 gas prices and clean up
JSHan94 Dec 21, 2023
0273865
remove unsafe optional chaining
JSHan94 Dec 22, 2023
0341818
remove chaining and use try-catch
JSHan94 Dec 26, 2023
c77f82b
use winston-embeded format for logger
JSHan94 Jan 2, 2024
3093c16
sanitize DailyRotateFile
JSHan94 Jan 3, 2024
7ff492f
fix convention in lib and lintjob
Vritra4 Jan 3, 2024
8ce89e2
fix convention
Vritra4 Jan 3, 2024
f29ef62
Merge pull request #14 from initia-labs/fix/convention
JSHan94 Jan 3, 2024
71cbd49
lint
JSHan94 Jan 3, 2024
7c383c6
disable lint for js file
JSHan94 Jan 3, 2024
c8afb11
bump ecmascript to es2021
Vritra4 Jan 3, 2024
2559557
fix import
Vritra4 Jan 3, 2024
3eab5e4
remove warning by replacing deps
Vritra4 Jan 3, 2024
b77a8a0
remove unnecessary castings to any
Vritra4 Jan 3, 2024
8ac34a8
Merge pull request #15 from initia-labs/bump-ecma
JSHan94 Jan 3, 2024
82e8fcf
use swagger
JSHan94 Jan 5, 2024
5694be8
Merge branch 'main' of https://github.com/initia-labs/OPinit into fea…
JSHan94 Jan 5, 2024
7542a26
support v0.50
JSHan94 Jan 5, 2024
da38a7c
notify chain id
JSHan94 Jan 5, 2024
b47a91f
fix fetch evts
JSHan94 Jan 8, 2024
ac8f7ea
add axios
JSHan94 Jan 8, 2024
8bc30fd
add initia.js
JSHan94 Jan 8, 2024
c93dbf9
bump to initia.js 1.0.27
JSHan94 Jan 17, 2024
7d457c9
remove unused import
JSHan94 Jan 17, 2024
417b5b1
fix descending condition
JSHan94 Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions bots/.env

This file was deleted.

33 changes: 18 additions & 15 deletions bots/.envrc_sample
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
export TYPEORM_CONNECTION=postgres
JSHan94 marked this conversation as resolved.
Show resolved Hide resolved
export TYPEORM_HOST=localhost
JSHan94 marked this conversation as resolved.
Show resolved Hide resolved
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
export TYPEORM_ENTITIES=src/orm/*Entity.ts
export USE_LOG_FILE=false

export EXECUTOR_PORT=3000
export BATCH_PORT=3001
export EXECUTOR_PORT=5000
export BATCH_PORT=5001

export L1_LCD_URI=https://next-stone-rest.initia.tech
export L1_RPC_URI=https://next-stone-rpc.initia.tech
export L2_LCD_URI=http://localhost:1318
export L2_RPC_URI=http://localhost:26658
export L2ID=0x56ccf33c45b99546cd1da172cf6849395bbf8573::s10r1::Minitia
# l2 setup (need challenger, output, executor mnemonic)
export SUBMISSION_INTERVAL=10000
export FINALIZED_TIME=10000
JSHan94 marked this conversation as resolved.
Show resolved Hide resolved
export IBC_METADATA='channel-1'

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: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
export OUTPUT_SUBMITTER_MNEMONIC=''
1 change: 1 addition & 0 deletions bots/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apidoc/
static/

.envrc
.env
build
logs/
testing/
Expand Down
3 changes: 0 additions & 3 deletions bots/.gitmodules

This file was deleted.

22 changes: 0 additions & 22 deletions bots/Dockerfile

This file was deleted.

155 changes: 65 additions & 90 deletions bots/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Initia Rollup JS
# OPinit Bots

Initia Optimistic Rollup Bots.

Expand All @@ -9,116 +9,91 @@ 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';

## Bridge Executor
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);
```

Bridge executor is a bot that monitor L1, L2 node and execute bridge transaction. It will execute following steps.
## Configuration

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<L2ID>` entry function in `bridge.move`
3. Run executor bot
- Execute L1, L2 monitor in bridge executor
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <https://stone-rest.initia.tech> |
| L1_RPC_URI | L1 node RPC URI | <https://stone-rpc.initia.tech> |
| L2_LCD_URI | L2 node LCD URI | <https://minitia-rest.initia.tech>|
| L2_RPC_URI | L2 node RPC URI | <https://minitia-rpc.initia.tech>|
| BRIDGE_ID | Bridge ID | '' |
| EXECUTOR_PORT | Executor port | 5000 |
| BATCH_PORT | Batch submitter port | 5001 |
| 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 | '' |

```bash
npm run executor
```
> In OPinit bots, we use [direnv](https://direnv.net) for managing environment variable for development. See [sample of .envrc](.envrc_sample).

- If you use pm2, you can run executor with following command.
## Bridge Executor

```bash
pm2 start executor.json
```
Bridge executor is a bot that monitor L1, L2 node and execute bridge transaction. It will execute following steps.

4. Register coin to bridge store and prepare deposit store
- Execute `register_token<L2ID, CoinType>`
5. Now you can deposit after registering coin is done
1. Set bridge executor mnemonic on `.envrc`.
```bash
export EXECUTOR_MNEMONIC="..."
```
2. Run executor bot
```bash
npm run executor
```

## 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 batch.json
```
1. Set batch submitter mnemonic on `.envrc`.
```bash
export BATCH_SUBMITTER_MNEMONIC="..."
```
2. Run batch submitter bot
```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<L2ID>` in `output.move`.

```bash
npm run output
```
Output submitter will get the L2 output results from executor and submit it to L1.

If you use pm2,

```bash
pm2 start output.json
```
1. Set output submitter mnemonic on `.envrc`.
```bash
export OUTPUT_SUBMITTER_MNEMONIC="..."
```
2. Run output submitter bot
```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 challenger.json
```

## Configuration

| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <https://stone-rest.initia.tech>' |
| L1_RPC_URI | L1 node RPC URI | <https://stone-rpc.initia.tech>' |
| L2_LCD_URI | L2 node LCD URI | <http://localhost:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://localhost:26657> |
| L2ID | L2ID | '' |
| BATCH_PORT | Batch submitter port | 3000 |
| EXECUTOR_PORT | Executor port | 3001 |
| EXECUTOR_URI | Executor URI (for output submitter) | <http://localhost:3000> |
| 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`.
```bash
export CHALLENGER_MNEMONIC="..."
```
2. Run challenger bot
```bash
npm run challenger
```
11 changes: 0 additions & 11 deletions bots/batch.json

This file was deleted.

11 changes: 0 additions & 11 deletions bots/challenger.json

This file was deleted.

7 changes: 0 additions & 7 deletions bots/docker-compose-reset

This file was deleted.

73 changes: 0 additions & 73 deletions bots/docker-compose.yml

This file was deleted.

Loading
Loading