diff --git a/zp-relayer/pool/RelayPool.ts b/zp-relayer/pool/RelayPool.ts index 8ae4a3ce..76a7fd87 100644 --- a/zp-relayer/pool/RelayPool.ts +++ b/zp-relayer/pool/RelayPool.ts @@ -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, @@ -50,13 +49,10 @@ export class RelayPool extends BasePool { 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 @@ -256,8 +252,6 @@ export class RelayPool extends BasePool { memo ) - await this.txStore.add(commitIndex, prefixedMemo) - if (nullifier) { logger.debug('Adding nullifier %s to OS', nullifier) await this.optimisticState.nullifiers.add([nullifier]) diff --git a/zp-relayer/services/relayer/endpoints.ts b/zp-relayer/services/relayer/endpoints.ts index 45e4a097..2c89caef 100644 --- a/zp-relayer/services/relayer/endpoints.ts +++ b/zp-relayer/services/relayer/endpoints.ts @@ -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() - const duplicates = new Set() - 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) { diff --git a/zp-relayer/state/TxStore.ts b/zp-relayer/state/TxStore.ts deleted file mode 100644 index 67782925..00000000 --- a/zp-relayer/state/TxStore.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { Redis } from 'ioredis' - -export class TxStore { - constructor(public name: string, private redis: Redis) {} - - async add(index: number, memo: string) { - await this.redis.hset(this.name, { [index]: memo }) - } - - async remove(index: string) { - await this.redis.hdel(this.name, index) - } - - async get(index: string) { - const memo = await this.redis.hget(this.name, index) - return memo - } - - async getAll() { - return await this.redis.hgetall(this.name) - } -}