Skip to content

Commit

Permalink
chore: Segment bundle delay stats by message status (#2070)
Browse files Browse the repository at this point in the history
## Motivation

Segment bundle delay stats by message status

## Change Summary

Describe the changes being made in 1-2 concise sentences.

## 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
- [x] 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.
- [x] All [commits have been
signed](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#22-signing-commits)

## Additional Context

If this is a relatively large or complex change, provide more details
here that will help reviewers


<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on segmenting bundle delay stats by message status in
the `handleGossipMessage` function of `Hubble`.

### Detailed summary
- Added tracking of bundle delay stats for invalid, success, and failure
cases
- Segmented bundle delay stats based on message status
- Improved reporting logic for gossip messages in `handleGossipMessage`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
sanjayprabhu authored Jun 18, 2024
1 parent 27a1cfc commit f25f133
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-bags-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/hubble": patch
---

chore: Segment bundle delay stats by message status
11 changes: 6 additions & 5 deletions apps/hubble/src/hubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,12 +1261,16 @@ export class Hub implements HubInterface {

private async handleGossipMessage(gossipMessage: GossipMessage, source: PeerId, msgId: string): HubAsyncResult<void> {
let reportedAsInvalid = false;
const currentTime = getFarcasterTime().unwrapOr(0);
const messageFirstGossipedTime = gossipMessage.timestamp ?? 0;
const gossipMessageDelay = currentTime - messageFirstGossipedTime;
if (gossipMessage.timestamp) {
// If message is older than seenTTL, we will try to merge it, but report it as invalid so it doesn't
// propogate across the network
const cutOffTime = getFarcasterTime().unwrapOr(0) - GOSSIP_SEEN_TTL / 1000;

if (gossipMessage.timestamp < cutOffTime) {
statsd().timing("gossip.message_bundle_delay.invalid", gossipMessageDelay);
await this.gossipNode.reportValid(msgId, peerIdFromString(source.toString()).toBytes(), false);
reportedAsInvalid = true;
}
Expand Down Expand Up @@ -1299,10 +1303,6 @@ export class Hub implements HubInterface {
return err(new HubError("unavailable", msg));
}

const currentTime = getFarcasterTime().unwrapOr(0);
const messageFirstGossipedTime = gossipMessage.timestamp ?? 0;
const gossipMessageDelay = currentTime - messageFirstGossipedTime;

// Merge the message
if (gossipMessage.message) {
const message = gossipMessage.message;
Expand Down Expand Up @@ -1353,6 +1353,7 @@ export class Hub implements HubInterface {
if (!reportedAsInvalid) {
await this.gossipNode.reportValid(msgId, peerIdFromString(source.toString()).toBytes(), true);
}
statsd().timing("gossip.message_bundle_delay.success", gossipMessageDelay);
} else {
const errCode = results[0]?._unsafeUnwrapErr()?.errCode as string;
const errMsg = results[0]?._unsafeUnwrapErr()?.message;
Expand All @@ -1378,8 +1379,8 @@ export class Hub implements HubInterface {
if (!reportedAsInvalid) {
await this.gossipNode.reportValid(msgId, peerIdFromString(source.toString()).toBytes(), false);
}
statsd().timing("gossip.message_bundle_delay.failure", gossipMessageDelay);
}
statsd().timing("gossip.message_bundle_delay", gossipMessageDelay);

return ok(undefined);
} else {
Expand Down

0 comments on commit f25f133

Please sign in to comment.