Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Aug 5, 2024
1 parent 760af5d commit f481967
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
4 changes: 3 additions & 1 deletion yarn-project/pxe/src/note_processor/note_processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ describe('Note Processor', () => {
}),
],
[],
account.address,
);
}, 25_000);

Expand All @@ -211,7 +212,7 @@ describe('Note Processor', () => {

expect(addNotesSpy).toHaveBeenCalledTimes(1);
// For outgoing notes, the resulting DAO does not contain index.
expect(addNotesSpy).toHaveBeenCalledWith([], [expect.objectContaining(request.note.payload)]);
expect(addNotesSpy).toHaveBeenCalledWith([], [expect.objectContaining(request.note.payload)], account.address);
}, 25_000);

it('should store multiple notes that belong to us', async () => {
Expand Down Expand Up @@ -249,6 +250,7 @@ describe('Note Processor', () => {
expect.objectContaining(requests[1].note.payload),
expect.objectContaining(requests[4].note.payload),
],
account.address,
);
}, 30_000);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class NoteProcessor {
const incomingNotes = blocksAndNotes.flatMap(b => b.incomingNotes);
const outgoingNotes = blocksAndNotes.flatMap(b => b.outgoingNotes);
if (incomingNotes.length || outgoingNotes.length) {
await this.db.addNotes(incomingNotes, outgoingNotes);
await this.db.addNotes(incomingNotes, outgoingNotes, this.account);
incomingNotes.forEach(noteDao => {
this.log.verbose(
`Added incoming note for contract ${noteDao.contractAddress} at slot ${
Expand Down
36 changes: 18 additions & 18 deletions yarn-project/pxe/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { type KeyStore } from '@aztec/key-store';
import { type DeferredNoteDao } from '../database/deferred_note_dao.js';
import { type IncomingNoteDao } from '../database/incoming_note_dao.js';
import { type PxeDatabase } from '../database/index.js';
import { type OutgoingNoteDao } from '../database/outgoing_note_dao.js';
import { NoteProcessor } from '../note_processor/index.js';

/**
Expand Down Expand Up @@ -334,35 +333,36 @@ export class Synchronizer {

// keep track of decoded notes
const incomingNotes: IncomingNoteDao[] = [];
const outgoingNotes: OutgoingNoteDao[] = [];

// now process each txHash
for (const deferredNotes of txHashToDeferredNotes.values()) {
// to be safe, try each note processor in case the deferred notes are for different accounts.
for (const processor of this.noteProcessors) {
const { incomingNotes: inNotes, outgoingNotes: outNotes } = await processor.decodeDeferredNotes(deferredNotes);
incomingNotes.push(...inNotes);
outgoingNotes.push(...outNotes);

await this.db.addNotes(inNotes, outNotes, processor.account);

inNotes.forEach(noteDao => {
this.log.debug(
`Decoded deferred incoming note under account ${processor.account.toString()} for contract ${
noteDao.contractAddress
} at slot ${noteDao.storageSlot} with nullifier ${noteDao.siloedNullifier.toString()}`,
);
});

outNotes.forEach(noteDao => {
this.log.debug(
`Decoded deferred outgoing note under account ${processor.account.toString()} for contract ${
noteDao.contractAddress
} at slot ${noteDao.storageSlot}`,
);
});
}
}

// now drop the deferred notes, and add the decoded notes
await this.db.removeDeferredNotesByContract(contractAddress);
await this.db.addNotes(incomingNotes, outgoingNotes);

incomingNotes.forEach(noteDao => {
this.log.debug(
`Decoded deferred incoming note for contract ${noteDao.contractAddress} at slot ${
noteDao.storageSlot
} with nullifier ${noteDao.siloedNullifier.toString()}`,
);
});

outgoingNotes.forEach(noteDao => {
this.log.debug(
`Decoded deferred outgoing note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`,
);
});

await this.#removeNullifiedNotes(incomingNotes);
}
Expand Down

0 comments on commit f481967

Please sign in to comment.