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(eibc): Expand list-demand-orders query with more parameters #851

Merged
merged 17 commits into from
Jun 10, 2024

Conversation

zale144
Copy link
Contributor

@zale144 zale144 commented Apr 17, 2024

Description


Closes #849

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here

----;

For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

---;

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

Summary by CodeRabbit

  • New Features

    • Introduced demand order filters for type, rollapp ID, and limit to enhance querying capabilities.
  • Refactor

    • Refactored query and filtering mechanisms to support new demand order filters, improving maintainability and flexibility.
  • Bug Fixes

    • Updated error handling for invalid statuses in demand order queries.
  • Tests

    • Enhanced test cases to validate new filtering options and ensure robust demand order functionality.
  • Chores

    • Updated documentation and comments to reflect the new demand order filter features.

@zale144 zale144 self-assigned this Apr 17, 2024
@zale144 zale144 force-pushed the zale144/849-list-demand-orders-filters branch from 43fc95c to 1e4569d Compare April 23, 2024 18:19
@zale144 zale144 changed the base branch from main to zale144/850-query-delayedack-by-type April 23, 2024 18:22
@zale144 zale144 changed the title Expand list-demand-orders query with more parameters chore(eibc): Expand list-demand-orders query with more parameters Apr 23, 2024
@zale144 zale144 marked this pull request as ready for review April 23, 2024 18:24
@zale144 zale144 requested a review from a team as a code owner April 23, 2024 18:24
@omritoptix omritoptix changed the title chore(eibc): Expand list-demand-orders query with more parameters feat(eibc): Expand list-demand-orders query with more parameters Apr 23, 2024
if err != nil {
return fmt.Errorf("limit must be an integer: %s", args[3])
}
request.Limit = int32(limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why we use limit instead of Pagination in cosmos-sdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, the intent of this added filtering is just for debugging, it's not supposed to be for end users

Copy link

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

proto/dymension/eibc/demand_order.proto Outdated Show resolved Hide resolved
proto/dymension/eibc/query.proto Outdated Show resolved Hide resolved
@@ -26,6 +26,7 @@ func PendingByRollappIDByMaxHeight(
End: commontypes.RollappPacketByStatusByRollappIDByProofHeightPrefix(rollappID, status, maxProofHeight+1), // inclusive end
},
},
FilterFunc: func(packet commontypes.RollappPacket) bool { return true },
Copy link
Contributor

Choose a reason for hiding this comment

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

should define it (func(packet commontypes.RollappPacket) bool { return true } )and reuse for readability

Base automatically changed from zale144/850-query-delayedack-by-type to main May 29, 2024 06:57
Copy link
Contributor

Choose a reason for hiding this comment

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

state breaking? will require migration

x/eibc/keeper/keeper.go Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Jun 10, 2024

Walkthrough

The changes introduce enhanced filtering capabilities for demand orders by adding support for filtering by type, rollapp ID, and limit. This includes modifications across various files to implement the new filters, update function signatures, and adjust tests accordingly.

Changes

Files/Paths Change Summaries
CHANGELOG.md Added summary of changes related to demand order filters.
ibctesting/eibc_test.go Updated imports, comments, and function calls for JSON unmarshalling and demand order filtering.
proto/dymension/eibc/demand_order.proto Added fields rollapp_id and type to DemandOrder message.
proto/dymension/eibc/query.proto Added imports and modified QueryDemandOrdersByStatusRequest message to include new fields.
x/eibc/client/cli/query_command_orders.go Updated CmdListDemandOrdersByStatus to handle new query parameters.
x/eibc/keeper/demand_order_test.go Modified test cases to include new filter parameter.
x/eibc/keeper/grpc_query.go Refactored DemandOrdersByStatus to incorporate new filtering logic.
x/eibc/keeper/grpc_query_test.go Updated handling of Status field in query tests.
x/eibc/keeper/invariants.go Added additional parameter to ListDemandOrdersByStatus calls.
x/eibc/keeper/keeper.go Modified ListDemandOrdersByStatus to accept new parameters and apply filtering logic.
x/eibc/types/demand_order.go Added RollappId and Type fields to NewDemandOrder and updated event attributes.
x/eibc/types/types.go Added new attributes related to demand order filtering.

Assessment against linked issues

Objective Addressed Explanation
Add filters to list-demand-orders (Issue #849)

Poem

In fields of code where logic hops,
New filters bloom, the queries pop,
By rollapp ID, type, and more,
Demand orders we now explore.
With limits set, the data flows,
A rabbit's joy, as progress shows. 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@zale144 zale144 requested a review from mtsitrin June 10, 2024 13:28
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: 5

Outside diff range and nitpick comments (5)
proto/dymension/eibc/demand_order.proto (1)

Line range hint 1-1: State migration may be required due to structural changes in stored data.

Please ensure a migration strategy is in place for these changes.

x/eibc/keeper/demand_order_test.go (1)

Line range hint 31-44: Consider adding more comprehensive tests to cover all new scenarios introduced by the additional parameters.

Would you like assistance in drafting these additional tests?

x/eibc/client/cli/query_command_orders.go (1)

52-52: The use of a simple limit for debugging purposes, as explained, is acceptable. However, consider documenting this clearly to avoid confusion about its intended use.

x/eibc/keeper/keeper.go (1)

Line range hint 160-188: Optimize the demand order listing with limit and filter options.

The current implementation processes all entries before applying the limit, which could be inefficient for large datasets. Consider applying the limit and filters directly in the database query if possible, or restructuring the loop to break early once the limit is reached and all filters are applied.

- for ; iterator.Valid(); iterator.Next() {
-     if limit > 0 && len(list) >= limit {
-         break
-     }
-     var val types.DemandOrder
-     k.cdc.MustUnmarshal(iterator.Value(), &val)
-     for _, opt := range opts {
-         if !opt(val) {
-             continue
-         }
-     }
-     list = append(list, &val)
- }
+ for ; iterator.Valid() && (limit <= 0 || len(list) < limit); iterator.Next() {
+     var val types.DemandOrder
+     k.cdc.MustUnmarshal(iterator.Value(), &val)
+     if !opts.All(val) {
+         continue
+     }
+     list = append(list, &val)
+ }
ibctesting/eibc_test.go (1)

Line range hint 234-330: Review the logic for handling IBC packet transfers and demand order fulfillment.

The test logic for handling IBC packet transfers and demand order fulfillment appears complex and could potentially be simplified or broken down into smaller, more manageable functions. Additionally, ensure that all edge cases are covered, such as handling of timeouts and error acknowledgements effectively.

- // complex nested logic here
+ // proposed refactoring or simplification here
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a74ffb0 and b3bfdce.

Files ignored due to path filters (3)
  • x/eibc/types/demand_order.pb.go is excluded by !**/*.pb.go
  • x/eibc/types/query.pb.go is excluded by !**/*.pb.go
  • x/eibc/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (12)
  • CHANGELOG.md (1 hunks)
  • ibctesting/eibc_test.go (4 hunks)
  • proto/dymension/eibc/demand_order.proto (2 hunks)
  • proto/dymension/eibc/query.proto (2 hunks)
  • x/eibc/client/cli/query_command_orders.go (1 hunks)
  • x/eibc/keeper/demand_order_test.go (3 hunks)
  • x/eibc/keeper/grpc_query.go (2 hunks)
  • x/eibc/keeper/grpc_query_test.go (2 hunks)
  • x/eibc/keeper/invariants.go (2 hunks)
  • x/eibc/keeper/keeper.go (3 hunks)
  • x/eibc/types/demand_order.go (3 hunks)
  • x/eibc/types/types.go (1 hunks)
Additional context used
LanguageTool
CHANGELOG.md

[uncategorized] ~85-~85: Do not mix variants of the same word (‘acknowledgement’ and ‘acknowledgment’) within a single text. (EN_WORD_COHERENCY)
Context: ....com//issues/822) Acknowledgement not written in case of ackerr - (rollap...

Additional comments not posted (10)
x/eibc/types/types.go (1)

11-13: The addition of new attribute keys aligns well with the expanded functionality of demand orders.

proto/dymension/eibc/demand_order.proto (2)

6-6: Import of rollapp_packet.proto is necessary for the new fields and is correctly placed.


31-33: Addition of rollapp_id and type fields to the DemandOrder message supports the new filtering capabilities as described in the PR.

x/eibc/keeper/demand_order_test.go (1)

31-31: The tests have been updated to include the new limit parameter, ensuring the new functionality is covered.

Also applies to: 41-41, 44-44

x/eibc/client/cli/query_command_orders.go (1)

18-53: The CLI command has been correctly updated to handle the new optional parameters for querying demand orders. The parsing and error handling for these parameters are well-implemented.

proto/dymension/eibc/query.proto (2)

9-10: Ensure the newly added imports are utilized effectively in the file.


48-54: The addition of status, type, rollapp_id, and limit fields in QueryDemandOrdersByStatusRequest aligns with the PR objectives to enhance the query's flexibility.

x/eibc/keeper/invariants.go (1)

33-33: The addition of a 0 as a parameter in calls to ListDemandOrdersByStatus seems to be a placeholder for limit. Confirm that this is the intended usage and that it aligns with the new function signature.

Also applies to: 38-38, 43-43

Verification successful

The usage of the 0 parameter in the ListDemandOrdersByStatus function calls is consistent with the new function signature and is intended as a placeholder for the limit parameter.

  • x/eibc/keeper/invariants.go: Lines 33, 38, 43
  • x/eibc/keeper/grpc_query.go: Line with ListDemandOrdersByStatus call
  • x/eibc/keeper/demand_order_test.go: Lines with ListDemandOrdersByStatus calls
  • ibctesting/eibc_test.go: Line with ListDemandOrdersByStatus call
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the `0` parameter in `ListDemandOrdersByStatus` calls.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'ListDemandOrdersByStatus'

Length of output: 1557

x/eibc/keeper/grpc_query.go (1)

58-64: The implementation of filtering in DemandOrdersByStatus using filterOpts is a robust enhancement that aligns with the PR's objectives to add more granular control over the query results.

x/eibc/types/demand_order.go (1)

75-77: The inclusion of RollappId and Type in the GetEvents method ensures that these attributes are available for event handling and logging, which is crucial for traceability.

Comment on lines +67 to +94
func filterOpts(req *types.QueryDemandOrdersByStatusRequest) []filterOption {
var opts []filterOption
if req.RollappId != "" {
opts = append(opts, isRollappId(req.RollappId))
}
ctx := sdk.UnwrapSDKContext(goCtx)
if req.Type != commontypes.RollappPacket_UNDEFINED {
opts = append(opts, isOrderType(req.Type))
}
return opts
}

// Get the demand orders by status
demandOrders, err := q.ListDemandOrdersByStatus(ctx, statusValue)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
type filterOption func(order types.DemandOrder) bool

func isRollappId(rollappId string) filterOption {
return func(order types.DemandOrder) bool {
return order.RollappId == rollappId
}
}

// Construct the response
return &types.QueryDemandOrdersByStatusResponse{DemandOrders: demandOrders}, nil
func isOrderType(orderType ...commontypes.RollappPacket_Type) filterOption {
return func(order types.DemandOrder) bool {
for _, ot := range orderType {
if order.Type == ot {
return true
}
}
return 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 helper functions filterOpts, isRollappId, and isOrderType are well-implemented to support the new filtering functionality. Ensure that these functions are covered by unit tests to verify their behavior.

Would you like me to help in writing these unit tests?

Comment on lines +29 to +30
RollappId: rollappPacket.RollappId,
Type: rollappPacket.Type,
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The ValidateBasic method in demand_order.go does not include validation for the newly added fields RollappId and Type. This oversight needs to be addressed to ensure the integrity of the data.

  • RollappId should be validated to ensure it is not empty and follows any specific format or constraints required.
  • Type should be validated to ensure it is within the expected set of values.

Please add the necessary validation logic for these fields in the ValidateBasic method.

  • [x/eibc/types/demand_order.go:34-59]
Analysis chain

The addition of RollappId and Type fields in the NewDemandOrder function is correctly implemented. Ensure these fields are validated appropriately in the ValidateBasic method.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the validation logic for `RollappId` and `Type`.

# Test: Search for validation logic in the `ValidateBasic` method.
rg --type go $'ValidateBasic'

Length of output: 4426



Script:

#!/bin/bash
# Extract the ValidateBasic method from demand_order.go to inspect its content.
ast-grep --lang go --pattern $'func (m *DemandOrder) ValidateBasic() error {
  $$$
}' x/eibc/types/demand_order.go

Length of output: 1572

@@ -76,15 +77,15 @@ func (suite *KeeperTestSuite) TestQueryDemandOrdersByStatus() {
suite.Require().NoError(err)

// Query demand orders by status
res, err := suite.queryClient.DemandOrdersByStatus(sdk.WrapSDKContext(suite.Ctx), &types.QueryDemandOrdersByStatusRequest{Status: status.String()})
res, err := suite.queryClient.DemandOrdersByStatus(sdk.WrapSDKContext(suite.Ctx), &types.QueryDemandOrdersByStatusRequest{Status: status})
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for invalid status codes.

The function DemandOrdersByStatus should handle invalid status codes gracefully by returning an appropriate error message. This ensures that the system behaves predictably even with unexpected inputs.

suite.Require().NoError(err)
suite.Require().NotNil(res.DemandOrders)
suite.Require().Len(res.DemandOrders, 1, fmt.Sprintf("Expected 1 demand order for status %s, but got %d", status, len(res.DemandOrders)))
suite.Require().Equal(demandOrder.Id, res.DemandOrders[0].Id)
}

// Query with invalid status should return an error
res, err := suite.queryClient.DemandOrdersByStatus(sdk.WrapSDKContext(suite.Ctx), &types.QueryDemandOrdersByStatusRequest{Status: "INVALID"})
res, err := suite.queryClient.DemandOrdersByStatus(sdk.WrapSDKContext(suite.Ctx), &types.QueryDemandOrdersByStatusRequest{Status: -1})
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test case for handling unexpected status values.

It's good to see error handling for an invalid status code. Consider adding more test cases for other potential invalid inputs to ensure robust error handling across the board.

@@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- (delayedack) [#849](https://github.com/dymensionxyz/dymension/issues/849) Add demand order filters: type, rollapp id and limit
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistency in terminology within documentation.

The term 'acknowledgement' is used here, but elsewhere 'acknowledgment' might be used. It's best to stick to one spelling to maintain consistency across the documentation.

- Acknowledgement not written in case of ackerr
+ Acknowledgment not written in case of ackerr

Committable suggestion was skipped due to low confidence.

@mtsitrin mtsitrin merged commit c3d9307 into main Jun 10, 2024
55 of 88 checks passed
@mtsitrin mtsitrin deleted the zale144/849-list-demand-orders-filters branch June 10, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add filters to list-demand-oders
4 participants