Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use confirmed commit level for logsSubscribe #1065

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/coinstacks/common/api/src/evm/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { ERC1155_ABI } from './abi/erc1155'
import { ERC721_ABI } from './abi/erc721'

const axiosNoRetry = axios.create({ timeout: 5000 })
const axiosWithRetry = createAxiosRetry({ timeout: 10000 })
const axiosWithRetry = createAxiosRetry({}, { timeout: 10000 })

type InternalTxFetchMethod = 'trace_transaction' | 'debug_traceTransaction'

Expand Down
11 changes: 8 additions & 3 deletions node/coinstacks/common/api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ export const handleError = (err: unknown): ApiError => {
return new ApiError('Internal Server Error', 500, 'unknown error')
}

export const createAxiosRetry = (axiosParams?: CreateAxiosDefaults) => {
type RetryConfig = {
retries?: number
delayFactor?: number
}

export const createAxiosRetry = (config: RetryConfig, axiosParams?: CreateAxiosDefaults) => {
const axiosWithRetry = axios.create(axiosParams)

axiosRetry(axiosWithRetry, {
shouldResetTimeout: true,
retries: 5,
retries: config.retries ?? 5,
retryDelay: (retryCount, err) => {
// don't add delay on top of request timeout
if (err.code === 'ECONNABORTED') return 0
// add exponential delay for network errors
return axiosRetry.exponentialDelay(retryCount, undefined, 500)
return axiosRetry.exponentialDelay(retryCount, undefined, config.delayFactor ?? 500)
},
retryCondition: (err) =>
isNetworkOrIdempotentRequestError(err) ||
Expand Down
9 changes: 8 additions & 1 deletion node/coinstacks/solana/api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ if (!INDEXER_URL) throw new Error('INDEXER_URL env var not set')
if (!RPC_API_KEY) throw new Error('RPC_API_KEY env var not set')

export const axiosNoRetry = axios.create({ timeout: 5000, params: { 'api-key': RPC_API_KEY } })
export const axiosWithRetry = createAxiosRetry({ timeout: 10000, params: { 'api-key': RPC_API_KEY } })

// Amounts to ~1 minutes worth of potential retries to account for logsSubscribe "confirmed" commit level
// and /transactions only returning "finalized" transactions. The "confirmed" commit level is required for logsSubscribe
// because "finalized" commit level is not stable and misses logs frequently.
export const axiosWithRetry = createAxiosRetry(
{ retries: 6, delayFactor: 1000 },
{ timeout: 10000, params: { 'api-key': RPC_API_KEY } }
)

export const getTransaction = async (txid: string, shouldRetry?: boolean, retryCount = 0): Promise<Tx> => {
try {
Expand Down
2 changes: 1 addition & 1 deletion node/coinstacks/solana/api/src/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class WebsocketClient extends BaseWebsocketClient {
jsonrpc: '2.0',
id: this.currentId.toString(),
method: 'logsSubscribe',
params: [{ mentions: [address] }],
params: [{ mentions: [address] }, { commitment: 'confirmed' }],
}

try {
Expand Down