Skip to content

Commit c2ad4b1

Browse files
authored
refactor(pxe): batch tagged private log queries across all secrets (#23048)
1 parent 315cd1e commit c2ad4b1

10 files changed

Lines changed: 530 additions & 615 deletions

yarn-project/pxe/src/contract_function_simulator/oracle/private_execution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe('Private Execution test suite', () => {
325325
// on the input.
326326
aztecNode.getPrivateLogsByTags.mockImplementation((tags: SiloedTag[]) => Promise.resolve(tags.map(() => [])));
327327

328-
// Mock getL2Tips and getBlockHeader for loadPrivateLogsForSenderRecipientPair
328+
// Mock getL2Tips and getBlockHeader for syncTaggedPrivateLogs
329329
l2TipsStore.getL2Tips.mockResolvedValue(makeL2Tips(anchorBlockHeader.globalVariables.blockNumber));
330330

331331
// TODO: refactor. Maybe it's worth stubbing a key store

yarn-project/pxe/src/logs/log_service.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { SenderAddressBookStore } from '../storage/tagging_store/sender_add
1414
import {
1515
getAllPrivateLogsByTags,
1616
getAllPublicLogsByTagsFromContract,
17-
loadPrivateLogsForSenderRecipientPair,
17+
syncTaggedPrivateLogs,
1818
} from '../tagging/index.js';
1919

2020
export class LogService {
@@ -116,37 +116,23 @@ export class LogService {
116116
public async fetchTaggedLogs(contractAddress: AztecAddress, recipient: AztecAddress): Promise<PendingTaggedLog[]> {
117117
this.log.verbose(`Fetching tagged logs for ${contractAddress.toString()}`);
118118

119-
// We only load logs from block up to and including the anchor block number
120-
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
121-
const anchorBlockHash = await this.anchorBlockHeader.hash();
122-
123119
const l2Tips = await this.l2TipsStore.getL2Tips();
124-
const currentTimestamp = this.anchorBlockHeader.globalVariables.timestamp;
125120
// Get all secrets for this recipient (one per sender)
126121
const secrets = await this.#getSecretsForSenders(contractAddress, recipient);
127122

128-
// Load logs for all sender-recipient pairs in parallel
129-
const logArrays = await Promise.all(
130-
secrets.map(secret =>
131-
loadPrivateLogsForSenderRecipientPair(
132-
secret,
133-
this.aztecNode,
134-
this.recipientTaggingStore,
135-
anchorBlockNumber,
136-
anchorBlockHash,
137-
currentTimestamp,
138-
l2Tips.finalized.block.number,
139-
this.jobId,
140-
),
141-
),
123+
const logs = await syncTaggedPrivateLogs(
124+
secrets,
125+
this.aztecNode,
126+
this.recipientTaggingStore,
127+
this.anchorBlockHeader,
128+
l2Tips.finalized.block.number,
129+
this.jobId,
142130
);
143131

144-
return logArrays
145-
.flat()
146-
.map(
147-
scopedLog =>
148-
new PendingTaggedLog(scopedLog.logData, scopedLog.txHash, scopedLog.noteHashes, scopedLog.firstNullifier),
149-
);
132+
return logs.map(
133+
scopedLog =>
134+
new PendingTaggedLog(scopedLog.logData, scopedLog.txHash, scopedLog.noteHashes, scopedLog.firstNullifier),
135+
);
150136
}
151137

152138
async #getSecretsForSenders(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ async function getAllPagesInBatches<Tag, T>(
3939
tags: Tag[],
4040
fetchAllPagesForBatch: (batch: Tag[]) => Promise<T[][]>,
4141
): Promise<T[][]> {
42+
if (tags.length === 0) {
43+
return [];
44+
}
45+
4246
if (tags.length <= MAX_RPC_LEN) {
4347
return fetchAllPagesForBatch(tags);
4448
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* The objective of the sender sync algorithm is to determine which tags have already been used by a sender, thereby
55
* deciding which tag should be used next.
66
*
7-
* The objective of the recipient sync algorithm is to load and process the corresponding logs.
7+
* The objective of the recipient sync algorithm is to fetch and sync the corresponding logs.
88
*
99
* @module tagging
1010
*/
1111

12-
export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
12+
export { syncTaggedPrivateLogs } from './recipient_sync/sync_tagged_private_logs.js';
1313
export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
1414
export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
1515
export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';

yarn-project/pxe/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.test.ts

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)