Skip to content

Commit

Permalink
Updating txHash in cached txs, introducing pendingDeltaIndex field in…
Browse files Browse the repository at this point in the history
… /info endpoint
  • Loading branch information
EvgenKor committed May 27, 2024
1 parent e4581aa commit 179dc44
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
23 changes: 15 additions & 8 deletions zp-relayer/pool/RelayPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,12 @@ export class RelayPool extends BasePool<Network> {
}

async onSend({ outCommit, nullifier, memo, commitIndex }: ProcessResult<RelayPool>, txHash: string): Promise<void> {
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<RelayPool>, txHash: string, callback?: () => Promise<void>, jobId?: string): Promise<void> {
Expand All @@ -274,10 +268,23 @@ export class RelayPool extends BasePool<Network> {
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
Expand Down
13 changes: 13 additions & 0 deletions zp-relayer/services/relayer/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 179dc44

Please sign in to comment.