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

[Full node streaming] emit taker order status at end of matching loop #2022

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

jonfung-dydx
Copy link
Contributor

@jonfung-dydx jonfung-dydx commented Aug 5, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a SendTakerOrderStatus function for better order status handling across multiple components.
    • Added real-time updates for taker orders in the matching process to improve responsiveness.
  • Bug Fixes

    • Updated method documentation for clarity on functionality related to streaming managers.
  • Documentation

    • Enhanced comments across various methods to ensure consistent understanding of order management.
  • Refactor

    • Added methods to interfaces and structs to improve the organization and clarity of order processing functionalities.

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent changes enhance the system's ability to manage and report on taker orders through the introduction of a new method, SendTakerOrderStatus, across multiple components, including managers and mocks. This functionality supports real-time updates and robust testing capabilities, fostering better order handling in trading systems. Additionally, methods enforcing the MatchableOrder interface requirements improve the structure and consistency of order management.

Changes

Files Grouped Change Summary
protocol/mocks/MemClobKeeper.go Added the SendTakerOrderStatus mock function to simulate taker order status updates.
protocol/streaming/full_node_streaming_manager.go Introduced SendTakerOrderStatus method to manage the sending of taker order statuses to the streaming service, incorporating logic for handling different order types.
protocol/streaming/noop_streaming_manager.go Added an empty SendTakerOrderStatus method for future implementation to handle taker order status updates.
protocol/streaming/types/interface.go Updated FullNodeStreamingManager interface to include SendTakerOrderStatus method.
protocol/testutil/memclob/keeper.go Added SendTakerOrderStatus method to FakeMemClobKeeper for enhanced testing capabilities.
protocol/x/clob/keeper/keeper.go Added SendTakerOrderStatus method in Keeper for communicating taker order statuses; updated documentation for other relevant methods.
protocol/x/clob/memclob/memclob.go Modified matchOrder method to generate a stream of taker order statuses when applicable.
protocol/x/clob/memclob/memclob_grpc_streaming.go Introduced GenerateStreamTakerOrder method to create stream-compatible taker order objects.
protocol/x/clob/types/liquidation_order.go Added MustGetLiquidationOrder method to LiquidationOrder struct to meet MatchableOrder interface requirements.
protocol/x/clob/types/mem_clob_keeper.go Updated MemClobKeeper interface to include SendTakerOrderStatus method.
protocol/x/clob/types/order.go Introduced MustGetLiquidationOrder method to Order struct to indicate it cannot be treated as a LiquidationOrder.
protocol/x/clob/types/orderbook.go Added MustGetLiquidationOrder method to MatchableOrder interface for clear handling of liquidation orders.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FullNodeStreamingManager
    participant MemClobKeeper
    participant Keeper

    User->>Keeper: SendTakerOrderStatus(takerOrder)
    Keeper->>FullNodeStreamingManager: SendTakerOrderStatus(takerOrder)
    FullNodeStreamingManager->>MemClobKeeper: SendTakerOrderStatus(takerOrder)
    MemClobKeeper-->>FullNodeStreamingManager: Acknowledge order status update
    FullNodeStreamingManager-->>Keeper: Confirm order status sent
    Keeper-->>User: Acknowledge order status processing
Loading

Poem

🐰 In fields of code, a rabbit hops,
With updates new, it never stops.
Taker orders dance, their statuses fly,
Through managers swift, like clouds in the sky.
Let's cheer for changes, bold and bright,
In the coding burrow, all feels just right! 🐇✨


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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 403fc9b and eec0cb2.

Files selected for processing (12)
  • protocol/mocks/MemClobKeeper.go (1 hunks)
  • protocol/streaming/full_node_streaming_manager.go (1 hunks)
  • protocol/streaming/noop_streaming_manager.go (1 hunks)
  • protocol/streaming/types/interface.go (1 hunks)
  • protocol/testutil/memclob/keeper.go (1 hunks)
  • protocol/x/clob/keeper/keeper.go (3 hunks)
  • protocol/x/clob/memclob/memclob.go (1 hunks)
  • protocol/x/clob/memclob/memclob_grpc_streaming.go (1 hunks)
  • protocol/x/clob/types/liquidation_order.go (1 hunks)
  • protocol/x/clob/types/mem_clob_keeper.go (1 hunks)
  • protocol/x/clob/types/order.go (1 hunks)
  • protocol/x/clob/types/orderbook.go (1 hunks)
Additional comments not posted (14)
protocol/streaming/types/interface.go (1)

37-41: LGTM! Verify the method usage in the codebase.

The addition of the SendTakerOrderStatus method to the FullNodeStreamingManager interface looks good. Ensure that all implementations of this interface have this method defined.

Verification successful

Verification of SendTakerOrderStatus Method Implementation

The SendTakerOrderStatus method has been correctly added to the FullNodeStreamingManager interface and implemented in the following files:

  • protocol/streaming/full_node_streaming_manager.go
  • protocol/streaming/noop_streaming_manager.go
  • protocol/testutil/memclob/keeper.go
  • protocol/x/clob/keeper/keeper.go
  • protocol/mocks/MemClobKeeper.go

All implementations of the FullNodeStreamingManager interface have the SendTakerOrderStatus method defined.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all implementations of the `FullNodeStreamingManager` interface have the `SendTakerOrderStatus` method defined.

# Test: Search for the method implementation. Expect: All implementations should include the new method.
rg --type go -A 5 'SendTakerOrderStatus'

Length of output: 3810

protocol/streaming/noop_streaming_manager.go (1)

45-50: LGTM! Verify the method usage in the codebase.

The addition of the SendTakerOrderStatus method to the NoopGrpcStreamingManager class looks good. Ensure that the empty body is intentional and does not affect the functionality.

Verification successful

LGTM! The empty body of the SendTakerOrderStatus method in the NoopGrpcStreamingManager is intentional and consistent with the no-op design of the manager.

  • NoopGrpcStreamingManager is designed as a no-operation implementation with all methods having empty bodies.
  • The Enabled method returns false, further indicating that this manager is not intended to perform any operations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `SendTakerOrderStatus` method in the codebase to ensure the empty body does not affect functionality.

# Test: Search for the method usage. Expect: Ensure that the empty body is intentional.
rg --type go -A 5 'SendTakerOrderStatus'

Length of output: 3810


Script:

#!/bin/bash
# Description: Check the definition and context of NoopGrpcStreamingManager to confirm the intent of the empty SendTakerOrderStatus method.

# Search for the definition of NoopGrpcStreamingManager class or struct.
rg --type go -A 10 'type NoopGrpcStreamingManager struct'

# Search for the usage of NoopGrpcStreamingManager in the codebase.
rg --type go -A 5 'NoopGrpcStreamingManager'

Length of output: 4521

protocol/x/clob/types/mem_clob_keeper.go (1)

107-110: LGTM! Verify the method usage in the codebase.

The addition of the SendTakerOrderStatus method to the MemClobKeeper interface looks good. Ensure that all implementations of this interface have this method defined.

protocol/x/clob/types/liquidation_order.go (1)

118-122: LGTM!

The MustGetLiquidationOrder method is correctly implemented to fulfill the MatchableOrder interface.

protocol/x/clob/types/order.go (1)

135-139: LGTM!

The MustGetLiquidationOrder method is correctly implemented to fulfill the MatchableOrder interface by panicking as expected.

protocol/x/clob/types/orderbook.go (1)

209-211: LGTM! But verify the usage of the new method.

The code changes are approved.

However, ensure that all implementations of the MatchableOrder interface correctly handle the new MustGetLiquidationOrder method.

Verification successful

Let's correct the regex pattern and rerun the search to verify the implementations of the MatchableOrder interface.


Let's search for the MustGetLiquidationOrder method and its implementations to ensure it is correctly handled.


The MustGetLiquidationOrder method is correctly implemented and used.

The method has been added to the MatchableOrder interface and implemented for both LiquidationOrder and Order. The Order implementation correctly panics, ensuring the expected behavior. The method is also being utilized in the codebase.

  • protocol/x/clob/types/orderbook.go
  • protocol/x/clob/types/liquidation_order.go
  • protocol/x/clob/types/order.go
  • protocol/x/clob/memclob/memclob_grpc_streaming.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all implementations of the `MatchableOrder` interface handle the new method.

# Test: Search for the implementations of the `MatchableOrder` interface. Expect: Implementations correctly handle the new method.
rg --type go -A 10 $'type MatchableOrder interface {'

Length of output: 180


Script:

#!/bin/bash
# Description: Verify all implementations of the `MatchableOrder` interface handle the new method.

# Test: Search for the implementations of the `MatchableOrder` interface. Expect: Implementations correctly handle the new method.
rg --type go -A 10 'type MatchableOrder interface \{'

Length of output: 1096


Script:

#!/bin/bash
# Description: Search for the `MustGetLiquidationOrder` method and its implementations in the codebase.

# Test: Search for the `MustGetLiquidationOrder` method in the codebase. Expect: Implementations correctly handle the new method.
rg --type go 'MustGetLiquidationOrder'

Length of output: 899

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

Line range hint 270-274:
Comment update approved.

The comment update clarifies the intended recipient of the updates.


Line range hint 286-292:
Comment update approved.

The comment update clarifies the intended recipient of the updates.


302-312: New method SendTakerOrderStatus approved.

The method is correctly implemented and follows the pattern of the existing methods.

protocol/streaming/full_node_streaming_manager.go (1)

365-391: New method SendTakerOrderStatus approved.

The method is correctly implemented and follows the pattern of the existing methods. The logic for determining the clobPairId is clear and ensures the correct clobPairId is used based on the type of order.

protocol/mocks/MemClobKeeper.go (1)

419-422: LGTM!

The new mock function SendTakerOrderStatus is consistent with the pattern established by other mock functions in the class and enhances the mock functionality.

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

772-775: Correct use of GenerateStreamTakerOrder.

The GenerateStreamTakerOrder function is correctly used to generate the stream taker order.


776-779: Correct use of SendTakerOrderStatus.

The SendTakerOrderStatus method of clobKeeper is correctly used to send the taker order status.


770-780: Ensure generateOrderbookUpdates is properly initialized.

The new conditional block correctly checks if generateOrderbookUpdates is enabled before emitting the taker order status. Ensure that generateOrderbookUpdates is properly initialized and managed to avoid unexpected behavior.

Verification successful

Ensure generateOrderbookUpdates is properly initialized.

The generateOrderbookUpdates field is correctly initialized to false in the constructor and managed via the SetGenerateOrderbookUpdates method. This ensures that the conditional check for generateOrderbookUpdates in the matchOrder method will function correctly based on its current state.

  • MemClobPriceTimePriority struct defines generateOrderbookUpdates.
  • Initialized to false in the constructor.
  • Managed via SetGenerateOrderbookUpdates method.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization and management of `generateOrderbookUpdates`.

# Test: Search for the initialization and management of `generateOrderbookUpdates`. Expect: Proper initialization and management.
rg --type go --context 5 'generateOrderbookUpdates'

Length of output: 5632

Comment on lines +161 to +184
// GenerateStreamTakerOrder returns a `StreamTakerOrder` object used in full node
// streaming from a matchableOrder and a taker order status.
func (m *MemClobPriceTimePriority) GenerateStreamTakerOrder(
takerOrder types.MatchableOrder,
takerOrderStatus types.TakerOrderStatus,
) types.StreamTakerOrder {
if takerOrder.IsLiquidation() {
liquidationOrder := takerOrder.MustGetLiquidationOrder()
streamLiquidationOrder := liquidationOrder.ToStreamLiquidationOrder()
return types.StreamTakerOrder{
TakerOrder: &types.StreamTakerOrder_LiquidationOrder{
LiquidationOrder: streamLiquidationOrder,
},
TakerOrderStatus: takerOrderStatus.ToStreamingTakerOrderStatus(),
}
}
order := takerOrder.MustGetOrder()
return types.StreamTakerOrder{
TakerOrder: &types.StreamTakerOrder_Order{
Order: &order,
},
TakerOrderStatus: takerOrderStatus.ToStreamingTakerOrderStatus(),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor suggestion: Simplify the nested if-else.

The nested if-else can be simplified for better readability.

func (m *MemClobPriceTimePriority) GenerateStreamTakerOrder(
	takerOrder types.MatchableOrder,
	takerOrderStatus types.TakerOrderStatus,
) types.StreamTakerOrder {
	if takerOrder.IsLiquidation() {
		liquidationOrder := takerOrder.MustGetLiquidationOrder()
		streamLiquidationOrder := liquidationOrder.ToStreamLiquidationOrder()
		return types.StreamTakerOrder{
			TakerOrder: &types.StreamTakerOrder_LiquidationOrder{
				LiquidationOrder: streamLiquidationOrder,
			},
			TakerOrderStatus: takerOrderStatus.ToStreamingTakerOrderStatus(),
		}
	}
	
	order := takerOrder.MustGetOrder()
	return types.StreamTakerOrder{
		TakerOrder: &types.StreamTakerOrder_Order{
			Order: &order,
		},
		TakerOrderStatus: takerOrderStatus.ToStreamingTakerOrderStatus(),
	}
}

Committable suggestion was skipped due to low confidence.

Comment on lines +515 to +519
func (f *FakeMemClobKeeper) SendTakerOrderStatus(
ctx sdk.Context,
takerOrder types.StreamTakerOrder,
) {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide a mock implementation or a TODO comment.

The new method SendTakerOrderStatus is added to the FakeMemClobKeeper struct but its implementation is empty. Consider providing a mock implementation or adding a TODO comment to indicate future work.

+  // TODO: Implement the mock logic for SendTakerOrderStatus
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (f *FakeMemClobKeeper) SendTakerOrderStatus(
ctx sdk.Context,
takerOrder types.StreamTakerOrder,
) {
}
func (f *FakeMemClobKeeper) SendTakerOrderStatus(
ctx sdk.Context,
takerOrder types.StreamTakerOrder,
) {
// TODO: Implement the mock logic for SendTakerOrderStatus
}

Comment on lines +383 to +385
UpdateMessage: &clobtypes.StreamUpdate_TakerOrder{
TakerOrder: &streamTakerOrder,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

for my understanding - do we need to send any fill amounts for taker orders?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should have the fill amounts in a following full node stream update if you are subscribed to the correct clob pair id!

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.

3 participants