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

[CT-709] Add flag to send subaccount websocket message from Ender for long term orders #1223

Merged
merged 5 commits into from
Mar 25, 2024

Conversation

dydxwill
Copy link
Contributor

@dydxwill dydxwill commented Mar 22, 2024

Changelist

Add flag to send subaccount websocket message from Ender for long term orders

Test Plan

Unit tested.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link
Contributor

coderabbitai bot commented Mar 22, 2024

Warning

Rate Limit Exceeded

@dydxwill has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 1 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 b473914 and 56d19ea.

Walkthrough

The updates primarily focus on enhancing functionality and organization within the indexer's Kafka and Redis components, along with adjustments in the Ender and Vulcan services. Key modifications include the division of a function for better clarity in Kafka, the introduction of a new conversion function in Redis, and the implementation of configuration-based logic for handling stateful order placements in Ender. Vulcan's changes streamline Redis order conversion by centralizing the functionality.

Changes

Files Change Summary
indexer/packages/kafka/src/websocket-helper.ts Split createSubaccountWebsocketMessage into two functions for improved clarity.
indexer/packages/redis/src/helpers/order-helper.ts
indexer/packages/redis/src/index.ts
Introduced convertToRedisOrder function and ensured its export.
indexer/services/ender/__tests__/.../stateful-order-placement-handler.test.ts
indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts
indexer/services/ender/src/config.ts
indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts
Enhanced testing and handling for stateful orders with new configuration flags and logic adjustments.
indexer/services/vulcan/__tests__/handlers/order-place-handler.test.ts
indexer/services/vulcan/src/handlers/helpers.ts
indexer/services/vulcan/src/handlers/order-place-handler.ts
Updated order placement logic to utilize centralized Redis order conversion. Removed redundant local conversion function.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 780410f and 9f664bb.
Files selected for processing (10)
  • indexer/packages/kafka/src/websocket-helper.ts (2 hunks)
  • indexer/packages/redis/src/helpers/order-helper.ts (1 hunks)
  • indexer/packages/redis/src/index.ts (1 hunks)
  • indexer/services/ender/tests/handlers/stateful-order/stateful-order-placement-handler.test.ts (5 hunks)
  • indexer/services/ender/tests/helpers/indexer-proto-helpers.ts (3 hunks)
  • indexer/services/ender/src/config.ts (1 hunks)
  • indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts (2 hunks)
  • indexer/services/vulcan/tests/handlers/order-place-handler.test.ts (3 hunks)
  • indexer/services/vulcan/src/handlers/helpers.ts (1 hunks)
  • indexer/services/vulcan/src/handlers/order-place-handler.ts (2 hunks)
Additional comments: 13
indexer/services/ender/src/config.ts (1)
  • 26-28: The addition of the SEND_SUBACCOUNT_WEBSOCKET_MESSAGE_FOR_STATEFUL_ORDERS configuration flag with a default value of false is a good practice for introducing new features in a controlled manner.
indexer/packages/redis/src/helpers/order-helper.ts (1)
  • 10-27: The convertToRedisOrder function correctly constructs a RedisOrder from an IndexerOrder and a PerpetualMarketFromDatabase. It's important to ensure that this function is always called with valid data to avoid potential runtime errors due to non-null assertions.
indexer/services/vulcan/src/handlers/helpers.ts (1)
  • 2-2: Adjustments to imports related to IndexerOrder and RedisOrder seem appropriate. Ensure that the removal of convertToRedisOrder (mentioned in the summary but not shown in the provided code) does not impact other functionalities.
indexer/packages/redis/src/index.ts (1)
  • 18-18: Exporting all entities from order-helper simplifies imports in other parts of the application. Ensure that all exported entities are intended to be part of the public API.
indexer/packages/kafka/src/websocket-helper.ts (2)
  • 41-52: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [44-93]

Splitting createSubaccountWebsocketMessage into generateSubaccountMessageContents and createSubaccountWebsocketMessage is a good practice for separating concerns. Ensure that optional fields are handled carefully to avoid potential issues.

  • 90-110: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [96-118]

The refactoring to use generateSubaccountMessageContents within createSubaccountWebsocketMessage maintains clarity and modularity in the code. The approach to constructing and encoding protobuf messages is correctly implemented.

indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts (1)
  • 1-85: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [27-118]

The additions and modifications in StatefulOrderPlacementHandler, including new methods for retrieving orderId and subaccountId, updates to the internalHandle method, and the refactor of createKafkaEvents, are well-implemented. Ensure thorough testing is conducted for the new functionality, especially with the use of configuration flags to toggle features.

indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts (1)
  • 138-153: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [39-198]

The modifications to the test cases, including the addition of expectOrderSubaccountKafkaMessage import, config import, and handling of emitSubaccountMessage based on a configuration flag, are well-implemented. Ensure that the configuration is reset after each test to avoid unintended side effects.

indexer/services/vulcan/src/handlers/order-place-handler.ts (1)
  • 17-17: Centralizing the convertToRedisOrder functionality in @dydxprotocol-indexer/redis and removing the duplicate import is a good practice for promoting code reuse and maintainability. Ensure that the centralized functionality is correctly implemented and thoroughly tested.
indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts (2)
  • 32-32: The import of OrderSubaccountMessageContents and ORDER_FLAG_CONDITIONAL has been added, which aligns with the PR's objective to enhance the handling of stateful orders and their messaging. Ensure these imports are utilized effectively in the subsequent code changes.
  • 709-732: The changes from lines 709 to 732 in the expectOrderSubaccountKafkaMessage function introduce logic to handle conditional orders differently from other orders. This is a key part of the PR's objective to enhance messaging for stateful orders. The refactoring is clear and maintains readability. However, ensure that the removal of fields like triggerPrice, totalFilled, and goodTilBlock from orderWithoutUnwantedFields is intentional and correctly aligns with the requirements for non-conditional orders.
indexer/services/vulcan/__tests__/handlers/order-place-handler.test.ts (2)
  • 120-136: The changes from lines 120 to 136 update the conversion of IndexerOrder to RedisOrder by using redisPackage.convertToRedisOrder. This modification ensures that the conversion logic is encapsulated within the redisPackage, promoting code reuse and maintainability. However, it's crucial to verify that the redisPackage.convertToRedisOrder function handles all the necessary fields and edge cases that might have been previously handled in the local convertToRedisOrder function. Ensure that the redisPackage version of the function has been thoroughly tested, especially for any custom logic that might have been present in the original implementation.
  • 281-281: The change on line 281 also applies the redisPackage.convertToRedisOrder for converting an IndexerOrder to a RedisOrder. This consistency in using the redisPackage for conversions across the test file is good practice. It centralizes the conversion logic, making future updates or fixes easier to manage. As with the previous instances, ensure comprehensive testing of the redisPackage.convertToRedisOrder function to cover all scenarios.

Comment on lines +696 to +698
function isConditionalOrder(order: OrderFromDatabase): boolean {
return Number(order.orderFlags) === ORDER_FLAG_CONDITIONAL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The isConditionalOrder function checks if an order is conditional based on its orderFlags. This is a straightforward and efficient way to determine the type of order. However, consider adding a brief comment explaining the significance of ORDER_FLAG_CONDITIONAL for future maintainability.

+ // Determines if an order is conditional based on its orderFlags
function isConditionalOrder(order: OrderFromDatabase): boolean {
  return Number(order.orderFlags) === ORDER_FLAG_CONDITIONAL;
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
function isConditionalOrder(order: OrderFromDatabase): boolean {
return Number(order.orderFlags) === ORDER_FLAG_CONDITIONAL;
}
// Determines if an order is conditional based on its orderFlags
function isConditionalOrder(order: OrderFromDatabase): boolean {
return Number(order.orderFlags) === ORDER_FLAG_CONDITIONAL;
}

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9f664bb and b473914.
Files selected for processing (1)
  • indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts

@dydxwill dydxwill changed the title Send subaccount websocket message from Ender for stateful orders [CT-709] Add flag to Ssnd subaccount websocket message from Ender for stateful orders Mar 22, 2024
Copy link

linear bot commented Mar 22, 2024

@dydxwill dydxwill changed the title [CT-709] Add flag to Ssnd subaccount websocket message from Ender for stateful orders [CT-709] Add flag to send subaccount websocket message from Ender for stateful orders Mar 22, 2024
@dydxwill dydxwill changed the title [CT-709] Add flag to send subaccount websocket message from Ender for stateful orders [CT-709] Add flag to send subaccount websocket message from Ender for long term orders Mar 22, 2024
@dydxwill dydxwill merged commit bf1a5c2 into main Mar 25, 2024
11 checks passed
@dydxwill dydxwill deleted the wl/send_to_ender branch March 25, 2024 17:28
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