Skip to content

Commit

Permalink
chore: add message hash to sync health errors (#2294)
Browse files Browse the repository at this point in the history
We need the message hash to understand the "message already merged
errors". Would be useful to search for the hash to understand when the
message got merged initially.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time
before submitting for review_

- [x] PR title adheres to the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [ ] PR has a
[changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets)
- [x] PR has been tagged with a change label(s) (i.e. documentation,
feature, bugfix, or chore)
- [ ] PR includes
[documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs)
if necessary.
  • Loading branch information
aditiharini authored Sep 4, 2024
1 parent 845d5bd commit 0b96a60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
13 changes: 10 additions & 3 deletions apps/hubble/src/network/sync/syncHealthJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import SyncEngine from "./syncEngine.js";
import { RpcMetadataRetriever, SyncEngineMetadataRetriever, SyncHealthProbe } from "../../utils/syncHealth.js";
import { HubInterface } from "hubble.js";
import { peerIdFromString } from "@libp2p/peer-id";
import { bytesToHexString, HubResult, Message, UserDataType } from "@farcaster/hub-nodejs";
import { bytesToHexString, Message, UserDataType } from "@farcaster/hub-nodejs";
import { Result } from "neverthrow";
import { SubmitError } from "../../utils/syncHealth.js";

const log = logger.child({
component: "SyncHealth",
Expand Down Expand Up @@ -60,7 +62,7 @@ export class MeasureSyncHealthJobScheduler {
return peers;
}

processSumbitResults(results: HubResult<Message>[], peerId: string) {
processSumbitResults(results: Result<Message, SubmitError>[], peerId: string) {
let numSuccesses = 0;
let numErrors = 0;
for (const result of results) {
Expand All @@ -80,7 +82,12 @@ export class MeasureSyncHealthJobScheduler {

numSuccesses += 1;
} else {
log.info({ errMessage: result.error.message, peerId }, "Failed to submit message via SyncHealth");
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, hash },
"Failed to submit message via SyncHealth",
);

numErrors += 1;
}
Expand Down
18 changes: 11 additions & 7 deletions apps/hubble/src/utils/syncHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import { appendFile } from "fs/promises";
import { addressInfoFromGossip, addressInfoToString } from "./p2p.js";

import { SyncId, timestampToPaddedTimestampPrefix } from "../network/sync/syncId.js";
import { err, ok } from "neverthrow";
import { err, ok, Result } from "neverthrow";
import { MAX_VALUES_RETURNED_PER_SYNC_ID_REQUEST, toTrieNodeMetadataResponse } from "../rpc/server.js";
import SyncEngine from "../network/sync/syncEngine.js";
import { HubInterface } from "hubble.js";

export type SubmitError = { hubError: HubError; originalMessage: Message };
class SyncHealthMessageStats {
primaryNumMessages: number;
peerNumMessages: number;
Expand All @@ -46,8 +47,8 @@ class SyncHealthMessageStats {

class Stats {
syncHealthMessageStats: SyncHealthMessageStats;
resultsUploadingToPeer: HubResult<Message>[];
resultsUploadingToPrimary: HubResult<Message>[];
resultsUploadingToPeer: Result<Message, SubmitError>[];
resultsUploadingToPrimary: Result<Message, SubmitError>[];
primary: string;
peer: string;
startTime: Date;
Expand All @@ -59,8 +60,8 @@ class Stats {
primary: string,
peer: string,
syncHealthMessageStats: SyncHealthMessageStats,
resultsUploadingToPeer: HubResult<Message>[],
resultsUploadingToPrimary: HubResult<Message>[],
resultsUploadingToPeer: Result<Message, SubmitError>[],
resultsUploadingToPrimary: Result<Message, SubmitError>[],
) {
this.startTime = startTime;
this.stopTime = stopTime;
Expand Down Expand Up @@ -88,7 +89,7 @@ class Stats {
const errorReasons = new Set();
for (const error of this.errorResults(who)) {
if (error.isErr()) {
errorReasons.add(error.error.message);
errorReasons.add(error.error.hubError.message);
}
}
return [...errorReasons];
Expand Down Expand Up @@ -505,7 +506,10 @@ export class SyncHealthProbe {
const results = [];
for (const message of messages.value.messages) {
const result = await metadataRetrieverMissingMessages.submitMessage(message);
results.push(result);
const augmentedResult = result.mapErr((err) => {
return { hubError: err, originalMessage: message };
});
results.push(augmentedResult);
}

return ok(results);
Expand Down

0 comments on commit 0b96a60

Please sign in to comment.