Skip to content

Commit

Permalink
enabled mainnet tx caching
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanshparashar committed Feb 18, 2025
1 parent e1d6b99 commit 135c096
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/arb-token-bridge-ui/.env.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ NEXT_PUBLIC_RPC_URL_NITRO_TESTNODE_L1="http://127.0.0.1:8545"
NEXT_PUBLIC_RPC_URL_NITRO_TESTNODE_L2="http://127.0.0.1:8547"
NEXT_PUBLIC_RPC_URL_NITRO_TESTNODE_L3="http://127.0.0.1:3347"

# Optimization flags
NEXT_PUBLIC_PROVIDER_CACHE_TX_RECEIPTS=mainnet,testnet
NEXT_PUBLIC_PROVIDER_BATCH_RPC=testnet
NEXT_PUBLIC_PROVIDER_CACHE_EVENT_LOGS=testnet

# ----- Other -----

NEXT_PUBLIC_SENTRY_DSN=
Expand All @@ -62,3 +67,5 @@ SELF_HOSTED_SUBGRAPH_API_KEY=
NEXT_PUBLIC_SCREENING_API_ENDPOINT=

NEXT_PUBLIC_POSTHOG_KEY=


Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@ class WebStorage implements Storage {
}

const localStorageKey = `arbitrum:bridge:tx-receipts-cache`
const enableCaching = true
const enableCaching = (chainId: number) => {
if (
isNetwork(chainId).isTestnet &&
process.env.NEXT_PUBLIC_PROVIDER_CACHE_TX_RECEIPTS?.includes('testnet')
) {
return true
}

if (
!isNetwork(chainId).isTestnet &&
process.env.NEXT_PUBLIC_PROVIDER_CACHE_TX_RECEIPTS?.includes('mainnet')
) {
return true
}

return false
}

const getCacheKey = (chainId: number | string, txHash: string) =>
`${chainId}:${txHash}`.toLowerCase()
Expand Down Expand Up @@ -77,12 +93,7 @@ export const shouldCacheTxReceipt = (
chainId: number,
txReceipt: TransactionReceipt
): boolean => {
if (!enableCaching) return false

// for now, only enable caching for testnets,
if (!isNetwork(chainId).isTestnet) {
return false
}
if (!enableCaching(chainId)) return false

// Finality checks to avoid caching re-org'ed transactions
if (
Expand All @@ -101,7 +112,7 @@ function getTxReceiptFromCache(
chainId: number,
txHash: string
) {
if (!enableCaching) return undefined
if (!enableCaching(chainId)) return undefined

const cachedReceipts = JSON.parse(storage.getItem(localStorageKey) || '{}')
const receipt = cachedReceipts[getCacheKey(chainId, txHash)]
Expand Down

0 comments on commit 135c096

Please sign in to comment.