Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort and slice db and pending notes. #1112

Merged
merged 2 commits into from
Jul 19, 2023
Merged

Sort and slice db and pending notes. #1112

merged 2 commits into from
Jul 19, 2023

Conversation

LeilaWang
Copy link
Collaborator

@LeilaWang LeilaWang commented Jul 19, 2023

Description

Closes #1030

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@LeilaWang LeilaWang requested a review from sirasistant July 19, 2023 11:39
Copy link
Collaborator

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Very nice work!

Comment on lines -10 to +22
* The format that noir contracts use to get notes.
* Information about a note needed during execution.
*/
export interface NoteLoadOracleInputs {
/**
* The nonce of the note.
*/
export interface NoteData {
/** The contract address of the note. */
contractAddress: AztecAddress;
/** The storage slot of the note. */
storageSlot: Fr;
/** The nonce of the note. */
nonce: Fr;
/**
* The preimage of the note.
*/
/** The preimage of the note */
preimage: Fr[];
/**
* The note's leaf index in the private data tree.
*/
index: bigint;
/** The note's leaf index in the private data tree. Undefined for pending notes. */
index?: bigint;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice cleanup merging these two structs

Comment on lines +117 to 120
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/920): don't 'get' notes nullified in pendingNullifiers
const pendingNotes = this.pendingNotes.filter(
n => n.contractAddress.equals(contractAddress) && n.storageSlot.equals(storageSlotField),
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean, nice.


import { SortOrder, pickNotes } from './pick_notes.js';

describe('getNotes', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests!

);

// TODO: Sort again.
const notes = [...pendingNotes, ...dbNotes].slice(offset, limit ? offset + limit : undefined);
const dbNotes = await this.db.getNotes(contractAddress, storageSlotField);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So will this just get ALL notes from the DB that match contractAddress & slot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we have to do that anyway :( Because the preimage is stored as a single field in the db. So we always need to get all notes matching the contractAddress and slot, to parse it, sort it, and slice it.

@LeilaWang LeilaWang merged commit 789ac03 into master Jul 19, 2023
@LeilaWang LeilaWang deleted the lw/get_notes branch July 19, 2023 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TS / Simulator] Enforce sorting/filtering for pendingNotes
2 participants