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
4 changes: 4 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Aztec is in full-speed development. Literally every version breaks compatibility

## TBD

### [aztec.js] Dropping note filtration by `TxHash`
It's no longer possible to filter notes by `TxHash`.
The utility of this feature has been low and it made the code less efficient.

### [PXE] Concurrent contract function simulation disabled

PXE is no longer be able to execute contract functions concurrently (e.g. by collecting calls to `simulateTx` and then using `await Promise.all`). They will instead be put in a job queue and executed sequentially in order of arrival.
Expand Down
20 changes: 5 additions & 15 deletions yarn-project/cli/src/utils/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LogFn } from '@aztec/foundation/log';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { siloNullifier } from '@aztec/stdlib/hash';
import type { PXE } from '@aztec/stdlib/interfaces/client';
import { type ExtendedNote, NoteStatus } from '@aztec/stdlib/note';
import type { ExtendedNote } from '@aztec/stdlib/note';
import type { TxHash } from '@aztec/stdlib/tx';

export async function inspectBlock(pxe: PXE, blockNumber: number, log: LogFn, opts: { showTxs?: boolean } = {}) {
Expand Down Expand Up @@ -40,11 +40,7 @@ export async function inspectTx(
log: LogFn,
opts: { includeBlockInfo?: boolean; artifactMap?: ArtifactMap } = {},
) {
const [receipt, effectsInBlock, getNotes] = await Promise.all([
pxe.getTxReceipt(txHash),
pxe.getTxEffect(txHash),
pxe.getNotes({ txHash, status: NoteStatus.ACTIVE_OR_NULLIFIED }),
]);
const [receipt, effectsInBlock] = await Promise.all([pxe.getTxReceipt(txHash), pxe.getTxEffect(txHash)]);
// Base tx data
log(`Tx ${txHash.toString()}`);
log(` Status: ${receipt.status} ${effectsInBlock ? `(${effectsInBlock.data.revertCode.getDescription()})` : ''}`);
Expand Down Expand Up @@ -85,16 +81,10 @@ export async function inspectTx(
}

// Created notes
const notes = effects.noteHashes;
if (notes.length > 0) {
const noteHashes = effects.noteHashes;
if (noteHashes.length > 0) {
log(' Created notes:');
log(` Total: ${notes.length}. Found: ${getNotes.length}.`);
if (getNotes.length) {
log(' Found notes:');
for (const note of getNotes) {
inspectNote(note, artifactMap, log);
}
}
log(` Total: ${noteHashes.length}.`);
}

// Nullifiers
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/constants/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,4 @@ export enum GeneratorIndex {
SYMMETRIC_KEY_2 = 55,
PUBLIC_TX_HASH = 56,
PRIVATE_TX_HASH = 57,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,11 @@ describe('e2e_blacklist_token_contract mint', () => {

await t.addPendingShieldNoteToPXE(asset, wallets[0], amount, secretHash, txHash);

const receiptClaim = await asset.methods
.redeem_shield(wallets[0].getAddress(), amount, secret)
.send()
.wait({ debug: true });
await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait();

tokenSim.mintPrivate(wallets[0].getAddress(), amount);
// Trigger a note sync
await asset.methods.sync_notes().simulate();
// 1 note should have been created containing `amount` of tokens
const visibleNotes = await wallets[0].getNotes({ txHash: receiptClaim.txHash });
expect(visibleNotes.length).toBe(1);
expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount);
});
});

Expand Down
45 changes: 17 additions & 28 deletions yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,18 @@ describe('e2e_crowdfunding_and_claim', () => {

// 2) We donate to the crowdfunding contract
{
const donateTxReceipt = await crowdfundingContract
.withWallet(donorWallets[0])
.methods.donate(donationAmount)
.send()
.wait({
debug: true,
});
await crowdfundingContract.withWallet(donorWallets[0]).methods.donate(donationAmount).send().wait();

// Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the UintNote)
await crowdfundingContract.withWallet(donorWallets[0]).methods.sync_notes().simulate();
const notes = await donorWallets[0].getNotes({ txHash: donateTxReceipt.txHash });
const filteredNotes = notes.filter(x => x.contractAddress.equals(crowdfundingContract.address));
expect(filteredNotes!.length).toEqual(1);
const notes = await donorWallets[0].getNotes({
contractAddress: crowdfundingContract.address,
recipient: donorWallets[0].getAddress(),
});
expect(notes.length).toEqual(1);

// Set the UintNote in a format which can be passed to claim function
uintNote = processUniqueNote(filteredNotes![0]);
uintNote = processUniqueNote(notes[0]);
}

// 3) We claim the reward token via the Claim contract
Expand Down Expand Up @@ -234,22 +230,18 @@ describe('e2e_crowdfunding_and_claim', () => {
}

// 2) We donate to the crowdfunding contract
const donateTxReceipt = await crowdfundingContract
.withWallet(donorWallet)
.methods.donate(donationAmount)
.send()
.wait({
debug: true,
});
await crowdfundingContract.withWallet(donorWallet).methods.donate(donationAmount).send().wait();

// Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the UintNote)
// Get the latest note emitted by the Crowdfunding contract
await crowdfundingContract.withWallet(unrelatedWallet).methods.sync_notes().simulate();
const notes = await unrelatedWallet.getNotes({ txHash: donateTxReceipt.txHash });
const filtered = notes.filter(x => x.contractAddress.equals(crowdfundingContract.address));
expect(filtered!.length).toEqual(1);
const notes = await unrelatedWallet.getNotes({
contractAddress: crowdfundingContract.address,
recipient: donorWallet.getAddress(),
});
expect(notes.length).toEqual(1);

// Set the UintNote in a format which can be passed to claim function
const anotherDonationNote = processUniqueNote(filtered![0]);
const anotherDonationNote = processUniqueNote(notes[0]);

// 3) We try to claim the reward token via the Claim contract with the unrelated wallet
{
Expand Down Expand Up @@ -288,12 +280,9 @@ describe('e2e_crowdfunding_and_claim', () => {
const arbitraryStorageSlot = 69;
{
const [arbitraryValue, sender] = [5n, owner];
const receipt = await testContract.methods
.call_create_note(arbitraryValue, owner, sender, arbitraryStorageSlot)
.send()
.wait({ debug: true });
await testContract.methods.call_create_note(arbitraryValue, owner, sender, arbitraryStorageSlot).send().wait();
await testContract.methods.sync_notes().simulate();
const notes = await wallets[0].getNotes({ txHash: receipt.txHash });
const notes = await wallets[0].getNotes({ contractAddress: testContract.address });
expect(notes.length).toEqual(1);
note = processUniqueNote(notes[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,10 @@ describe('e2e_pending_note_hashes_contract', () => {
const sender = owner;
// Add a note of value 10, with a note log
// Then emit another note log with the same counter as the one above, but with value 5
const txReceipt = await deployedContract.methods.test_emit_bad_note_log(owner, sender).send().wait();
const txReceipt = await deployedContract.methods.test_emit_bad_note_log(owner, sender).send().wait({ debug: true });

await deployedContract.methods.sync_notes().simulate();

const notes = await wallet.getNotes({ txHash: txReceipt.txHash });

expect(notes.length).toBe(1);
expect(txReceipt.debugInfo?.noteHashes.length).toBe(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ export class PXEOracleInterface implements ExecutionDataProvider {
content: Fr[],
noteHash: Fr,
nullifier: Fr,
txHash: Fr,
txHash: Fr, // TODO (#12550): remove this parameter
recipient: AztecAddress,
): Promise<void> {
// We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
Expand Down Expand Up @@ -685,7 +685,6 @@ export class PXEOracleInterface implements ExecutionDataProvider {
nonce,
noteHash,
siloedNullifier,
new TxHash(txHash),
txReceipt.blockNumber!,
txReceipt.blockHash!.toString(),
uniqueNoteHashTreeIndex,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class PXEService implements PXE {
}
recipient = completeAddress.address;
}
return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.nonce);
return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.nonce);
});
return Promise.all(extendedNotes);
}
Expand Down
9 changes: 0 additions & 9 deletions yarn-project/pxe/src/storage/note_data_provider/note_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ export class NoteDao implements NoteData {
public siloedNullifier: Fr,

// Metadata
/** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g.
* when searching for txEffects.
*/
public txHash: TxHash,
/** The L2 block number in which the tx with this note was included. Used for note management while processing
* reorgs.*/
public l2BlockNumber: number,
Expand All @@ -66,7 +62,6 @@ export class NoteDao implements NoteData {
this.nonce,
this.noteHash,
this.siloedNullifier,
this.txHash,
this.l2BlockNumber,
Fr.fromHexString(this.l2BlockHash),
this.index,
Expand All @@ -83,7 +78,6 @@ export class NoteDao implements NoteData {
const nonce = Fr.fromBuffer(reader);
const noteHash = Fr.fromBuffer(reader);
const siloedNullifier = Fr.fromBuffer(reader);
const txHash = reader.readObject(TxHash);
const l2BlockNumber = reader.readNumber();
const l2BlockHash = Fr.fromBuffer(reader).toString();
const index = toBigIntBE(reader.readBytes(32));
Expand All @@ -96,7 +90,6 @@ export class NoteDao implements NoteData {
nonce,
noteHash,
siloedNullifier,
txHash,
l2BlockNumber,
l2BlockHash,
index,
Expand Down Expand Up @@ -130,7 +123,6 @@ export class NoteDao implements NoteData {
nonce = Fr.random(),
noteHash = Fr.random(),
siloedNullifier = Fr.random(),
txHash = TxHash.random(),
l2BlockNumber = Math.floor(Math.random() * 1000),
l2BlockHash = Fr.random().toString(),
index = Fr.random().toBigInt(),
Expand All @@ -143,7 +135,6 @@ export class NoteDao implements NoteData {
nonce,
noteHash,
siloedNullifier,
txHash,
l2BlockNumber,
l2BlockHash,
index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Fr } from '@aztec/foundation/fields';
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
import { randomTxHash } from '@aztec/stdlib/testing';

import times from 'lodash.times';

Expand Down Expand Up @@ -37,9 +36,6 @@ describe('NoteDataProvider', () => {
],
[() => Promise.resolve({ storageSlot: Fr.random() }), () => Promise.resolve([])],

[() => Promise.resolve({ txHash: notes[0].txHash }), () => Promise.resolve([notes[0]])],
[() => Promise.resolve({ txHash: randomTxHash() }), () => Promise.resolve([])],

[
() => Promise.resolve({ recipient: recipients[0] }),
() => Promise.resolve(notes.filter(note => note.recipient.equals(recipients[0]))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ export class NoteDataProvider implements DataProvider {
#nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
#nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
#nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
#nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
#nullifiedNotesByRecipient: AztecAsyncMultiMap<string, string>;
#nullifiedNotesByNullifier: AztecAsyncMap<string, string>;

#scopes: AztecAsyncMap<string, true>;
#notesToScope: AztecAsyncMultiMap<string, string>;
#notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
#notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
#notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
#notesByRecipientAndScope: Map<string, AztecAsyncMultiMap<string, string>>;

private constructor(store: AztecAsyncKVStore) {
Expand All @@ -41,15 +39,13 @@ export class NoteDataProvider implements DataProvider {
this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
this.#nullifiedNotesByRecipient = store.openMultiMap('nullified_notes_by_recipient');
this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');

this.#scopes = store.openMap('scopes');
this.#notesToScope = store.openMultiMap('notes_to_scope');
this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
this.#notesByRecipientAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
}

Expand All @@ -58,7 +54,6 @@ export class NoteDataProvider implements DataProvider {
for await (const scope of pxeDB.#scopes.keysAsync()) {
pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
pxeDB.#notesByRecipientAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_recipient`));
}
return pxeDB;
Expand All @@ -74,7 +69,6 @@ export class NoteDataProvider implements DataProvider {
await this.#scopes.set(scopeString, true);
this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
this.#notesByRecipientAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_recipient`));

return true;
Expand All @@ -98,7 +92,6 @@ export class NoteDataProvider implements DataProvider {

await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
}
});
Expand All @@ -117,7 +110,6 @@ export class NoteDataProvider implements DataProvider {
const scopes = await toArray(this.#scopes.keysAsync());
for (const scope of scopes) {
await this.#notesByRecipientAndScope.get(scope)!.deleteValue(noteDao.recipient.toString(), noteIndex);
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
}
Expand Down Expand Up @@ -159,7 +151,6 @@ export class NoteDataProvider implements DataProvider {
for (const scope of scopes) {
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
await this.#notesToScope.set(noteIndex, scope);
}
Expand All @@ -169,7 +160,6 @@ export class NoteDataProvider implements DataProvider {
await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
await this.#nullifiedNotesByRecipient.deleteValue(dao.recipient.toString(), noteIndex);
await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
}
Expand Down Expand Up @@ -198,10 +188,6 @@ export class NoteDataProvider implements DataProvider {
? await toArray(
this.#notesByRecipientAndScope.get(formattedScopeString)!.getValuesAsync(filter.recipient.toString()),
)
: filter.txHash
? await toArray(
this.#notesByTxHashAndScope.get(formattedScopeString)!.getValuesAsync(filter.txHash.toString()),
)
: filter.contractAddress
? await toArray(
this.#notesByContractAndScope
Expand All @@ -225,8 +211,6 @@ export class NoteDataProvider implements DataProvider {
candidateNoteSources.push({
ids: filter.recipient
? await toArray(this.#nullifiedNotesByRecipient.getValuesAsync(filter.recipient.toString()))
: filter.txHash
? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
: filter.contractAddress
? await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()))
: filter.storageSlot
Expand All @@ -249,10 +233,6 @@ export class NoteDataProvider implements DataProvider {
continue;
}

if (filter.txHash && !note.txHash.equals(filter.txHash)) {
continue;
}

if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) {
continue;
}
Expand Down Expand Up @@ -309,7 +289,6 @@ export class NoteDataProvider implements DataProvider {

for (const scope of scopes) {
await this.#notesByRecipientAndScope.get(scope)!.deleteValue(note.recipient.toString(), noteIndex);
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
}
Expand All @@ -323,7 +302,6 @@ export class NoteDataProvider implements DataProvider {
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
await this.#nullifiedNotesByRecipient.set(note.recipient.toString(), noteIndex);
await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);

Expand Down
Loading
Loading