From 795518cf24942363d1eeb66c7cfd3f9080407958 Mon Sep 17 00:00:00 2001 From: JSHan94 Date: Tue, 5 Dec 2023 20:15:33 +0900 Subject: [PATCH] fix to handle block --- bots/src/config.ts | 4 +- bots/src/scripts/fundAccounts.ts | 89 +++++++++++++++++++++++ bots/src/scripts/setupL2.ts | 2 +- bots/src/worker/bridgeExecutor/Monitor.ts | 8 +- 4 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 bots/src/scripts/fundAccounts.ts diff --git a/bots/src/config.ts b/bots/src/config.ts index a06d28d4..bf88ce1e 100644 --- a/bots/src/config.ts +++ b/bots/src/config.ts @@ -90,11 +90,11 @@ export class Config implements ConfigInterface { this.BATCH_SUBMITTER_MNEMONIC = BATCH_SUBMITTER_MNEMONIC; this.CHALLENGER_MNEMONIC = CHALLENGER_MNEMONIC; this.USE_LOG_FILE = !!JSON.parse(USE_LOG_FILE); - this.l1lcd = new LCDClient(L1_LCD_URI, { + this.l1lcd = new LCDClient(this.L1_LCD_URI[0], { gasPrices: '0.15uinit', gasAdjustment: '2' }); - this.l2lcd = new LCDClient(L2_LCD_URI, { + this.l2lcd = new LCDClient(this.L2_LCD_URI[0], { gasPrices: '0.15umin', gasAdjustment: '2' }); diff --git a/bots/src/scripts/fundAccounts.ts b/bots/src/scripts/fundAccounts.ts new file mode 100644 index 00000000..d9dc4b4b --- /dev/null +++ b/bots/src/scripts/fundAccounts.ts @@ -0,0 +1,89 @@ +import { MnemonicKey, MsgSend, Wallet } from "@initia/initia.js"; +import { getConfig } from "config"; +import { sendTx } from "lib/tx"; + +const config = getConfig(); +const L1_FUNDER = new Wallet( + config.l1lcd, + new MnemonicKey({ + mnemonic: '' + }) +) +const L2_FUNDER = new Wallet( + config.l2lcd, + new MnemonicKey({ + mnemonic: '' + }) +) + +async function fundL1(){ + const executor = new Wallet(config.l1lcd, new MnemonicKey({mnemonic: config.EXECUTOR_MNEMONIC})) + const output = new Wallet(config.l1lcd, new MnemonicKey({mnemonic: config.OUTPUT_SUBMITTER_MNEMONIC})) + const batch = new Wallet(config.l1lcd, new MnemonicKey({mnemonic: config.BATCH_SUBMITTER_MNEMONIC})) + const challenger = new Wallet(config.l1lcd, new MnemonicKey({mnemonic: config.CHALLENGER_MNEMONIC})) + + const sendMsg = [ + new MsgSend( + L1_FUNDER.key.accAddress, + executor.key.accAddress, + "50000000000uinit" + ), + new MsgSend( + L1_FUNDER.key.accAddress, + output.key.accAddress, + "50000000000uinit" + ), + new MsgSend( + L1_FUNDER.key.accAddress, + batch.key.accAddress, + "50000000000uinit" + ), + new MsgSend( + L1_FUNDER.key.accAddress, + challenger.key.accAddress, + "50000000000uinit" + ) + ] + await sendTx(L1_FUNDER, sendMsg); +} + +async function fundL2(){ + const executor = new Wallet(config.l2lcd, new MnemonicKey({mnemonic: config.EXECUTOR_MNEMONIC})) + const output = new Wallet(config.l2lcd, new MnemonicKey({mnemonic: config.OUTPUT_SUBMITTER_MNEMONIC})) + const batch = new Wallet(config.l2lcd, new MnemonicKey({mnemonic: config.BATCH_SUBMITTER_MNEMONIC})) + const challenger = new Wallet(config.l2lcd, new MnemonicKey({mnemonic: config.CHALLENGER_MNEMONIC})) + + const sendMsg = [ + new MsgSend( + L2_FUNDER.key.accAddress, + executor.key.accAddress, + "1umin" + ), + new MsgSend( + L2_FUNDER.key.accAddress, + output.key.accAddress, + "1umin" + ), + new MsgSend( + L2_FUNDER.key.accAddress, + batch.key.accAddress, + "1umin" + ), + new MsgSend( + L2_FUNDER.key.accAddress, + challenger.key.accAddress, + "1umin" + ) + ] + await sendTx(L2_FUNDER, sendMsg); +} + +async function main(){ + // await fundL1(); + // await fundL2(); + console.log('Funded accounts'); +} + +if (require.main === module) { + main(); +} \ No newline at end of file diff --git a/bots/src/scripts/setupL2.ts b/bots/src/scripts/setupL2.ts index 9449f814..3b6b6a1c 100644 --- a/bots/src/scripts/setupL2.ts +++ b/bots/src/scripts/setupL2.ts @@ -6,7 +6,7 @@ import { executor, challenger, outputSubmitter } from 'test/utils/helper'; const config = getConfig(); const SUBMISSION_INTERVAL = 3600; // 1 hour const FINALIZED_TIME = 3600; // 1 hour -const IBC_METADATA = 'channel-3'; +const IBC_METADATA = 'channel-2'; // ibc channel name class L2Initializer { l2id = config.BRIDGE_ID; diff --git a/bots/src/worker/bridgeExecutor/Monitor.ts b/bots/src/worker/bridgeExecutor/Monitor.ts index ea73c275..b58bef79 100644 --- a/bots/src/worker/bridgeExecutor/Monitor.ts +++ b/bots/src/worker/bridgeExecutor/Monitor.ts @@ -79,9 +79,13 @@ export abstract class Monitor { if (nextHeight % 10 === 0) { this.logger.info(`${this.name()} height ${nextHeight}`); } - - if (parseInt(metadata.num_txs) === 0) { + + if (parseInt(metadata.num_txs) !== 0) { + await this.handleBlock(manager); this.syncedHeight++; + await manager + .getRepository(StateEntity) + .update({ name: this.name() }, { height: this.syncedHeight }); continue; }