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

feat: add lastSyncTimestamp to GetInfo rpc endpoint #2071

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .changeset/five-students-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@farcaster/hub-nodejs": minor
"@farcaster/hub-web": minor
"@farcaster/hubble": minor
---

feat: added lastSyncTimestamp to GetInfo rpc
9 changes: 9 additions & 0 deletions apps/hubble/src/network/sync/syncEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ class SyncEngine extends TypedEmitter<SyncEvents> {
// Has the syncengine started yet?
private _started = false;

// Time of last successful sync
private _lastSyncTimestamp?: number;

private _dbStats: DbStats = {
approxSize: 0,
numItems: 0,
Expand Down Expand Up @@ -511,6 +514,10 @@ class SyncEngine extends TypedEmitter<SyncEvents> {
log.info("Sync engine stopped");
}

public getLastSyncTimestamp(): number | undefined {
return this._lastSyncTimestamp;
}

public getBadPeerIds(): string[] {
return this._peerScorer.getBadPeerIds();
}
Expand Down Expand Up @@ -907,6 +914,8 @@ class SyncEngine extends TypedEmitter<SyncEvents> {

await auditPeerPromise; // Wait for audit to complete

this._lastSyncTimestamp = Date.now();

log.info({ syncResult: this.curSync.fullResult }, "Perform sync: Sync Complete");
statsd().timing("syncengine.sync_time_ms", Date.now() - startTimestamp);
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions apps/hubble/src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export default class Server {
(e) => e,
)().unwrapOr(""),
hubOperatorFid: this.hub?.hubOperatorFid ?? 0,
lastSyncTimestamp: this.syncEngine?.getLastSyncTimestamp() ?? 0,
});

if (call.request.dbStats && this.syncEngine) {
Expand Down
2 changes: 2 additions & 0 deletions apps/hubble/src/rpc/test/syncService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe("getInfo", () => {
await engine.mergeOnChainEvent(storageEvent);
await engine.mergeMessage(castAdd);
await engine.mergeMessage(castAdd2);
await syncEngine.performSync("test", client);

await sleepWhile(() => syncEngine.syncTrieQSize > 0, SLEEPWHILE_TIMEOUT);

Expand All @@ -84,6 +85,7 @@ describe("getInfo", () => {
expect(result._unsafeUnwrap().dbStats?.numFidEvents).toEqual(1);
expect(result._unsafeUnwrap().dbStats?.numFnameEvents).toEqual(0);
expect(result._unsafeUnwrap().dbStats?.approxSize).toBeGreaterThan(0);
expect(result._unsafeUnwrap().lastSyncTimestamp).toBeGreaterThan(0);
});
});

Expand Down
1 change: 1 addition & 0 deletions apps/hubble/www/docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ Response Types for the Sync RPC Methods
| nickname | [string](#string) | | |
| root_hash | [string](#string) | | |
| db_stats | [DbStats](#DbStats) | | |
| last_sync_timestamp | [uint64]([#uint64]) | | |

### SyncStatusRequest

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/protobufs/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function userDataTypeToJSON(object: UserDataType): string {
}
}

/** Type of Protocol to disambiguate verification addresses */
/** Type of cast */
export enum CastType {
CAST = 0,
LONG_CAST = 1,
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/protobufs/generated/request_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
dbStats: DbStats | undefined;
peerId: string;
hubOperatorFid: number;
lastSyncTimestamp: number;
}

export interface DbStats {
Expand Down Expand Up @@ -580,6 +581,7 @@
dbStats: undefined,
peerId: "",
hubOperatorFid: 0,
lastSyncTimestamp: 0,
};
}

Expand All @@ -606,6 +608,9 @@
if (message.hubOperatorFid !== 0) {
writer.uint32(56).uint64(message.hubOperatorFid);
}
if (message.lastSyncTimestamp !== 0) {
writer.uint32(64).uint64(message.lastSyncTimestamp);

Check warning on line 612 in packages/core/src/protobufs/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/protobufs/generated/request_response.ts#L612

Added line #L612 was not covered by tests
}
return writer;
},

Expand Down Expand Up @@ -665,6 +670,13 @@

message.hubOperatorFid = longToNumber(reader.uint64() as Long);
continue;
case 8:

Check warning on line 673 in packages/core/src/protobufs/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/protobufs/generated/request_response.ts#L673

Added line #L673 was not covered by tests
if (tag != 64) {
break;

Check warning on line 675 in packages/core/src/protobufs/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/protobufs/generated/request_response.ts#L675

Added line #L675 was not covered by tests
}

message.lastSyncTimestamp = longToNumber(reader.uint64() as Long);
continue;

Check warning on line 679 in packages/core/src/protobufs/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/protobufs/generated/request_response.ts#L678-L679

Added lines #L678 - L679 were not covered by tests
}
if ((tag & 7) == 4 || tag == 0) {
break;
Expand All @@ -683,6 +695,7 @@
dbStats: isSet(object.dbStats) ? DbStats.fromJSON(object.dbStats) : undefined,
peerId: isSet(object.peerId) ? String(object.peerId) : "",
hubOperatorFid: isSet(object.hubOperatorFid) ? Number(object.hubOperatorFid) : 0,
lastSyncTimestamp: isSet(object.lastSyncTimestamp) ? Number(object.lastSyncTimestamp) : 0,
};
},

Expand All @@ -695,6 +708,7 @@
message.dbStats !== undefined && (obj.dbStats = message.dbStats ? DbStats.toJSON(message.dbStats) : undefined);
message.peerId !== undefined && (obj.peerId = message.peerId);
message.hubOperatorFid !== undefined && (obj.hubOperatorFid = Math.round(message.hubOperatorFid));
message.lastSyncTimestamp !== undefined && (obj.lastSyncTimestamp = Math.round(message.lastSyncTimestamp));
return obj;
},

Expand All @@ -713,6 +727,7 @@
: undefined;
message.peerId = object.peerId ?? "";
message.hubOperatorFid = object.hubOperatorFid ?? 0;
message.lastSyncTimestamp = object.lastSyncTimestamp ?? 0;
return message;
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/hub-nodejs/src/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function userDataTypeToJSON(object: UserDataType): string {
}
}

/** Type of Protocol to disambiguate verification addresses */
/** Type of cast */
export enum CastType {
CAST = 0,
LONG_CAST = 1,
Expand Down
15 changes: 15 additions & 0 deletions packages/hub-nodejs/src/generated/request_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
dbStats: DbStats | undefined;
peerId: string;
hubOperatorFid: number;
lastSyncTimestamp: number;
}

export interface DbStats {
Expand Down Expand Up @@ -580,6 +581,7 @@
dbStats: undefined,
peerId: "",
hubOperatorFid: 0,
lastSyncTimestamp: 0,
};
}

Expand All @@ -606,6 +608,9 @@
if (message.hubOperatorFid !== 0) {
writer.uint32(56).uint64(message.hubOperatorFid);
}
if (message.lastSyncTimestamp !== 0) {
writer.uint32(64).uint64(message.lastSyncTimestamp);

Check warning on line 612 in packages/hub-nodejs/src/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/hub-nodejs/src/generated/request_response.ts#L612

Added line #L612 was not covered by tests
}
return writer;
},

Expand Down Expand Up @@ -665,6 +670,13 @@

message.hubOperatorFid = longToNumber(reader.uint64() as Long);
continue;
case 8:

Check warning on line 673 in packages/hub-nodejs/src/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/hub-nodejs/src/generated/request_response.ts#L673

Added line #L673 was not covered by tests
if (tag != 64) {
break;

Check warning on line 675 in packages/hub-nodejs/src/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/hub-nodejs/src/generated/request_response.ts#L675

Added line #L675 was not covered by tests
}

message.lastSyncTimestamp = longToNumber(reader.uint64() as Long);
continue;

Check warning on line 679 in packages/hub-nodejs/src/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/hub-nodejs/src/generated/request_response.ts#L678-L679

Added lines #L678 - L679 were not covered by tests
}
if ((tag & 7) == 4 || tag == 0) {
break;
Expand All @@ -683,6 +695,7 @@
dbStats: isSet(object.dbStats) ? DbStats.fromJSON(object.dbStats) : undefined,
peerId: isSet(object.peerId) ? String(object.peerId) : "",
hubOperatorFid: isSet(object.hubOperatorFid) ? Number(object.hubOperatorFid) : 0,
lastSyncTimestamp: isSet(object.lastSyncTimestamp) ? Number(object.lastSyncTimestamp) : 0,

Check warning on line 698 in packages/hub-nodejs/src/generated/request_response.ts

View check run for this annotation

Codecov / codecov/patch

packages/hub-nodejs/src/generated/request_response.ts#L698

Added line #L698 was not covered by tests
};
},

Expand All @@ -695,6 +708,7 @@
message.dbStats !== undefined && (obj.dbStats = message.dbStats ? DbStats.toJSON(message.dbStats) : undefined);
message.peerId !== undefined && (obj.peerId = message.peerId);
message.hubOperatorFid !== undefined && (obj.hubOperatorFid = Math.round(message.hubOperatorFid));
message.lastSyncTimestamp !== undefined && (obj.lastSyncTimestamp = Math.round(message.lastSyncTimestamp));
return obj;
},

Expand All @@ -713,6 +727,7 @@
: undefined;
message.peerId = object.peerId ?? "";
message.hubOperatorFid = object.hubOperatorFid ?? 0;
message.lastSyncTimestamp = object.lastSyncTimestamp ?? 0;
return message;
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/hub-web/src/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function userDataTypeToJSON(object: UserDataType): string {
}
}

/** Type of Protocol to disambiguate verification addresses */
/** Type of cast */
export enum CastType {
CAST = 0,
LONG_CAST = 1,
Expand Down
15 changes: 15 additions & 0 deletions packages/hub-web/src/generated/request_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface HubInfoResponse {
dbStats: DbStats | undefined;
peerId: string;
hubOperatorFid: number;
lastSyncTimestamp: number;
}

export interface DbStats {
Expand Down Expand Up @@ -580,6 +581,7 @@ function createBaseHubInfoResponse(): HubInfoResponse {
dbStats: undefined,
peerId: "",
hubOperatorFid: 0,
lastSyncTimestamp: 0,
};
}

Expand All @@ -606,6 +608,9 @@ export const HubInfoResponse = {
if (message.hubOperatorFid !== 0) {
writer.uint32(56).uint64(message.hubOperatorFid);
}
if (message.lastSyncTimestamp !== 0) {
writer.uint32(64).uint64(message.lastSyncTimestamp);
}
return writer;
},

Expand Down Expand Up @@ -665,6 +670,13 @@ export const HubInfoResponse = {

message.hubOperatorFid = longToNumber(reader.uint64() as Long);
continue;
case 8:
if (tag != 64) {
break;
}

message.lastSyncTimestamp = longToNumber(reader.uint64() as Long);
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
Expand All @@ -683,6 +695,7 @@ export const HubInfoResponse = {
dbStats: isSet(object.dbStats) ? DbStats.fromJSON(object.dbStats) : undefined,
peerId: isSet(object.peerId) ? String(object.peerId) : "",
hubOperatorFid: isSet(object.hubOperatorFid) ? Number(object.hubOperatorFid) : 0,
lastSyncTimestamp: isSet(object.lastSyncTimestamp) ? Number(object.lastSyncTimestamp) : 0,
};
},

Expand All @@ -695,6 +708,7 @@ export const HubInfoResponse = {
message.dbStats !== undefined && (obj.dbStats = message.dbStats ? DbStats.toJSON(message.dbStats) : undefined);
message.peerId !== undefined && (obj.peerId = message.peerId);
message.hubOperatorFid !== undefined && (obj.hubOperatorFid = Math.round(message.hubOperatorFid));
message.lastSyncTimestamp !== undefined && (obj.lastSyncTimestamp = Math.round(message.lastSyncTimestamp));
return obj;
},

Expand All @@ -713,6 +727,7 @@ export const HubInfoResponse = {
: undefined;
message.peerId = object.peerId ?? "";
message.hubOperatorFid = object.hubOperatorFid ?? 0;
message.lastSyncTimestamp = object.lastSyncTimestamp ?? 0;
return message;
},
};
Expand Down
1 change: 1 addition & 0 deletions protobufs/schemas/request_response.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ message HubInfoResponse {
DbStats db_stats = 5;
string peerId = 6;
uint64 hub_operator_fid = 7;
uint64 last_sync_timestamp = 8;
}

message DbStats {
Expand Down
Loading