From 6d9594492e8a7d59c956eeff48512e743039f4c5 Mon Sep 17 00:00:00 2001 From: porco <88586592+porco-rosso-j@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:21:50 +0700 Subject: [PATCH] Batch getLogsByTags calls in syncTaggedLogs to prevent RPC limit errors Batch tags in #getPrivateLogsByTags to avoid exceeding MAX_RPC_LEN and flatten the results. --- .../pxe_oracle_interface.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/contract_function_simulator/pxe_oracle_interface.ts b/yarn-project/pxe/src/contract_function_simulator/pxe_oracle_interface.ts index d35d6c917c43..4830aa631b92 100644 --- a/yarn-project/pxe/src/contract_function_simulator/pxe_oracle_interface.ts +++ b/yarn-project/pxe/src/contract_function_simulator/pxe_oracle_interface.ts @@ -944,7 +944,22 @@ export class PXEOracleInterface implements ExecutionDataProvider { // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change. async #getPrivateLogsByTags(tags: Fr[]): Promise { - const allLogs = await this.aztecNode.getLogsByTags(tags); + // Batch tags to avoid exceeding MAX_RPC_LEN + const tagBatches = tags.reduce( + (acc, tag) => { + if (acc[acc.length - 1].length < MAX_RPC_LEN) { + acc[acc.length - 1].push(tag); + } else { + acc.push([tag]); + } + return acc; + }, + [[]] as Fr[][], + ); + + const allLogsBatched = await Promise.all(tagBatches.map(batch => this.aztecNode.getLogsByTags(batch))); + + const allLogs = allLogsBatched.flat(); return allLogs.map(logs => logs.filter(log => !log.isFromPublic)); }