Skip to content

Commit

Permalink
Remove additional logic from getTransactionV2
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed May 20, 2024
1 parent 2ac7a8d commit b1cf354
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.
6 changes: 0 additions & 6 deletions zp-relayer/pool/RelayPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { logger } from '@/lib/appLogger'
import { Network } from '@/lib/network'
import { redis } from '@/lib/redisClient'
import { JobState, PoolTx, poolTxQueue, WorkerTxType } from '@/queue/poolTxQueue'
import { TxStore } from '@/state/TxStore'
import { ENERGY_SIZE, MOCK_CALLDATA, PERMIT2_CONTRACT, TOKEN_SIZE, TRANSFER_INDEX_SIZE } from '@/utils/constants'
import {
applyDenominator,
Expand Down Expand Up @@ -50,13 +49,10 @@ export class RelayPool extends BasePool<Network> {
public permitRecover: PermitRecover | null = null
private proxyAddress!: string
private indexerUrl!: string
txStore!: TxStore

async init(permitConfig: PermitConfig, proxyAddress: string, indexerUrl: string) {
if (this.isInitialized) return

this.txStore = new TxStore('tmp-tx-store', redis)

this.proxyAddress = proxyAddress
this.indexerUrl = indexerUrl

Expand Down Expand Up @@ -256,8 +252,6 @@ export class RelayPool extends BasePool<Network> {
memo
)

await this.txStore.add(commitIndex, prefixedMemo)

if (nullifier) {
logger.debug('Adding nullifier %s to OS', nullifier)
await this.optimisticState.nullifiers.add([nullifier])
Expand Down
34 changes: 1 addition & 33 deletions zp-relayer/services/relayer/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,7 @@ async function getTransactionsV2(req: Request, res: Response, { pool }: PoolInje
throw new Error(`Failed to fetch transactions from indexer. Status: ${res.status}`)
}
const indexerTxs: string[] = await response.json()

const lastIndex = offset + indexerTxs.length * OUTPLUSONE
const txStore = (pool as RelayPool).txStore
const indices = await txStore.getAll().then(keys => {
return Object.entries(keys)
.map(([i, v]) => [parseInt(i), v] as [number, string])
.filter(([i]) => offset <= i && i <= lastIndex)
.sort(([i1], [i2]) => i1 - i2)
})

// TODO: optimize
const optimisticTxs = new Set<string>()
const duplicates = new Set<string>()
for (const tx of indexerTxs) {
const commit = tx.slice(65, 129)
for (const [index, memoV2] of indices) {
const commitLocal = memoV2.slice(0, 64)
if (commit === commitLocal) {
duplicates.add(index.toString())
} else {
optimisticTxs.add(memoV2)
}
}
}

for (const index of duplicates) {
logger.info('Deleting index from optimistic state', { index })
await txStore.remove(index.toString())
}

const txs: string[] = [...indexerTxs, ...Array.from(optimisticTxs.values()).map(tx => txToV2Format('0', tx))]

res.json(txs)
res.json(indexerTxs)
}

async function getJob(req: Request, res: Response, { pool }: PoolInjection) {
Expand Down
22 changes: 0 additions & 22 deletions zp-relayer/state/TxStore.ts

This file was deleted.

0 comments on commit b1cf354

Please sign in to comment.