From 676c083080f53723228205f13d64993976ec7386 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Mon, 16 Oct 2023 08:41:42 +0000 Subject: [PATCH] fix: report status of note processor catching up --- .../pxe/src/synchronizer/synchronizer.test.ts | 20 ++++++++++++++++--- .../pxe/src/synchronizer/synchronizer.ts | 7 ++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts index 29833507e2b..4e5505ffa78 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts @@ -1,7 +1,7 @@ import { CompleteAddress, Fr, GrumpkinScalar, HistoricBlockData } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { TestKeyStore } from '@aztec/key-store'; -import { AztecNode, INITIAL_L2_BLOCK_NUM, L2Block, MerkleTreeId } from '@aztec/types'; +import { AztecNode, L2Block, MerkleTreeId } from '@aztec/types'; import { MockProxy, mock } from 'jest-mock-extended'; import omit from 'lodash.omit'; @@ -99,7 +99,7 @@ describe('Synchronizer', () => { await synchronizer.work(); // Used in synchronizer.isAccountStateSynchronized - aztecNode.getBlockNumber.mockResolvedValueOnce(1); + aztecNode.getBlockNumber.mockResolvedValue(1); // Manually adding account to database so that we can call synchronizer.isAccountStateSynchronized const keyStore = new TestKeyStore(await Grumpkin.new()); @@ -109,11 +109,25 @@ describe('Synchronizer', () => { await database.addCompleteAddress(completeAddress); // Add the account which will add the note processor to the synchronizer - synchronizer.addAccount(completeAddress.publicKey, keyStore, INITIAL_L2_BLOCK_NUM); + synchronizer.addAccount(completeAddress.publicKey, keyStore, 1); + + expect(await synchronizer.isAccountStateSynchronized(completeAddress.address)).toBe(false); + expect(synchronizer.getSyncStatus()).toEqual({ + blocks: 1, + notes: { + [completeAddress.publicKey.toString()]: 0, + }, + }); await synchronizer.workNoteProcessorCatchUp(); expect(await synchronizer.isAccountStateSynchronized(completeAddress.address)).toBe(true); + expect(synchronizer.getSyncStatus()).toEqual({ + blocks: 1, + notes: { + [completeAddress.publicKey.toString()]: 1, + }, + }); }); }); diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index bc3ad8c03d6..e600d6628f3 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -288,7 +288,12 @@ export class Synchronizer { public getSyncStatus() { return { blocks: this.synchedToBlock, - notes: Object.fromEntries(this.noteProcessors.map(n => [n.publicKey.toString(), n.status.syncedToBlock])), + notes: Object.fromEntries( + [...this.noteProcessors, ...this.noteProcessorsToCatchUp].map(n => [ + n.publicKey.toString(), + n.status.syncedToBlock, + ]), + ), }; } }