Skip to content

Commit

Permalink
fix: remove retries from msgBroadcaster
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Nov 16, 2023
1 parent c6e4805 commit a60bc4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface MsgBroadcasterLocalOptions {
privateKey: string | PrivateKey /* hex or PrivateKey class */
ethereumChainId?: EthereumChainId
simulateTx?: boolean
increaseSequenceLocally?: boolean
}

/**
Expand All @@ -71,6 +72,8 @@ export class MsgBroadcasterLocal {

public simulateTx: boolean = false

public increaseSequenceLocally: boolean = false

public baseAccount: BaseAccount | undefined = undefined

public txCount: number = 0
Expand All @@ -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
Expand Down Expand Up @@ -302,7 +306,7 @@ export class MsgBroadcasterLocal {
}

private async getAccountDetails() {
if (this.baseAccount) {
if (this.baseAccount && this.increaseSequenceLocally) {
return this.baseAccount.toAccountDetails()
}

Expand All @@ -317,6 +321,8 @@ export class MsgBroadcasterLocal {
}

private async incrementTxCount() {
this.txCount += 1
if (this.increaseSequenceLocally) {
this.txCount += 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +53,6 @@ interface MsgBroadcasterWithPkOptions {
ethereumChainId?: EthereumChainId
simulateTx?: boolean
loggingEnabled?: boolean
retries?: Record<RetriesType, boolean>
}

/**
Expand All @@ -81,19 +76,12 @@ export class MsgBroadcasterWithPk {

public loggingEnabled: boolean = false

public retries: Record<RetriesType, boolean> = {
[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
Expand All @@ -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
*
Expand Down

0 comments on commit a60bc4e

Please sign in to comment.