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

refactor: simplify sign mode (2/2) #23476

Merged
merged 2 commits into from
Jan 22, 2025
Merged

refactor: simplify sign mode (2/2) #23476

merged 2 commits into from
Jan 22, 2025

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jan 22, 2025

Description

we actually do not need to have those converting helpers at all.
Especially internally when someone can extend the sign mode


Author Checklist

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.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Release Notes

  • Improvements

    • Simplified sign mode handling across the SDK
    • Streamlined API interactions related to signature modes
  • Removed Functionality

    • Eliminated APISignModeToInternal and InternalSignModeToAPI conversion methods
    • Removed unnecessary intermediate sign mode conversion steps
  • Technical Updates

    • Updated import and usage of sign mode types from new API package
    • Direct type casting replaced complex conversion logic

These changes simplify the SDK's signing process, making it more straightforward for developers to work with transaction signatures.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jan 22, 2025
@julienrbrt julienrbrt requested a review from tac0turtle January 22, 2025 11:59
@julienrbrt julienrbrt requested review from a team and JulianToledano as code owners January 22, 2025 11:59
Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

📝 Walkthrough

Walkthrough

This pull request focuses on simplifying the handling of sign modes across the Cosmos SDK. The primary changes involve removing the APISignModeToInternal and InternalSignModeToAPI conversion functions, and directly using sign modes from the apisigning package. The modifications streamline the sign mode conversion process by eliminating intermediate conversion steps and reducing dependencies. Files across multiple packages have been updated to reflect this new approach, including client/tx, types/tx, and x/auth modules.

Changes

File Change Summary
CHANGELOG.md Removed old functionality note, added note about removing APISignModeToInternal
client/tx/aux_builder.go Simplified sign mode assignment by direct casting
client/tx/aux_builder_test.go Updated sign mode validation to use direct type conversion
types/tx/direct_aux.go Added apisigning import, modified GetSignatureV2 to use direct sign mode conversion
types/tx/direct_aux_test.go Added apisigning import, updated sign mode handling in tests
types/tx/signing/signature.go Added signingv1beta1 import, updated sign mode conversions
types/tx/signing/types.go Deleted file, removing APISignModeToInternal and InternalSignModeToAPI functions
x/auth/tx/sigs.go Simplified sign mode conversion in SignatureDataToModeInfoAndSig

Possibly related PRs

Suggested labels

C:x/tx, C:Simulations, T:Docs

Suggested reviewers

  • JulianToledano
  • lucaslopezf
  • tac0turtle
  • testinginprod
  • kocubinski

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 930cb33 and 72e32f6.

📒 Files selected for processing (1)
  • types/tx/signing/signature.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • types/tx/signing/signature.go
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: build (amd64)
  • GitHub Check: Summary

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. (Beta)
  • @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.

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

🧹 Nitpick comments (2)
CHANGELOG.md (2)

Line range hint 14-20: Consider adding more context to the guiding principles section.

While the guiding principles section provides good high-level guidance, it could benefit from brief explanations of why each principle is important. For example, explain why changelogs are "for humans" and what makes a good changelog entry.


Line range hint 22-29: Usage section could be clearer about required format.

The usage section should provide a more explicit example of the expected format for changelog entries, including:

  • Exact formatting of the issue reference
  • Required components of a changelog entry
  • Examples of good vs bad entries
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e441778 and 930cb33.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • client/tx/aux_builder.go (1 hunks)
  • client/tx/aux_builder_test.go (1 hunks)
  • types/tx/direct_aux.go (2 hunks)
  • types/tx/direct_aux_test.go (2 hunks)
  • types/tx/signing/signature.go (3 hunks)
  • types/tx/signing/types.go (0 hunks)
  • x/auth/tx/sigs.go (1 hunks)
💤 Files with no reviewable changes (1)
  • types/tx/signing/types.go
🧰 Additional context used
📓 Path-based instructions (7)
client/tx/aux_builder_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

types/tx/direct_aux.go (1)

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

x/auth/tx/sigs.go (1)

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

types/tx/direct_aux_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

client/tx/aux_builder.go (1)

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

types/tx/signing/signature.go (1)

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

CHANGELOG.md (1)

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

🪛 GitHub Actions: Lint
types/tx/signing/signature.go

[error] 6-8: File is not properly formatted according to gci standards. Import order should follow: --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-system-v2
  • GitHub Check: test-integration
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (9)
types/tx/direct_aux.go (2)

6-6: LGTM! Import addition for direct sign mode usage.

The addition of the apisigning import aligns with the PR's objective of simplifying sign mode handling.


58-58: LGTM! Direct sign mode assignment.

The direct usage of apisigning.SignMode(a.Mode) simplifies the code by removing unnecessary conversion steps.

types/tx/direct_aux_test.go (2)

8-8: LGTM! Import addition for test assertions.

The addition of the apisigning import enables direct sign mode comparisons in tests.


81-81: LGTM! Updated test assertion.

The test assertion now correctly uses direct sign mode comparison, maintaining test coverage while aligning with the simplified approach.

types/tx/signing/signature.go (1)

39-39: LGTM! Consistent sign mode handling.

The direct usage of SignMode in both conversion functions maintains consistency and simplifies the codebase.

Also applies to: 71-71

x/auth/tx/sigs.go (1)

26-26: LGTM! Simplified sign mode conversion.

The direct casting to signing.SignMode aligns with the PR's objective of removing unnecessary conversion helpers.

client/tx/aux_builder_test.go (1)

251-251: LGTM! Sign mode comparison simplified.

The direct type conversion apisigning.SignMode(auxSignerData.Mode) aligns with the PR's goal of removing unnecessary conversion helpers while maintaining the same validation logic.

client/tx/aux_builder.go (1)

139-139: LGTM! Sign mode assignment simplified.

The direct type conversion signing.SignMode(mode) aligns with the PR's goal of removing unnecessary conversion helpers. The change maintains correctness as the validation of allowed sign modes is still performed in the switch statement above.

CHANGELOG.md (1)

Line range hint 1-1: LGTM! The CHANGELOG follows the standard Keep a Changelog format.

The file properly documents changes across versions in a clear and organized way, with changes appropriately categorized into sections like Features, Improvements, Bug Fixes, etc.

Comment on lines 6 to 8
signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
gogoprotoany "github.com/cosmos/gogoproto/types/any"

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix import ordering according to gci standards.

The imports should follow this order:

  1. Standard library
  2. Default packages
  3. Packages with prefix "cosmossdk.io"
  4. Packages with prefix "github.com/cosmos/cosmos-sdk"

Apply this diff to fix the import ordering:

import (
	"fmt"

-	signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
-	gogoprotoany "github.com/cosmos/gogoproto/types/any"
+	signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
+	gogoprotoany "github.com/cosmos/gogoproto/types/any"
	cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Actions: Lint

[error] 6-8: File is not properly formatted according to gci standards. Import order should follow: --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

@julienrbrt julienrbrt added this pull request to the merge queue Jan 22, 2025
Merged via the queue into main with commit 39b0244 Jan 22, 2025
73 of 74 checks passed
@julienrbrt julienrbrt deleted the julien/fix branch January 22, 2025 12:29
mergify bot pushed a commit that referenced this pull request Jan 22, 2025
(cherry picked from commit 39b0244)

# Conflicts:
#	CHANGELOG.md
julienrbrt added a commit that referenced this pull request Jan 22, 2025
Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:CLI C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants