Skip to content

Commit e8de31f

Browse files
committed
refactor!: splitting getLogsByTags to private and public versions
Fixes #14555 ## New PR Description As mentioned in the old PR description I originally planned to just type the arg of `getLogsByTags` but while addressing this PR's feedback I realized that I made a mistake: the `getLogsByTags` endpoint was used for both private and public logs and the issue is that for public logs we use "unsiloed" tag and for private logs we use siloed tag. Having these 2 endpoints merged was just a tech debt: there is not a place where we would call this endpoint expecting only 1 type of logs. This led to us having ugly utilities that filtered out one kind of logs after retrieval. We didn't split this before because we didn't want to introduce a breaking change to the API. Given that I am already breaking backwards compatibility and given the error I made it made sense to fix this by splitting the two endpoints. Now we have `getPrivateLogsByTag` and `getPublicLogsByTagsFromContract` endpoints. ## Old PR Description In this PR I used the `SiloedTag` type for the param in `getLogsByTags`. This allowed me to drop some ugly type conversions. This was just a tech debt. The diff turned out to be quite large because I needed to move the type from `pxe` to `stdlib`. As mentioned in a PR down the stack this is second of 3 PRs in which I clean up the `getLogsByTags` endpoint: 1. First PR - including block timestamp in return value, 2. This is the second PR - I type the tag arg of the function to be `SiloedTag`, 3. in the last PR I will drop pagination from this endpoint. Co-authored-by: Jan Beneš <[email protected]>
1 parent e007e7b commit e8de31f

33 files changed

+727
-410
lines changed

yarn-project/archiver/src/archiver/archiver.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ import {
6464
} from '@aztec/stdlib/epoch-helpers';
6565
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
6666
import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
67-
import { ContractClassLog, type LogFilter, type PrivateLog, type PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
67+
import {
68+
ContractClassLog,
69+
type LogFilter,
70+
type PrivateLog,
71+
type PublicLog,
72+
type SiloedTag,
73+
Tag,
74+
TxScopedL2Log,
75+
} from '@aztec/stdlib/logs';
6876
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
6977
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
7078
import { type BlockHeader, type IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
@@ -1407,14 +1415,16 @@ export class Archiver
14071415
return this.store.getSettledTxReceipt(txHash);
14081416
}
14091417

1410-
/**
1411-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
1412-
* @param tags - The tags to filter the logs by.
1413-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
1414-
* that tag.
1415-
*/
1416-
getLogsByTags(tags: Fr[]): Promise<TxScopedL2Log[][]> {
1417-
return this.store.getLogsByTags(tags);
1418+
getPrivateLogsByTags(tags: SiloedTag[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
1419+
return this.store.getPrivateLogsByTags(tags, logsPerTag);
1420+
}
1421+
1422+
getPublicLogsByTagsFromContract(
1423+
contractAddress: AztecAddress,
1424+
tags: Tag[],
1425+
logsPerTag?: number,
1426+
): Promise<TxScopedL2Log[][]> {
1427+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, logsPerTag);
14181428
}
14191429

14201430
/**
@@ -2072,8 +2082,15 @@ export class ArchiverStoreHelper
20722082
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
20732083
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
20742084
}
2075-
getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
2076-
return this.store.getLogsByTags(tags, logsPerTag);
2085+
getPrivateLogsByTags(tags: SiloedTag[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
2086+
return this.store.getPrivateLogsByTags(tags, logsPerTag);
2087+
}
2088+
getPublicLogsByTagsFromContract(
2089+
contractAddress: AztecAddress,
2090+
tags: Tag[],
2091+
logsPerTag?: number,
2092+
): Promise<TxScopedL2Log[][]> {
2093+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, logsPerTag);
20772094
}
20782095
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
20792096
return this.store.getPublicLogs(filter);

yarn-project/archiver/src/archiver/archiver_store.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
UtilityFunctionWithMembershipProof,
1515
} from '@aztec/stdlib/contract';
1616
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
17-
import type { LogFilter, TxScopedL2Log } from '@aztec/stdlib/logs';
17+
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
1818
import { BlockHeader, type IndexedTxEffect, type TxHash, type TxReceipt } from '@aztec/stdlib/tx';
1919
import type { UInt64 } from '@aztec/stdlib/types';
2020

@@ -206,13 +206,27 @@ export interface ArchiverDataStore {
206206
getTotalL1ToL2MessageCount(): Promise<bigint>;
207207

208208
/**
209-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
210-
* @param tags - The tags to filter the logs by.
209+
* Gets all private logs that match any of the received tags (i.e. logs with their first field equal to a SiloedTag).
210+
* @param tags - The SiloedTags to filter the logs by.
211211
* @param logsPerTag - The number of logs to return per tag. Defaults to everything
212-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
212+
* @returns For each received tag, an array of matching private logs is returned. An empty array implies no logs match
213213
* that tag.
214214
*/
215-
getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]>;
215+
getPrivateLogsByTags(tags: SiloedTag[], logsPerTag?: number): Promise<TxScopedL2Log[][]>;
216+
217+
/**
218+
* Gets all public logs that match any of the received tags from the specified contract (i.e. logs with their first field equal to a Tag).
219+
* @param contractAddress - The contract that emitted the public logs.
220+
* @param tags - The Tags to filter the logs by.
221+
* @param logsPerTag - The number of logs to return per tag. Defaults to everything
222+
* @returns For each received tag, an array of matching public logs is returned. An empty array implies no logs match
223+
* that tag.
224+
*/
225+
getPublicLogsByTagsFromContract(
226+
contractAddress: AztecAddress,
227+
tags: Tag[],
228+
logsPerTag?: number,
229+
): Promise<TxScopedL2Log[][]>;
216230

217231
/**
218232
* Gets public logs based on the provided filter.

0 commit comments

Comments
 (0)