Skip to content

Commit

Permalink
[PAY-2576] Solana relay retries if initial send fails (#7910)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored Mar 27, 2024
1 parent 6e71ce2 commit ae77ce8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
1 change: 0 additions & 1 deletion .circleci/src/workflows/identity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
requires:
- push-identity-service


# Deploy audius-protocol `main` branch (stage)
- deploy-stage-nodes:
name: deploy-stage-identity-service
Expand Down
23 changes: 7 additions & 16 deletions packages/libs/src/services/solana/transactionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AddressLookupTableAccount,
VersionedTransaction
} from '@solana/web3.js'
import bs58 from 'bs58'

import type { Logger, Nullable } from '../../utils'
import type { IdentityService, RelayTransactionData } from '../identity'
Expand Down Expand Up @@ -214,6 +215,7 @@ export class TransactionHandler {
recentBlockhash ??
(await this.connection.getLatestBlockhash('confirmed')).blockhash
let rawTransaction: Buffer | Uint8Array
let txid: string

// Branch on whether to send a legacy or v0 transaction. Some duplicated code
// unfortunately due to type errors, eg `add` does not exist on VersionedTransaction.
Expand Down Expand Up @@ -252,6 +254,7 @@ export class TransactionHandler {
tx.addSignature(new PublicKey(publicKey), signature)
})
}
txid = bs58.encode(tx.signatures[0]!)
rawTransaction = tx.serialize()
} else {
// Otherwise send a legacy transaction
Expand All @@ -267,6 +270,7 @@ export class TransactionHandler {
tx.addSignature(new PublicKey(publicKey), signature)
})
}
txid = bs58.encode(tx.signatures[0]!.signature!)
rawTransaction = tx.serialize()
}

Expand All @@ -280,23 +284,11 @@ export class TransactionHandler {
})
}

let txid
try {
txid = await sendRawTransaction()
await sendRawTransaction()
} catch (e) {
// Rarely, this intiial send will fail
logger.error(`transactionHandler: Initial send failed: ${e}`)
let errorCode = null
let error = null
if (e instanceof Error) {
error = e.message
errorCode = this._parseSolanaErrorCode(error)
}
return {
res: null,
error,
errorCode
}
}

let done = false
Expand All @@ -305,16 +297,15 @@ export class TransactionHandler {
// to send the transaction until it hits a timeout.
let sendCount = 0
const startTime = Date.now()
let retryTxId
if (retry) {
;(async () => {
let elapsed = Date.now() - startTime
// eslint-disable-next-line no-unmodified-loop-condition
while (!done && elapsed < this.retryTimeoutMs) {
try {
retryTxId = sendRawTransaction()
sendRawTransaction()
logger.info(
`transactionHandler: retrying txId ${txid} with retryTxId ${retryTxId}, sendCount ${sendCount}`
`transactionHandler: retrying txId ${txid}, sendCount ${sendCount}`
)
} catch (e) {
logger.error(
Expand Down

0 comments on commit ae77ce8

Please sign in to comment.