From 03e00d86d4be57273eed46f6c1e0aa93b9bcaf03 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 5 Oct 2023 09:53:29 +0000 Subject: [PATCH] WIP --- .../archiver/src/archiver/archiver_store.ts | 5 ++++- yarn-project/aztec.js/src/contract/sent_tx.ts | 10 +++++++++- .../src/e2e_public_token_contract.test.ts | 4 ++-- yarn-project/end-to-end/src/fixtures/utils.ts | 15 ++++++++++++++- yarn-project/types/src/logs/l2_logs_source.ts | 15 +-------------- yarn-project/types/src/tx/tx.ts | 10 ++++++++++ 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index 255262f39f62..6493392edfd6 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -373,7 +373,10 @@ export class MemoryArchiverStore implements ArchiverDataStore { const txHash = filter.txHash; - const fromBlockIndex = (filter.fromBlock || INITIAL_L2_BLOCK_NUM) - INITIAL_L2_BLOCK_NUM; + const fromBlockIndex = filter.fromBlock === undefined ? 0 : filter.fromBlock - INITIAL_L2_BLOCK_NUM; + if (fromBlockIndex < 0) { + throw new Error(`"fromBlock" (${filter.fromBlock}) smaller than genesis block number (${INITIAL_L2_BLOCK_NUM}).`); + } if (fromBlockIndex > this.unencryptedLogs.length) { return Promise.resolve([]); } diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 9ab94c115e3a..f47953dc01c8 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -1,6 +1,6 @@ import { FieldsOf } from '@aztec/circuits.js'; import { retryUntil } from '@aztec/foundation/retry'; -import { PXE, TxHash, TxReceipt, TxStatus } from '@aztec/types'; +import { ExtendedUnencryptedL2Log, PXE, TxHash, TxReceipt, TxStatus } from '@aztec/types'; import every from 'lodash.every'; @@ -80,6 +80,14 @@ export class SentTx { return receipt.status === TxStatus.MINED; } + /** + * Gets unencrypted logs emitted by this tx. + * @returns The requested logs. + */ + public async getUnencryptedLogs(): Promise { + return this.pxe.getUnencryptedLogs({ txHash: await this.getTxHash() }); + } + protected async waitForReceipt(opts?: WaitOpts): Promise { const txHash = await this.getTxHash(); return await retryUntil( diff --git a/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts index 32b85181195f..2707988a2fc2 100644 --- a/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts @@ -5,7 +5,7 @@ import { CompleteAddress, PXE, TxStatus } from '@aztec/types'; import times from 'lodash.times'; -import { expectUnencryptedLogsFromLastBlockToBe, setup } from './fixtures/utils.js'; +import { expectUnencryptedLogsFromLastBlockToBe, expectUnencryptedLogsInTxToBe, setup } from './fixtures/utils.js'; describe('e2e_public_token_contract', () => { let pxe: PXE; @@ -52,7 +52,7 @@ describe('e2e_public_token_contract', () => { const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient }); expect(balance).toBe(mintAmount); - await expectUnencryptedLogsFromLastBlockToBe(pxe, ['Coins minted']); + await expectUnencryptedLogsInTxToBe(tx, ['Coins minted']); }, 45_000); // Regression for https://github.com/AztecProtocol/aztec-packages/issues/640 diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 2bb5cf220615..ef5d637cefa2 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -6,6 +6,7 @@ import { CompleteAddress, EthAddress, EthCheatCodes, + SentTx, Wallet, createAccounts, createPXEClient, @@ -526,7 +527,19 @@ export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async ( /** * Checks that the last block contains the given expected unencrypted log messages. - * @param pxe - The instance of PXE for retrieving the logs. + * @param tx - An instance of SentTx for which to retrieve the logs. + * @param logMessages - The set of expected log messages. + */ +export const expectUnencryptedLogsInTxToBe = async (tx: SentTx, logMessages: string[]) => { + const unencryptedLogs = await tx.getUnencryptedLogs(); + const asciiLogs = unencryptedLogs.map(extendedLog => extendedLog.log.data.toString('ascii')); + + expect(asciiLogs).toStrictEqual(logMessages); +}; + +/** + * Checks that the last block contains the given expected unencrypted log messages. + * @param pxe - An instance of PXE for retrieving the logs. * @param logMessages - The set of expected log messages. */ export const expectUnencryptedLogsFromLastBlockToBe = async (pxe: PXE, logMessages: string[]) => { diff --git a/yarn-project/types/src/logs/l2_logs_source.ts b/yarn-project/types/src/logs/l2_logs_source.ts index af318629cc65..4e606baad328 100644 --- a/yarn-project/types/src/logs/l2_logs_source.ts +++ b/yarn-project/types/src/logs/l2_logs_source.ts @@ -4,7 +4,7 @@ import { LogFilter } from './log_filter.js'; import { LogType } from './log_type.js'; /** - * Interface of classes allowing for the retrieval of encrypted logs. + * Interface of classes allowing for the retrieval of logs. */ export interface L2LogsSource { /** @@ -23,19 +23,6 @@ export interface L2LogsSource { */ getUnencryptedLogs(filter: LogFilter): Promise; - /** - * Starts the encrypted logs source. - * @param blockUntilSynced - If true, blocks until the data source has fully synced. - * @returns A promise signalling completion of the start process. - */ - start(blockUntilSynced: boolean): Promise; - - /** - * Stops the encrypted logs source. - * @returns A promise signalling completion of the stop process. - */ - stop(): Promise; - /** * Gets the number of the latest L2 block processed by the implementation. * @returns The number of the latest L2 block processed by the implementation. diff --git a/yarn-project/types/src/tx/tx.ts b/yarn-project/types/src/tx/tx.ts index 4486aa8b8aba..6fe4540a8ef4 100644 --- a/yarn-project/types/src/tx/tx.ts +++ b/yarn-project/types/src/tx/tx.ts @@ -10,6 +10,7 @@ import { arrayNonEmptyLength } from '@aztec/foundation/collection'; import { BufferReader, Tuple } from '@aztec/foundation/serialize'; import { ExtendedContractData } from '../contract_data.js'; +import { ExtendedUnencryptedL2Log, L2LogsSource } from '../index.js'; import { TxL2Logs } from '../logs/tx_l2_logs.js'; import { TxHash } from './tx_hash.js'; @@ -112,6 +113,15 @@ export class Tx { }; } + /** + * Gets unencrypted logs emitted by this tx. + * @param logsSource - An instance of L2LogsSource which can be used to obtain the logs. + * @returns The requested logs. + */ + public async getUnencryptedLogs(logsSource: L2LogsSource): Promise { + return logsSource.getUnencryptedLogs({ txHash: await this.getTxHash() }); + } + /** * Convert a plain JSON object to a Tx class object. * @param obj - A plain Tx JSON object.