Skip to content

Commit

Permalink
feat: feeding (#26)
Browse files Browse the repository at this point in the history
* async feeding

* fix logging

* lint

* add resurrector on l1 monitor

* fix resurrector

* make l1 gas price config

* update readme
  • Loading branch information
JSHan94 authored May 30, 2024
1 parent fc89fd6 commit ad6cacc
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 188 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ TYPEORM_ENTITIES=dist/orm/*Entity.js # entity path
| 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> |
| L2_GAS_PRICES | Gas prices for L2 chain | '0.15umin' |
| L1_GAS_PRICES | Gas prices for L1 chain | '0.15uinit' |
| L2_GAS_PRICES | Gas prices for L2 chain | '0umin' |
| BRIDGE_ID | Bridge ID | '' |
| EXECUTOR_PORT | Executor port | 5000 |
| EXECUTOR_MNEMONIC | Mnemonic seed for executor | '' |
Expand All @@ -98,6 +99,7 @@ TYPEORM_ENTITIES=dist/orm/*Entity.js # entity path
| ------------------------- | ------------------------------------------ | ------------------------ |
| 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> |
| L1_GAS_PRICES | Gas prices for L1 chain | '0.15uinit' |
| BRIDGE_ID | Bridge ID | '' |
| OUTPUT_SUBMITTER_MNEMONIC | Mnemonic seed for output submitter | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |
Expand Down Expand Up @@ -128,7 +130,7 @@ TYPEORM_ENTITIES=dist/orm/*Entity.js # entity path
| ENABLE_API_ONLY | Enable API only mode (optional) | false |
| BATCH_METRICS_PORT | Batch metrics port | 8082 |
| PROMETHEUS_METRICS_MODE | Prometheus metrics mode ['pull', 'push'] | 'pull' |
| PROMETHEUS_GATEWAY_URI | Prometheus push gateway URI | 'http://127.0.0.1:9091' |
| PROMETHEUS_GATEWAY_URI | Prometheus push gateway URI | 'http://127.0.0.1:9091' |
| PROMETHEUS_TIME_OUT | Prometheus push time out (unit: ms) | 5000 |

- `.env.challenger`
Expand All @@ -139,6 +141,7 @@ TYPEORM_ENTITIES=dist/orm/*Entity.js # entity path
| 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> |
| L1_GAS_PRICES | Gas prices for L1 chain | '0.15uinit' |
| BRIDGE_ID | Bridge ID | '' |
| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' |
| DELETE_OUTPUT_PROPOSAL | Delete output proposal | false |
Expand Down
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
BATCH_SUBMITTER_MNEMONIC,
CHALLENGER_MNEMONIC,
USE_LOG_FILE,
L1_GAS_PRICES,
L2_GAS_PRICES,
L1_CHAIN_ID,
L2_CHAIN_ID,
Expand Down Expand Up @@ -150,7 +151,7 @@ export const config = {
l1lcd: new LCDClientL1(
getUri(L1_LCD_URI),
{
gasPrices: '0.15uinit',
gasPrices: L1_GAS_PRICES || '0.15uinit',
gasAdjustment: '2',
chainId: L1_CHAIN_ID
},
Expand Down Expand Up @@ -225,3 +226,5 @@ validateCelestiaConfig()
export const INTERVAL_BATCH = 100_000
export const INTERVAL_MONITOR = 100
export const INTERVAL_OUTPUT = 10_000

export const SECOND = 1_000
2 changes: 1 addition & 1 deletion src/worker/batchSubmitter/batchSubmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { delay } from 'bluebird'
import { INTERVAL_BATCH } from '../../config'
import { config } from '../../config'
import MonitorHelper from '../../lib/monitor/helper'
import MonitorHelper from '../bridgeExecutor/monitor/helper'
import { createBlob, getCelestiaFeeGasLimit } from '../../celestia/utils'
import { bech32 } from 'bech32'
import { TxWalletL1 } from '../../lib/walletL1'
Expand Down
124 changes: 0 additions & 124 deletions src/worker/bridgeExecutor/Resurrector.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/worker/bridgeExecutor/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { RPCClient } from '../../lib/rpc'
import { L1Monitor } from '../../lib/monitor/l1'
import { L2Monitor } from '../../lib/monitor/l2'
import { L1Monitor } from './monitor/l1'
import { L2Monitor } from './monitor/l2'
import { executorController, metricsController } from '../../controller'

import { executorLogger as logger } from '../../lib/logger'
import { initORM, finalizeORM } from './db'
import { initServer, finalizeServer, initMetricsServer } from '../../loader'
import { once } from 'lodash'
import { config } from '../../config'
import { Resurrector } from './Resurrector'

let monitors

async function runBot(): Promise<void> {
monitors = [
new L1Monitor(new RPCClient(config.L1_RPC_URI, logger), logger),
new L2Monitor(new RPCClient(config.L2_RPC_URI, logger), logger),
new Resurrector(logger)
new L2Monitor(new RPCClient(config.L2_RPC_URI, logger), logger)
]
try {
await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import {
TxSearchOptions,
TxSearchResult
} from 'initia-l2'
import { getLatestOutputFromExecutor, getOutputFromExecutor } from '../query'
import { WithdrawStorage } from '../storage'
import { WithdrawalTx } from '../types'
import { sha3_256 } from '../util'
import OutputEntity from '../../orm/executor/OutputEntity'
import {
getLatestOutputFromExecutor,
getOutputFromExecutor
} from '../../../lib/query'
import { WithdrawStorage } from '../../../lib/storage'
import { WithdrawalTx } from '../../../lib/types'
import { sha3_256 } from '../../../lib/util'
import OutputEntity from '../../../orm/executor/OutputEntity'
import { EntityManager, EntityTarget, ObjectLiteral } from 'typeorm'
import { Block, BlockResults, RPCClient } from '../../lib/rpc'
import { Block, BlockResults, RPCClient } from '../../../lib/rpc'

class MonitorHelper {
///
Expand Down Expand Up @@ -202,8 +205,7 @@ class MonitorHelper {
let attempt = 0
while (!blockResults && attempt < maxRetry) {
try {
blockResults = await rpcClient
.getBlockResults(minHeight + i)
blockResults = await rpcClient.getBlockResults(minHeight + i)
} catch {
if (attempt === maxRetry) {
throw new Error('Failed to feed block results')
Expand Down
File renamed without changes.
37 changes: 24 additions & 13 deletions src/lib/monitor/l1.ts → src/worker/bridgeExecutor/monitor/l1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ import {
ExecutorUnconfirmedTxEntity,
ExecutorOutputEntity,
StateEntity
} from '../../orm'
} from '../../../orm'
import { EntityManager } from 'typeorm'
import { RPCClient } from '../rpc'
import { getDB } from '../../worker/bridgeExecutor/db'
import { RPCClient } from '../../../lib/rpc'
import { getDB } from '../db'
import winston from 'winston'
import { config } from '../../config'
import { TxWalletL2, WalletType, getWallet, initWallet } from '../walletL2'
import { config } from '../../../config'
import {
TxWalletL2,
WalletType,
getWallet,
initWallet
} from '../../../lib/walletL2'
import { Resurrector } from './resurrector'

export class L1Monitor extends Monitor {
executorL2: TxWalletL2
oracleHeight: number
resurrector: Resurrector

constructor(
public rpcClient: RPCClient,
Expand All @@ -32,7 +39,7 @@ export class L1Monitor extends Monitor {
[this.db] = getDB()
initWallet(WalletType.Executor, config.l2lcd)
this.executorL2 = getWallet(WalletType.Executor)

this.resurrector = new Resurrector(logger, this.executorL2)
this.oracleHeight = 0
}

Expand Down Expand Up @@ -100,18 +107,22 @@ export class L1Monitor extends Monitor {
}

public async handleNewBlock(): Promise<void> {
await this.resurrector.ressurect()

if (!config.ENABLE_ORACLE) return
if (!this.latestHeight) return
if (!this.latestHeight || this.oracleHeight == this.latestHeight) {
this.logger.info(
`[handleNewBlock - ${this.name()}] No new block to update oracle tx`
)
return
}

const latestTx0 = this.getBlockByHeight(this.latestHeight)?.block.data
.txs[0]

if (
!latestTx0 ||
this.oracleHeight == this.latestHeight
) {
if (!latestTx0) {
this.logger.info(
`[handleNewBlock - ${this.name()}] No new block to update oracle tx`
`[handleNewBlock - ${this.name()}] No txs in height: ${this.latestHeight}`
)
return
}
Expand Down Expand Up @@ -190,7 +201,7 @@ export class L1Monitor extends Monitor {
}

public async handleEvents(manager: EntityManager): Promise<any> {
const blockResults = this.getBlockResultsByHeight(this.currentHeight)
const blockResults = await this.getBlockResultsByHeight(this.currentHeight)
const [isEmpty, events] = await this.helper.fetchAllEvents(blockResults)
if (isEmpty) {
this.logger.info(
Expand Down
19 changes: 12 additions & 7 deletions src/lib/monitor/l2.ts → src/worker/bridgeExecutor/monitor/l2.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { ExecutorOutputEntity, ExecutorWithdrawalTxEntity } from '../../orm'
import { ExecutorOutputEntity, ExecutorWithdrawalTxEntity } from '../../../orm'
import { Monitor } from './monitor'
import { EntityManager } from 'typeorm'
import { BlockInfo } from 'initia-l2'
import { getDB } from '../../worker/bridgeExecutor/db'
import { RPCClient } from '../rpc'
import { getDB } from '../db'
import { RPCClient } from '../../../lib/rpc'
import winston from 'winston'
import { config } from '../../config'
import { getBridgeInfo, getLastOutputInfo } from '../query'
import { TxWalletL2, WalletType, getWallet, initWallet } from '../walletL2'
import { config } from '../../../config'
import { getBridgeInfo, getLastOutputInfo } from '../../../lib/query'
import {
TxWalletL2,
WalletType,
getWallet,
initWallet
} from '../../../lib/walletL2'

export class L2Monitor extends Monitor {
executorL2: TxWalletL2
Expand Down Expand Up @@ -89,7 +94,7 @@ export class L2Monitor extends Monitor {
}

public async handleEvents(manager: EntityManager): Promise<boolean> {
const blockResults = this.getBlockResultsByHeight(this.currentHeight)
const blockResults = await this.getBlockResultsByHeight(this.currentHeight)
const [isEmpty, events] = await this.helper.fetchAllEvents(blockResults)
if (isEmpty) {
this.logger.info(
Expand Down
Loading

0 comments on commit ad6cacc

Please sign in to comment.