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

Fix/query sign requests broadcast type #1127

Merged
merged 6 commits into from
Dec 5, 2024

Conversation

mn13
Copy link
Contributor

@mn13 mn13 commented Dec 5, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new OptionalBroadcastType enum for more flexible handling of broadcast types in sign requests.
    • Enhanced the signRequests function to accept the new optional broadcast type parameter.
    • Added the ability for contracts to approve actions and a service for relaying transactions into Ethereum.
  • Bug Fixes

    • Improved error handling and validation for request parameters to prevent runtime errors.
  • Tests

    • Expanded test cases to cover new scenarios for automatic and disabled sign requests.
  • Documentation

    • Updated documentation for the signRequests function to clarify the new optional parameter.

@mn13 mn13 requested review from Svetomech and backsapc December 5, 2024 11:53
@mn13 mn13 self-assigned this Dec 5, 2024
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the IWarden smart contract interface and its associated files. Key updates include the introduction of a new enum OptionalBroadcastType, changes to the signRequests method to utilize this new enum, and enhancements to the ABI metadata. Additionally, the handling of broadcast types in request and response structures has been refined, improving the flexibility of the contract's methods. The changes also encompass adjustments in test cases to reflect the new broadcast type handling.

Changes

File Change Summary
precompiles/warden/IWarden.go - Added import for abi.ConvertType.
- Updated ABI metadata for IWarden contract, changing broadcastType to optionalBroadcastType in signRequests.
- Updated bindIWarden to use GetAbi().
precompiles/warden/IWarden.sol - Added new enum OptionalBroadcastType with values Nonspecified, Disabled, and Automatic.
- Updated signRequests method to use OptionalBroadcastType.
precompiles/warden/abi.json - Changed broadcastType parameter in signRequests from enum BroadcastType to optionalBroadcastType with type enum OptionalBroadcastType.
precompiles/warden/query_types.go - Added OptionalBroadcastType field in signRequestsInput struct.
- Updated newSignRequestsRequest to handle optional broadcast type.
proto/warden/warden/v1beta3/query.proto - Added import for google/protobuf/struct.proto.
- Changed broadcast_type field in QuerySignRequestsRequest to a oneof construct.
tests/cases/warden_precompile_action.go - Renamed variable newSignRequestTx to signRequestAutomatic.
- Added test case for BROADCAST_TYPE_DISABLED.
- Updated assertions for new broadcast types.
warden/x/warden/keeper/query_sign_requests.go - Updated SignRequests method to check OptionalBroadcastType before comparison with value.BroadcastType.

Possibly related PRs

Suggested labels

go-client, keychain

Suggested reviewers

  • artur-abliazimov
  • backsapc
  • Svetomech

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.

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.

This comment has been minimized.

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

🧹 Outside diff range and nitpick comments (3)
tests/cases/warden_precompile_action.go (2)

Line range hint 250-273: Avoid adding +1 to BroadcastType enum values

Adding +1 to BroadcastType enum values to represent optionality can be confusing and error-prone. Consider refactoring to handle optional broadcast types more explicitly.


Line range hint 218-301: Refactor duplicated code into helper functions

The code for creating and asserting new sign requests with different broadcast types is duplicated. Refactor this logic into reusable helper functions to improve maintainability and reduce redundancy.

precompiles/warden/IWarden.sol (1)

116-120: LGTM! Well-structured enum for optional broadcast types.

The new OptionalBroadcastType enum is well-designed with Nonspecified as the default (0), maintaining compatibility with the existing BroadcastType values.

Consider documenting the enum values and their intended usage in comments, especially the relationship between OptionalBroadcastType and BroadcastType.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fae2674 and 29e18ce.

⛔ Files ignored due to path filters (2)
  • api/warden/warden/v1beta3/query.pulsar.go is excluded by !api/**
  • warden/x/warden/types/v1beta3/query.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (7)
  • precompiles/warden/IWarden.go (5 hunks)
  • precompiles/warden/IWarden.sol (2 hunks)
  • precompiles/warden/abi.json (1 hunks)
  • precompiles/warden/query_types.go (1 hunks)
  • proto/warden/warden/v1beta3/query.proto (2 hunks)
  • tests/cases/warden_precompile_action.go (5 hunks)
  • warden/x/warden/keeper/query_sign_requests.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
warden/x/warden/keeper/query_sign_requests.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tests/cases/warden_precompile_action.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

precompiles/warden/query_types.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

precompiles/warden/IWarden.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

📓 Learnings (2)
precompiles/warden/IWarden.sol (1)
Learnt from: Svetomech
PR: warden-protocol/wardenprotocol#1042
File: precompiles/warden/abi.json:1633-1637
Timestamp: 2024-11-14T15:15:53.719Z
Learning: In the `precompiles/warden/abi.json` file, the `broadcastType` parameter in the `newSignRequest` method is intentionally defined as `enum BroadcastType` (uint8), even though it's defined as `int32` in other locations.
precompiles/warden/abi.json (1)
Learnt from: Svetomech
PR: warden-protocol/wardenprotocol#1042
File: precompiles/warden/abi.json:1633-1637
Timestamp: 2024-11-14T15:15:53.719Z
Learning: In the `precompiles/warden/abi.json` file, the `broadcastType` parameter in the `newSignRequest` method is intentionally defined as `enum BroadcastType` (uint8), even though it's defined as `int32` in other locations.
🔇 Additional comments (6)
precompiles/warden/IWarden.go (2)

29-29: Approved: Added reference to suppress unused import errors

The addition of _ = abi.ConvertType correctly suppresses unused import errors.


240-244: Approved: Use of GetAbi() enhances ABI handling

Switching to IWardenMetaData.GetAbi() improves maintainability and reduces potential errors from manual ABI string parsing.

warden/x/warden/keeper/query_sign_requests.go (1)

35-35: Approved: Proper handling of optional broadcast type

The updated condition correctly checks if OptionalBroadcastType is nil before comparing, ensuring accurate filtering logic.

proto/warden/warden/v1beta3/query.proto (1)

185-189: Approved: Use of oneof for optional_broadcast_type

The oneof construct appropriately allows broadcast_type to be optional, enhancing flexibility in request handling.

precompiles/warden/IWarden.sol (1)

440-447: LGTM! Parameter type change enhances query flexibility.

The change from BroadcastType to OptionalBroadcastType in the signRequests function allows for more flexible queries by making the broadcast type optional.

Let's verify that all callers of this function are updated:

✅ Verification successful

Parameter type change appears safe to proceed

Based on the codebase analysis:

  1. The signRequests function is only defined in the interface (IWarden.sol)
  2. No direct calls to this function were found in the codebase
  3. The mock implementation (MockWardenPrecompile.sol) doesn't implement this function
  4. The only usage of IWarden is in BasicOrder.sol which doesn't call this specific function

The change from BroadcastType to OptionalBroadcastType appears to be an interface-only modification with no impact on existing implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for function calls to signRequests to ensure they're updated
rg -A 2 'signRequests.*BroadcastType' --type go --type solidity

Length of output: 98


Script:

#!/bin/bash
# Search for function calls to signRequests with proper file type
rg -t sol 'signRequests\(' -A 2

Length of output: 61


Script:

#!/bin/bash
# First, find all Solidity files
fd '\.sol$' 

# Then search for signRequests function calls in those files
rg 'signRequests\(' --type-add 'sol:*.sol' -t sol -A 2

Length of output: 869


Script:

#!/bin/bash
# Let's check for any implementations or usages of this interface
rg -B 2 -A 5 'IWarden' --type-add 'sol:*.sol' -t sol

Length of output: 5623


Script:

#!/bin/bash
# Let's check the BasicOrder.sol file for any calls to signRequests
rg -B 5 -A 5 'signRequests' --type-add 'sol:*.sol' -t sol solidity/orders/src/BasicOrder.sol

# Also check the mock implementation for any relevant code
rg -B 5 -A 5 'signRequests' --type-add 'sol:*.sol' -t sol solidity/orders/mocks/MockWardenPrecompile.sol

Length of output: 197

precompiles/warden/abi.json (1)

1929-1930: LGTM! ABI changes correctly reflect the interface modifications.

The ABI correctly defines the new parameter type as enum OptionalBroadcastType while maintaining the underlying uint8 type, consistent with Solidity's enum representation.

Comment on lines 399 to 420
if input.OptionalBroadcastType != 0 {
if _, ok := types.BroadcastType_name[int32(input.OptionalBroadcastType-1)]; !ok {
return nil, fmt.Errorf("invalid BroadcastType value: %d", input.OptionalBroadcastType-1)
}

broadcastType := types.QuerySignRequestsRequest_BroadcastType{
BroadcastType: types.BroadcastType(int32(input.OptionalBroadcastType - 1)),
}
return &types.QuerySignRequestsRequest{
Pagination: &input.PageRequest,
KeychainId: input.KeychainId,
Status: types.SignRequestStatus(int32(input.Status)),
OptionalBroadcastType: &broadcastType,
}, nil
} else {
return &types.QuerySignRequestsRequest{
Pagination: &input.PageRequest,
KeychainId: input.KeychainId,
Status: types.SignRequestStatus(int32(input.Status)),
OptionalBroadcastType: nil,
}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid adjusting OptionalBroadcastType by subtracting 1

Subtracting 1 from OptionalBroadcastType to align with the BroadcastType enum can lead to confusion and potential errors. Consider using a more explicit approach to represent optional broadcast types, such as defining a sentinel value or using pointers.

@@ -113,6 +113,12 @@ enum BroadcastType {
Automatic
}

enum OptionalBroadcastType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Tbh, if we just made BroadcastType to have Unspecified value initially, this problem wouldn't occur

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, but it will require migration for existing sign requests

Copy link
Contributor

Choose a reason for hiding this comment

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

@backsapc I did so initially, but as @Pitasi pointed out back then, only 2 enum values are better in this case, since this way we didn't need any migrations

backsapc
backsapc previously approved these changes Dec 5, 2024
Svetomech
Svetomech previously approved these changes Dec 5, 2024
Copy link
Contributor

@Svetomech Svetomech left a comment

Choose a reason for hiding this comment

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

LGTM

@mn13 mn13 dismissed stale reviews from Svetomech and backsapc via 99f3579 December 5, 2024 13:42
Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
warden-help-center ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 1:42pm

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)
CHANGELOG.md (1)

56-56: Improve changelog entry format and clarity

The changelog entry needs some improvements:

  1. Fix grammar: "return" should be "returns"
  2. Add GitHub issue reference as per guidelines
  3. Clarify the change's impact

Consider revising to:

- * (x/warden) Sign requests query return all request (not only with broadcastType=BroadcastType.Disabled)
+ * (x/warden) #1127 Sign requests query returns all requests (previously filtered to only broadcastType=BroadcastType.Disabled)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 29e18ce and 99f3579.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • precompiles/warden/query_types.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • precompiles/warden/query_types.go
🧰 Additional context used
📓 Path-based instructions (1)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

@mn13 mn13 requested review from backsapc and Svetomech December 5, 2024 14:12
@mn13 mn13 merged commit d7f79f9 into main Dec 5, 2024
18 checks passed
@mn13 mn13 deleted the fix/query-sign-requests-broadcast-type branch December 5, 2024 14:23
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.

[Bug] Sign requests query do not return requests with automatic type
3 participants