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

Fix logic for whether we're currently catching up #698

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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'],
Comment on lines +31 to +33
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes a TypeScript complaint

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah good catch. It's an edge case (maybe an error somewhere else if so), but should we do:

catchingUp: fullSyncHeight < latestBlockHeight,

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/penumbra-zone/penumbra/blob/d3bbe4c920dd03981ed883d347ed579dae6af363/crates/view/src/service.rs#L326-L334
rust view service also returns catchingUp=false if the difference is only 1 block

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, nice find

partialSyncHeight: fullSyncHeight,
fullSyncHeight: fullSyncHeight,
};
Expand Down
Loading