diff --git a/src/controller/batch/BatchController.ts b/src/controller/batch/BatchController.ts index 5eddba2..0cb83e2 100644 --- a/src/controller/batch/BatchController.ts +++ b/src/controller/batch/BatchController.ts @@ -7,8 +7,8 @@ import { } from 'koa-joi-controllers' import { responses, routeConfig, z } from 'koa-swagger-decorator' import { success } from '../../lib/response' -import { GetBatchResponse } from 'sawgger/batch_model' -import { getBatch } from 'service/batch/BatchService' +import { GetBatchResponse } from '../../swagger/batch_model' +import { getBatch } from '../../service/batch/BatchService' const Joi = Validator.Joi diff --git a/src/lib/slack.ts b/src/lib/slack.ts index dc5fd00..2f18742 100644 --- a/src/lib/slack.ts +++ b/src/lib/slack.ts @@ -15,25 +15,32 @@ const ax = axios.create({ timeout: 15000 }) -export async function notifySlack(key: string, text: { text: string }, isError: boolean = true) { - if (config.SLACK_WEB_HOOK === undefined || config.SLACK_WEB_HOOK === '') return +export async function notifySlack( + key: string, + text: { text: string }, + isError: boolean = true +) { + if (config.SLACK_WEB_HOOK === undefined || config.SLACK_WEB_HOOK === '') + return const keyExists = postedKeys.has(key) if (isError) { - if (!keyExists) { - await ax.post(config.SLACK_WEB_HOOK, text) - postedKeys.add(key) - } + if (!keyExists) { + await ax.post(config.SLACK_WEB_HOOK, text) + postedKeys.add(key) + } } else { - if (keyExists) { - await ax.post(config.SLACK_WEB_HOOK, text) - postedKeys.delete(key) - } + if (keyExists) { + await ax.post(config.SLACK_WEB_HOOK, text) + postedKeys.delete(key) + } } } -export function buildResolveErrorNotification(description: string): { text: string } { +export function buildResolveErrorNotification(description: string): { + text: string; +} { let notification = '```' notification += `[INFO] Error Resolved Notification\n` notification += `\n` @@ -44,7 +51,6 @@ export function buildResolveErrorNotification(description: string): { text: stri } } - export function buildNotEnoughBalanceNotification( wallet: Wallet, balance: number, diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index 912b889..f05ac7f 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -9,7 +9,11 @@ import { } from '@initia/initia.js' import { sendTx } from './tx' import { config } from '../config' -import { buildNotEnoughBalanceNotification, buildResolveErrorNotification, notifySlack } from './slack' +import { + buildNotEnoughBalanceNotification, + buildResolveErrorNotification, + notifySlack +} from './slack' export enum WalletType { Challenger = 'challenger', @@ -87,15 +91,23 @@ export class TxWallet extends Wallet { denom ) - const key = `${this.key.accAddress}-${balance.amount}`; - if (balance.amount && parseInt(balance.amount) < config.SLACK_NOT_ENOUGH_BALANCE_THRESHOLD) { + const key = `${this.key.accAddress}-${balance.amount}` + if ( + balance.amount && + parseInt(balance.amount) < config.SLACK_NOT_ENOUGH_BALANCE_THRESHOLD + ) { await notifySlack( - key, buildNotEnoughBalanceNotification(this, parseInt(balance.amount), denom) + key, + buildNotEnoughBalanceNotification(this, parseInt(balance.amount), denom) ) } else { await notifySlack( - key, buildResolveErrorNotification(`Balance for ${this.key.accAddress} is restored.`), false - ); + key, + buildResolveErrorNotification( + `Balance for ${this.key.accAddress} is restored.` + ), + false + ) } } diff --git a/src/sawgger/batch_model.ts b/src/sawgger/batch_model.ts deleted file mode 100644 index 231766a..0000000 --- a/src/sawgger/batch_model.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { z } from 'koa-swagger-decorator' - -const L1DataPathsSchema = z.array( - z.object({ - index: z.number(), - txHash: z.string() - }) -) - -const L1BatchInfoSchema = z.object({ - type: z.literal('l1'), - dataPaths: L1DataPathsSchema -}) - -const CelestiaDataPathsSchema = z.array( - z.object({ - index: z.number(), - height: z.number(), - commitment: z.string() - }) -) - -const CelestiaBatchInfoSchema = z.object({ - type: z.literal('celestia'), - dataPaths: CelestiaDataPathsSchema -}) - -const BatchInfoStruct = z.union([L1BatchInfoSchema, CelestiaBatchInfoSchema]) - -const GetBatchResponse = z.object({ - bridge_id: z.number(), - batch_index: z.number(), - batch_info: BatchInfoStruct -}) - -export { GetBatchResponse } diff --git a/src/swagger/batch_model.ts b/src/swagger/batch_model.ts index e69de29..231766a 100644 --- a/src/swagger/batch_model.ts +++ b/src/swagger/batch_model.ts @@ -0,0 +1,36 @@ +import { z } from 'koa-swagger-decorator' + +const L1DataPathsSchema = z.array( + z.object({ + index: z.number(), + txHash: z.string() + }) +) + +const L1BatchInfoSchema = z.object({ + type: z.literal('l1'), + dataPaths: L1DataPathsSchema +}) + +const CelestiaDataPathsSchema = z.array( + z.object({ + index: z.number(), + height: z.number(), + commitment: z.string() + }) +) + +const CelestiaBatchInfoSchema = z.object({ + type: z.literal('celestia'), + dataPaths: CelestiaDataPathsSchema +}) + +const BatchInfoStruct = z.union([L1BatchInfoSchema, CelestiaBatchInfoSchema]) + +const GetBatchResponse = z.object({ + bridge_id: z.number(), + batch_index: z.number(), + batch_info: BatchInfoStruct +}) + +export { GetBatchResponse } diff --git a/src/worker/bridgeExecutor/Resurrector.ts b/src/worker/bridgeExecutor/Resurrector.ts index bcb0f82..6cd9aae 100644 --- a/src/worker/bridgeExecutor/Resurrector.ts +++ b/src/worker/bridgeExecutor/Resurrector.ts @@ -6,7 +6,11 @@ import { DataSource } from 'typeorm' import Bluebird from 'bluebird' import winston from 'winston' import { TxWallet, WalletType, getWallet, initWallet } from '../../lib/wallet' -import { buildFailedTxNotification, buildResolveErrorNotification, notifySlack } from '../../lib/slack' +import { + buildFailedTxNotification, + buildResolveErrorNotification, + notifySlack +} from '../../lib/slack' export class Resurrector { private db: DataSource @@ -35,7 +39,9 @@ export class Resurrector { ) } - async resubmitFailedDepositTx(unconfirmedTx: UnconfirmedTxEntity): Promise { + async resubmitFailedDepositTx( + unconfirmedTx: UnconfirmedTxEntity + ): Promise { const txKey = `${unconfirmedTx.sender}-${unconfirmedTx.receiver}-${unconfirmedTx.amount}` const msg = new MsgFinalizeTokenDeposit( this.executor.key.accAddress, @@ -50,7 +56,13 @@ export class Resurrector { try { await this.executor.transaction([msg]) await this.updateProcessed(unconfirmedTx) - await notifySlack(txKey, buildResolveErrorNotification(`[INFO] Transaction successfully resubmitted and processed for ${unconfirmedTx.sender} to ${unconfirmedTx.receiver} of amount ${unconfirmedTx.amount}.`), false) + await notifySlack( + txKey, + buildResolveErrorNotification( + `[INFO] Transaction successfully resubmitted and processed for ${unconfirmedTx.sender} to ${unconfirmedTx.receiver} of amount ${unconfirmedTx.amount}.` + ), + false + ) } catch (err) { if (this.errorCounter++ < 20) { await Bluebird.delay(5 * 1000) diff --git a/src/worker/challenger/challenger.ts b/src/worker/challenger/challenger.ts index b9f2a60..1a7c0fe 100644 --- a/src/worker/challenger/challenger.ts +++ b/src/worker/challenger/challenger.ts @@ -313,7 +313,10 @@ export class Challenger { await this.deleteOutputProposal(outputIndex) } - await notifySlack(`${outputIndex}-${this.bridgeId}`, buildChallengerNotification(challengedOutput)); - process.exit(); + await notifySlack( + `${outputIndex}-${this.bridgeId}`, + buildChallengerNotification(challengedOutput) + ) + process.exit() } }