diff --git a/zp-relayer/pool/RelayPool.ts b/zp-relayer/pool/RelayPool.ts index 8907b8c..ef5d53b 100644 --- a/zp-relayer/pool/RelayPool.ts +++ b/zp-relayer/pool/RelayPool.ts @@ -250,18 +250,12 @@ export class RelayPool extends BasePool { } async onSend({ outCommit, nullifier, memo, commitIndex }: ProcessResult, txHash: string): Promise { - const prefixedMemo = buildPrefixedMemo( - outCommit, - txHash, - memo - ) - - await this.txStore.add(commitIndex, prefixedMemo) - if (nullifier) { logger.debug('Adding nullifier %s to OS', nullifier) await this.optimisticState.nullifiers.add([nullifier]) } + + await this.cacheTxLocally(commitIndex, outCommit, txHash, memo); } async onConfirmed(res: ProcessResult, txHash: string, callback?: () => Promise, jobId?: string): Promise { @@ -274,10 +268,23 @@ export class RelayPool extends BasePool { poolJob.data.transaction.state = JobState.COMPLETED; poolJob.data.transaction.txHash = txHash; await poolJob.update(poolJob.data); + + await this.cacheTxLocally(res.commitIndex, res.outCommit, txHash, res.memo); } } } + protected async cacheTxLocally(index: number, commit: string, txHash: string, memo: string) { + // store or updating local tx store + // (we should keep sent transaction until the indexer grab them) + const prefixedMemo = buildPrefixedMemo( + commit, + txHash, + memo + ); + await this.txStore.add(index, prefixedMemo); + } + async getIndexerInfo() { const info = await fetchJson(this.indexerUrl, '/info', []) return info diff --git a/zp-relayer/services/relayer/endpoints.ts b/zp-relayer/services/relayer/endpoints.ts index 36ca754..6f6a650 100644 --- a/zp-relayer/services/relayer/endpoints.ts +++ b/zp-relayer/services/relayer/endpoints.ts @@ -187,6 +187,19 @@ async function relayerInfo(req: Request, res: Response, { pool }: PoolInjection) } const info = await response.json() + const indexerMaxIdx = Math.max(parseInt(info.deltaIndex ?? '0'), parseInt(info.optimisticDeltaIndex ?? '0')) + + const txStore = (pool as RelayPool).txStore + const pendingCnt = await txStore.getAll() + .then(keys => { + return Object.entries(keys) + .map(([i]) => parseInt(i) as number) + .filter(i => indexerMaxIdx <= i) + }) + .then(a => a.length); + + info.pendingDeltaIndex = indexerMaxIdx + pendingCnt * OUTPLUSONE; + res.json(info) }