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

feat: CosmWasm Pool raw state query #9006

Merged
merged 11 commits into from
Feb 28, 2025
Merged

feat: CosmWasm Pool raw state query #9006

merged 11 commits into from
Feb 28, 2025

Conversation

crnbarr93
Copy link
Contributor

@crnbarr93 crnbarr93 commented Feb 28, 2025

What is the purpose of the change

These changes add a new query to the x/cosmwasmpool module that allows querying raw contract state. The query also accepts a filtering string for both key and/or value that will only return values that contain the string for the provided filters.

Testing and Verifying

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@crnbarr93 crnbarr93 added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v28.x backport patches to v28.x branch labels Feb 28, 2025
@github-actions github-actions bot added the C:CLI label Feb 28, 2025
@crnbarr93 crnbarr93 marked this pull request as ready for review February 28, 2025 10:15
Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Walkthrough

The change introduces a new raw state query feature for CosmWasm Pools. It updates the changelog with a new feature entry and extends functionalities in the code by adding new RPC methods, Querier methods, and Keeper functions to support filtered state queries. Additionally, the interface for the WasmKeeper is enhanced with a new state iteration method, and corresponding test code is updated to incorporate these changes.

Changes

Files Summary
CHANGELOG.md New entry added in the "State Compatible" section documenting the CosmWasm Pool raw state query feature ([#9006]).
proto/osmosis/…/query.proto, x/cosmwasmpool/client/…/grpc_query.go, x/cosmwasmpool/client/…/query_proto_wrap.go, x/cosmwasmpool/store.go, x/cosmwasmpool/types/…/expected_keepers.go Introduced a new RPC method PoolRawFilteredState with corresponding request/response messages, Querier methods for GRPC and proto wrapping, a Keeper method (GetPoolRawFilteredState) for retrieving filtered state, and an update to the WasmKeeper interface to include IterateContractState.
ingest/sqs/pools/…/alloy_transmuter_test.go Added a new function and field (IterateContractStateFn and IterateContractState) in the mockWasmKeeper struct to support iteration over contract state during tests.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Querier
    participant Keeper
    participant WasmKeeper

    Client->>Querier: PoolRawFilteredState Request
    Querier->>Keeper: GetPoolRawFilteredState(poolId, keyFilter, valueFilter)
    Keeper->>WasmKeeper: IterateContractState(ctx, contractAddress, callback)
    WasmKeeper-->>Keeper: Return filtered state values
    Keeper-->>Querier: Return PoolRawFilteredStateResponse
    Querier-->>Client: PoolRawFilteredState Response
Loading

Suggested labels

C:docs, A:no-changelog

Suggested reviewers

  • p0mvn
  • PaddyMc
  • AlpinYukseloglu
  • mattverse

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a639f0 and 9a1be9e.

📒 Files selected for processing (1)
  • ingest/sqs/pools/transformer/alloy_transmuter_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e
  • GitHub Check: go-split-test-files
  • GitHub Check: check-proto
  • GitHub Check: Run golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (3)
ingest/sqs/pools/transformer/alloy_transmuter_test.go (3)

12-13: LGTM: Import added for CosmWasm pool types

The new import is correctly added and properly organized in the import block.


20-24: LGTM: Mock struct field addition

The addition of IterateContractStateFn to the mockWasmKeeper struct is well structured and follows the existing pattern. The field reformatting improves readability.


42-49: LGTM: Proper implementation of IterateContractState

The implementation correctly follows the same pattern as other methods in this mock, checking if the function is set before using it and properly returning afterward to avoid the panic branch.

This implementation fixes the issue noted in a previous review by adding the return statement after calling the function.

✨ Finishing Touches
  • 📝 Generate Docstrings

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 generate docstrings to generate docstrings for this 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.

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

🧹 Nitpick comments (1)
x/cosmwasmpool/store.go (1)

76-105: Consider performance optimizations for large state queries

The current implementation may not be performant for contracts with large state:

  1. No pagination support means all matching results are loaded into memory
  2. Using bytes.Contains for every key/value pair may be inefficient for large datasets

Consider:

  • Implementing pagination support
  • Adding a limit parameter to cap result size
  • Using more efficient filtering mechanisms
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b1a78d and 9a639f0.

⛔ Files ignored due to path filters (3)
  • proto/osmosis/cosmwasmpool/v1beta1/query.yml is excluded by !**/*.yml
  • x/cosmwasmpool/client/queryproto/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/cosmwasmpool/client/queryproto/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • ingest/sqs/pools/transformer/alloy_transmuter_test.go (2 hunks)
  • proto/osmosis/cosmwasmpool/v1beta1/query.proto (2 hunks)
  • x/cosmwasmpool/client/grpc/grpc_query.go (1 hunks)
  • x/cosmwasmpool/client/query_proto_wrap.go (1 hunks)
  • x/cosmwasmpool/store.go (2 hunks)
  • x/cosmwasmpool/types/expected_keepers.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: go (03)
  • GitHub Check: go (02)
  • GitHub Check: go (01)
  • GitHub Check: go (00)
  • GitHub Check: e2e
  • GitHub Check: Summary
🔇 Additional comments (8)
CHANGELOG.md (1)

53-53: New feature for CosmWasm Pool raw state query added

The changelog entry properly documents the addition of the raw state query feature for CosmWasm Pools, connected to PR #9006. This is correctly placed in the "State Compatible" section since it adds functionality without breaking existing state.

x/cosmwasmpool/client/grpc/grpc_query.go (1)

34-42: Implementation of gRPC handler for PoolRawFilteredState looks correct

The implementation follows the established pattern in the file for other query methods:

  • Proper nil request validation
  • Context unwrapping
  • Delegation to the underlying querier

This is a clean implementation of the gRPC handler for the new raw state query feature.

x/cosmwasmpool/types/expected_keepers.go (1)

61-61: New WasmKeeper interface method for iterating contract state

Adding IterateContractState to the interface provides the necessary functionality to implement the raw state query feature. The method signature correctly includes a callback function pattern that's commonly used for iterating collections in Go.

x/cosmwasmpool/client/query_proto_wrap.go (1)

48-56: Implementation of querier method for raw filtered state

The method correctly delegates to the keeper's GetPoolRawFilteredState function, passing along the request parameters. The error handling and response construction follow the established pattern in the codebase.

proto/osmosis/cosmwasmpool/v1beta1/query.proto (3)

31-35: RPC method looks well-implemented

The new PoolRawFilteredState RPC method is properly defined with appropriate HTTP endpoint mapping.


70-80: Request message well-structured with appropriate field annotations

The PoolRawFilteredStateRequest message is well-defined with clear field descriptions and proper YAML annotations.


82-85: Response message structure looks good

The PoolRawFilteredStateResponse message properly uses a repeated bytes field to return values.

x/cosmwasmpool/store.go (1)

92-93: Address the TODO comment before finalizing

The TODO comment raises an important concern about handling cases where no filter is passed, which could potentially return large amounts of data. Consider implementing pagination or placing a reasonable limit on the number of returned items.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@crnbarr93 crnbarr93 merged commit c2f0905 into main Feb 28, 2025
1 check passed
@crnbarr93 crnbarr93 deleted the connor/cw-pool-raw-query branch February 28, 2025 17:08
mergify bot pushed a commit that referenced this pull request Feb 28, 2025
* feat: orderbook orders raw grpc query

* chore: comment

* ref: generalised pool raw state query

* fix: generate proto

* fix: remove unused keeper

* Generated protofile changes

* chore: changelog

* fix: readd query

* Generated protofile changes

* fix: register new grpc query

* Update ingest/sqs/pools/transformer/alloy_transmuter_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit c2f0905)

# Conflicts:
#	CHANGELOG.md
#	ingest/sqs/pools/transformer/alloy_transmuter_test.go
#	x/cosmwasmpool/client/queryproto/query.pb.go
crnbarr93 added a commit that referenced this pull request Feb 28, 2025
* feat: CosmWasm Pool raw state query (#9006)

* feat: orderbook orders raw grpc query

* chore: comment

* ref: generalised pool raw state query

* fix: generate proto

* fix: remove unused keeper

* Generated protofile changes

* chore: changelog

* fix: readd query

* Generated protofile changes

* fix: register new grpc query

* Update ingest/sqs/pools/transformer/alloy_transmuter_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit c2f0905)

# Conflicts:
#	CHANGELOG.md
#	ingest/sqs/pools/transformer/alloy_transmuter_test.go
#	x/cosmwasmpool/client/queryproto/query.pb.go

* Generated protofile changes

* fix: conflicts

---------

Co-authored-by: Connor Barr <crnbarr@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v28.x backport patches to v28.x branch C:CLI V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants