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(x/tx): DecodedTx implements core/transaction.Tx #20424

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented May 19, 2024

Description

Originally a part of #20412, this PR implements core/transaction.Tx for DecodedTx. #20412 implements core/transaction.Tx on the gogo wrapper. Transaction representation can be simplified now that we are committed to gogo types, the gogo wrapper can likely be deleted.

This PR needs more work.


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
  • 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.

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

  • New Features

    • Enhanced transaction decoding with more detailed message handling.
    • Improved struct initialization for better performance and clarity.
  • Bug Fixes

    • Fixed issues with message conversions and field population in transaction wrappers.
  • Refactor

    • Simplified parameter passing and removed unnecessary fields in transaction-related functions and structs.
    • Reorganized import paths in go.work.example for better structure.
  • Documentation

    • Updated changelog to reflect new requirements for proto codec in decode options.

@kocubinski kocubinski requested a review from a team as a code owner May 19, 2024 20:40
Copy link
Contributor

coderabbitai bot commented May 19, 2024

Walkthrough

Walkthrough

The updates primarily focus on refactoring and enhancing the transaction decoding and building processes within the Cosmos SDK. Key changes include modifying the assignment of messages in transaction builders, simplifying the gogotx wrapper, and extending the DecodedTx struct with additional fields and methods. Additionally, the decode.Options now requires a proto codec for unmarshalling and resolving types. Minor reorganization of import paths was also performed in the go.work.example file.

Changes

File(s) Change Summary
x/auth/tx/builder.go Modified newBuilderFromDecodedTx function to use decoded.decodedTx.Messages instead of decoded.msgs.
x/auth/tx/gogotx.go Refactored newWrapperFromDecodedTx to simplify parameters and struct initialization, removed unnecessary fields, and updated methods to use decodedTx directly.
x/tx/decode/decode.go Added new fields and methods to DecodedTx struct, including ReflectMessages, cachedHash, cachedBytes, cachedHashed, and methods for hashing, gas limit, and message retrieval. Introduced gogoProtoCodec interface.
x/tx/decode/decode_test.go, x/tx/decode/fuzz_test.go Updated tests to use the new ProtoCodec with testGogoCodec and adjusted import paths.
x/tx/CHANGELOG.md Documented the API breaking change requiring decode.Options to use a proto codec capable of unmarshalling and resolving types.
go.work.example Reorganized import paths, moving ./server/v2/stf under ./tests/systemtests and ./server/v2/appmanager under ./runtime/v2.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Builder
    participant Decoder
    participant DecodedTx

    User ->> Builder: Call newBuilderFromDecodedTx
    Builder ->> Decoder: Decode transaction
    Decoder ->> DecodedTx: Populate decodedTx fields
    DecodedTx ->> Builder: Return decodedTx with Messages
    Builder ->> User: Return Builder with msgs: decoded.decodedTx.Messages
sequenceDiagram
    participant User
    participant gogoTxWrapper
    participant DecodedTx

    User ->> gogoTxWrapper: Call newWrapperFromDecodedTx
    gogoTxWrapper ->> DecodedTx: Populate fields directly
    DecodedTx ->> gogoTxWrapper: Return fields including fees
    gogoTxWrapper ->> User: Return gogoTxWrapper with updated methods

These diagrams illustrate the high-level interactions and flow of the refactored transaction building and decoding processes.


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 full the 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.

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

Out of diff range and nitpick comments (2)
x/tx/decode/decode.go (2)

23-33: Ensure proper documentation for new fields in DecodedTx.

The new fields ReflectMessages, cachedHash, cachedBytes, and cachedHashed are added to the DecodedTx struct. It would be beneficial to add comments describing the purpose and usage of these fields to maintain code readability and ease future maintenance.


Line range hint 123-173: Review and optimize the Decode method for error handling and efficiency.

The Decode method has several new lines of code handling different aspects of transaction decoding. Consider refactoring this method to separate concerns more clearly, possibly by breaking it down into smaller helper functions. This can improve readability and make the code easier to maintain.

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9fd3d13 and d5c012b.
Files ignored due to path filters (2)
  • x/tx/go.mod is excluded by !**/*.mod
  • x/tx/go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • x/tx/decode/decode.go (3 hunks)
Additional Context Used
Path-based Instructions (1)
x/tx/decode/decode.go (1)

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

Additional comments not posted (1)
x/tx/decode/decode.go (1)

40-40: Good use of type assertion to ensure interface implementation.

The type assertion var _ transaction.Tx = (*DecodedTx)(nil) is a good practice to ensure at compile time that DecodedTx implements the transaction.Tx interface.

x/tx/decode/decode.go Show resolved Hide resolved
x/tx/decode/decode.go Show resolved Hide resolved
x/tx/decode/decode.go Show resolved Hide resolved
x/tx/decode/decode.go Show resolved Hide resolved
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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between d5c012b and 0d41468.
Files ignored due to path filters (1)
  • x/tx/go.mod is excluded by !**/*.mod
Files selected for processing (5)
  • x/auth/tx/builder.go (1 hunks)
  • x/auth/tx/gogotx.go (4 hunks)
  • x/tx/decode/decode.go (4 hunks)
  • x/tx/decode/decode_test.go (4 hunks)
  • x/tx/decode/fuzz_test.go (3 hunks)
Additional Context Used
GitHub Check Runs (1)
dependency-review failure (7)

x/auth/tx/builder.go: [failure] 59-59:
cannot use decoded.decodedTx.Messages (variable of type []protoreflect.ProtoMessage) as []"github.com/cosmos/gogoproto/proto".Message value in struct literal


x/auth/tx/gogotx.go: [failure] 107-107:
cannot use w.decodedTx.Messages (variable of type []protoreflect.ProtoMessage) as []"github.com/cosmos/gogoproto/proto".Message value in return statement


x/auth/tx/gogotx.go: [failure] 111-111:
w.decodedTx.ReflectMessages undefined (type *decode.DecodedTx has no field or method ReflectMessages)

Path-based Instructions (5)
x/tx/decode/fuzz_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"

x/tx/decode/decode_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"

x/tx/decode/decode.go (1)

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

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

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

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

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

Additional comments not posted (8)
x/tx/decode/fuzz_test.go (2)

Line range hint 1-1: The function generateAndAddSeedsFromTx is well-implemented for fuzz testing purposes.


Line range hint 92-117: The function FuzzDecode is correctly set up for fuzzing the decoding process of transactions.

x/tx/decode/decode_test.go (2)

Line range hint 26-57: The function TestDecode effectively covers both successful and error scenarios in decoding transactions.


143-143: The function TestDecodeTxBodyPanic correctly tests for error handling in the decoding process.

x/tx/decode/decode.go (2)

22-33: The DecodedTx type is well-structured and includes necessary methods for transaction handling.


35-62: The Decoder type is correctly implemented for decoding transactions and handles various error scenarios effectively.

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

Line range hint 30-77: The gogoTxWrapper type is well-implemented for wrapping decoded transactions and includes necessary methods for transaction handling.

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

Line range hint 1-1: The builder type is correctly implemented for building transactions and includes comprehensive methods for setting transaction details.

x/tx/decode/decode.go Fixed Show fixed Hide fixed
@kocubinski kocubinski marked this pull request as draft May 20, 2024 14:45
@github-actions github-actions bot removed the C:x/auth label May 20, 2024
@kocubinski kocubinski marked this pull request as ready for review May 20, 2024 15:47
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

Out of diff range and nitpick comments (2)
x/tx/CHANGELOG.md (2)

Line range hint 157-157: When referring to system architectures, use a hyphen: change "32 bit" to "32-bit".

- Fix int64 usage for 32 bit platforms.
+ Fix int64 usage for 32-bit platforms.

Line range hint 142-153: The indentation for the unordered list items should be consistent. Adjust to match the expected indentation.

- * [#15871](https://github.com/cosmos/cosmos-sdk/pull/15871)
-     * `HandlerMap` now has a `DefaultMode()` getter method
-     * Textual types use `signing.ProtoFileResolver` instead of `protoregistry.Files`
+ * [#15871](https://github.com/cosmos/cosmos-sdk/pull/15871)
+   * `HandlerMap` now has a `DefaultMode()` getter method
+   * Textual types use `signing.ProtoFileResolver` instead of `protoregistry.Files`
Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0d41468 and 6923019.
Files selected for processing (4)
  • x/tx/CHANGELOG.md (1 hunks)
  • x/tx/decode/decode.go (4 hunks)
  • x/tx/decode/decode_test.go (5 hunks)
  • x/tx/decode/fuzz_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/tx/decode/decode_test.go
  • x/tx/decode/fuzz_test.go
Additional Context Used
LanguageTool (1)
x/tx/CHANGELOG.md (1)

Near line 157: When ‘32-bit’ is used as a modifier, it is usually spelled with a hyphen.
Context: ...mos-sdk/pull/15849) Fix int64 usage for 32 bit platforms. ## v0.5.1 ### Features * ...

Path-based Instructions (2)
x/tx/decode/decode.go (1)

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

x/tx/CHANGELOG.md (1)

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

Additional comments not posted (8)
x/tx/decode/decode.go (7)

21-22: The update to DecodedTx struct to include ReflectMessages aligns with the new interface requirements.


29-31: Caching mechanism for hash and bytes is a good performance optimization.


35-37: The gogoProtoCodec interface might need additional methods like Marshal to be fully functional.


46-47: Ensure that the new fields codec in Decoder and ProtoCodec in Options are properly handled to avoid nil references.

Also applies to: 53-54, 71-72


62-67: Proper error handling for nil checks on new codec-related fields in Decoder construction.


187-192: Optimize the Hash method by checking cachedHashed at the start to skip unnecessary computations.


226-235: Replace the use of panic in computeHashAndBytes with more graceful error handling to improve robustness.

x/tx/CHANGELOG.md (1)

38-39: The changelog entry clearly communicates the breaking changes related to decode.Options requiring a proto codec.

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6923019 and c887e74.
Files selected for processing (1)
  • x/tx/decode/decode_test.go (5 hunks)
Additional Context Used
Path-based Instructions (1)
x/tx/decode/decode_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"

Additional comments not posted (6)
x/tx/decode/decode_test.go (6)

10-13: The new imports are correctly added to support the updated test implementations.


25-39: The new type definitions for testGogoCodec and resolver are well-defined and crucial for the updated testing strategy.


41-48: The Unmarshal method in testGogoCodec is correctly implemented to handle both V1 and V2 message types, aligning with the new ProtoCodec requirements.


75-76: The setup of ProtoCodec and AnyResolver using testGogoCodec and resolver is correctly implemented to align with the new decoding logic.


87-87: The addition of the SimpleSigner test case is appropriate to ensure coverage of new message types in the decoding process.


162-163: The consistent setup of ProtoCodec and AnyResolver in TestDecodeTxBodyPanic ensures uniform testing conditions across test functions.

@@ -33,6 +33,10 @@ Since v0.13.0, x/tx follows Cosmos SDK semver: https://github.com/cosmos/cosmos-

## [Unreleased]

### API Breaking

* [#20424](https://github.com/cosmos/cosmos-sdk/pull/20424) `decode.Options` now requires a proto codec capable of unmarshalling and resolving types.
Copy link
Member

Choose a reason for hiding this comment

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

Is it used in v0.50? I don't think it is, we if so we should add an example and make sure v0.50 is updated. Otherwise we'll need a compatibility matrix for x/tx and we don't want that.

Copy link
Member Author

Choose a reason for hiding this comment

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

x/tx/decode is used in v0.50, or which did you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Then I missed it (on my phone - and still am). What does it mean for people on v0.50 then? Do we need a patch release that supports that behavior change then?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, you are correct, it is unused in v0.50.

@kocubinski kocubinski marked this pull request as draft May 20, 2024 21:55
@kocubinski kocubinski marked this pull request as ready for review May 28, 2024 13:36
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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between c887e74 and 0845955.
Files ignored due to path filters (2)
  • x/epochs/go.mod is excluded by !**/*.mod
  • x/epochs/go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.work.example (1 hunks)
Files skipped from review due to trivial changes (1)
  • go.work.example

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0845955 and 2cd2c78.
Files ignored due to path filters (2)
  • x/epochs/go.mod is excluded by !**/*.mod
  • x/epochs/go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • go.work.example (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go.work.example

@kocubinski kocubinski mentioned this pull request May 28, 2024
12 tasks
@kocubinski kocubinski marked this pull request as draft May 28, 2024 20:52
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.

None yet

2 participants