From a60bc4eefc30c8e460e748c5e38bb97e8315c45e Mon Sep 17 00:00:00 2001 From: Bojan Angjelkoski Date: Thu, 16 Nov 2023 15:47:10 +0100 Subject: [PATCH] fix: remove retries from msgBroadcaster --- .../tx/broadcaster/MsgBroadcasterLocal.ts | 10 +++- .../tx/broadcaster/MsgBroadcasterWithPk.ts | 47 ------------------- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterLocal.ts b/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterLocal.ts index cc737cf3a..edcf5d9b5 100644 --- a/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterLocal.ts +++ b/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterLocal.ts @@ -50,6 +50,7 @@ interface MsgBroadcasterLocalOptions { privateKey: string | PrivateKey /* hex or PrivateKey class */ ethereumChainId?: EthereumChainId simulateTx?: boolean + increaseSequenceLocally?: boolean } /** @@ -71,6 +72,8 @@ export class MsgBroadcasterLocal { public simulateTx: boolean = false + public increaseSequenceLocally: boolean = false + public baseAccount: BaseAccount | undefined = undefined public txCount: number = 0 @@ -80,6 +83,7 @@ export class MsgBroadcasterLocal { const endpoints = getNetworkEndpoints(options.network) this.simulateTx = options.simulateTx || false + this.increaseSequenceLocally = options.increaseSequenceLocally || false this.chainId = networkInfo.chainId this.ethereumChainId = options.ethereumChainId || networkInfo.ethereumChainId @@ -302,7 +306,7 @@ export class MsgBroadcasterLocal { } private async getAccountDetails() { - if (this.baseAccount) { + if (this.baseAccount && this.increaseSequenceLocally) { return this.baseAccount.toAccountDetails() } @@ -317,6 +321,8 @@ export class MsgBroadcasterLocal { } private async incrementTxCount() { - this.txCount += 1 + if (this.increaseSequenceLocally) { + this.txCount += 1 + } } } diff --git a/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterWithPk.ts b/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterWithPk.ts index bae72e134..31af1944a 100644 --- a/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterWithPk.ts +++ b/packages/sdk-ts/src/core/modules/tx/broadcaster/MsgBroadcasterWithPk.ts @@ -26,10 +26,6 @@ import { IndexerGrpcTransactionApi } from '../../../../client' import { AccountDetails } from '../../../../types/auth' import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts' -export enum RetriesType { - Sequence = 'sequence', -} - interface MsgBroadcasterTxOptions { msgs: Msgs | Msgs[] memo?: string @@ -57,7 +53,6 @@ interface MsgBroadcasterWithPkOptions { ethereumChainId?: EthereumChainId simulateTx?: boolean loggingEnabled?: boolean - retries?: Record } /** @@ -81,19 +76,12 @@ export class MsgBroadcasterWithPk { public loggingEnabled: boolean = false - public retries: Record = { - [RetriesType.Sequence]: false, - } - constructor(options: MsgBroadcasterWithPkOptions) { const networkInfo = getNetworkInfo(options.network) const endpoints = getNetworkEndpoints(options.network) this.simulateTx = options.simulateTx || false this.loggingEnabled = options.loggingEnabled || false - this.retries = options.retries || { - [RetriesType.Sequence]: false, - } this.chainId = networkInfo.chainId this.ethereumChainId = options.ethereumChainId || networkInfo.ethereumChainId @@ -116,41 +104,6 @@ export class MsgBroadcasterWithPk { return await this.broadcastTxRaw(txRaw) } - /** - * Broadcasting the transaction using the client - * - * @param tx - * @returns {string} transaction hash - */ - async broadcastWithRetry(transaction: MsgBroadcasterTxOptions) { - const { retries } = this - const { txRaw, accountDetails } = await this.prepareTxForBroadcast( - transaction, - ) - - try { - const txResponse = await this.broadcastTxRaw(txRaw) - - return txResponse - } catch (e: unknown) { - if (e instanceof GeneralException) { - /** If the transaction fails because of sequence error, retry with higher sequence number */ - if (e.message.includes('sequence') && retries.sequence) { - const { txRaw } = await this.prepareTxForBroadcast(transaction, { - ...accountDetails, - sequence: accountDetails.sequence + 1, - }) - - const txResponse = await this.broadcastTxRaw(txRaw) - - return txResponse - } - } - - throw e - } - } - /** * Broadcasting the transaction with fee delegation services *