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

[OTE-529] feat(OE): Deprecate in-mem Untriggered Conditional Orders #1879

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

teddyding
Copy link
Contributor

@teddyding teddyding commented Jul 10, 2024

Changelist

Deprecate UntriggeredConditionalOrders object on the ClobKeeper and triggers based on state instead. This is required for OE integration. Since this slightly increases EndBlocker latency (see results below), will hold-off on merging until OE is ready to be released. More context here

Test Plan

Tested this implementation on mainnet full node (relevant period, details):

  • No app hash issue so change is non-breaking
  • p50 UCO trigger latency increased from 0.8ms -> 2.3ms; p99 1.2ms->3.6ms.

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.

Summary by CodeRabbit

  • New Features

    • Added new conditional order types for various buying and selling scenarios with specific parameters.
  • Bug Fixes

    • Improved management of conditional orders to enhance system reliability and performance.
  • Refactor

    • Simplified the logic for managing untriggered conditional orders and removed unnecessary complexity.
  • Tests

    • Updated and added test cases to validate changes in conditional order handling and ensure robustness of new features.

Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

The recent updates enhance the management of conditional orders within the system by adding new order configurations, removing logic for expired orders, and improving how untriggered conditional orders are organized. These changes streamline order processing, optimize memory usage, and facilitate more flexible trading strategies for users.

Changes

File Path Change Summary
protocol/testutil/constants/stateful_orders.go Added new conditional order declarations for various buying and selling scenarios.
protocol/x/clob/abci.go, protocol/x/clob/abci_test.go, protocol/x/clob/keeper/clob_pair_test.go Removed logic for handling expired untriggered conditional orders and adjusted related test cases.
protocol/x/clob/keeper/final_settlement.go, protocol/x/clob/keeper/keeper.go Removed logic for deleting untriggered conditional orders from memory; simplified Keeper struct.
protocol/x/clob/keeper/orders.go, protocol/x/clob/keeper/orders_test.go Removed the HydrateUntriggeredConditionalOrders function and its related test.
protocol/x/clob/keeper/untriggered_conditional_orders.go, protocol/x/clob/keeper/untriggered_conditional_orders_test.go Removed Add and Prune functions; added a new function to organize untriggered conditional orders and updated tests accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant System
    participant OrderManager
    participant MemoryStore

    User->>System: Place Conditional Order
    System->>OrderManager: Add Conditional Order
    OrderManager->>MemoryStore: Store Conditional Order
    MemoryStore-->>OrderManager: Confirm Storage

    Note over OrderManager: On specific event

    OrderManager->>MemoryStore: Retrieve Conditional Orders
    MemoryStore-->>OrderManager: Provide Orders
    OrderManager->>System: Trigger Conditional Orders
    System->>User: Confirmation
Loading

Poem

In the realm of code so bright,
Conditional orders take flight. 🕊️
No more memory to confound,
Streamlined orders now abound.
Triggered fast, without a pause,
Celebrating these new laws! 🎉


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 Configuration 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.

// trigger in the same block they are placed. Skip triggering orders which have been cancelled
// or expired.
// TODO(CLOB-773) Support conditional order replacements. Ensure replacements are de-duplicated.
conditionalOrdersIds := keeper.GetDeliveredConditionalOrderIds(ctx)
Copy link
Contributor Author

@teddyding teddyding Jul 10, 2024

Choose a reason for hiding this comment

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

Don't think GetDeliveredConditionalOrderIds is used for anything else, so we can remove it as well

@teddyding teddyding force-pushed the td/deprecate-mem-uco branch from 0c451ef to 40cbc21 Compare July 10, 2024 01:50
@@ -235,8 +235,6 @@ func TestEndBlocker_Success(t *testing.T) {
orderToPrune1 := constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20
orderToPrune2 := constants.ConditionalOrder_Alice_Num0_Id1_Clob0_Buy15_Price25_GTBT15_StopLoss25
orderToPrune3 := constants.ConditionalOrder_Alice_Num0_Id0_Clob1_Buy5_Price10_GTBT15_TakeProfit20
// cancelled order
orderToPrune4 := constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTB30_TakeProfit20
Copy link
Contributor Author

Choose a reason for hiding this comment

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

EndBlocker doesn't require this information anymore

@teddyding teddyding marked this pull request as ready for review July 10, 2024 01:53
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 3161af0 and 40cbc21.

Files selected for processing (10)
  • protocol/testutil/constants/stateful_orders.go (5 hunks)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/abci_test.go (6 hunks)
  • protocol/x/clob/keeper/clob_pair_test.go (3 hunks)
  • protocol/x/clob/keeper/final_settlement.go (1 hunks)
  • protocol/x/clob/keeper/keeper.go (3 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (1 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders.go (5 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders_test.go (4 hunks)
Files skipped from review due to trivial changes (3)
  • protocol/x/clob/abci.go
  • protocol/x/clob/keeper/clob_pair_test.go
  • protocol/x/clob/keeper/orders_test.go
Additional comments not posted (17)
protocol/x/clob/keeper/final_settlement.go (2)

Line range hint 9-12:
LGTM!

The function correctly forcefully cancels all stateful orders for the given clob pair.


Line range hint 15-61:
LGTM!

The function correctly cancels stateful orders, appends to RemovedStatefulOrderIds, and adds events to the indexer event manager.

protocol/x/clob/keeper/keeper.go (2)

31-31: Removal of MemClob field.

Ensure that the removal of the MemClob field does not affect other parts of the codebase that might rely on it.


94-113: LGTM!

The initialization logic correctly sets up the Keeper struct without the MemClob field.

protocol/x/clob/keeper/untriggered_conditional_orders.go (1)

178-196: LGTM!

The function correctly organizes untriggered conditional orders read from state and returns them in the expected format.

protocol/x/clob/keeper/untriggered_conditional_orders_test.go (4)

90-90: LGTM!

The test cases correctly cover the scenarios for adding untriggered conditional orders.


126-216: LGTM!

The test cases correctly cover the scenarios for organizing untriggered conditional orders from state.


285-285: LGTM!

The test cases correctly cover the scenarios for removing untriggered conditional orders.


285-285: LGTM!

The test cases correctly cover the scenarios for polling triggered conditional orders.

protocol/x/clob/abci_test.go (3)

310-324: Ensure correct initialization of untriggered conditional orders.

The added lines initialize a list of untriggered conditional orders. Verify that these orders are correctly set up and reflect the intended test scenario.


327-328: Verify order placement in the state.

The loop places each untriggered conditional order in the state. Ensure that this setup is necessary for the test case and that the orders are correctly placed.


747-752: Check the organization of untriggered conditional orders.

The OrganizeUntriggeredConditionalOrdersFromState function is used to organize untriggered conditional orders from the state. Verify that this function is correctly used and that the expected and actual results are accurately compared.

Also applies to: 756-756

protocol/testutil/constants/stateful_orders.go (5)

459-472: LGTM!

The ConditionalOrder_Alice_Num1_Id0_Clob0_Buy5_Price20_GTBT15_StopLoss20 order is correctly defined.


571-584: LGTM!

The ConditionalOrder_Alice_Num1_Id1_Clob0_Buy15_Price25_GTBT15_StopLoss25 order is correctly defined.


655-668: LGTM!

The ConditionalOrder_Alice_Num1_Id2_Clob0_Sell20_Price20_GTBT15_TakeProfit20 order is correctly defined.


711-724: LGTM!

The ConditionalOrder_Alice_Num1_Id3_Clob0_Buy25_Price25_GTBT15_StopLoss25 order is correctly defined.


781-794: LGTM!

The ConditionalOrder_Alice_Num0_Id1_Clob1_Buy5_Price10_GTBT15_StopLoss20 order is correctly defined.

@teddyding teddyding changed the title feat(OE): Deprecate in-mem Untriggered Conditional Orders [OTE-529] feat(OE): Deprecate in-mem Untriggered Conditional Orders Jul 10, 2024
Copy link

linear bot commented Jul 10, 2024

@@ -64,94 +64,6 @@ func assertFillAmountAndPruneState(
}
}

func TestEndBlocker_Failure(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested scenario no longer applies

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 40cbc21 and 45b3363.

Files selected for processing (1)
  • protocol/x/clob/abci_test.go (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/clob/abci_test.go

@teddyding teddyding force-pushed the td/deprecate-mem-uco branch from 45b3363 to 645a161 Compare July 13, 2024 17:23
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 45b3363 and 645a161.

Files selected for processing (10)
  • protocol/testutil/constants/stateful_orders.go (5 hunks)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/abci_test.go (7 hunks)
  • protocol/x/clob/keeper/clob_pair_test.go (3 hunks)
  • protocol/x/clob/keeper/final_settlement.go (1 hunks)
  • protocol/x/clob/keeper/keeper.go (3 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (1 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders.go (5 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders_test.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/clob/keeper/clob_pair_test.go
Files skipped from review as they are similar to previous changes (9)
  • protocol/testutil/constants/stateful_orders.go
  • protocol/x/clob/abci.go
  • protocol/x/clob/abci_test.go
  • protocol/x/clob/keeper/final_settlement.go
  • protocol/x/clob/keeper/keeper.go
  • protocol/x/clob/keeper/orders.go
  • protocol/x/clob/keeper/orders_test.go
  • protocol/x/clob/keeper/untriggered_conditional_orders.go
  • protocol/x/clob/keeper/untriggered_conditional_orders_test.go

@teddyding teddyding force-pushed the td/deprecate-mem-uco branch from 645a161 to 46451c3 Compare July 25, 2024 17:55
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: 2

Outside diff range, codebase verification and nitpick comments (6)
protocol/x/clob/keeper/untriggered_conditional_orders.go (2)

178-179: Improve function comment.

The function comment should be more descriptive and grammatically correct.

-// OrganizeUntriggeredConditionalOrdersFromState takes in a list of conditional orders read from
-// state, organize them and return in form of `UntriggeredConditionalOrders` struct.
+// OrganizeUntriggeredConditionalOrdersFromState takes a list of conditional orders read from
+// the state, organizes them, and returns them in the form of a `UntriggeredConditionalOrders` struct.

197-197: Update function comment.

The function comment should be updated to reflect the new logic of organizing untriggered conditional orders.

-// any conditional orders in `UntriggeredConditionalOrders` that can be triggered. For each triggered
+// any conditional orders that can be triggered. For each triggered
protocol/x/clob/keeper/untriggered_conditional_orders_test.go (1)

126-126: Fix typo in test case names.

There is a typo in the test case names. It should be ClobPair instead of ClobPair.

-		"Only GTE orders, one ClobPair": {
+		"Only GTE orders, one ClobPair": {
protocol/x/clob/abci_test.go (3)

239-239: Remove commented-out code.

The TODO comment indicates that the test assertions should be replaced with new verifications on the operations queue. Ensure that the commented-out code is removed once the new verifications are implemented.


239-239: Ensure consistent naming conventions.

The function name TestPrepareCheckState_WithProcessProposerMatchesEventsWithBadBlockHeight is quite long. Consider using a more concise and consistent naming convention for better readability.


239-239: Ensure consistent naming conventions.

The function name TestCommitBlocker_WithProcessProposerMatchesEventsWithBadBlockHeight is quite long. Consider using a more concise and consistent naming convention for better readability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 645a161 and 46451c3.

Files selected for processing (10)
  • protocol/testutil/constants/stateful_orders.go (5 hunks)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/abci_test.go (7 hunks)
  • protocol/x/clob/keeper/clob_pair_test.go (3 hunks)
  • protocol/x/clob/keeper/final_settlement.go (1 hunks)
  • protocol/x/clob/keeper/keeper.go (3 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (1 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders.go (5 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders_test.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/clob/keeper/clob_pair_test.go
Additional comments not posted (17)
protocol/x/clob/keeper/final_settlement.go (1)

Line range hint 10-13:
LGTM!

The code changes are approved.

protocol/x/clob/abci.go (3)

Line range hint 16-19:
LGTM!

The code changes are approved.


Line range hint 22-31:
LGTM!

The code changes are approved.


Line range hint 34-80:
Verify the correctness of the new approach.

The removal of logic related to untriggered conditional orders simplifies the function, but it's important to ensure that the new approach is correctly integrated.

protocol/x/clob/keeper/keeper.go (3)

93-114: Verify the correctness of the new approach.

The removal of UntriggeredConditionalOrders initialization simplifies the function, but it's important to ensure that the new approach is correctly integrated.


30-32: Verify the correctness of the new approach.

The removal of UntriggeredConditionalOrders simplifies the struct, but it's important to ensure that the new approach is correctly integrated.


Line range hint 142-160:
Verify the correctness of the new approach.

The removal of the call to k.HydrateUntriggeredConditionalOrders simplifies the function, but it's important to ensure that the new approach is correctly integrated.

Verification successful

The search results indicate that UntriggeredConditionalOrders is still being referenced in multiple files, suggesting that it has not been completely deprecated. To ensure the correctness of the new approach, we need to verify if the removal of k.HydrateUntriggeredConditionalOrders from the InitializeForGenesis function has been compensated by other initializations or if there are any alternative mechanisms in place.

Let's search for the usage of HydrateUntriggeredConditionalOrders and related initializations within the codebase to understand the impact of its removal.


Verify the correctness of the new approach.

The removal of k.HydrateUntriggeredConditionalOrders has been confirmed, and no alternative initialization or related mechanism was found in the InitializeForGenesis function or elsewhere in the codebase. This indicates that the functionality has been deprecated or is no longer required.

  • protocol/x/clob/keeper/keeper.go: InitializeForGenesis function does not initialize UntriggeredConditionalOrders.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of the new approach for handling conditional orders.

# Test: Search for the usage of `UntriggeredConditionalOrders` to ensure it has been completely deprecated.
rg --type go 'UntriggeredConditionalOrders'

Length of output: 8133


Script:

#!/bin/bash
# Description: Verify the impact of the removal of `k.HydrateUntriggeredConditionalOrders` by checking for its usage and related initializations.

# Test: Search for the usage of `HydrateUntriggeredConditionalOrders` to understand its impact.
rg --type go 'HydrateUntriggeredConditionalOrders'

# Test: Search for the initialization of `UntriggeredConditionalOrders` to check for any alternative mechanisms.
rg --type go 'InitializeForGenesis'

Length of output: 3181

protocol/x/clob/keeper/untriggered_conditional_orders_test.go (1)

90-90: LGTM!

The changes improve the test setup by using NewUntriggeredConditionalOrders directly.

protocol/x/clob/keeper/orders.go (1)

Line range hint 1-1: Verify new mechanism for managing untriggered conditional orders.

The removal of HydrateUntriggeredConditionalOrders indicates a change in how untriggered conditional orders are managed. Ensure that the new mechanism is thoroughly tested and documented.

protocol/x/clob/abci_test.go (2)

222-236: Ensure comprehensive test coverage for all scenarios.

The test cases for TestEndBlocker_Success seem to cover various scenarios, but it's crucial to ensure that all edge cases are tested, especially with the removal of TestEndBlocker_Failure. Consider adding more test cases if any edge cases are missed.


239-239: Ensure comprehensive test coverage for all scenarios.

The test cases for TestBeginBlocker_Success seem to cover various scenarios, but it's crucial to ensure that all edge cases are tested. Consider adding more test cases if any edge cases are missed.

protocol/testutil/constants/stateful_orders.go (5)

459-472: LGTM!

The new conditional order ConditionalOrder_Alice_Num1_Id0_Clob0_Buy5_Price20_GTBT15_StopLoss20 is consistent with the existing order structure and parameters.


571-584: LGTM!

The new conditional order ConditionalOrder_Alice_Num1_Id1_Clob0_Buy15_Price25_GTBT15_StopLoss25 is consistent with the existing order structure and parameters.


655-668: LGTM!

The new conditional order ConditionalOrder_Alice_Num1_Id2_Clob0_Sell20_Price20_GTBT15_TakeProfit20 is consistent with the existing order structure and parameters.


711-724: LGTM!

The new conditional order ConditionalOrder_Alice_Num1_Id3_Clob0_Buy25_Price25_GTBT15_StopLoss25 is consistent with the existing order structure and parameters.


781-794: LGTM!

The new conditional order ConditionalOrder_Alice_Num0_Id1_Clob1_Buy5_Price10_GTBT15_StopLoss20 is consistent with the existing order structure and parameters.

protocol/x/clob/keeper/orders_test.go (1)

Line range hint 15-15:
Ensure adequate test coverage for untriggered conditional orders.

The removal of the TestHydrateUntriggeredConditionalOrdersInMemClob function suggests a change in the testing strategy or a refactor in how untriggered conditional orders are managed. Ensure that the functionality covered by this test is still adequately tested elsewhere.

Verification successful

Ensure adequate test coverage for untriggered conditional orders.

The removal of the TestHydrateUntriggeredConditionalOrdersInMemClob function suggests a change in the testing strategy or a refactor in how untriggered conditional orders are managed. Ensure that the functionality covered by this test is still adequately tested elsewhere.

Based on the results from the shell script, it appears that there are multiple test cases related to untriggered conditional orders in other files, such as protocol/x/clob/abci_test.go and protocol/x/clob/keeper/stateful_order_state_test.go. These tests seem to cover various aspects of untriggered conditional orders, including their organization, removal, and triggering.

  • File: protocol/x/clob/abci_test.go

    • Tests related to expected untriggered conditional orders and their handling.
  • File: protocol/x/clob/keeper/stateful_order_state_test.go

    • Tests for reading stateful orders and ensuring untriggered conditional orders are returned correctly.
  • File: protocol/x/clob/keeper/untriggered_conditional_orders_test.go

    • Tests for organizing, adding, and removing untriggered conditional orders.

These findings suggest that the functionality related to untriggered conditional orders is still being tested in other parts of the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the functionality covered by the removed test is still adequately tested.

# Test: Search for tests related to untriggered conditional orders. Expect: Tests covering the relevant functionality.
rg --type go -A 5 'UntriggeredConditionalOrders'

Length of output: 28670

Comment on lines 17 to 19
}

// mustCancelStatefulOrdersForFinalSettlement forcefully cancels all stateful orders
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder: Address the TODO comment.

The TODO comment indicates a potential improvement to iterate over stateful orders for only the specified clob pair.

Do you want me to generate the code to address this TODO or open a GitHub issue to track this task?

@teddyding teddyding force-pushed the td/deprecate-mem-uco branch from 46451c3 to a5fd89d Compare July 25, 2024 21:37
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: 1

Outside diff range, codebase verification and nitpick comments (1)
protocol/x/clob/keeper/untriggered_conditional_orders_test.go (1)

Add Edge Cases to TestRemoveUntriggeredConditionalOrders

The current test cases are comprehensive but do not explicitly cover some important edge cases. Please consider adding the following edge cases to ensure robustness:

  • No orders to remove.

  • Orders with the same ID.

  • Orders with invalid IDs.

  • Orders with boundary conditions (e.g., minimum and maximum values).

Analysis chain

Line range hint 217-285:
LGTM! Ensure edge cases are covered.

The test cases are comprehensive and validate the removal logic effectively.

Verify that all edge cases are covered appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify edge cases in TestRemoveUntriggeredConditionalOrders function.

# Test: Search for edge cases in TestRemoveUntriggeredConditionalOrders function. Expect: Proper coverage.
rg --type go -A 5 'func TestRemoveUntriggeredConditionalOrders' | rg 'edge cases'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify edge cases in TestRemoveUntriggeredConditionalOrders function.

# Test: Search for specific edge cases in TestRemoveUntriggeredConditionalOrders function.

# Check for test cases with no orders to remove
rg --type go -A 10 'func TestRemoveUntriggeredConditionalOrders' | rg -i 'no orders'

# Check for test cases with orders having the same ID
rg --type go -A 10 'func TestRemoveUntriggeredConditionalOrders' | rg -i 'same id'

# Check for test cases with orders having invalid IDs
rg --type go -A 10 'func TestRemoveUntriggeredConditionalOrders' | rg -i 'invalid id'

# Check for test cases with boundary conditions (e.g., min and max values)
rg --type go -A 10 'func TestRemoveUntriggeredConditionalOrders' | rg -i 'boundary|min|max'

Length of output: 353


Script:

#!/bin/bash
# Description: Extract and review test cases in TestRemoveUntriggeredConditionalOrders function to identify implicit coverage of edge cases.

# Extract the entire TestRemoveUntriggeredConditionalOrders function for review
rg --type go -A 100 'func TestRemoveUntriggeredConditionalOrders' | rg -v '^\s*$'

Length of output: 10636

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 46451c3 and a5fd89d.

Files selected for processing (10)
  • protocol/testutil/constants/stateful_orders.go (5 hunks)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/abci_test.go (7 hunks)
  • protocol/x/clob/keeper/clob_pair_test.go (3 hunks)
  • protocol/x/clob/keeper/final_settlement.go (1 hunks)
  • protocol/x/clob/keeper/keeper.go (3 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/keeper/orders_test.go (1 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders.go (5 hunks)
  • protocol/x/clob/keeper/untriggered_conditional_orders_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/testutil/constants/stateful_orders.go
  • protocol/x/clob/abci.go
  • protocol/x/clob/keeper/final_settlement.go
  • protocol/x/clob/keeper/keeper.go
Additional comments not posted (10)
protocol/x/clob/keeper/untriggered_conditional_orders.go (2)

Line range hint 197-215:
LGTM! Verify edge cases and metrics emission.

The function is straightforward and performs the necessary state mutations.

Verify that all edge cases are handled appropriately and metrics are emitted correctly.


Line range hint 197-218:
LGTM! Ensure proper error handling.

The function is well-organized and utilizes the new OrganizeUntriggeredConditionalOrdersFromState function effectively.

Verify that all error handling scenarios are covered appropriately.

protocol/x/clob/keeper/untriggered_conditional_orders_test.go (3)

Line range hint 286-486:
LGTM! Ensure edge cases are covered.

The test cases are comprehensive and validate the polling logic effectively.

Verify that all edge cases are covered appropriately.

Verification successful

Test cases cover edge cases effectively.

The TestPollTriggeredConditionalOrders function includes comprehensive test cases, including critical edge cases related to rounding behavior.

  • No conditional orders triggered
  • Trigger GTE orders
  • Trigger LTE orders
  • Edge cases involving rounding (e.g., rounding down to not trigger, rounding up to not trigger)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify edge cases in TestPollTriggeredConditionalOrders function.

# Test: Search for edge cases in TestPollTriggeredConditionalOrders function. Expect: Proper coverage.
rg --type go -A 5 'func TestPollTriggeredConditionalOrders' | rg 'edge cases'

Length of output: 79


Script:

#!/bin/bash
# Extract the entire TestPollTriggeredConditionalOrders function to verify edge case coverage.
ast-grep --lang go --pattern 'func TestPollTriggeredConditionalOrders($_, $_) { $$$ }'

Length of output: 88


Script:

#!/bin/bash
# Extract the TestPollTriggeredConditionalOrders function to verify edge case coverage.
rg --type go -A 100 'func TestPollTriggeredConditionalOrders' 

Length of output: 12044


126-216: LGTM! Ensure edge cases are covered.

The test cases are comprehensive and validate the organization logic effectively.

Verify that all edge cases are covered appropriately.


Line range hint 1-90:
LGTM! Ensure edge cases are covered.

The test cases are comprehensive and validate the addition logic effectively.

Verify that all edge cases are covered appropriately.

protocol/x/clob/keeper/clob_pair_test.go (1)

Line range hint 1-486:
LGTM! Ensure edge cases are covered.

The test cases are comprehensive and validate the update logic effectively.

Verify that all edge cases are covered appropriately.

protocol/x/clob/keeper/orders.go (1)

Line range hint 15-18:
Verify the removal of HydrateUntriggeredConditionalOrders and its impact.

The removal of HydrateUntriggeredConditionalOrders changes how untriggered conditional orders are managed. Ensure that the new mechanism for handling untriggered conditional orders is in place and properly documented.

Verification successful

Verify the removal of HydrateUntriggeredConditionalOrders and its impact.

The function HydrateUntriggeredConditionalOrders has been removed, and the new mechanism for handling untriggered conditional orders is in place. The system now uses functions like MaybeTriggerConditionalOrders and the UntriggeredConditionalOrders data structure to manage these orders.

  • The new mechanism is documented and implemented across various parts of the codebase, ensuring proper handling of untriggered conditional orders.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of `HydrateUntriggeredConditionalOrders` and ensure that the new mechanism for handling untriggered conditional orders is in place.

# Test: Search for the function usage. Expect: No occurrences of the old function and presence of new mechanism.
rg --type go -A 5 $'HydrateUntriggeredConditionalOrders'

Length of output: 55


Script:

#!/bin/bash
# Description: Verify the new mechanism for handling untriggered conditional orders.

# Search for keywords related to untriggered conditional orders in Go files.
rg --type go -i 'untriggered' -A 5

# Check for changes in relevant files that might indicate a new mechanism.
git diff HEAD~1 -- protocol/x/clob/keeper/orders.go

Length of output: 80814

protocol/x/clob/abci_test.go (2)

222-240: LGTM! Simplified logic for handling untriggered conditional orders.

The changes to TestEndBlocker_Success simplify the logic by reducing the complexity of handling orders based on their trigger conditions. This improves readability and maintainability.


67-67: Verify the removal of TestEndBlocker_Failure and its impact.

The removal of TestEndBlocker_Failure indicates that the scenarios it tested are no longer relevant. Ensure that these scenarios are covered by other tests or are no longer applicable.

protocol/x/clob/keeper/orders_test.go (1)

Line range hint 1-1:
Significant Test Removal: Ensure Coverage is Maintained

The removal of the TestHydrateUntriggeredConditionalOrdersInMemClob function indicates a shift in testing strategy or functionality. Ensure that the new system of triggering based on state is adequately tested elsewhere to maintain coverage.

@teddyding teddyding merged commit 749dff9 into main Jul 26, 2024
18 checks passed
@teddyding teddyding deleted the td/deprecate-mem-uco branch July 26, 2024 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants