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-1320] proto for FNS price updates #2586

Merged
merged 3 commits into from
Nov 21, 2024
Merged

[CT-1320] proto for FNS price updates #2586

merged 3 commits into from
Nov 21, 2024

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented Nov 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.

Summary by CodeRabbit

  • New Features
    • Introduced a new streaming service for real-time price updates alongside orderbook updates.
    • Added support for market IDs in price update requests, enhancing data granularity.
    • Enhanced event structure to include price updates, improving the responsiveness of market data.

These updates improve the overall functionality and responsiveness of the service for users tracking market prices.

@jayy04 jayy04 requested a review from a team as a code owner November 20, 2024 16:47
Copy link

linear bot commented Nov 20, 2024

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in this pull request involve modifications to Protocol Buffers files within the dydxprotocol package. The query.proto file is updated to import a new streaming protocol and to enhance the StreamOrderbookUpdatesRequest and StreamUpdate messages with additional fields for market IDs and price updates. Additionally, a new file, streaming.proto, is introduced, defining the StreamPriceUpdate message, which includes fields for market ID, price, and snapshot status. The bundle.ts and query.ts files are also updated to reflect these changes.

Changes

File Path Change Summary
proto/dydxprotocol/clob/query.proto - Added import for dydxprotocol/prices/streaming.proto.
- Added repeated uint32 market_ids = 3; to StreamOrderbookUpdatesRequest.
- Added dydxprotocol.prices.StreamPriceUpdate price_update = 7; to StreamUpdate.
proto/dydxprotocol/prices/streaming.proto - Introduced StreamPriceUpdate message with fields: uint32 market_id = 1;, MarketPrice price = 2;, bool snapshot = 3;.
indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts - Added multiple imports related to prices and other modules.
- Updated export structure for various modules.
indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts - Added properties marketIds and priceUpdate in StreamOrderbookUpdatesRequest and StreamUpdate interfaces.
indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/streaming.ts - Introduced StreamPriceUpdate interface and methods for encoding/decoding.
indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/streaming.ts - Added priceUpdate to StagedFinalizeBlockEvent interface and updated encoding/decoding methods.
proto/dydxprotocol/clob/streaming.proto - Added import for dydxprotocol/prices/streaming.proto.
- Updated StagedFinalizeBlockEvent to include price_update.

Possibly related PRs

Suggested reviewers

  • teddyding

🐇 In the meadow, updates flow,
With market IDs, our prices grow.
Streaming data, swift and bright,
Orderbooks dance in the light.
New fields added, a joyful cheer,
In the world of trading, we persevere! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Comment on lines +175 to +176
// Market ids for price updates.
repeated uint32 market_ids = 3;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

technically we can derive these from the clob pair ids, but i think this is slightly more flexible

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

🧹 Outside diff range and nitpick comments (5)
proto/dydxprotocol/prices/streaming.proto (3)

11-12: Enhance market_id field documentation

Consider adding more context to the market_id field documentation, such as valid ranges or special values if any.

-  // The `Id` of the `Market`.
+  // The unique identifier of the Market. Must be a valid market ID in the system.
+  // References a Market in the markets module.
   uint32 market_id = 1;

14-15: Consider adding validation rules for price field

The price field is correctly marked as non-nullable, but consider adding validation rules or constraints if applicable.

Would you like assistance in defining validation rules for the price field using the validate.rules option?


17-18: Enhance snapshot field documentation

The snapshot field could benefit from more detailed documentation explaining when it's true vs false and its implications.

-  // Snapshot indicates if the response is from a snapshot of the price.
+  // Snapshot indicates if this update is part of an initial state snapshot (true)
+  // or a real-time price update (false). Snapshots are typically sent when
+  // first subscribing to price updates for a market.
   bool snapshot = 3;
proto/dydxprotocol/clob/query.proto (2)

174-176: Add documentation comment for the market_ids field.

While the field addition is correct, consider adding a documentation comment similar to other fields in the message to explain its purpose and usage.

   // Subaccount ids to stream subaccount updates for.
   repeated dydxprotocol.subaccounts.SubaccountId subaccount_ids = 2;

+  // Market ids to stream price updates for.
   repeated uint32 market_ids = 3;

174-176: Well-designed integration of price updates into existing streaming infrastructure.

The approach of adding price updates to the existing streaming infrastructure is clean and maintainable:

  1. It reuses the established streaming patterns
  2. It maintains backward compatibility
  3. It allows clients to selectively subscribe to price updates for specific markets

Consider documenting the following aspects in the service documentation:

  • Expected frequency of price updates
  • Ordering guarantees between different update types
  • Handling of price update errors

Also applies to: 202-202

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 76c18b6 and 4c25c04.

⛔ Files ignored due to path filters (2)
  • protocol/x/clob/types/query.pb.go is excluded by !**/*.pb.go
  • protocol/x/prices/types/streaming.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (2)
  • proto/dydxprotocol/clob/query.proto (3 hunks)
  • proto/dydxprotocol/prices/streaming.proto (1 hunks)
🧰 Additional context used
🪛 buf
proto/dydxprotocol/prices/streaming.proto

4-4: import "gogoproto/gogo.proto": file does not exist

(COMPILE)

🔇 Additional comments (4)
proto/dydxprotocol/prices/streaming.proto (2)

9-19: Well-structured message definition for price updates

The StreamPriceUpdate message is well-designed with appropriate field types and clear separation of concerns. The inclusion of the snapshot flag is a good practice for streaming implementations.


4-4: Verify gogoproto dependency availability

The static analysis indicates that "gogoproto/gogo.proto" file is not found. This dependency is required for the nullable option used in the price field.

✅ Verification successful

gogoproto dependency is properly configured and widely used

The verification shows that:

  1. The project has github.com/gogo/protobuf dependency correctly set up in protocol/go.mod
  2. The gogoproto/gogo.proto import is consistently used across 65+ proto files in the codebase
  3. This is a standard pattern in the project's protobuf definitions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if gogoproto is properly set up in the project
fd -t f go.mod | xargs grep -l "gogo/protobuf"

# Verify other proto files using gogoproto
rg -t proto "import.*gogoproto/gogo.proto"

Length of output: 137


Script:

#!/bin/bash
# Check the content of go.mod to verify gogo/protobuf dependency
cat protocol/go.mod

# Use find to locate proto files and grep for gogoproto imports
find . -name "*.proto" -type f -exec grep -l "import.*gogoproto/gogo.proto" {} \;

Length of output: 29093

🧰 Tools
🪛 buf

4-4: import "gogoproto/gogo.proto": file does not exist

(COMPILE)

proto/dydxprotocol/clob/query.proto (2)

17-17: LGTM: Import statement is correctly placed and necessary.

The import of the prices streaming proto is properly organized with other related imports and is required for the new price update functionality.


202-202: Verify the StreamPriceUpdate message structure.

The addition to the oneof group is correct, but let's verify the structure of the StreamPriceUpdate message to ensure it contains all necessary fields for price updates.

✅ Verification successful

StreamPriceUpdate message structure is well-defined and properly integrated

The StreamPriceUpdate message has a well-defined structure with all necessary fields for price updates:

  • Contains market_id (uint32) for market identification
  • Uses MarketPrice message (from market_price.proto) which includes id and exponent fields
  • Has a snapshot flag to indicate if the response is from a price snapshot

The message structure is complete and properly integrated with the required imports and dependencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the structure of StreamPriceUpdate message

# Look for the StreamPriceUpdate message definition
rg -A 10 "message StreamPriceUpdate" --type proto

# Verify any existing usage patterns
ast-grep --pattern 'StreamPriceUpdate $var = $_'

Length of output: 132


Script:

#!/bin/bash
# Search for StreamPriceUpdate message definition using ripgrep without file type restriction
rg -A 10 "message StreamPriceUpdate"

# Search for proto files containing StreamPriceUpdate
fd . -e proto -x rg -l "StreamPriceUpdate" {}

Length of output: 851


Script:

#!/bin/bash
# Let's check the MarketPrice message structure since it's used in StreamPriceUpdate
rg -A 10 "message MarketPrice" proto/dydxprotocol/prices/streaming.proto

Length of output: 74


Script:

#!/bin/bash
# Let's check the MarketPrice message structure in any proto file
rg -A 10 "message MarketPrice"

# Also check for any imports in the streaming.proto file to locate MarketPrice
rg "^import" proto/dydxprotocol/prices/streaming.proto

Length of output: 2986

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

🧹 Outside diff range and nitpick comments (4)
indexer/packages/v4-protos/src/codegen/google/bundle.ts (1)

8-14: LGTM - Generated code maintains correct structure

The namespace exports maintain the correct sequential structure and properly incorporate the new protobuf/any type. The changes appear to be automatically generated from protocol buffer definitions, maintaining consistency with Google's protobuf standards.

Since this is generated code, ensure that any manual modifications to proto files that led to these changes are properly documented and follow the protobuf best practices.

indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/streaming.ts (3)

4-15: Clean up documentation formatting.

Remove unnecessary blank lines in the documentation comments to improve readability.

 /** StreamPriceUpdate provides information on a price update. */
-
 export interface StreamPriceUpdate {
   /** The `Id` of the `Market`. */
   marketId: number;
   /** The updated price. */
-
   price?: MarketPrice;
   /** Snapshot indicates if the response is from a snapshot of the price. */
-
   snapshot: boolean;
 }

16-27: Remove redundant interface documentation.

The documentation comment for StreamPriceUpdateSDKType is redundant since it's just an SDK type mapping of StreamPriceUpdate.

-/** StreamPriceUpdate provides information on a price update. */
-
 export interface StreamPriceUpdateSDKType {

38-52: Add null check for message parameter.

The encode method should validate the input message parameter to prevent runtime errors.

 encode(message: StreamPriceUpdate, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+    if (!message) {
+      return writer;
+    }
+
     if (message.marketId !== 0) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c25c04 and 01818ed.

📒 Files selected for processing (5)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (13 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/streaming.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts (1 hunks)
  • indexer/packages/v4-protos/src/codegen/google/bundle.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts
🔇 Additional comments (21)
indexer/packages/v4-protos/src/codegen/google/bundle.ts (1)

1-6: Verify the usage of newly added protobuf/any import

The addition of protobuf/any import suggests new dynamic type handling requirements in the codebase. Let's verify where this is being used.

✅ Verification successful

The protobuf/any import is correctly added and actively used

The protobuf/any import is being used in the delaymsg module for handling delayed messages. Specifically:

  • It's imported and used in dydxprotocol/delaymsg/tx.ts and dydxprotocol/delaymsg/delayed_message.ts
  • The corresponding proto files (delaymsg/tx.proto and delaymsg/delayed_message.proto) explicitly import google/protobuf/any.proto
  • The Any type is used to wrap arbitrary protocol messages in the delayed message system
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of google.protobuf.Any in proto files and generated code
# This will help understand why the Any type was needed

# Search for Any type usage in proto files
echo "Searching for Any type usage in proto files..."
rg -t proto "google\.protobuf\.Any"

# Search for _136 (protobuf/any) usage in generated TypeScript files
echo "Searching for Any type usage in generated TypeScript files..."
rg "_136\." "indexer/packages/v4-protos/src/codegen/"

Length of output: 357


Script:

#!/bin/bash
# Let's try a different approach to find Any type usage

# Search for "Any" in TypeScript files within the v4-protos package
echo "Searching for Any type references..."
rg "Any" "indexer/packages/v4-protos/src/"

# List all .proto files to understand available proto definitions
echo -e "\nListing .proto files..."
fd ".proto$"

# Check if there are any imports or references to "any.proto"
echo -e "\nSearching for any.proto references..."
rg "any\.proto"

Length of output: 11431

indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/streaming.ts (4)

29-35: LGTM!

The base object creation is well-implemented with appropriate default values for each field type.


54-82: LGTM!

The decode implementation correctly handles all message fields and includes proper error handling for unknown fields.


84-91: LGTM!

The fromPartial implementation correctly handles undefined/null cases and provides appropriate default values.


1-92: Verify integration with existing price update handlers.

The StreamPriceUpdate implementation looks solid, but we should verify its integration with existing price update handlers to ensure compatibility.

✅ Verification successful

Let me gather more specific information about the price update implementations to verify compatibility.


Based on the gathered information, I can now provide a final response:

StreamPriceUpdate implementation is correctly integrated with the price update system

The implementation is verified to be correct because:

  • The StreamPriceUpdate interface correctly uses the existing MarketPrice type which matches the protocol's price representation (with id, exponent, and price fields)
  • It's properly integrated into the CLOB (Central Limit Order Book) query system as shown by its usage in dydxprotocol/clob/query.ts
  • The implementation follows the same protobuf encoding/decoding patterns as other price-related structures in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing price update handlers that might need updates
echo "Searching for existing price handlers..."
rg -t ts "price.*update" --glob '!*.test.ts' -l

# Look for potential message type conflicts
echo "Checking for potential message type conflicts..."
ast-grep --pattern 'interface $name {
  $$$
  price?: $type
  $$$
}'

Length of output: 1203


Script:

#!/bin/bash
# Check the implementation of market price update handler
echo "Checking market price update handler implementation..."
rg -A 10 "class MarketPriceUpdateHandler" indexer/services/ender/src/handlers/markets/market-price-update-handler.ts

# Check the MarketPrice type implementation
echo "Checking MarketPrice type implementation..."
cat indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts

# Check for any direct usage of StreamPriceUpdate
echo "Checking StreamPriceUpdate usage..."
rg -A 5 "StreamPriceUpdate" --type ts

Length of output: 12315

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (4)

10-10: LGTM: Clean import addition for price update types.

The import statement is well-structured and correctly imports both the main and SDK types for price updates.


260-262: LGTM: Consistent implementation of market IDs field.

The marketIds field is properly implemented across the interface definition and encoding/decoding logic, following protobuf standards.

Also applies to: 275-277, 1203-1204, 1222-1228, 1258-1270, 1284-1284


1342-1343: LGTM: Well-structured price update field addition.

The priceUpdate field is properly implemented as an optional field with consistent encoding/decoding logic.

Also applies to: 1373-1376, 1413-1416, 1434-1434


Line range hint 1-1434: Verify consistency with proto definitions.

Let's ensure the TypeScript code matches the underlying proto definitions.

✅ Verification successful

Based on the proto file output, I can verify the TypeScript code matches the proto definitions. Let me generate the final response:

TypeScript code matches proto definitions

The TypeScript code correctly implements the proto definitions:

  • StreamOrderbookUpdatesRequest matches with correct field numbers:

    • clobPairId (1)
    • subaccountIds (2)
    • marketIds (3)
  • StreamUpdate matches with correct field numbers and oneof:

    • blockHeight (1)
    • execMode (2)
    • oneof updateMessage:
      • orderbookUpdate (3)
      • orderFill (4)
      • takerOrder (5)
      • subaccountUpdate (6)
      • priceUpdate (7)

All field types, structures and message definitions are consistent between the TypeScript code and proto definitions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check proto definitions for field numbers and types

# Find and check the corresponding proto file
fd -e proto -x grep -l "StreamOrderbookUpdatesRequest\|StreamUpdate" {} \; | xargs cat

# Verify field numbers and types
rg "market_ids.*=.*3" --type proto
rg "price_update.*=.*7" --type proto

Length of output: 10377

indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts (12)

83-88: Addition of new imports for the 'prices' module is appropriate.

The newly added imports for ./prices/streaming and ./prices/tx enhance the functionality of the prices module. These additions are correctly implemented.


332-335: Updates to the 'prices' module exports are correct.

The export for the prices module now appropriately includes the new modules _87, _88, _148, _168, and _187. This ensures that all functionalities are properly exported.


337-345: Inclusion of new modules in 'ratelimit' exports is valid.

The ratelimit export now includes the additional modules, which enhances its capabilities. The updates are implemented correctly.


347-354: Revisions to the 'revshare' module exports are appropriate.

The added modules to the revshare export are correctly integrated, ensuring expanded functionality.


356-363: Enhancements to the 'rewards' module exports are correctly implemented.

The export now includes the necessary modules to support new features in the rewards module.


365-370: 'Sending' module exports updated appropriately.

The inclusion of new modules in the sending export is correct and aligns with the changes made in the imports.


372-379: Updates to the 'stats' module exports are valid.

The stats export now properly includes the additional modules, ensuring comprehensive functionality.


381-388: 'Subaccounts' module exports are correctly updated.

The export modifications for the subaccounts module are appropriate and correctly implemented.


390-395: Enhancements to the 'vault' module exports are appropriate.

The updates ensure that all new functionalities in the vault module are properly exported.


400-407: 'Vest' module exports updated correctly.

The vest export now includes the necessary modules, reflecting the changes in the imports.


408-410: ClientFactory exports are properly updated.

The ClientFactory now includes the new modules _195, _196, and _197, ensuring that the client can utilize the latest functionalities.


126-135: Verify potential missing imports due to numbering gap.

There is a gap in the import numbering from _129 to _137, which could indicate that imports for modules _130 to _136 are missing. Please ensure all necessary modules are included.

Run the following script to check for missing module imports in bundle.ts:

option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/prices/types";

// StreamPriceUpdate provides information on a price update.
message StreamPriceUpdate {
Copy link
Contributor

@teddyding teddyding Nov 20, 2024

Choose a reason for hiding this comment

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

Do we need to add this to StagedFinalizeBlockEvent? We probably want price update streams to go through similar flows (store in transient store, stream in Precommit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

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

🧹 Outside diff range and nitpick comments (1)
proto/dydxprotocol/clob/streaming.proto (1)

Line range hint 11-18: Consider the impact on stream consumers and performance

The addition of price updates to the streaming system has several implications to consider:

  1. Ensure consumers can handle the increased message frequency from price updates
  2. Consider implementing rate limiting or batching for high-frequency price updates
  3. Document the expected update frequency for consumers
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 01818ed and 48889e4.

⛔ Files ignored due to path filters (1)
  • protocol/x/clob/types/streaming.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/streaming.ts (5 hunks)
  • proto/dydxprotocol/clob/streaming.proto (2 hunks)
🔇 Additional comments (9)
proto/dydxprotocol/clob/streaming.proto (2)

5-5: LGTM: Import statement follows protobuf conventions

The new import for prices streaming proto is properly placed and follows the package structure conventions.


17-17: LGTM: Field addition follows protobuf best practices

The addition of the price_update field to the oneof event is well-structured and maintains backward compatibility. The field number 4 follows the sequential ordering.

Let's verify the field number uniqueness and message structure:

✅ Verification successful

Let me gather more information about the StreamPriceUpdate message structure since the previous command didn't show its definition.


Let me check one more thing to verify the StreamPriceUpdate message import and definition.


Field number and message structure verified successfully

The verification confirms:

  • Field number 4 is unique within the StagedFinalizeBlockEvent message
  • StreamPriceUpdate message is properly defined in prices/streaming.proto with a clear structure
  • The import statement is correctly added to clob/streaming.proto
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify field number uniqueness and message structure

# Check for any other usage of field number 4 in this message
rg -A 10 "StagedFinalizeBlockEvent" | rg "= 4"

# Verify the structure of StreamPriceUpdate message
ast-grep --pattern 'message StreamPriceUpdate {
  $$$
}'

Length of output: 205


Script:

#!/bin/bash
# Search for StreamPriceUpdate message definition in prices proto files
fd "prices" --extension proto --exec cat {} | rg -A 10 "message StreamPriceUpdate"

# Also verify there are no other field number 4 usages in the same message
rg -B 5 -A 5 "StagedFinalizeBlockEvent" proto/dydxprotocol/clob/streaming.proto

Length of output: 681


Script:

#!/bin/bash
# Check if the prices/streaming.proto file exists and show its content
fd "streaming.proto" --full-path | grep "prices" | xargs cat

# Verify the import statement is correctly added
rg "import.*prices/streaming.proto" proto/dydxprotocol/clob/streaming.proto

Length of output: 716

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/streaming.ts (7)

3-3: LGTM: Import statement is correctly structured

The new import for StreamPriceUpdate types follows the existing pattern and is properly organized with other streaming-related imports.


12-12: LGTM: Interface updates maintain consistency

The new price update fields are properly added to both interfaces with:

  • Correct naming conventions (camelCase/snake_case)
  • Consistent optional field marking
  • Appropriate type references

Also applies to: 20-20


27-28: LGTM: Base object initialization is consistent

The initialization of the new priceUpdate field follows the established pattern of setting optional fields to undefined.


46-49: LGTM: Protocol Buffer encoding is correctly implemented

The encoding logic for priceUpdate follows the Protocol Buffers wire format specification:

  • Correct field number (4)
  • Proper wire type for message (2)
  • Consistent with other message field encodings

74-77: LGTM: Protocol Buffer decoding is correctly implemented

The decoding logic for priceUpdate is properly implemented:

  • Correct field number in switch case
  • Proper use of StreamPriceUpdate.decode
  • Maintains consistency with other field decodings

92-92: LGTM: Partial object creation is properly implemented

The fromPartial implementation for priceUpdate correctly handles:

  • Null/undefined checks
  • Type conversion using StreamPriceUpdate.fromPartial
  • Consistent with other field implementations

Line range hint 1-96: Verify consistency with source proto file

Since this is generated code, it's important to ensure that these changes align with the corresponding proto file definitions.

✅ Verification successful

Generated code matches proto definition perfectly

The TypeScript code in indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/streaming.ts is correctly generated from the proto definition in proto/dydxprotocol/clob/streaming.proto. The generated interface matches the proto message structure exactly:

  • All fields are present with correct types and numbers (orderFill:1, subaccountUpdate:2, orderbookUpdate:3, priceUpdate:4)
  • Imports correctly reflect the cross-package references (subaccounts, prices)
  • The oneof event semantics is properly translated to optional fields in TypeScript
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the corresponding proto file definition
rg -A 10 "message StagedFinalizeBlockEvent" --type proto

Length of output: 88


Script:

#!/bin/bash
# Let's find proto files without relying on file type
fd -e proto | xargs rg -A 10 "message StagedFinalizeBlockEvent"

Length of output: 771

@jayy04 jayy04 merged commit e700de9 into main Nov 21, 2024
39 checks passed
@jayy04 jayy04 deleted the jy/price-proto branch November 21, 2024 00:13
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