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-700] separate indexer and grpc streaming events #1209

Merged
merged 4 commits into from
Mar 20, 2024
Merged

[CT-700] separate indexer and grpc streaming events #1209

merged 4 commits into from
Mar 20, 2024

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented Mar 20, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

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 20, 2024

Walkthrough

The recent updates aim to enhance the orderbook update mechanism in a decentralized trading protocol. A new SendOrderbookUpdates mock function is added to ClobKeeper and MemClobKeeper for improved orderbook update handling. Changes in GrpcStreamingManagerImpl and various components ensure updates are accumulated before streaming. Refinements in orderbook update logic, including better order removal and update handling, enhance off-chain messaging efficiency.

Changes

Files Change Summary
protocol/mocks/ClobKeeper.go, protocol/mocks/MemClobKeeper.go Added SendOrderbookUpdates mock function.
protocol/streaming/grpc/grpc_streaming_manager.go Modified SendOrderbookUpdates logic to accumulate updates.
protocol/testutil/memclob/keeper.go Added SendOrderbookUpdates method to FakeMemClobKeeper.
protocol/x/clob/keeper/keeper.go, protocol/x/clob/types/clob_keeper.go, protocol/x/clob/types/mem_clob_keeper.go Updated interfaces and implementations to include SendOrderbookUpdates function.
protocol/x/clob/keeper/orders.go Removed call to SendOrderbookUpdates within SendOffchainMessages.
protocol/x/clob/memclob/... Added logic for sending orderbook updates, handling order operations, and improved off-chain messaging.

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.

Comment on lines +113 to +120
if err := subscription.srv.Send(
&clobtypes.StreamOrderbookUpdatesResponse{
Updates: updatesToSend,
Snapshot: snapshot,
},
); err != nil {
idsToRemove = append(idsToRemove, id)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

send one snapshot for all updates instead of one snapshot / clob pair

Copy link

linear bot commented Mar 20, 2024

Comment on lines -1313 to -1314

k.GetGrpcStreamingManager().SendOrderbookUpdates(offchainUpdates, false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

decouple grpc events and indexer events

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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9888453 and 4b1cca9.
Files selected for processing (11)
  • protocol/mocks/ClobKeeper.go (1 hunks)
  • protocol/mocks/MemClobKeeper.go (1 hunks)
  • protocol/streaming/grpc/grpc_streaming_manager.go (1 hunks)
  • protocol/testutil/memclob/keeper.go (1 hunks)
  • protocol/x/clob/keeper/keeper.go (1 hunks)
  • protocol/x/clob/keeper/orders.go (1 hunks)
  • protocol/x/clob/memclob/memclob.go (4 hunks)
  • protocol/x/clob/memclob/memclob_grpc_streaming.go (5 hunks)
  • protocol/x/clob/memclob/memclob_grpc_streaming_test.go (4 hunks)
  • protocol/x/clob/types/clob_keeper.go (1 hunks)
  • protocol/x/clob/types/mem_clob_keeper.go (1 hunks)
Additional comments: 13
protocol/x/clob/types/mem_clob_keeper.go (1)
  • 118-121: The addition of the SendOrderbookUpdates method to the MemClobKeeper interface aligns well with the PR objectives of enhancing the efficiency of streaming orderbook updates. The method signature is clear and appropriately takes offchainUpdates and a snapshot boolean parameter.
protocol/x/clob/memclob/memclob_grpc_streaming_test.go (2)
  • 24-24: The call to clobKeeper.SendOrderbookUpdates in the test setup aligns with the new method introduced in the MemClobKeeper interface, ensuring that the tests are updated to reflect the changes in the implementation.
  • 48-50: Replacing calls to GetOffchainUpdatesForOrder with GetOrderbookUpdatesForOrderPlacement in the test assertions correctly reflects the renaming and functionality update in the implementation. This ensures that the tests remain relevant and accurate.
protocol/x/clob/types/clob_keeper.go (1)
  • 147-152: The addition of the InitializeNewGrpcStreams and SendOrderbookUpdates methods to the ClobKeeper interface aligns well with the PR objectives of enhancing the efficiency of streaming orderbook updates and managing gRPC streams. The method signatures are clear and appropriately defined.
protocol/x/clob/memclob/memclob_grpc_streaming.go (2)
  • 59-62: Renaming GetOffchainUpdatesForOrder to GetOrderbookUpdatesForOrderPlacement improves clarity and aligns with the functionality of generating updates for order placements. This change enhances the readability and understanding of the code.
  • 92-128: The addition of GetOrderbookUpdatesForOrderRemoval and GetOrderbookUpdatesForOrderUpdate functions is a significant improvement, providing specific functionalities for handling order removals and updates. These functions contribute to the overall goal of enhancing the efficiency and organization of streaming orderbook updates.
protocol/streaming/grpc/grpc_streaming_manager.go (1)
  • 106-120: The modifications to the SendOrderbookUpdates method, specifically the accumulation of updates before sending them to subscribers, align with the PR objectives of enhancing the efficiency of streaming orderbook updates. This approach can improve performance by reducing the frequency and volume of data transmitted.
protocol/x/clob/keeper/keeper.go (2)
  • 236-237: The modification in the InitializeNewGrpcStreams method to call SendOrderbookUpdates of the Keeper struct itself instead of the streamingManager directly is a good architectural change. It encapsulates the functionality within the Keeper and provides a clear separation of concerns.
  • 239-244: The addition of the SendOrderbookUpdates method in the Keeper struct is necessary for the architectural change made in the InitializeNewGrpcStreams method. This method aligns with the PR objectives of enhancing the efficiency of streaming orderbook updates.
protocol/testutil/memclob/keeper.go (1)
  • 515-519: The method SendOrderbookUpdates has been added to the FakeMemClobKeeper struct but currently has an empty implementation. This is expected for mock or fake implementations used in testing. However, it's crucial to ensure that this method aligns with the interface it's supposed to mock or mimic, in terms of parameters and return types. If this method is intended for future expansion or specific testing scenarios, consider adding a comment to clarify its purpose or future intentions.
protocol/mocks/MemClobKeeper.go (1)
  • 437-440: The addition of the SendOrderbookUpdates mock function to the MemClobKeeper struct is consistent with the changes outlined in the PR objectives. This mock function is essential for testing the new SendOrderbookUpdates functionality in various components. It's important to ensure that the parameters and the way this mock function is set up align with the actual implementation of SendOrderbookUpdates in the corresponding interfaces. This ensures that tests using this mock will accurately reflect real-world usage and behavior.
protocol/mocks/ClobKeeper.go (1)
  • 1133-1136: The addition of the SendOrderbookUpdates mock function aligns with the PR objectives and seems well-structured for testing purposes. Ensure that this function is adequately utilized in unit tests to simulate the behavior of sending order book updates, both incremental and snapshot types.
protocol/x/clob/memclob/memclob.go (1)
  • 1989-2001: > 📝 NOTE

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

The logic for sending orderbook updates to gRPC streams after removing or updating an order in the orderbook is correctly implemented. However, it's essential to handle potential errors from SendOrderbookUpdates method calls and log them for debugging purposes. This ensures the reliability of the orderbook streaming functionality and aids in troubleshooting.

- m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false)
+ if err := m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false); err != nil {
+     log.ErrorLog(ctx, "Failed to send orderbook updates for order removal/update", "error", err)
+ }

Comment on lines 1219 to 1230
// For order matches in the last block, send an orderbook update
// to the grpc streams.
// Note that fully filled orders are removed from the orderbook in `RemoveOrderIfFilled` above.
allUpdates := types.NewOffchainUpdates()
for _, orderId := range filledOrderIds {
if m.openOrders.hasOrder(ctx, orderId) {
orderbookUpdate := m.GetOrderbookUpdatesForOrderUpdate(ctx, orderId)
allUpdates.Append(orderbookUpdate)
}
}
m.clobKeeper.SendOrderbookUpdates(allUpdates, false)

Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for sending orderbook updates to gRPC streams after processing filled orders is correctly placed. However, it's important to ensure that the SendOrderbookUpdates method handles potential errors gracefully and logs them for debugging purposes. This is crucial for maintaining the reliability of the orderbook streaming functionality.

- m.clobKeeper.SendOrderbookUpdates(allUpdates, false)
+ if err := m.clobKeeper.SendOrderbookUpdates(allUpdates, false); err != nil {
+     log.ErrorLog(ctx, "Failed to send orderbook updates", "error", err)
+ }

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
// For order matches in the last block, send an orderbook update
// to the grpc streams.
// Note that fully filled orders are removed from the orderbook in `RemoveOrderIfFilled` above.
allUpdates := types.NewOffchainUpdates()
for _, orderId := range filledOrderIds {
if m.openOrders.hasOrder(ctx, orderId) {
orderbookUpdate := m.GetOrderbookUpdatesForOrderUpdate(ctx, orderId)
allUpdates.Append(orderbookUpdate)
}
}
m.clobKeeper.SendOrderbookUpdates(allUpdates, false)
// For order matches in the last block, send an orderbook update
// to the grpc streams.
// Note that fully filled orders are removed from the orderbook in `RemoveOrderIfFilled` above.
allUpdates := types.NewOffchainUpdates()
for _, orderId := range filledOrderIds {
if m.openOrders.hasOrder(ctx, orderId) {
orderbookUpdate := m.GetOrderbookUpdatesForOrderUpdate(ctx, orderId)
allUpdates.Append(orderbookUpdate)
}
}
if err := m.clobKeeper.SendOrderbookUpdates(allUpdates, false); err != nil {
log.ErrorLog(ctx, "Failed to send orderbook updates", "error", err)
}

Comment on lines 1525 to 1528

// Send an orderbook update to grpc streams.
orderbookUpdate := m.GetOrderbookUpdatesForOrderPlacement(ctx, newOrder)
m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for sending orderbook updates to gRPC streams after adding an order to the orderbook is correctly implemented. Similar to the previous comment, ensure that potential errors from SendOrderbookUpdates are handled and logged appropriately to maintain the reliability of the orderbook streaming functionality.

- m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false)
+ if err := m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false); err != nil {
+     log.ErrorLog(ctx, "Failed to send orderbook updates for order placement", "error", err)
+ }

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
// Send an orderbook update to grpc streams.
orderbookUpdate := m.GetOrderbookUpdatesForOrderPlacement(ctx, newOrder)
m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false)
// Send an orderbook update to grpc streams.
orderbookUpdate := m.GetOrderbookUpdatesForOrderPlacement(ctx, newOrder)
if err := m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false); err != nil {
log.ErrorLog(ctx, "Failed to send orderbook updates for order placement", "error", err)
}

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 4b1cca9 and 225a383.
Files selected for processing (2)
  • protocol/x/clob/memclob/memclob_purge_invalid_memclob_state_test.go (5 hunks)
  • protocol/x/clob/memclob/memclob_remove_order_test.go (1 hunks)
Additional comments: 7
protocol/x/clob/memclob/memclob_purge_invalid_memclob_state_test.go (5)
  • 253-256: The changes from lines 253 to 256 introduce a mock setup for SendOrderbookUpdates in the TestPurgeInvalidMemclobState function. This is a good practice for isolating the unit under test and controlling its environment. However, it's important to ensure that the mock's behavior closely mimics the real implementation to avoid false positives or negatives in the test results.
  • 343-346: The changes from lines 343 to 346 repeat the setup for SendOrderbookUpdates in the TestPurgeInvalidMemclobState_PanicsWhenCalledWithDuplicateCanceledStatefulOrderIds function. Consistency in mock setup across different test cases is beneficial for maintainability. However, consider abstracting common mock setups into a helper function to reduce duplication and improve readability.
  • 376-379: The changes from lines 376 to 379 show the mock setup for SendOrderbookUpdates in the TestPurgeInvalidMemclobState_PanicsWhenNonStatefulOrderIsCanceled function. This is consistent with the previous setups. As mentioned earlier, abstracting common setups into a helper function could enhance the test code's maintainability and readability.
  • 407-410: The changes from lines 407 to 410 in the TestPurgeInvalidMemclobState_PanicsWhenCalledWithDuplicateExpiredStatefulOrders function again demonstrate the mock setup for SendOrderbookUpdates. The repetition of this setup across multiple test functions reinforces the suggestion to abstract common setups into a helper function.
  • 441-444: The changes from lines 441 to 444 in the TestPurgeInvalidMemclobState_PanicsWhenCalledWithShortTermExpiredStatefulOrders function show the same mock setup for SendOrderbookUpdates. This consistent setup across tests is good practice, but again, consider using a helper function to reduce code duplication and enhance clarity.
protocol/x/clob/memclob/memclob_remove_order_test.go (2)
  • 333-333: The addition of the SendOrderbookUpdates mock expectation is appropriate for testing the new functionality. Ensure that its usage is verified across all relevant test cases to confirm that order book updates are correctly sent when expected.
  • 333-333: The test cases provided cover a wide range of scenarios for removing orders from the order book. It's recommended to verify that all edge cases are covered and that the assertions correctly reflect the expected outcomes of each test case.

allUpdates.Append(orderbookUpdate)
}
}
m.clobKeeper.SendOrderbookUpdates(allUpdates, false)
Copy link
Contributor

@jonfung-dydx jonfung-dydx Mar 20, 2024

Choose a reason for hiding this comment

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

Would it make sense to move out of PurgeInvalidMemclobState to a new memclob function called in PCS of abci go? It seems that we depend on filledOrderIds, which is read off of processProposerMatchesEvents.OrderIdsFilledInLastBlock. I don't think sending updates is related to purging memclob state?

@@ -86,3 +88,41 @@ func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrder(

return offchainUpdates
}

// GetOrderbookUpdatesForOrderRemoval returns a place order offchain message and
Copy link
Contributor

Choose a reason for hiding this comment

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

finish comment? same with below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

omg copilot failed me


// Send an orderbook update to grpc streams.
orderbookUpdate := m.GetOrderbookUpdatesForOrderPlacement(ctx, newOrder)
m.clobKeeper.SendOrderbookUpdates(orderbookUpdate, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't feel too strongly about this comment but would it make more sense to push these orderbook updates down a callstack level into the func (m *memclobOpenOrders) mustRemoveOrder memclobOpenOrders functions? Don't think we do this currently but in the future if we ever do direct order removal operations on the memclob open orders function orderbook updates won't be emitted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same with the removal below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thought about this when I am implementing but memclobOpenOrders does not hold a reference to memclob and therefore does not hold to reference to clob keeper to send messages 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's keep it that way for now? memclob holding a reference to clob is already kind of ugly in my opinion so don't want to introduce another backwards pointer to the parent

@@ -86,3 +88,41 @@ func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrder(

return offchainUpdates
}

// GetOrderbookUpdatesForOrderRemoval returns a place order offchain message and
func (m *MemClobPriceTimePriority) GetOrderbookUpdatesForOrderRemoval(
Copy link
Contributor

@jonfung-dydx jonfung-dydx Mar 20, 2024

Choose a reason for hiding this comment

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

In MemclobPriceTimepriority object we store a bool that indicates if we should be emitting offchain events.

	// ---- Fields for determining if off-chain update messages should be generated ----
	generateOffchainUpdates bool

Can we do the same for orderbook updates? It would be nice to have all these no-op if this isn't a full node with streaming turned on.

Comment on lines +997 to +998
memClob := clobmodulememclob.NewMemClobPriceTimePriority(app.IndexerEventManager.Enabled())
memClob.SetGenerateOrderbookUpdates(app.GrpcStreamingManager.Enabled())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should probably also get rid to the app.IndexerEventManager.Enabled() in the builder method and use the Set... method instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hard to add arguments to the constructor method since we have a ton of tests that need to be modified

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: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 225a383 and 9cc7ba8.
Files selected for processing (6)
  • protocol/app/app.go (1 hunks)
  • protocol/mocks/MemClob.go (1 hunks)
  • protocol/x/clob/abci.go (1 hunks)
  • protocol/x/clob/memclob/memclob.go (6 hunks)
  • protocol/x/clob/memclob/memclob_grpc_streaming.go (5 hunks)
  • protocol/x/clob/types/memclob.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/clob/memclob/memclob.go
  • protocol/x/clob/memclob/memclob_grpc_streaming.go
Additional comments: 1
protocol/app/app.go (1)
  • 994-1001: > 📝 NOTE

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

Consider modularizing the initialization logic for different modules and services to improve the readability and maintainability of the code. Breaking down the large New function into smaller, more focused functions can make the code easier to understand and modify. Additionally, ensure consistent error handling and resource management practices throughout the file to prevent potential resource leaks and unhandled errors.

Comment on lines 994 to 1001
clobFlags := clobflags.GetClobFlagValuesFromOptions(appOpts)
logger.Info("Parsed CLOB flags", "Flags", clobFlags)

memClob := clobmodulememclob.NewMemClobPriceTimePriority(
app.IndexerEventManager.Enabled() || app.GrpcStreamingManager.Enabled(),
)
memClob := clobmodulememclob.NewMemClobPriceTimePriority(app.IndexerEventManager.Enabled())
memClob.SetGenerateOrderbookUpdates(app.GrpcStreamingManager.Enabled())

app.ClobKeeper = clobmodulekeeper.NewKeeper(
appCodec,
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [726-726]

The gRPC server is initialized without specifying SSL/TLS credentials, which could expose the server to security vulnerabilities such as man-in-the-middle attacks. It's crucial to secure the gRPC connection by including credentials derived from an SSL certificate. You can create credentials using credentials.NewServerTLSFromFile("cert.pem", "cert.key") and include them in the server options.

- app.Server = daemonserver.NewServer(logger, grpc.NewServer(), &daemontypes.FileHandlerImpl{}, daemonFlags.Shared.SocketAddress)
+ creds, err := credentials.NewServerTLSFromFile("cert.pem", "cert.key")
+ if err != nil {
+     panic(err)
+ }
+ app.Server = daemonserver.NewServer(logger, grpc.NewServer(grpc.Creds(creds)), &daemontypes.FileHandlerImpl{}, daemonFlags.Shared.SocketAddress)

Comment on lines +140 to +151
GetOrderbookUpdatesForOrderPlacement(
ctx sdk.Context,
order Order,
) (offchainUpdates *OffchainUpdates)
GetOrderbookUpdatesForOrderRemoval(
ctx sdk.Context,
orderId OrderId,
) (offchainUpdates *OffchainUpdates)
GetOrderbookUpdatesForOrderUpdate(
ctx sdk.Context,
orderId OrderId,
) (offchainUpdates *OffchainUpdates)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding documentation comments for the newly introduced methods GetOrderbookUpdatesForOrderPlacement, GetOrderbookUpdatesForOrderRemoval, and GetOrderbookUpdatesForOrderUpdate. Documentation is crucial for maintaining code readability and helping other developers understand the purpose and usage of these methods.

Comment on lines +169 to +179
// For orders that are filled in the last block, send an orderbook update to the grpc streams.
if keeper.GetGrpcStreamingManager().Enabled() {
allUpdates := types.NewOffchainUpdates()
for _, orderId := range processProposerMatchesEvents.OrderIdsFilledInLastBlock {
if _, exists := keeper.MemClob.GetOrder(ctx, orderId); exists {
orderbookUpdate := keeper.MemClob.GetOrderbookUpdatesForOrderUpdate(ctx, orderId)
allUpdates.Append(orderbookUpdate)
}
}
keeper.SendOrderbookUpdates(allUpdates, false)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The changes from lines 169 to 179 introduce a loop to send orderbook updates for orders filled in the last block. Consider the following improvements:

  • Add error handling for the retrieval of orderbook updates in case GetOrderbookUpdatesForOrderUpdate fails.
  • Evaluate the performance impact of this loop, especially in scenarios with a high volume of orders. Consider batching updates or other optimization strategies if necessary.

Comment on lines +322 to +380
// GetOrderbookUpdatesForOrderPlacement provides a mock function with given fields: ctx, order
func (_m *MemClob) GetOrderbookUpdatesForOrderPlacement(ctx types.Context, order clobtypes.Order) *clobtypes.OffchainUpdates {
ret := _m.Called(ctx, order)

if len(ret) == 0 {
panic("no return value specified for GetOrderbookUpdatesForOrderPlacement")
}

var r0 *clobtypes.OffchainUpdates
if rf, ok := ret.Get(0).(func(types.Context, clobtypes.Order) *clobtypes.OffchainUpdates); ok {
r0 = rf(ctx, order)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*clobtypes.OffchainUpdates)
}
}

return r0
}

// GetOrderbookUpdatesForOrderRemoval provides a mock function with given fields: ctx, orderId
func (_m *MemClob) GetOrderbookUpdatesForOrderRemoval(ctx types.Context, orderId clobtypes.OrderId) *clobtypes.OffchainUpdates {
ret := _m.Called(ctx, orderId)

if len(ret) == 0 {
panic("no return value specified for GetOrderbookUpdatesForOrderRemoval")
}

var r0 *clobtypes.OffchainUpdates
if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) *clobtypes.OffchainUpdates); ok {
r0 = rf(ctx, orderId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*clobtypes.OffchainUpdates)
}
}

return r0
}

// GetOrderbookUpdatesForOrderUpdate provides a mock function with given fields: ctx, orderId
func (_m *MemClob) GetOrderbookUpdatesForOrderUpdate(ctx types.Context, orderId clobtypes.OrderId) *clobtypes.OffchainUpdates {
ret := _m.Called(ctx, orderId)

if len(ret) == 0 {
panic("no return value specified for GetOrderbookUpdatesForOrderUpdate")
}

var r0 *clobtypes.OffchainUpdates
if rf, ok := ret.Get(0).(func(types.Context, clobtypes.OrderId) *clobtypes.OffchainUpdates); ok {
r0 = rf(ctx, orderId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*clobtypes.OffchainUpdates)
}
}

return r0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding documentation comments for the mock functions GetOrderbookUpdatesForOrderPlacement, GetOrderbookUpdatesForOrderRemoval, and GetOrderbookUpdatesForOrderUpdate. While these are mock functions, documentation can improve readability and help developers understand their purpose and usage in tests.

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 9cc7ba8 and 7b5297c.
Files selected for processing (2)
  • protocol/x/clob/keeper/keeper.go (1 hunks)
  • protocol/x/clob/memclob/memclob.go (6 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/clob/keeper/keeper.go
  • protocol/x/clob/memclob/memclob.go

@jayy04 jayy04 merged commit 75937e1 into main Mar 20, 2024
17 checks passed
@jayy04 jayy04 deleted the jy/ct-700 branch March 20, 2024 23:48
jayy04 added a commit that referenced this pull request Mar 28, 2024
* [CT-700] separate indexer and grpc streaming events

* fix tests

* comments

* update
jayy04 added a commit that referenced this pull request Mar 28, 2024
* [CT-700] separate indexer and grpc streaming events

* fix tests

* comments

* update
jayy04 added a commit that referenced this pull request Mar 28, 2024
* [CT-645] Move off chain updates and v1 to a different package (#1131)

* [CT-645] Add protos for orderbook stream query service

* move removal reasons to a separate package

* [CT-645] Add protos for orderbook stream query service (#1133)

* [CT-645] Add protos for orderbook stream query service

* make update not nullable

* fix build

* [CT-644] instantiate grpc stream manager (#1134)

* [CT-644] instantiate grpc stream manager

* update type

* update channel type

* [CT-646] stream offchain updates through stream manager (#1138)

* [CT-646] stream offchain updates through stream manager

* comments

* fix lint

* get rid of finished

* comments

* comments

* [CT-652] add command line flag for full node streaming (#1145)

* [CT-647] construct the initial orderbook snapshot (#1147)

* [CT-647] construct the initial orderbook snapshot

* [CT-647] initialize new streams and send orderbook snapshot (#1152)

* [CT-647] initialize new streams and send orderbook snapshot

* use sync once

* comments

* [CT-700] separate indexer and grpc streaming events (#1209)

* [CT-700] separate indexer and grpc streaming events

* fix tests

* comments

* update

* [CT-700] only send response when there is at least one update (#1216)

* [CT-712] send order update when short term order state fill amounts are pruned (#1241)

* [CT-712] send fill amount updates for reverted operations (#1240)

* [CT-723] add block number + stage to grpc updates (#1252)

* [CT-723] add block number + stage to grpc updates

* add indexer changes

* [CT-727] avoid state reads when sending updates (#1261)
jayy04 added a commit that referenced this pull request Apr 1, 2024
…#1269)

* [CT-700] separate indexer and grpc streaming events (#1209)

* [CT-700] separate indexer and grpc streaming events

* fix tests

* comments

* update

* [CT-700] only send response when there is at least one update (#1216)

* [CT-712] send order update when short term order state fill amounts are pruned (#1241)

* [CT-712] send fill amount updates for reverted operations (#1240)

* [CT-723] add block number + stage to grpc updates (#1252)

* [CT-723] add block number + stage to grpc updates

* add indexer changes

* [CT-727] avoid state reads when sending updates (#1261)

* fix lint|

* [CT-712] send updates for both normal order matches and liquidation (#1280)

* fix test

* fix test

* update type
dydxwill pushed a commit that referenced this pull request Apr 8, 2024
* [CT-645] Move off chain updates and v1 to a different package (#1131)

* [CT-645] Add protos for orderbook stream query service

* move removal reasons to a separate package

* [CT-645] Add protos for orderbook stream query service (#1133)

* [CT-645] Add protos for orderbook stream query service

* make update not nullable

* fix build

* [CT-644] instantiate grpc stream manager (#1134)

* [CT-644] instantiate grpc stream manager

* update type

* update channel type

* [CT-646] stream offchain updates through stream manager (#1138)

* [CT-646] stream offchain updates through stream manager

* comments

* fix lint

* get rid of finished

* comments

* comments

* [CT-652] add command line flag for full node streaming (#1145)

* [CT-647] construct the initial orderbook snapshot (#1147)

* [CT-647] construct the initial orderbook snapshot

* [CT-647] initialize new streams and send orderbook snapshot (#1152)

* [CT-647] initialize new streams and send orderbook snapshot

* use sync once

* comments

* [CT-700] separate indexer and grpc streaming events (#1209)

* [CT-700] separate indexer and grpc streaming events

* fix tests

* comments

* update

* [CT-700] only send response when there is at least one update (#1216)

* [CT-712] send order update when short term order state fill amounts are pruned (#1241)

* [CT-712] send fill amount updates for reverted operations (#1240)

* [CT-723] add block number + stage to grpc updates (#1252)

* [CT-723] add block number + stage to grpc updates

* add indexer changes

* [CT-727] avoid state reads when sending updates (#1261)
dydxwill added a commit that referenced this pull request Apr 8, 2024
* [OTE-221] Add query for PendingSendPacket (backport #1176) (#1221)


---------

Co-authored-by: Teddy Ding <teddy@dydx.exchange>
(cherry picked from commit e545bbf)

# Conflicts:
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts
#	indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts
#	indexer/packages/v4-protos/src/codegen/google/bundle.ts
#	protocol/go.mod

* fix protos

* update go.mod

---------

Co-authored-by: Mohammed Affan <affanmd@nyu.edu>
Co-authored-by: affan <affan@dydx.exchange>

* [Backport v4.x] backport full node streaming to v4.x branch (#1270)

* [CT-645] Move off chain updates and v1 to a different package (#1131)

* [CT-645] Add protos for orderbook stream query service

* move removal reasons to a separate package

* [CT-645] Add protos for orderbook stream query service (#1133)

* [CT-645] Add protos for orderbook stream query service

* make update not nullable

* fix build

* [CT-644] instantiate grpc stream manager (#1134)

* [CT-644] instantiate grpc stream manager

* update type

* update channel type

* [CT-646] stream offchain updates through stream manager (#1138)

* [CT-646] stream offchain updates through stream manager

* comments

* fix lint

* get rid of finished

* comments

* comments

* [CT-652] add command line flag for full node streaming (#1145)

* [CT-647] construct the initial orderbook snapshot (#1147)

* [CT-647] construct the initial orderbook snapshot

* [CT-647] initialize new streams and send orderbook snapshot (#1152)

* [CT-647] initialize new streams and send orderbook snapshot

* use sync once

* comments

* [CT-700] separate indexer and grpc streaming events (#1209)

* [CT-700] separate indexer and grpc streaming events

* fix tests

* comments

* update

* [CT-700] only send response when there is at least one update (#1216)

* [CT-712] send order update when short term order state fill amounts are pruned (#1241)

* [CT-712] send fill amount updates for reverted operations (#1240)

* [CT-723] add block number + stage to grpc updates (#1252)

* [CT-723] add block number + stage to grpc updates

* add indexer changes

* [CT-727] avoid state reads when sending updates (#1261)

* [CT-712] send updates for both normal order matches and liquidation (#1280) (#1281)

* Fix lib.ErrorLogWithError: properly pass in args (#1306) (#1310)

(cherry picked from commit a91c1ca)

Co-authored-by: Jonathan Fung <121899091+jonfung-dydx@users.noreply.github.com>

* fix broken tests (#1312) (#1316)

(cherry picked from commit 5ec37d2)

Co-authored-by: Jonathan Fung <121899091+jonfung-dydx@users.noreply.github.com>

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Mohammed Affan <affanmd@nyu.edu>
Co-authored-by: affan <affan@dydx.exchange>
Co-authored-by: jayy04 <103467857+jayy04@users.noreply.github.com>
Co-authored-by: Jonathan Fung <121899091+jonfung-dydx@users.noreply.github.com>
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