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

bug: Handle paginated querying to prices-keeper in slinky + pricefeed daemon #1177

Merged

Conversation

nivasan1
Copy link
Contributor

@nivasan1 nivasan1 commented Mar 14, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

Unit testing + changes loadtested using petri

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

Walkthrough

The recent updates focus on optimizing the efficiency and reliability of fetching market parameters within a blockchain protocol's daemons. The changes involve transitioning to a new method of retrieving market parameters in a paginated manner to enhance data handling and reduce network resource load. These optimizations are applied consistently across various components, such as market pair fetching and price feed updates, leading to a more scalable and robust system for managing market data.

Changes

Files Summary
protocol/daemons/slinky/client/market_pair_fetcher.go Updated FetchIdMappings in MarketPairFetcherImpl to use a new function for retrieving market parameters, adjusting data handling accordingly.
protocol/daemons/pricefeed/client/sub_task_runner.go Replaced pricesQueryClient.AllMarketParams with daemonlib.AllPaginatedMarketParams in RunMarketParamUpdaterTaskLoop; configs.UpdateMarkets now directly takes marketParams.
protocol/daemons/types/paginated_grpc_request.go
protocol/daemons/shared/paginated_grpc_request.go
Introduced functionality for handling paginated gRPC requests, including fetching and managing MarketParams pagination. Defined interfaces for paginated responses and queries.
protocol/daemons/types/paginated_grpc_request_test.go
protocol/daemons/shared/paginated_grpc_request_test.go
Added tests for paginated gRPC request functionality, focusing on querying market parameters with pagination and ensuring correct aggregation and error handling.

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.

@nivasan1 nivasan1 changed the title bug: Handle paginated querying to prices-keeper in daemons bug: Handle paginated querying to prices-keeper in slinky + pricefeed daemon Mar 14, 2024
@nivasan1 nivasan1 force-pushed the nv/handle-grpc-request-pagination branch from 6f374ca to 768c4bc Compare March 14, 2024 21:14
@nivasan1 nivasan1 added the bug Something isn't working label Mar 14, 2024
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 c0cd790 and 6f374ca.
Files selected for processing (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go (2 hunks)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (1 hunks)
  • protocol/daemons/types/paginated_grpc_request.go (1 hunks)
  • protocol/daemons/types/paginated_grpc_request_test.go (1 hunks)
Additional comments: 5
protocol/daemons/types/paginated_grpc_request.go (2)
  • 14-37: The implementation of AllPaginatedMarketParams correctly handles pagination for gRPC requests. However, consider adding error logging within the function for better observability and troubleshooting.
  • 48-63: The HandlePaginatedQuery function is well-implemented for handling paginated queries. It's recommended to add comments explaining the logic, especially around the pagination continuation condition, to improve readability.
protocol/daemons/slinky/client/market_pair_fetcher.go (1)
  • 91-96: The update to use AllPaginatedMarketParams in FetchIdMappings is correct and aligns with the PR's objective to handle large datasets efficiently. Ensure that error handling from AllPaginatedMarketParams is adequately addressed downstream.
protocol/daemons/types/paginated_grpc_request_test.go (1)
  • 20-97: The tests for AllPaginatedMarketParams and error handling scenarios are comprehensive and correctly validate the functionality. Consider adding a test case for scenarios where the pagination response is empty or malformed to ensure robustness.
protocol/daemons/pricefeed/client/sub_task_runner.go (1)
  • 352-360: > 📝 NOTE

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

The update to use AllPaginatedMarketParams in RunMarketParamUpdaterTaskLoop is correct and improves the efficiency of market parameter updates. Ensure that the error handling and logging mechanisms are sufficient to identify issues during runtime.

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 c0cd790 and 768c4bc.
Files selected for processing (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go (2 hunks)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (1 hunks)
  • protocol/daemons/types/paginated_grpc_request.go (1 hunks)
  • protocol/daemons/types/paginated_grpc_request_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go
  • protocol/daemons/slinky/client/market_pair_fetcher.go
  • protocol/daemons/types/paginated_grpc_request.go
  • protocol/daemons/types/paginated_grpc_request_test.go

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 768c4bc and 67a1613.
Files selected for processing (3)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (1 hunks)
  • protocol/daemons/types/paginated_grpc_request.go (1 hunks)
  • protocol/daemons/types/paginated_grpc_request_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protocol/daemons/slinky/client/market_pair_fetcher.go
  • protocol/daemons/types/paginated_grpc_request.go
  • protocol/daemons/types/paginated_grpc_request_test.go


// AllPaginatedMarketParams returns all MarketParams from the prices module, paginating through the results and
// returning a list of all the aggregated market-params.
func AllPaginatedMarketParams(ctx context.Context, client pricestypes.QueryClient) ([]pricestypes.MarketParam, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe we can move this function to daemons/pricefeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is method is used in both the pricefeed / slinky daemon. Hence I didn't want to introduce a dependency from one of those to the other. Happy to move this into pricefeed if this is not a concern

Copy link
Contributor

@tqin7 tqin7 Mar 15, 2024

Choose a reason for hiding this comment

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

Gotcha makes sense!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 67a1613 and ff6ee5f.
Files selected for processing (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go (3 hunks)
  • protocol/daemons/shared/paginated_grpc_request.go (1 hunks)
  • protocol/daemons/shared/paginated_grpc_request_test.go (1 hunks)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/daemons/pricefeed/client/sub_task_runner.go
  • protocol/daemons/slinky/client/market_pair_fetcher.go
Additional comments: 4
protocol/daemons/shared/paginated_grpc_request.go (2)
  • 10-11: The PaginatedRequestLimit is set to 10,000, which might be too high for certain environments or could lead to memory issues if not handled properly. Consider making this configurable or validating this choice with load testing to ensure it's a safe default for your system's expected load and infrastructure capabilities.
  • 14-37: The AllPaginatedMarketParams function correctly implements paginated querying to fetch all market parameters. However, it's important to ensure that the client.AllMarketParams call does not have any side effects or limitations on the number of items it can fetch in a single call that could affect the pagination logic. Additionally, consider adding error handling for potential issues with the network or the gRPC service itself, ensuring robustness in real-world scenarios.
protocol/daemons/shared/paginated_grpc_request_test.go (2)
  • 20-97: The test TestPaginatedGRPCRequests effectively covers the scenario of successfully fetching paginated market parameters. It's well-structured and mocks the expected behavior of the gRPC client. However, consider adding assertions to verify that the pagination requests are made with the correct NextKey values and that the limit is respected in each request. This would ensure the pagination logic is correctly implemented and adheres to the expected behavior.
  • 100-143: The test TestPaginatedGRPCRequestsWithError correctly tests the error handling in the paginated request process. It's important to also test scenarios where errors occur after the first page has been successfully fetched, to ensure the function behaves correctly in partially successful scenarios. This would provide a more comprehensive test coverage for the error handling logic.

Comment on lines +48 to +64
func HandlePaginatedQuery(ctx context.Context, pq PaginatedQuery, initialPagination *query.PageRequest) error {
for {
// make the query
resp, err := pq(ctx, initialPagination)
if err != nil {
return err
}

// break if there is no next-key
if resp.GetPagination() == nil || len(resp.GetPagination().NextKey) == 0 {
return nil
}

// otherwise, update the next-key and continue
initialPagination.Key = resp.GetPagination().NextKey
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The HandlePaginatedQuery function effectively implements the pagination logic. However, it's crucial to consider the potential for infinite loops if the service continuously returns a NextKey. Implementing a safeguard, such as a maximum number of iterations or a timeout, could prevent such scenarios, ensuring the function doesn't hang indefinitely under certain conditions.

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 ff6ee5f and 6dbf4eb.
Files selected for processing (1)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/daemons/slinky/client/market_pair_fetcher.go

@nivasan1 nivasan1 force-pushed the nv/handle-grpc-request-pagination branch from 6dbf4eb to bc4720a Compare March 20, 2024 15:39
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 12e9e28 and bc4720a.
Files selected for processing (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go (3 hunks)
  • protocol/daemons/shared/paginated_grpc_request.go (1 hunks)
  • protocol/daemons/shared/paginated_grpc_request_test.go (1 hunks)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (2 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go
  • protocol/daemons/shared/paginated_grpc_request.go
  • protocol/daemons/shared/paginated_grpc_request_test.go
  • protocol/daemons/slinky/client/market_pair_fetcher.go

@nivasan1 nivasan1 force-pushed the nv/handle-grpc-request-pagination branch from bc4720a to e424602 Compare March 20, 2024 15:47
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 12e9e28 and e424602.
Files selected for processing (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go (3 hunks)
  • protocol/daemons/shared/paginated_grpc_request.go (1 hunks)
  • protocol/daemons/shared/paginated_grpc_request_test.go (1 hunks)
  • protocol/daemons/slinky/client/market_pair_fetcher.go (2 hunks)
Files skipped from review as they are similar to previous changes (4)
  • protocol/daemons/pricefeed/client/sub_task_runner.go
  • protocol/daemons/shared/paginated_grpc_request.go
  • protocol/daemons/shared/paginated_grpc_request_test.go
  • protocol/daemons/slinky/client/market_pair_fetcher.go

@Christopher-Li Christopher-Li merged commit 852930e into dydxprotocol:main Mar 20, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working protocol
Development

Successfully merging this pull request may close these issues.

3 participants