@@ -8,27 +8,38 @@ import { SiloedTag } from './siloed_tag.js';
88import { 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+ */
1425export 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
95106async 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