Skip to content

Commit

Permalink
use .env.WORKER_NAME as default
Browse files Browse the repository at this point in the history
  • Loading branch information
JSHan94 committed Dec 15, 2023
1 parent 4974623 commit 81b56d2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
36 changes: 32 additions & 4 deletions bots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const msg = new MsgCreateBridge(executor.key.accAddress, bridgeConfig);

## Configuration

- `.env.executor`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
Expand All @@ -37,15 +38,42 @@ const msg = new MsgCreateBridge(executor.key.accAddress, bridgeConfig);
| L2_RPC_URI | L2 node RPC URI | <http://127.0.0.1:26657> |
| 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 | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

- `.env.output`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| OUTPUT_SUBMITTER_MNEMONIC | Mnemonic seed for output submitter | '' |
| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

- `.env.batch`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| L2_LCD_URI | L2 node LCD URI | <http://127.0.0.1:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| BATCH_PORT | Batch submitter port | 5001 |
| BATCH_SUBMITTER_MNEMONIC | Mnemonic seed for submitter | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

- `.env.challenger`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| L2_LCD_URI | L2 node LCD URI | <http://127.0.0.1:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

> In OPinit bots, we use [.dotenv](https://www.npmjs.com/package/dotenv) for managing environment variable for development. See [.env_sample](.env_sample). If you want to set `.env` by worker, you should name it as `.env.{WORKER_NAME}` and set `WORKER_NAME` in [`executor`, `output`, `batch`, `challenger`].
> In OPinit bots, we use [.dotenv](https://www.npmjs.com/package/dotenv) for managing environment variable for development. If you want to set `.env` by worker, you should name it as `.env.{WORKER_NAME}` and set `WORKER_NAME` in [`executor`, `output`, `batch`, `challenger`].
For example, if you want to set `.env` for `executor`, you should name it as `.env.executor` and set `WORKER_NAME=executor` in local environment.

## Bridge Executor
Expand Down
12 changes: 6 additions & 6 deletions bots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"node": ">=16"
},
"scripts": {
"executor": "ts-node -r tsconfig-paths/register ./src/worker/bridgeExecutor/index.ts",
"batch": "ts-node -r tsconfig-paths/register ./src/worker/batchSubmitter/index.ts",
"challenger": "ts-node -r tsconfig-paths/register ./src/worker/challenger/index.ts",
"output": "ts-node -r tsconfig-paths/register ./src/worker/outputSubmitter/index.ts",
"executor": "export WORKER_NAME=executor && ts-node -r tsconfig-paths/register ./src/worker/bridgeExecutor/index.ts",
"batch": "export WORKER_NAME=batch && ts-node -r tsconfig-paths/register ./src/worker/batchSubmitter/index.ts",
"challenger": "export WORKER_NAME=challenger && ts-node -r tsconfig-paths/register ./src/worker/challenger/index.ts",
"output": "export WORKER_NAME=output && ts-node -r tsconfig-paths/register ./src/worker/outputSubmitter/index.ts",
"build": "tsc --module commonjs && webpack --mode production",
"test": "jest",
"test:integration": "ts-node -r tsconfig-paths/register ./src/test/integration.ts",
"test:integration": "export NODE_ENV=test && ts-node -r tsconfig-paths/register ./src/test/integration.ts",
"prettier": "prettier --write ./src/**/**/**/**/*.ts",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"do": "ts-node -T --files -r tsconfig-paths/register",
"apidoc": "npm run do src/loader/generateApiDoc.ts",
"prepublishOnly": "npm run build",
"l2setup": "ts-node -r tsconfig-paths/register ./src/scripts/setupL2.ts"
"l2setup": "export NODE_ENV=test && ts-node -r tsconfig-paths/register ./src/scripts/setupL2.ts"
},
"repository": {
"type": "git",
Expand Down
8 changes: 5 additions & 3 deletions bots/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LCDClient } from '@initia/initia.js';
import * as dotenv from 'dotenv';

const envFile = process.env.WORKER_NAME
? `.env.${process.env.WORKER_NAME}`
: '.env';
const envFile = process.env.NODE_ENV === 'test'
? `.env`
: `.env.${process.env.WORKER_NAME}`;

console.log(envFile);
dotenv.config({ path: envFile });

const {
Expand Down
17 changes: 6 additions & 11 deletions bots/src/worker/outputSubmitter/outputSubmitter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Wallet, MnemonicKey, MsgProposeOutput } from '@initia/initia.js';
import { MsgProposeOutput } from '@initia/initia.js';
import { INTERVAL_OUTPUT } from 'config';
import { ExecutorOutputEntity } from 'orm';
import { delay } from 'bluebird';
import { outputLogger as logger } from 'lib/logger';
import { ErrorTypes } from 'lib/error';
import { config } from 'config';
import { sendTx } from 'lib/tx';
import { getLastOutputInfo } from 'lib/query';
import MonitorHelper from 'worker/bridgeExecutor/MonitorHelper';
import { DataSource, EntityManager } from 'typeorm';
import { getDB } from './db';
import { TxWallet, WalletType, getWallet, initWallet } from 'lib/wallet';

export class OutputSubmitter {
private db: DataSource;
private submitter: Wallet;
private submitter: TxWallet;
private syncedOutputIndex = 1;
private processedBlockNumber = 1;
private isRunning = false;
Expand All @@ -22,10 +22,8 @@ export class OutputSubmitter {

async init() {
[this.db] = getDB();
this.submitter = new Wallet(
config.l1lcd,
new MnemonicKey({ mnemonic: config.OUTPUT_SUBMITTER_MNEMONIC })
);
initWallet(WalletType.OutputSubmitter, config.l1lcd);
this.submitter = getWallet(WalletType.OutputSubmitter);
this.bridgeId = config.BRIDGE_ID;
this.isRunning = true;
}
Expand Down Expand Up @@ -83,10 +81,7 @@ export class OutputSubmitter {
outputEntity.outputRoot
);

const { account_number, sequence } =
await this.submitter.accountNumberAndSequence();

await sendTx(this.submitter, [msg], account_number, sequence);
await this.submitter.transaction([msg]);

this.processedBlockNumber = outputEntity.endBlockNumber;
}
Expand Down

0 comments on commit 81b56d2

Please sign in to comment.