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

BE-687 | Cache for different swap methods #614

Merged
merged 2 commits into from
Feb 17, 2025
Merged

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Feb 14, 2025

This PR is a follow up from discussion on previous PR.

Proposed solution updates cache to accept swap method to avoid collisions caching different types swap routes.

Considered alternatives:

  • Accept swap method ( current proposal ): increases memory usage, ripple effect of the change in the code base
  • For in given out read cache returning out given in and invert results: adds more complexity in the clients using cache ( including tests ) and complexity in terms of mental load, will complicate debugging related with InGivenOut cache.
  • Create dedicated cache instances for each type: ripple effect of the change in the code base

Summary by CodeRabbit

  • Refactor
    • Enhanced cache management for route estimation by incorporating token swap methods, allowing for more precise handling of routing data.
    • Updated method signatures to include a token swap method parameter for improved cache key specificity.

Update cache to accept swap method to avoid collisions
Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request updates the caching mechanism within the router use case. The cache keys are now structured with an additional parameter representing the token swap method. In the optimized_routes.go file, cache deletion logic in both quote estimation methods is modified to use the new key structure. In the router_usecase.go file, cache key formatting functions are updated to accept the new parameter. These changes enhance the precision of cache management during route estimation.

Changes

File(s) Change Summary
router/usecase/optimized_routes.go Modified cache deletion logic in estimateAndRankSingleRouteQuoteOutGivenIn and estimateAndRankSingleRouteQuoteInGivenOut to include token swap method.
router/usecase/router_usecase.go Updated cache key formatting functions (formatRouteCacheKey, formatRankedRouteCacheKey, formatCandidateRouteCacheKey) to accept a token swap method.
domain/mocks/router_usecase_mock.go Updated GetCachedCandidateRoutes method to include method domain.TokenSwapMethod parameter.
domain/mvc/router.go Modified GetCachedCandidateRoutes method signature in RouterUsecase interface to accept method domain.TokenSwapMethod.
router/delivery/http/router_handler.go Updated invocation of GetCachedCandidateRoutes to include domain.TokenSwapMethodExactIn as the first argument.

Possibly related PRs

  • BE-687 | Cache for different swap methods #614: The changes in the main PR are directly related to those in the retrieved PR as both involve modifications to the cache key formatting and logic in the routerUseCaseImpl struct, specifically incorporating the domain.TokenSwapMethod parameter in the cache management functions.
  • BE-678 | InGivenOut APIs for Cosmwasm pool #606: The changes in the main PR are related to the modifications in the caching mechanism and method signatures that include the domain.TokenSwapMethod, which aligns with the updates in the retrieved PR that also involve changes to method signatures and caching logic.
  • BE-686 | Implement FindCandidateRoutesInGivenOut #612: The changes in the main PR are related to the modifications in the cache deletion logic and method signatures for route estimation, which directly connect to the updates in the GetCachedCandidateRoutes method in the retrieved PR that also involves cache key formatting and method signature changes.

Suggested reviewers

  • p0mvn

Poem

I'm a rabbit hopping through the code,
Cache keys now count three, not just a pair,
Token swaps and logic finely towed,
Bugs run off in a delightful scare,
With each hop, the routes take a merry ride,
Celebrate the change with a bunny cheer! 🐇💻


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f71882 and 284bd28.

⛔ Files ignored due to path filters (2)
  • router/usecase/optimized_routes_test.go is excluded by !**/*_test.go
  • router/usecase/router_usecase_test.go is excluded by !**/*_test.go
📒 Files selected for processing (4)
  • domain/mocks/router_usecase_mock.go (2 hunks)
  • domain/mvc/router.go (1 hunks)
  • router/delivery/http/router_handler.go (1 hunks)
  • router/usecase/router_usecase.go (10 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

🧹 Nitpick comments (1)
router/usecase/router_usecase.go (1)

424-424: Consider adding a comment explaining the swap method choice.

While the implementation is correct, it would be helpful to add a comment explaining why TokenSwapMethodExactIn is used here and how it relates to the overall caching strategy.

+    // Use TokenSwapMethodExactIn for ranked route caching as this is the primary swap method.
+    // The cache key includes the method to prevent collisions with other swap methods.
     r.rankedRouteCache.Set(formatRankedRouteCacheKey(domain.TokenSwapMethodExactIn, tokenIn.Denom, tokenOutDenom, tokenInOrderOfMagnitude), convertedCandidateRoutes, time.Duration(routingOptions.RankedRouteCacheExpirySeconds)*time.Second)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a77240 and 2f71882.

⛔ Files ignored due to path filters (3)
  • router/usecase/export_test.go is excluded by !**/*_test.go
  • router/usecase/optimized_routes_test.go is excluded by !**/*_test.go
  • router/usecase/router_usecase_test.go is excluded by !**/*_test.go
📒 Files selected for processing (2)
  • router/usecase/optimized_routes.go (2 hunks)
  • router/usecase/router_usecase.go (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (6)
router/usecase/optimized_routes.go (2)

62-64: LGTM! Cache invalidation updated to include swap method.

The cache invalidation logic has been correctly updated to include domain.TokenSwapMethodExactIn for the exact-in swap method.


127-129: LGTM! Cache invalidation updated to include swap method.

The cache invalidation logic has been correctly updated to include domain.TokenSwapMethodExactOut for the exact-out swap method.

router/usecase/router_usecase.go (4)

779-791: LGTM! Cache key formatting functions updated to include swap method.

The cache key formatting functions have been correctly updated to include the swap method as part of the key, which will prevent cache collisions between different swap methods.


384-390: LGTM! Cache operations updated to include swap method.

Cache operations in computeAndRankRoutesByDirectQuote have been correctly updated to use domain.TokenSwapMethodExactIn when caching routes.


710-710: LGTM! Cache operation updated to include swap method.

Cache operation in handleCandidateRoutes has been correctly updated to use domain.TokenSwapMethodExactIn when caching candidate routes.


616-616: LGTM! Cache retrieval operations updated to include swap method.

Cache retrieval operations in GetCachedCandidateRoutes and GetCachedRankedRoutes have been correctly updated to use domain.TokenSwapMethodExactIn when retrieving cached routes.

Also applies to: 649-649

@deividaspetraitis deividaspetraitis merged commit b8bc4ba into v28.x Feb 17, 2025
9 checks passed
@deividaspetraitis deividaspetraitis deleted the BE-687-cache branch February 17, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants