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

Remove unnecessary ProductKeeper abstraction #1765

Merged
merged 1 commit into from
Jun 25, 2024
Merged

Remove unnecessary ProductKeeper abstraction #1765

merged 1 commit into from
Jun 25, 2024

Conversation

BrendanChou
Copy link
Contributor

@BrendanChou BrendanChou commented Jun 25, 2024

Changelist

Remove unnecessary ProductKeeper abstraction

Summary by CodeRabbit

  • New Features
    • Improved error handling for duplicate update IDs in position updates.
  • Refactor
    • Simplified code structure by integrating checkPositionUpdatable directly into the update validation process.
    • Consolidated product type handling by removing specific constants and methods.
    • Merged ProductKeeper interface methods into AssetsKeeper and PerpetualsKeeper interfaces, streamlining the code.
  • Tests
    • Updated test cases to reference new error message constants related to product position updatability.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Warning

Rate limit exceeded

@BrendanChou has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 0 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 603ac87 and dea8a88.

Walkthrough

The recent updates streamline and refactor several functions and interfaces related to subaccounts and position updates within the system. By integrating the checkPositionUpdatable function logic directly, removing redundant product type constants, and consolidating the ProductKeeper interface methods into AssetsKeeper and PerpetualsKeeper, the codebase has become more efficient and maintainable.

Changes

File Path Change Summary
protocol/x/subaccounts/keeper/subaccount.go Removed checkPositionUpdatable function and integrated its functionality directly.
protocol/x/subaccounts/lib/updates.go Modified ApplyUpdatesToPositions to handle non-unique updates, removed errors import.
protocol/x/subaccounts/types/position_size.go Deleted product type constants and GetProductType methods from multiple structs.
protocol/x/subaccounts/types/expected_keepers.go Removed ProductKeeper interface; consolidated methods into AssetsKeeper and PerpetualsKeeper.
protocol/testing/e2e/gov/add_new_market_test.go Updated reference to an error message constant for product position updatability.

Poem

In code so swift, a rabbit's touch,
Refactor all, removing much.
Consolidate, the pathways clear,
Efficiency and grace appear.
With keepers strong and structs refined,
Simpler logic, intertwined.
Hoppy code, robust and neat,
A bunny's work is quite the feat! 🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@BrendanChou BrendanChou marked this pull request as ready for review June 25, 2024 00:47
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 568e95a and 4e10d06.

Files selected for processing (3)
  • protocol/x/subaccounts/keeper/subaccount.go (2 hunks)
  • protocol/x/subaccounts/lib/updates.go (2 hunks)
  • protocol/x/subaccounts/types/position_size.go (6 hunks)
Additional comments not posted (2)
protocol/x/subaccounts/lib/updates.go (1)

162-165: Added Duplicate ID Check in ApplyUpdatesToPositions:

The addition of a check for duplicate update IDs is a critical improvement for ensuring data integrity. This change prevents the application of conflicting updates, which could corrupt the state or lead to unintended behavior.

  • Correctness: The implementation uses a utility function to map update IDs and check for duplicates, which is a clean and efficient approach.
  • Error Handling: The function correctly returns an error if duplicates are detected, which aligns with best practices in robust error handling.
protocol/x/subaccounts/keeper/subaccount.go (1)

564-574: Integrated Position Updatability Checks in internalCanUpdateSubaccounts:

The integration of direct checks using perpetualsKeeper and assetsKeeper for position updatability into internalCanUpdateSubaccounts enhances the modularity and reduces redundancy.

  • Efficiency: By eliminating the checkPositionUpdatable function and integrating its logic directly, the code is more streamlined.
  • Error Handling: The function handles errors from the IsPositionUpdatable checks appropriately, using wrapped errors to provide more context, which aids in debugging and error resolution.

Also applies to: 579-589

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4e10d06 and 603ac87.

Files selected for processing (3)
  • protocol/testing/e2e/gov/add_new_market_test.go (2 hunks)
  • protocol/x/subaccounts/keeper/subaccount.go (2 hunks)
  • protocol/x/subaccounts/types/expected_keepers.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/testing/e2e/gov/add_new_market_test.go
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/subaccounts/keeper/subaccount.go
Additional comments not posted (4)
protocol/x/subaccounts/types/expected_keepers.go (4)

14-14: Method ConvertAssetToCoin approved.

The consolidation of ConvertAssetToCoin into AssetsKeeper from ProductKeeper is logical and helps streamline the interface structure.


40-40: Detailed methods in PerpetualsKeeper are well-defined.

Methods such as GetPerpetual, GetPerpetualAndMarketPrice, and others are specific and crucial for the operations within the perpetuals domain. These methods are well-defined and seem to be correctly placed within the interface.


14-14: Ensure method calls are updated for IsPositionUpdatable.

The method signature of IsPositionUpdatable has been modified to use a simpler id parameter instead of a PositionSize object. This change should simplify interactions but requires updating all method calls.

Also applies to: 34-40

Verification successful

Ensure method calls are updated for IsPositionUpdatable.

The method signature of IsPositionUpdatable has been modified to use a simpler id parameter instead of a PositionSize object. This change should simplify interactions but requires updating all method calls.

The search for the old method signature did not return any results, indicating that all instances have been updated.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `IsPositionUpdatable` are updated.

# Test: Search for the function usage with old signature. Expect: No occurrences.
rg --type go $'IsPositionUpdatable\\(.+PositionSize.+\\)'

Length of output: 56


34-40: Consistency maintained across keeper interfaces.

The IsPositionUpdatable method in PerpetualsKeeper now uses an id parameter, aligning with the changes in AssetsKeeper. Ensure all method calls are updated to reflect this change.

@BrendanChou BrendanChou changed the title cleanup code Remove unnecessary ProductKeeper abstraction Jun 25, 2024
@BrendanChou BrendanChou merged commit 0c9637e into main Jun 25, 2024
17 of 18 checks passed
@BrendanChou BrendanChou deleted the bc/cleanup branch June 25, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants