Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions yarn-project/archiver/src/store/kv_archiver_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,24 @@ describe('KVArchiverDataStore', () => {
}
});

it('"tag" filter param is respected', async () => {
// Get a random tag from the logs
const targetBlockIndex = randomInt(numBlocksForPublicLogs);
const targetBlock = publishedCheckpoints[targetBlockIndex].checkpoint.blocks[0];
const targetTxIndex = randomInt(getTxsPerBlock(targetBlock));
const targetLogIndex = randomInt(getPublicLogsPerTx(targetBlock, targetTxIndex));
const targetTag = targetBlock.body.txEffects[targetTxIndex].publicLogs[targetLogIndex].fields[0];

const response = await store.getPublicLogs({ tag: targetTag });

expect(response.maxLogsHit).toBeFalsy();
expect(response.logs.length).toBeGreaterThan(0);

for (const extendedLog of response.logs) {
expect(extendedLog.log.fields[0].equals(targetTag)).toBeTruthy();
}
});

it('"afterLog" filter param is respected', async () => {
// Get a random log as reference
const targetBlockIndex = randomInt(numBlocksForPublicLogs);
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/archiver/src/store/log_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ export class LogStore {
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
for (; logIndex < txLogs.length; logIndex++) {
const log = txLogs[logIndex];
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
if (
(!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) &&
(!filter.tag || log.fields[0]?.equals(filter.tag))
) {
results.push(
new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log),
);
Expand Down
5 changes: 5 additions & 0 deletions yarn-project/stdlib/src/logs/log_filter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Fr } from '@aztec/foundation/curves/bn254';

import { z } from 'zod';

import type { AztecAddress } from '../aztec-address/index.js';
Expand All @@ -20,6 +22,8 @@ export type LogFilter = {
afterLog?: LogId;
/** The contract address to filter logs by. */
contractAddress?: AztecAddress;
/** The tag (first field of the log) to filter logs by. */
tag?: Fr;
};

export const LogFilterSchema: ZodFor<LogFilter> = z.object({
Expand All @@ -28,4 +32,5 @@ export const LogFilterSchema: ZodFor<LogFilter> = z.object({
toBlock: schemas.Integer.optional(),
afterLog: LogId.schema.optional(),
contractAddress: schemas.AztecAddress.optional(),
tag: schemas.Fr.optional(),
});
Loading