Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 5, 2023
1 parent 09eabe0 commit 03e00d8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
5 changes: 4 additions & 1 deletion yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand Down
10 changes: 9 additions & 1 deletion yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<ExtendedUnencryptedL2Log[]> {
return this.pxe.getUnencryptedLogs({ txHash: await this.getTxHash() });
}

protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
const txHash = await this.getTxHash();
return await retryUntil(
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_public_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CompleteAddress,
EthAddress,
EthCheatCodes,
SentTx,
Wallet,
createAccounts,
createPXEClient,
Expand Down Expand Up @@ -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[]) => {
Expand Down
15 changes: 1 addition & 14 deletions yarn-project/types/src/logs/l2_logs_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -23,19 +23,6 @@ export interface L2LogsSource {
*/
getUnencryptedLogs(filter: LogFilter): Promise<ExtendedUnencryptedL2Log[]>;

/**
* 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<void>;

/**
* Stops the encrypted logs source.
* @returns A promise signalling completion of the stop process.
*/
stop(): Promise<void>;

/**
* Gets the number of the latest L2 block processed by the implementation.
* @returns The number of the latest L2 block processed by the implementation.
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/types/src/tx/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<ExtendedUnencryptedL2Log[]> {
return logsSource.getUnencryptedLogs({ txHash: await this.getTxHash() });
}

/**
* Convert a plain JSON object to a Tx class object.
* @param obj - A plain Tx JSON object.
Expand Down

0 comments on commit 03e00d8

Please sign in to comment.