Skip to content

Commit a72fad4

Browse files
committed
feat: ExecutionTaggingIndexCache
1 parent cea4b30 commit a72fad4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2+
3+
/**
4+
* A map that stores the tagging index for a given sender and recipient pair.
5+
*/
6+
export class ExecutionTaggingIndexCache {
7+
private taggingIndexMap: Map<string, number> = new Map();
8+
9+
public getTaggingIndex(sender: AztecAddress, recipient: AztecAddress): number | undefined {
10+
return this.taggingIndexMap.get(`${sender}-${recipient}`);
11+
}
12+
13+
public setTaggingIndex(sender: AztecAddress, recipient: AztecAddress, index: number) {
14+
this.taggingIndexMap.set(`${sender}-${recipient}`, index);
15+
}
16+
}

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution_oracle.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828

2929
import type { ExecutionDataProvider } from '../execution_data_provider.js';
3030
import type { ExecutionNoteCache } from '../execution_note_cache.js';
31+
import { ExecutionTaggingIndexCache } from '../execution_tagging_index_cache.js';
3132
import type { HashedValuesCache } from '../hashed_values_cache.js';
3233
import { pickNotes } from '../pick_notes.js';
3334
import type { IPrivateExecutionOracle, NoteData } from './interfaces.js';
@@ -75,6 +76,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
7576
capsules: Capsule[],
7677
private readonly executionCache: HashedValuesCache,
7778
private readonly noteCache: ExecutionNoteCache,
79+
private readonly taggingIndexCache: ExecutionTaggingIndexCache,
7880
executionDataProvider: ExecutionDataProvider,
7981
private totalPublicCalldataCount: number = 0,
8082
protected sideEffectCounter: number = 0,
@@ -192,6 +194,11 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
192194
* @returns An app tag to be used in a log.
193195
*/
194196
public async privateGetNextAppTagAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<Fr> {
197+
// here we would check if we have the index in cache and if so, return it from there.
198+
// --> If not, we would call the executionDataProvider.getNextAppTagAsSender.
199+
200+
// What do I need to store in cache? Just { contractAddress-sender-recipient: index }
201+
195202
return await this.executionDataProvider.getNextAppTagAsSender(this.contractAddress, sender, recipient);
196203
}
197204

0 commit comments

Comments
 (0)