Skip to content

Commit

Permalink
Set proper index for local transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenKor committed Aug 29, 2024
1 parent 49b64ab commit b552ece
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions zp-relayer/pool/RelayPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ export class RelayPool extends BasePool<Network> {
const calldata = data.join('')

const memoTruncated = truncateMemoTxPrefixProverV2(memo, txType)
// TODO: we call indexer twice (during validation and tx build)
const indexerInfo = await this.getIndexerInfo()

// Commit index should be treated as an optimistic checkpoint
// It can increase after the transaction is included into the Merkle tree
const commitIndex = await this.assumeNextPendingTxIndex();

return {
data: calldata,
func,
outCommit,
nullifier,
memo: memoTruncated,
// Commit index should be treated as an optimistic checkpoint
// It can increase after the transaction is included
commitIndex: indexerInfo.optimisticDeltaIndex,
commitIndex,
}
}

Expand Down Expand Up @@ -311,6 +311,7 @@ export class RelayPool extends BasePool<Network> {
return info
}

// It's just an assumption needed for internal purposes. The final index may be changed
private async assumeNextPendingTxIndex() {
const [indexerInfo, localCache] = await Promise.all([this.getIndexerInfo(), this.txStore.getAll()]);

Expand Down

0 comments on commit b552ece

Please sign in to comment.