🦺 server: filter notifications to known tokens only#974
Conversation
391e906 to
b5ee87a
Compare
🦋 Changeset detectedLatest commit: e736d6f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR adds token filtering to the "Funds received" OneSignal notification system. A new async ChangesToken Filtering for Notifications
Sequence DiagramsequenceDiagram
participant Client as Client
participant ActivityHook as Activity Hook
participant Redis as Redis Cache
participant LiFi as LiFi API
participant Sentry as Sentry
participant OneSignal as OneSignal
Client->>ActivityHook: ADDRESS_ACTIVITY event
ActivityHook->>ActivityHook: Check marketsByAsset
alt Token in marketsByAsset
ActivityHook->>OneSignal: Send notification
else Token not in marketsByAsset
ActivityHook->>Redis: Check isKnownToken (SISMEMBER + SCARD)
alt Cache hit (non-empty, token found)
Redis-->>ActivityHook: true
ActivityHook->>OneSignal: Send notification
else Cache miss (empty set)
ActivityHook->>LiFi: Fetch tokens for chain
LiFi-->>ActivityHook: Token list
ActivityHook->>Redis: Populate cache with tokens
alt Token in fetched list
ActivityHook->>OneSignal: Send notification
else Token not in fetched list
ActivityHook-->>Client: Skip notification
end
else LiFi or Redis error
ActivityHook->>Sentry: Capture error { level: "error" }
ActivityHook->>OneSignal: Send notification (fail-open)
end
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #974 +/- ##
==========================================
+ Coverage 72.35% 72.80% +0.45%
==========================================
Files 231 231
Lines 8884 9020 +136
Branches 2874 2943 +69
==========================================
+ Hits 6428 6567 +139
- Misses 2199 2200 +1
+ Partials 257 253 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ecdf4f2 to
4d6172b
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
server/hooks/activity.ts (1)
143-143:⚠️ Potential issue | 🟠 MajorBlocking webhook response on a per-transfer LiFi fetch.
await isKnownToken(chain.id, underlying)runs serially inside thefor (const ... of transfers)loop beforec.json({})returns. On cache miss, this adds up to 5s (plus Redis RTTs) per unknown-token transfer, serialized across transfers in the payload. Alchemy may retry slow webhooks, which can amplify downstream work (poking, autoCredit, duplicate sends).Consider resolving the known-token check off the response path — e.g. kick off the LiFi/Redis checks in parallel and gate only the
sendPushNotification(...)call on an already-resolved decision, so the handler acks quickly regardless of LiFi latency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3560abdd-a0de-493c-8582-db8f20162cb6
📒 Files selected for processing (4)
.changeset/sharp-sails-guess.mdcspell.jsonserver/hooks/activity.tsserver/test/hooks/activity.test.ts
4d6172b to
53dadc1
Compare
8e731f9 to
2705d5f
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
server/hooks/activity.ts (1)
143-163:⚠️ Potential issue | 🟠 MajorStill blocking the webhook on
isKnownToken.This
awaitruns inside the transfer loop before the handler reachesc.json({}), so a cold LiFi/Redis miss still holds the webhook open and serializes that delay across unknown transfers in the same payload. Move the allowlist check off the response path or resolve it in parallel with the rest of the async work.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5a008653-b200-47f8-a977-8b35a899f3cf
📒 Files selected for processing (4)
.changeset/sharp-sails-guess.mdcspell.jsonserver/hooks/activity.tsserver/test/hooks/activity.test.ts
2705d5f to
e92aef2
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
server/hooks/activity.ts (1)
143-143:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftTake the token check off the webhook ack path and dedupe cold refreshes.
await isKnownToken(...)keeps the handler waiting on Redis and a potential 5s LiFi fetch beforec.json({}), and every concurrent cold miss on the samechainIdstill performs its own refresh because nothing coordinates thecount === 0path. That makes the slow path both serialized per transfer and stampede-prone. Move the notification gating into the existing fire-and-forget work and add a short per-chain refresh lock/sentinel so one miss produces one upstream fetch.Also applies to: 338-363
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8c348a5a-b475-4041-b12f-73a07cb88538
📒 Files selected for processing (3)
.changeset/sharp-sails-guess.mdserver/hooks/activity.tsserver/test/hooks/activity.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e92aef2445
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e92aef2 to
f3acb2c
Compare
8bfb559 to
3e8a975
Compare
3e8a975 to
e736d6f
Compare
closes #906
Summary by CodeRabbit
Bug Fixes
Tests