Skip to content

Commit 588cef2

Browse files
committed
wip
1 parent 4f3561f commit 588cef2

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

yarn-project/pxe/src/contract_function_simulator/execution_data_provider.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,7 @@ export interface ExecutionDataProvider {
227227
recipient: AztecAddress,
228228
): Promise<DirectionalAppTaggingSecret>;
229229

230-
/**
231-
* Updates the highest finalized tagging index and pending tagging indexes for a given secret.
232-
* @param secret - The secret that's unique for (sender, recipient, contract) tuple while the direction
233-
* of sender -> recipient matters.
234-
* @param contractAddress - The address of the contract that the logs are tagged for. Needs to be provided to store
235-
* because the function performs second round of siloing which is necessary because kernels do it as well (they silo
236-
* first field of the private log which corresponds to the tag).
237-
* @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the
238-
* highest pending and highest finalized indexes as that guides the next index choice when sending a log. The next
239-
* index choice is simply the highest pending index plus one (or finalized if pending is undefined).
240-
*/
230+
// docs available in sync_sender_tagging_indexes.ts
241231
syncTaggedLogsAsSender(secret: DirectionalAppTaggingSecret, contractAddress: AztecAddress): Promise<void>;
242232

243233
/**

yarn-project/pxe/src/pxe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import { PrivateEventDataProvider } from './storage/private_event_data_provider/
7878
import { SyncDataProvider } from './storage/sync_data_provider/sync_data_provider.js';
7979
import { TaggingDataProvider } from './storage/tagging_data_provider/tagging_data_provider.js';
8080
import { Synchronizer } from './synchronizer/index.js';
81-
import { WINDOW_SIZE as SENDER_TAGGING_INDEXES_SYNC_WINDOW_SIZE } from './tagging/sync_sender_tagging_indexes.js';
81+
import { WINDOW_LEN as SENDER_TAGGING_INDEXES_SYNC_WINDOW_LEN } from './tagging/sync_sender_tagging_indexes.js';
8282

8383
/**
8484
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
@@ -768,9 +768,9 @@ export class PXE {
768768
// the highest finalized index.
769769
for (const preTag of preTagsUsedInTheTx) {
770770
const finalizedIndex = (await this.taggingDataProvider.getHighestFinalizedIndex(preTag.secret)) ?? 0;
771-
if (preTag.index > finalizedIndex + SENDER_TAGGING_INDEXES_SYNC_WINDOW_SIZE) {
771+
if (preTag.index > finalizedIndex + SENDER_TAGGING_INDEXES_SYNC_WINDOW_LEN) {
772772
throw new Error(
773-
`Highest used index ${preTag.index} is further than window length from the highest finalized index ${finalizedIndex}. Tagging window length ${SENDER_TAGGING_INDEXES_SYNC_WINDOW_SIZE} is configured too low. Contact the Aztec team to increase it!`,
773+
`Highest used index ${preTag.index} is further than window length from the highest finalized index ${finalizedIndex}. Tagging window length ${SENDER_TAGGING_INDEXES_SYNC_WINDOW_LEN} is configured too low. Contact the Aztec team to increase it!`,
774774
);
775775
}
776776
}

yarn-project/pxe/src/tagging/sync_sender_tagging_indexes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { type MockProxy, mock } from 'jest-mock-extended';
99

1010
import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
1111
import { DirectionalAppTaggingSecret, SiloedTag, Tag } from './index.js';
12-
import { WINDOW_SIZE, syncSenderTaggingIndexes } from './sync_sender_tagging_indexes.js';
12+
import { WINDOW_LEN, syncSenderTaggingIndexes } from './sync_sender_tagging_indexes.js';
1313

1414
describe('syncSenderTaggingIndexes', () => {
1515
// Contract address and secret to be used on the input of the syncSenderTaggingIndexes function.
@@ -127,7 +127,7 @@ describe('syncSenderTaggingIndexes', () => {
127127
// Move finalized block into the future
128128
const newFinalizedBlockNumber = finalizedBlockNumberStep1 + 5;
129129
const newHighestFinalizedIndex = finalizedIndexStep1 + 4;
130-
const newHighestUsedIndex = newHighestFinalizedIndex + WINDOW_SIZE;
130+
const newHighestUsedIndex = newHighestFinalizedIndex + WINDOW_LEN;
131131

132132
// Create tx hashes for new logs
133133
const newHighestFinalizedTxHash = TxHash.random();

yarn-project/pxe/src/tagging/sync_sender_tagging_indexes.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,38 @@ import { SiloedTag } from './siloed_tag.js';
88
import { Tag } from './tag.js';
99

1010
// This window has to be larger than the largest expected number of logs emitted in a tx for a given directional app
11-
// tagging secret. If we get more logs than this window size, an error is thrown in `PXE::proveTx` function.
12-
export const WINDOW_SIZE = 30;
13-
11+
// tagging secret. If we get more logs than this window length, an error is thrown in `PXE::proveTx` function.
12+
export const WINDOW_LEN = 30;
13+
14+
/**
15+
* Syncs the highest finalized tagging index and pending tagging indexes for a given secret.
16+
* @param secret - The secret that's unique for (sender, recipient, contract) tuple while the direction of
17+
* sender -> recipient matters.
18+
* @param app - The address of the contract that the logs are tagged for. Needs to be provided because we perform
19+
* second round of siloing in this function which is necessary because kernels do it as well (they silo first field
20+
* of the private log which corresponds to the tag).
21+
* @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
22+
* pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
23+
* is simply the highest pending index plus one (or finalized if pending is undefined).
24+
*/
1425
export async function syncSenderTaggingIndexes(
1526
secret: DirectionalAppTaggingSecret,
16-
contractAddress: AztecAddress,
27+
app: AztecAddress,
1728
aztecNode: AztecNode,
1829
taggingDataProvider: TaggingDataProvider,
1930
): Promise<void> {
2031
const finalizedIndex = await taggingDataProvider.getHighestFinalizedIndex(secret);
2132

2233
let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
23-
let end = start + WINDOW_SIZE;
34+
let end = start + WINDOW_LEN;
2435

2536
let previousFinalizedIndex = finalizedIndex;
2637
let newFinalizedIndex = undefined;
2738

2839
while (true) {
2940
// Load and store indexes for the current window. These indexes may already exist in the database if txs using
3041
// them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
31-
await loadAndStoreNewTaggingIndexes(secret, contractAddress, start, end, aztecNode, taggingDataProvider);
42+
await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingDataProvider);
3243

3344
// We get all the indexes for a given window from the store.
3445
const pendingTxHashes = await taggingDataProvider.getTxHashesOfPendingIndexesForRangeForSecretAsSender(
@@ -83,7 +94,7 @@ export async function syncSenderTaggingIndexes(
8394
// New window: [21, 22, 23]
8495

8596
const previousEnd = end;
86-
end = newFinalizedIndex! + 1 + WINDOW_SIZE;
97+
end = newFinalizedIndex! + 1 + WINDOW_LEN;
8798
start = previousEnd;
8899
previousFinalizedIndex = newFinalizedIndex;
89100
} else {
@@ -94,7 +105,7 @@ export async function syncSenderTaggingIndexes(
94105

95106
async function loadAndStoreNewTaggingIndexes(
96107
secret: DirectionalAppTaggingSecret,
97-
contractAddress: AztecAddress,
108+
app: AztecAddress,
98109
start: number,
99110
end: number,
100111
aztecNode: AztecNode,
@@ -105,7 +116,7 @@ async function loadAndStoreNewTaggingIndexes(
105116
.fill(0)
106117
.map((_, i) => ({ secret, index: start + i }));
107118
const siloedTagsForWindow = await Promise.all(
108-
preTagsForWindow.map(async preTag => SiloedTag.compute(await Tag.compute(preTag), contractAddress)),
119+
preTagsForWindow.map(async preTag => SiloedTag.compute(await Tag.compute(preTag), app)),
109120
);
110121

111122
const possibleLogs = await getPrivateLogsByTags(siloedTagsForWindow, aztecNode);

0 commit comments

Comments
 (0)