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: pull missing messages into sync trie via sync health job #2326

Merged
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fast-icons-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/hubble": patch
---

feat: add missing messages to sync trie via sync health job
51 changes: 33 additions & 18 deletions apps/hubble/src/network/sync/syncHealthJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { bytesToHexString, fromFarcasterTime, Message, UserDataType } from "@farcaster/hub-nodejs";
import { Result } from "neverthrow";
import { SubmitError } from "../../utils/syncHealth.js";
import { SyncId } from "./syncId.js";

const log = logger.child({
component: "SyncHealth",
Expand Down Expand Up @@ -75,9 +76,15 @@
return undefined;
}

processSumbitResults(results: Result<Message, SubmitError>[], peerId: string, startTime: number, stopTime: number) {
async processSumbitResults(
results: Result<Message, SubmitError>[],
peerId: string,
startTime: number,
stopTime: number,
) {

Check warning on line 84 in apps/hubble/src/network/sync/syncHealthJob.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/network/sync/syncHealthJob.ts#L84

Added line #L84 was not covered by tests
let numSuccesses = 0;
let numErrors = 0;
let numAlreadyMerged = 0;

Check warning on line 87 in apps/hubble/src/network/sync/syncHealthJob.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/network/sync/syncHealthJob.ts#L87

Added line #L87 was not covered by tests
for (const result of results) {
if (result.isOk()) {
const hashString = bytesToHexString(result.value.hash);
Expand Down Expand Up @@ -105,25 +112,31 @@
} else {
const hashString = bytesToHexString(result.error.originalMessage.hash);
const hash = hashString.isOk() ? hashString.value : "unable to show hash";
log.info(
{
errMessage: result.error.hubError.message,
peerId,
startTime,
stopTime,
msgDetails: {
fid: result.error.originalMessage.data?.fid,
timestamp: this.unixTimestampFromMessage(result.error.originalMessage),
hash,
},
},
"Failed to submit message via SyncHealth",
);

numErrors += 1;
const logTags = {

Check warning on line 116 in apps/hubble/src/network/sync/syncHealthJob.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/network/sync/syncHealthJob.ts#L116

Added line #L116 was not covered by tests
errMessage: result.error.hubError.message,
peerId,
startTime,
stopTime,
msgDetails: {
fid: result.error.originalMessage.data?.fid,
timestamp: this.unixTimestampFromMessage(result.error.originalMessage),
hash,
},
};
if (result.error.hubError.errCode === "bad_request.duplicate") {
// This message has already been merged into the DB, but for some reason is not in the Trie.
// Just update the trie.
await this._metadataRetriever._syncEngine.trie.insert(SyncId.fromMessage(result.error.originalMessage));
log.info(logTags, "Merged missing message into sync trie via SyncHealth");
numAlreadyMerged += 1;
} else {
log.info(logTags, "Failed to submit message via SyncHealth");
numErrors += 1;

Check warning on line 135 in apps/hubble/src/network/sync/syncHealthJob.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/network/sync/syncHealthJob.ts#L130-L135

Added lines #L130 - L135 were not covered by tests
}
}
}
return { numSuccesses, numErrors };
return { numSuccesses, numErrors, numAlreadyMerged };

Check warning on line 139 in apps/hubble/src/network/sync/syncHealthJob.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/network/sync/syncHealthJob.ts#L139

Added line #L139 was not covered by tests
}

async doJobs() {
Expand Down Expand Up @@ -178,13 +191,15 @@
continue;
}

const processedResults = await this.processSumbitResults(resultsPushingToUs.value, peerId, startTime, stopTime);

Check warning on line 194 in apps/hubble/src/network/sync/syncHealthJob.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/network/sync/syncHealthJob.ts#L194

Added line #L194 was not covered by tests

log.info(
{
ourNumMessages: syncHealthMessageStats.value.primaryNumMessages,
theirNumMessages: syncHealthMessageStats.value.peerNumMessages,
syncHealth: syncHealthMessageStats.value.computeDiff(),
syncHealthPercentage: syncHealthMessageStats.value.computeDiffPercentage(),
resultsPushingToUs: this.processSumbitResults(resultsPushingToUs.value, peerId, startTime, stopTime),
resultsPushingToUs: processedResults,
peerId,
startTime,
stopTime,
Expand Down
Loading