Skip to content

Commit

Permalink
Fix logic for whether we're currently catching up (#698)
Browse files Browse the repository at this point in the history
* Fix logic for whether we're currently catching up

It's currently backwards.

* Tweak logic
  • Loading branch information
jessepinho authored Mar 7, 2024
1 parent 3754c70 commit 71e2c5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/router/src/grpc/view-protocol-server/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe('Status request handler', () => {
};

mockServices = {
getWalletServices: vi.fn(() => Promise.resolve({ indexedDb: mockIndexedDb })),
getWalletServices: vi.fn(() =>
Promise.resolve({ indexedDb: mockIndexedDb }),
) as MockServices['getWalletServices'],
querier: {
tendermint: mockTendermint,
},
Expand All @@ -51,15 +53,15 @@ describe('Status request handler', () => {
mockIndexedDb.getFullSyncHeight?.mockResolvedValue(222n);
mockTendermint.latestBlockHeight?.mockResolvedValue(222n);
const statusResponse = new StatusResponse(await status(new StatusRequest(), mockCtx));
expect(statusResponse.catchingUp).toBeTruthy();
expect(statusResponse.catchingUp).toBe(false);
expect(statusResponse.fullSyncHeight === 222n).toBeTruthy();
});

test('should receive status when view service synchronizes and lags behind last known block in tendermint', async () => {
mockIndexedDb.getFullSyncHeight?.mockResolvedValue(111n);
mockTendermint.latestBlockHeight?.mockResolvedValue(222n);
const statusResponse = new StatusResponse(await status(new StatusRequest(), mockCtx));
expect(statusResponse.catchingUp).toBeFalsy();
expect(statusResponse.catchingUp).toBe(true);
expect(statusResponse.partialSyncHeight === 111n).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/grpc/view-protocol-server/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const status: Impl['status'] = async (_, ctx) => {
if (!fullSyncHeight) throw new Error('Last block synced not in db');

return {
catchingUp: fullSyncHeight === latestBlockHeight,
catchingUp: fullSyncHeight < latestBlockHeight,
partialSyncHeight: fullSyncHeight,
fullSyncHeight: fullSyncHeight,
};
Expand Down

0 comments on commit 71e2c5d

Please sign in to comment.