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

fix(screener): fix the cache #3412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Nov 27, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Introduced a default time-to-live (TTL) for cache entries, enhancing cache management.
  • Improvements

    • Enhanced cache accuracy by automatically removing non-risky addresses from the cache.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes introduce a new constant, defaultTTL, set to 24 * time.Hour, in the chainalysisapi.go file. This constant is used in the NewClient function for configuring the registrationCache with a default time-to-live (TTL). Additionally, the checkBlacklist method is updated to delete non-risky addresses from the cache, enhancing cache management and accuracy.

Changes

File Path Change Summary
contrib/screener-api/chainalysis/chainalysisapi.go Added constant defaultTTL and modified NewClient to use it for cache TTL; updated checkBlacklist to delete non-risky addresses from the cache.

Possibly related PRs

Suggested labels

go, size/xs, needs-go-generate-services/rfq

Suggested reviewers

  • trajan0x

🐇 In the code where rabbits hop,
A constant now, we’ll never stop!
With defaultTTL, our cache is neat,
Non-risky addresses, we’ll delete!
A cleaner world, we’ll surely see,
Hopping along, so code can be free! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Nov 27, 2024
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 26.04982%. Comparing base (79a40b5) to head (076ff95).
Report is 55 commits behind head on master.

Files with missing lines Patch % Lines
contrib/screener-api/chainalysis/chainalysisapi.go 0.00000% 6 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##             master       #3412          +/-   ##
===================================================
+ Coverage   3.10368%   26.04982%   +22.94614%     
===================================================
  Files            44         254         +210     
  Lines          2932       15455       +12523     
  Branches          0          82          +82     
===================================================
+ Hits             91        4026        +3935     
- Misses         2838       11060        +8222     
- Partials          3         369         +366     
Flag Coverage Δ
cctp-relayer 31.97848% <ø> (?)
opbot 0.18282% <ø> (ø)
promexporter 6.81642% <ø> (ø)
rfq 24.85882% <ø> (?)
screener-api 29.70779% <0.00000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
contrib/screener-api/chainalysis/chainalysisapi.go (2)

44-44: Consider making TTL configurable

While 24 hours is a reasonable default TTL for caching risk assessments, different deployments might require different cache durations based on their risk policies and compliance requirements.

Consider making this configurable through environment variables or configuration files, similar to how maxCacheSizeGB is planned to be configurable (as noted in the TODO comment).


139-140: Consider implementing negative caching

Currently, non-risky addresses are simply deleted from the cache. This could lead to repeated API calls for frequently checked safe addresses. Consider implementing negative caching (caching the "safe" status) to reduce API calls.

Example implementation:

-c.registrationCache.Delete(address)
+// Store false to indicate non-risky status
+c.registrationCache.Set(address, false)

// Update the cache check in ScreenAddress method:
-if _, ok := c.registrationCache.Get(address); ok {
+if val, ok := c.registrationCache.Get(address); ok {
+    // Return true only if the address was cached as risky
+    return val == struct{}{}, nil
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 91dee92 and 076ff95.

📒 Files selected for processing (1)
  • contrib/screener-api/chainalysis/chainalysisapi.go (3 hunks)
🔇 Additional comments (1)
contrib/screener-api/chainalysis/chainalysisapi.go (1)

57-60: LGTM: Cache configuration is well-structured

The cache configuration is comprehensive with:

  • LRU eviction policy for efficient memory usage
  • Memory limits to prevent OOM issues
  • Default TTL for automatic cleanup

Let's verify the cache configuration impact:

✅ Verification successful

Cache configuration is correctly implemented and isolated

The cache configuration is properly implemented with:

  • Single instance of cache initialization in the codebase
  • Appropriate constants defined for memory limits (3GB) and TTL (24 hours)
  • Consistent usage throughout the file for address screening and registration
  • No conflicting cache configurations found in other parts of the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for memory-related configurations and potential issues
# Look for other cache configurations that might conflict
rg -A 2 'NewCache\(\)' 
# Look for memory-related configurations
rg 'WithMaxMemoryUsage|maxCacheSizeGB'

Length of output: 542


Script:

#!/bin/bash
# Check for any other cache configurations or memory settings in the file
cat contrib/screener-api/chainalysis/chainalysisapi.go

Length of output: 4811

Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 076ff95
Status: ✅  Deploy successful!
Preview URL: https://104d148d.sanguine-fe.pages.dev
Branch Preview URL: https://fix-cache-screener.sanguine-fe.pages.dev

View logs

Copy link

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants