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(x/warden): resolve space.owners for SignIntents #159

Merged
merged 3 commits into from
Apr 5, 2024
Merged

Conversation

Pitasi
Copy link
Contributor

@Pitasi Pitasi commented Apr 5, 2024

Intents referencing warden.space.owners were only working when used for Actions that had a SpaceId field in the message, this is not the case for NewSignatureRequest and NewSignTransactionRequest that only have a KeyId field instead.

From the Key it's possible to go back to its Space, which is what PR adds to x/warden intent's expander.

Summary by CodeRabbit

  • Refactor
    • Updated context handling in key management functions for improved alignment with Go standards.
    • Enhanced the shield expansion logic to support additional key identification methods.

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Apr 5, 2024

Warning

Rate Limit Exceeded

@Pitasi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 20 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 89d9d0d and 4e946cd.

Walkthrough

The changes encompass enhancing context management in the KeysKeeper struct by transitioning to context.Context from sdk.Context, ensuring better compatibility with Go's context handling. Furthermore, the WardenShieldExpander struct has been refined to streamline the extraction of SpaceId by introducing an interface for retrieving keyID from a message, leading to improved data retrieval and processing efficiencies in the system.

Changes

File Summary
.../keeper/keys.go, .../keeper/shield.go Updated KeysKeeper functions to use context.Context and improved SpaceId retrieval in WardenShieldExpander through new interface integration.

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.

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.
  • 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/coderabbit-overrides.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: 5

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between e3a980b and db305d0.
Files selected for processing (2)
  • warden/x/warden/keeper/keys.go (2 hunks)
  • warden/x/warden/keeper/shield.go (2 hunks)
Additional Context Used
Path-based Instructions (2)
warden/x/warden/keeper/keys.go (1)

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

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

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

@@ -26,16 +27,16 @@ func NewKeysKeeper(sb *collections.SchemaBuilder, cdc codec.BinaryCodec) KeysKee
}
}

func (k KeysKeeper) New(ctx sdk.Context, key types.Key, keyRequest types.KeyRequest) error {
func (k KeysKeeper) New(ctx context.Context, key types.Key, keyRequest types.KeyRequest) error {
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 and logging for context cancellation in New method.

func (k KeysKeeper) New(ctx context.Context, key types.Key, keyRequest types.KeyRequest) error {
+  if ctx.Err() != nil {
+    return ctx.Err()
+  }
   key.Id = keyRequest.Id
   return k.Set(ctx, key)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (k KeysKeeper) New(ctx context.Context, key types.Key, keyRequest types.KeyRequest) error {
func (k KeysKeeper) New(ctx context.Context, key types.Key, keyRequest types.KeyRequest) error {
if ctx.Err() != nil {
return ctx.Err()
}
key.Id = keyRequest.Id
return k.Set(ctx, key)
}

key.Id = keyRequest.Id
return k.Set(ctx, key)
}

func (k KeysKeeper) Get(ctx sdk.Context, id uint64) (types.Key, error) {
func (k KeysKeeper) Get(ctx context.Context, id uint64) (types.Key, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify context cancellation handling in Get method.

func (k KeysKeeper) Get(ctx context.Context, id uint64) (types.Key, error) {
+  if ctx.Err() != nil {
+    return types.Key{}, ctx.Err()
+  }
   return k.keys.Get(ctx, id)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (k KeysKeeper) Get(ctx context.Context, id uint64) (types.Key, error) {
func (k KeysKeeper) Get(ctx context.Context, id uint64) (types.Key, error) {
if ctx.Err() != nil {
return types.Key{}, ctx.Err()
}
return k.keys.Get(ctx, id)
}

return k.keys.Get(ctx, id)
}

func (k KeysKeeper) Set(ctx sdk.Context, key types.Key) error {
func (k KeysKeeper) Set(ctx context.Context, key types.Key) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add context cancellation check in Set method to ensure graceful handling.

func (k KeysKeeper) Set(ctx context.Context, key types.Key) error {
+  if ctx.Err() != nil {
+    return ctx.Err()
+  }
   if err := k.keysBySpace.Set(ctx, collections.Join(key.SpaceId, key.Id)); err != nil {
       return err
   }
   return k.keys.Set(ctx, key.Id, key)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (k KeysKeeper) Set(ctx context.Context, key types.Key) error {
func (k KeysKeeper) Set(ctx context.Context, key types.Key) error {
if ctx.Err() != nil {
return ctx.Err()
}
if err := k.keysBySpace.Set(ctx, collections.Join(key.SpaceId, key.Id)); err != nil {
return err
}
return k.keys.Set(ctx, key.Id, key)
}

@@ -20,7 +20,7 @@ func (w WardenShieldExpander) Expand(goCtx context.Context, ident *ast.Identifie
ctx := cosmoshield.UnwrapContext(goCtx)
msg := ctx.Msg()

spaceID, err := extractSpaceID(msg)
spaceID, err := w.extractSpaceID(ctx, msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding detailed error messages to improve debugging in Expand method.

if err != nil {
-   return nil, err
+   return nil, fmt.Errorf("failed to extract SpaceID: %w", err)
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
spaceID, err := w.extractSpaceID(ctx, msg)
spaceID, err := w.extractSpaceID(ctx, msg)
if err != nil {
return nil, fmt.Errorf("failed to extract SpaceID: %w", err)
}

Comment on lines 56 to 67
func (w WardenShieldExpander) extractSpaceID(ctx context.Context, msg sdk.Msg) (uint64, error) {
if msg, ok := msg.(getSpaceIder); ok {
return msg.GetSpaceId(), nil
}
if msg, ok := msg.(getKeyIder); ok {
keyID := msg.GetKeyId()
key, err := w.keeper.KeysKeeper.Get(ctx, keyID)
if err != nil {
return 0, err
}
return key.SpaceId, 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 extractSpaceID to reduce nesting and improve readability.

func (w WardenShieldExpander) extractSpaceID(ctx context.Context, msg sdk.Msg) (uint64, error) {
-   if msg, ok := msg.(getSpaceIder); ok {
-       return msg.GetSpaceId(), nil
-   }
-   if msg, ok := msg.(getKeyIder); ok {
-       keyID := msg.GetKeyId()
-       key, err := w.keeper.KeysKeeper.Get(ctx, keyID)
-       if err != nil {
-           return 0, err
-       }
-       return key.SpaceId, nil
-   }
-   return 0, fmt.Errorf("message does not have a SpaceId field")
+   switch msg := msg.(type) {
+   case getSpaceIder:
+       return msg.GetSpaceId(), nil
+   case getKeyIder:
+       keyID := msg.GetKeyId()
+       key, err := w.keeper.KeysKeeper.Get(ctx, keyID)
+       if err != nil {
+           return 0, fmt.Errorf("failed to get key by ID: %w", err)
+       }
+       return key.SpaceId, nil
+   default:
+       return 0, fmt.Errorf("message does not have a SpaceId or KeyId field")
+   }
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (w WardenShieldExpander) extractSpaceID(ctx context.Context, msg sdk.Msg) (uint64, error) {
if msg, ok := msg.(getSpaceIder); ok {
return msg.GetSpaceId(), nil
}
if msg, ok := msg.(getKeyIder); ok {
keyID := msg.GetKeyId()
key, err := w.keeper.KeysKeeper.Get(ctx, keyID)
if err != nil {
return 0, err
}
return key.SpaceId, nil
}
func (w WardenShieldExpander) extractSpaceID(ctx context.Context, msg sdk.Msg) (uint64, error) {
switch msg := msg.(type) {
case getSpaceIder:
return msg.GetSpaceId(), nil
case getKeyIder:
keyID := msg.GetKeyId()
key, err := w.keeper.KeysKeeper.Get(ctx, keyID)
if err != nil {
return 0, fmt.Errorf("failed to get key by ID: %w", err)
}
return key.SpaceId, nil
default:
return 0, fmt.Errorf("message does not have a SpaceId or KeyId field")
}
}

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

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between db305d0 and 89d9d0d.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional Context Used
Path-based Instructions (1)
CHANGELOG.md (1)

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

Additional comments not posted (1)
CHANGELOG.md (1)

52-58: > 📝 NOTE

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

Review and correct grammatical errors and spelling mistakes throughout the CHANGELOG.md file. For instance, ensure proper capitalization and spelling of technical terms and identifiers.

Would you like assistance in performing a comprehensive grammar and spelling check on this document?

@@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* (shield) [#148](https://github.com/warden-protocol/wardenprotocol/pull/148) Use protobufs for defining the AST
* (x/intent) [#155](https://github.com/warden-protocol/wardenprotocol/pull/155) Add MsgUpdateIntent, creators of an Intent can use it to change name and definition of their Intents.
* (x/warden) [#159](https://github.com/warden-protocol/wardenprotocol/pull/159) Resolve `warden.space.owners` in Intent definitions for MsgNewSignatureRequest and MsgNewSignTransactionRequest
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the entry for PR #159 in the changelog is clear and accurately reflects the changes made.

- * (x/warden) [#159](https://github.com/warden-protocol/wardenprotocol/pull/159) Resolve `warden.space.owners` in Intent definitions for MsgNewSignatureRequest and MsgNewSignTransactionRequest
+ * (x/warden) [#159](https://github.com/warden-protocol/wardenprotocol/pull/159) Enhanced the resolution of `warden.space.owners` within Intent definitions to support `MsgNewSignatureRequest` and `MsgNewSignTransactionRequest`, improving module versatility.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* (x/warden) [#159](https://github.com/warden-protocol/wardenprotocol/pull/159) Resolve `warden.space.owners` in Intent definitions for MsgNewSignatureRequest and MsgNewSignTransactionRequest
* (x/warden) [#159](https://github.com/warden-protocol/wardenprotocol/pull/159) Enhanced the resolution of `warden.space.owners` within Intent definitions to support `MsgNewSignatureRequest` and `MsgNewSignTransactionRequest`, improving module versatility.

@Pitasi Pitasi merged commit 20caac3 into main Apr 5, 2024
9 checks passed
@Pitasi Pitasi deleted the fix-sign-intents branch April 5, 2024 13:33
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.

1 participant