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(core): add a new codec to core #22326

Merged
merged 9 commits into from
Oct 28, 2024
Merged

feat(core): add a new codec to core #22326

merged 9 commits into from
Oct 28, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Oct 21, 2024

Description

this pr adds simple codec to core to avoid importing the sdk. This is the second to final step to have sdk modules that do not depend on the sdk


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

  • New Features

    • Introduced a codec package for encoding and decoding data in binary and JSON formats.
    • Added support for encoding boolean values and generic protobuf messages.
    • Enhanced testing coverage for the collections/protocodec module.
  • Bug Fixes

    • Improved error handling during encoding and decoding processes.
  • Tests

    • Implemented unit tests for codec functionalities to ensure correctness in encoding and decoding operations.
  • Chores

    • Updated dependency management and configuration files for improved automation and organization.

@tac0turtle tac0turtle requested a review from a team as a code owner October 21, 2024 14:26
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new codec package that defines interfaces for encoding and decoding data in binary and JSON formats. The codec.go file establishes a Codec interface, along with BinaryCodec and JSONCodec interfaces, outlining methods for marshaling and unmarshaling messages. Additional files implement specific codecs for boolean values and generic protobuf messages, accompanied by unit tests. A new Go module and updates to GitHub workflows for testing and dependency management are also included, enhancing the overall functionality and maintainability of the Cosmos SDK.

Changes

File Path Change Summary
core/codec/codec.go Introduced Codec, BinaryCodec, and JSONCodec interfaces with methods for marshaling and unmarshaling messages in binary and JSON formats.
collections/protocodec/collections.go Added BoolValue codec and generic CollValue and CollValueV2 functions for encoding/decoding boolean values and protobuf messages.
collections/protocodec/collections_test.go Added unit tests for CollValueV2 and BoolValue to verify encoding and decoding processes.
collections/protocodec/go.mod Introduced new Go module with specified Go version and listed dependencies.
.github/dependabot.yml Added scheduled update for collections/protocodec directory; corrected formatting for existing entry.
.github/pr_labeler.yml Added new label category for collections/protocodec path.
.github/workflows/test.yml Introduced test-collections-protocodec job to run tests for the collections/protocodec module.
go.work.example Added ./collections/protocodec module path to the use block for dependency management.

Possibly related PRs

Suggested labels

C:x/tx, C:server/v2, C:orm, C:Hubl, C:schema

Suggested reviewers

  • testinginprod
  • sontrinh16
  • julienrbrt
  • kocubinski

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.

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 (3)
core/codec/codec.go (3)

5-9: LGTM: Codec interface is well-designed.

The Codec interface follows good Go practices by composing BinaryCodec and JSONCodec. The naming convention is correct for an exported interface.

Consider slightly modifying the comment to be more idiomatic:

-// Codec defines a Binary Codec and JSON Codec for modules to encode and decode data
+// Codec combines Binary and JSON encoding/decoding capabilities for modules

11-16: LGTM: BinaryCodec interface is well-defined.

The BinaryCodec interface is focused and its methods follow Go conventions. The comment provides useful information about the encoding method.

Consider using a more generic type for the message parameter:

 type BinaryCodec interface {
-	Marshal(transaction.Msg) ([]byte, error)
-	Unmarshal([]byte, transaction.Msg) error
+	Marshal(proto.Message) ([]byte, error)
+	Unmarshal([]byte, proto.Message) error
 }

This change would make the interface more flexible and reusable for different types of protobuf messages, not just transaction messages.


18-22: LGTM: JSONCodec interface is well-defined, with minor suggestions.

The JSONCodec interface is focused and its methods follow Go conventions for JSON encoding/decoding.

Consider the following improvements:

  1. Enhance the comment to provide more context:
-// JSONCodec defines a JSON encoding and decoding interface for modules to encode and decode data
+// JSONCodec defines an interface for JSON encoding and decoding of transaction messages
  1. Use a more generic type for the message parameter, similar to the suggestion for BinaryCodec:
 type JSONCodec interface {
-	MarshalJSON(transaction.Msg) ([]byte, error)
-	UnmarshalJSON([]byte, transaction.Msg) error
+	MarshalJSON(proto.Message) ([]byte, error)
+	UnmarshalJSON([]byte, proto.Message) error
 }

These changes would improve clarity and make the interface more flexible for different types of messages.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 681366e and beec467.

📒 Files selected for processing (1)
  • core/codec/codec.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
core/codec/codec.go (1)

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

🔇 Additional comments (1)
core/codec/codec.go (1)

1-3: LGTM: Package declaration and import statement are correct.

The package name 'codec' is appropriate for the content, and the import statement is correctly formatted and necessary for the transaction.Msg type used in the interfaces.

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

🧹 Outside diff range and nitpick comments (4)
collections/protocodec/collections_test.go (3)

19-39: LGTM: Comprehensive test coverage for CollValueV2 codec.

The test thoroughly covers both binary and JSON encoding/decoding operations for CollValueV2. It appropriately uses protocmp.Transform() to handle protobuf version differences in comparisons. The test checks for successful operations, value equality after encoding and decoding, and ensures the encoder's value type is not empty.

Consider adding test cases for error scenarios, such as decoding invalid input, to ensure robust error handling.


41-56: LGTM: Thorough testing of BoolValue codec with custom assertions.

The test effectively covers both true and false values for the BoolValue codec. The use of colltest.TestValueCodec demonstrates good reuse of testing utilities. The custom valueAssert function provides an additional layer of verification by comparing the encoded bytes with gogotypes.BoolValue.

Consider adding a brief comment explaining the purpose of the valueAssert function to improve code readability and maintainability.


1-57: Overall: Well-structured and comprehensive test suite for codec functionality.

This test file demonstrates good testing practices for the codec implementations. It covers both CollValueV2 and BoolValue codecs, including binary and JSON operations. The tests are well-organized, use appropriate testing utilities, and show attention to detail in handling protobuf version differences.

To further enhance the test suite:

  1. Consider adding more error case scenarios to ensure robust error handling.
  2. Add brief comments for custom functions like valueAssert to improve code readability.
  3. If applicable, consider testing with edge cases such as empty or very large values to ensure codec stability across a wide range of inputs.
collections/protocodec/collections.go (1)

90-92: Provide More Descriptive ValueType Identifiers

In the ValueType methods of both collValue and collValue2, consider returning more precise type information by including the full package path and type name. This improves clarity when debugging or logging type information.

Also applies to: 135-137

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between beec467 and c64ea01.

⛔ Files ignored due to path filters (1)
  • collections/protocodec/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • codec/collections.go (1 hunks)
  • collections/protocodec/collections.go (1 hunks)
  • collections/protocodec/collections_test.go (1 hunks)
  • collections/protocodec/go.mod (1 hunks)
  • go.mod (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • collections/protocodec/go.mod
🧰 Additional context used
📓 Path-based instructions (3)
codec/collections.go (1)

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

collections/protocodec/collections.go (1)

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

collections/protocodec/collections_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"

🪛 GitHub Check: split-test-files
codec/collections.go

[failure] 12-12:
module cosmossdk.io/collections/protocodec provides package cosmossdk.io/collections/protocodec and is replaced but not required; to add it:

🪛 GitHub Check: dependency-review
codec/collections.go

[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
module cosmossdk.io/collections/protocodec provides package cosmossdk.io/collections/protocodec and is replaced but not required; to add it:


[failure] 12-12:
could not import cosmossdk.io/collections/protocodec (invalid package name: "")

🔇 Additional comments (5)
collections/protocodec/collections_test.go (1)

3-15: LGTM: Import statements are well-organized and follow best practices.

The import statements are grouped correctly, separating standard library imports from third-party and internal project imports. This organization aligns with the Uber Go Style Guide recommendations.

go.mod (1)

188-188: New module added: collections/protocodec

The addition of cosmossdk.io/collections/protocodec => ./collections/protocodec introduces a new local module to the project. This aligns with the PR objective of adding a new codec to the core.

Please ensure:

  1. The ./collections/protocodec directory exists and contains the necessary Go files.
  2. The module is correctly implemented and integrated with the rest of the project.

Consider updating the project documentation to reflect this new module and its purpose within the SDK.

To verify the module's existence and basic structure, you can run:

✅ Verification successful

Module collections/protocodec Verified Successfully

The cosmossdk.io/collections/protocodec directory exists, contains the necessary Go files, and includes a correctly configured go.mod file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the directory exists and contains Go files
if [ -d "./collections/protocodec" ] && [ "$(find ./collections/protocodec -name '*.go' | wc -l)" -gt 0 ]; then
    echo "collections/protocodec directory exists and contains Go files."
    ls -R ./collections/protocodec
else
    echo "Error: collections/protocodec directory is missing or doesn't contain Go files."
fi

# Check if there's a go.mod file for the new module
if [ -f "./collections/protocodec/go.mod" ]; then
    echo "go.mod file exists for collections/protocodec:"
    cat ./collections/protocodec/go.mod
else
    echo "Warning: No go.mod file found for collections/protocodec."
fi

Length of output: 2815

codec/collections.go (1)

15-17: Simplify code by aliasing 'BoolValue' to 'protocodec.BoolValue'

Replacing the custom BoolValue implementation with an alias to protocodec.BoolValue enhances code maintainability by reusing existing functionality and reducing redundancy.

collections/protocodec/collections.go (2)

16-19: Implementation of BoolValue Codec is Correct

The BoolValue variable properly provides a collcodec.ValueCodec[bool] implementation, ensuring backward compatibility with prototypes.BoolValue.


23-31: Methods of boolValue Struct are Correctly Implemented

The Encode and Decode methods for boolValue correctly handle the marshaling and unmarshaling of boolean values using gogotypes.BoolValue.

collcodec "cosmossdk.io/collections/codec"
"cosmossdk.io/collections/protocodec"
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 the import path for 'protocodec' package

The import statement for "cosmossdk.io/collections/protocodec" may cause build failures due to missing module requirements. According to the static analysis hints, the module is not properly included in your go.mod file.

To resolve this issue, ensure that the cosmossdk.io/collections module is required in your go.mod file. You can add it by running:

go get cosmossdk.io/collections@latest

This command will fetch the latest version of the module and update your go.mod file accordingly.

🧰 Tools
🪛 GitHub Check: split-test-files

[failure] 12-12:
module cosmossdk.io/collections/protocodec provides package cosmossdk.io/collections/protocodec and is replaced but not required; to add it:

🪛 GitHub Check: dependency-review

[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
no required module provides package cosmossdk.io/collections/protocodec; to add it:


[failure] 12-12:
module cosmossdk.io/collections/protocodec provides package cosmossdk.io/collections/protocodec and is replaced but not required; to add it:


[failure] 12-12:
could not import cosmossdk.io/collections/protocodec (invalid package name: "")

Comment on lines +63 to +137
type collValue[T any, PT protoMessage[T]] struct {
cdc corecodec.Codec
messageName string
}

func (c collValue[T, PT]) Encode(value T) ([]byte, error) {
return c.cdc.Marshal(PT(&value))
}

func (c collValue[T, PT]) Decode(b []byte) (value T, err error) {
err = c.cdc.Unmarshal(b, PT(&value))
return value, err
}

func (c collValue[T, PT]) EncodeJSON(value T) ([]byte, error) {
return c.cdc.MarshalJSON(PT(&value))
}

func (c collValue[T, PT]) DecodeJSON(b []byte) (value T, err error) {
err = c.cdc.UnmarshalJSON(b, PT(&value))
return
}

func (c collValue[T, PT]) Stringify(value T) string {
return PT(&value).String()
}

func (c collValue[T, PT]) ValueType() string {
return "github.com/cosmos/gogoproto/" + c.messageName
}

type protoMessageV2[T any] interface {
*T
protov2.Message
}

// CollValueV2 is used for protobuf values of the newest google.golang.org/protobuf API.
func CollValueV2[T any, PT protoMessageV2[T]]() collcodec.ValueCodec[PT] {
return &collValue2[T, PT]{
messageName: string(PT(new(T)).ProtoReflect().Descriptor().FullName()),
}
}

type collValue2[T any, PT protoMessageV2[T]] struct {
messageName string
}

func (c collValue2[T, PT]) Encode(value PT) ([]byte, error) {
protov2MarshalOpts := protov2.MarshalOptions{Deterministic: true}
return protov2MarshalOpts.Marshal(value)
}

func (c collValue2[T, PT]) Decode(b []byte) (PT, error) {
var value T
err := protov2.Unmarshal(b, PT(&value))
return &value, err
}

func (c collValue2[T, PT]) EncodeJSON(value PT) ([]byte, error) {
return protojson.Marshal(value)
}

func (c collValue2[T, PT]) DecodeJSON(b []byte) (PT, error) {
var value T
err := protojson.Unmarshal(b, PT(&value))
return &value, err
}

func (c collValue2[T, PT]) Stringify(value PT) string {
return fmt.Sprintf("%v", value)
}

func (c collValue2[T, PT]) ValueType() string {
return "google.golang.org/protobuf/" + c.messageName
}
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

Refactor to Eliminate Code Duplication Between collValue and collValue2

The structs collValue and collValue2, along with their methods, share similar logic. Consider refactoring to reduce code duplication by abstracting the common functionality into a single generic struct or interface. This adheres to the DRY (Don't Repeat Yourself) principle and improves maintainability.

Comment on lines +55 to +59
func CollValue[T any, PT protoMessage[T]](cdc interface {
Marshal(proto.Message) ([]byte, error)
Unmarshal([]byte, proto.Message) error
},
) collcodec.ValueCodec[T] {
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

Define a Specific Interface Instead of Using an Anonymous Interface for cdc

Using an anonymous interface for the cdc parameter reduces clarity and type safety. Consider defining a specific interface or using an existing one that includes the required methods (Marshal and Unmarshal). This enhances readability and ensures better compile-time checks.

Comment on lines +55 to +61
func CollValue[T any, PT protoMessage[T]](cdc interface {
Marshal(proto.Message) ([]byte, error)
Unmarshal([]byte, proto.Message) error
},
) collcodec.ValueCodec[T] {
return &collValue[T, PT]{cdc.(corecodec.Codec), proto.MessageName(PT(new(T)))}
}
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

Handle Type Assertion Safely to Prevent Potential Panic

In the CollValue function, the type assertion cdc.(corecodec.Codec) may cause a panic if cdc does not implement corecodec.Codec. It's safer to perform a checked type assertion to prevent runtime errors.

Apply this diff to safely handle the type assertion:

 func CollValue[T any, PT protoMessage[T]](cdc interface {
 	Marshal(proto.Message) ([]byte, error)
 	Unmarshal([]byte, proto.Message) error
 },
 ) collcodec.ValueCodec[T] {
-	return &collValue[T, PT]{cdc.(corecodec.Codec), proto.MessageName(PT(new(T)))}
+	coreCdc, ok := cdc.(corecodec.Codec)
+	if !ok {
+		// Handle the error appropriately, perhaps return an error
+		return nil // or return an error
+	}
+	return &collValue[T, PT]{coreCdc, proto.MessageName(PT(new(T)))}
 }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func CollValue[T any, PT protoMessage[T]](cdc interface {
Marshal(proto.Message) ([]byte, error)
Unmarshal([]byte, proto.Message) error
},
) collcodec.ValueCodec[T] {
return &collValue[T, PT]{cdc.(corecodec.Codec), proto.MessageName(PT(new(T)))}
}
func CollValue[T any, PT protoMessage[T]](cdc interface {
Marshal(proto.Message) ([]byte, error)
Unmarshal([]byte, proto.Message) error
},
) collcodec.ValueCodec[T] {
coreCdc, ok := cdc.(corecodec.Codec)
if !ok {
// Handle the error appropriately, perhaps return an error
return nil // or return an error
}
return &collValue[T, PT]{coreCdc, proto.MessageName(PT(new(T)))}
}

@julienrbrt julienrbrt changed the title chore: add a new codec to core feat(core): add a new codec to core Oct 21, 2024

This comment has been minimized.

@tac0turtle tac0turtle requested a review from julienrbrt October 21, 2024 16:26
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

If we go the with new go.mod, can we follow the guidelines for a new go.mod addition directly in this PR?

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 (4)
go.work.example (1)

8-8: LGTM! Consider alphabetical ordering for consistency.

The addition of the ./collections/protocodec module path is correct and aligns with the PR objectives. This change appropriately includes the new codec package in the workspace.

For improved readability and consistency, consider ordering the collections related module paths alphabetically:

 use (
 	.
 	./api
 	./client/v2
 	./collections
-	./collections/protocodec
+	./collections/protocodec
 	./core
 	./core/testing
 	./depinject
.github/pr_labeler.yml (1)

21-22: LGTM! Consider adding a comment for clarity.

The addition of the "C:collections/protocodec" label category is appropriate and aligns with the PR objectives. This will help in automatically categorizing future PRs related to the new codec implementation.

Consider adding a brief comment above this new entry to explain its purpose, for example:

# Label for the new codec implementation in collections
"C:collections/protocodec":
  - collections/protocodec/*

This would improve maintainability and provide context for other developers.

.github/dependabot.yml (1)

181-189: LGTM with a minor suggestion.

The new Dependabot entry for /collections/protocodec is correctly structured and consistent with existing entries. It aligns well with the PR objectives of introducing a new codec to the core.

Consider adding a comment above this entry to explain its purpose, similar to other sections in the file. For example:

  # Dependency updates for the new codec in collections
  - package-ecosystem: gomod
    directory: "/collections/protocodec"
    ...

This would improve readability and maintainability of the configuration file.

.github/workflows/test.yml (1)

638-668: Consider adding race detection to the test command.

The new test-collections-protocodec job looks good and follows the structure of other testing jobs in the workflow. However, to maintain consistency with other test jobs and potentially catch race conditions, consider adding the -race flag to the test command.

Update the test command in line 659 as follows:

-          go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock' ./...
+          go test -mod=readonly -race -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock' ./...

This change will align the test command with other similar jobs in the workflow and enable race detection during testing.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c64ea01 and c63aece.

📒 Files selected for processing (4)
  • .github/dependabot.yml (1 hunks)
  • .github/pr_labeler.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • go.work.example (1 hunks)
🧰 Additional context used

@tac0turtle tac0turtle requested a review from julienrbrt October 22, 2024 10:12
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

ACK, but the follow up, should alias the codec from the sdk to this, so we don't have duplicates

gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace cosmossdk.io/core => ../../core
Copy link
Member

Choose a reason for hiding this comment

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

TODO in follow up delete this.

core/codec/codec.go Outdated Show resolved Hide resolved
@tac0turtle tac0turtle enabled auto-merge October 25, 2024 09:48
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)
core/CHANGELOG.md (1)

41-41: Improve changelog entry conciseness and context.

The current entry can be more concise and provide better context about the initiative. Consider revising to:

-* [#22326](https://github.com/cosmos/cosmos-sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK dependency in modules. 
+* [#22326](https://github.com/cosmos/cosmos-sdk/pull/22326) Introduce codec package to enable SDK-independent module development.
🧰 Tools
🪛 LanguageTool

[style] ~41-~41: Consider a shorter alternative to avoid wordiness.
Context: ...sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK depend...

(IN_ORDER_TO_PREMIUM)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c63aece and 376d1bf.

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

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

🪛 LanguageTool
core/CHANGELOG.md

[style] ~41-~41: Consider a shorter alternative to avoid wordiness.
Context: ...sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK depend...

(IN_ORDER_TO_PREMIUM)

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 (2)
core/CHANGELOG.md (2)

41-41: Improve changelog entry conciseness.

The entry can be more concise by removing "in order to":

-* [#22326](https://github.com/cosmos/cosmos-sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK dependency in modules. 
+* [#22326](https://github.com/cosmos/cosmos-sdk/pull/22326) Introduce codec package to facilitate removal of Cosmos SDK dependency in modules. 
🧰 Tools
🪛 LanguageTool

[style] ~41-~41: Consider a shorter alternative to avoid wordiness.
Context: ...sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK depend...

(IN_ORDER_TO_PREMIUM)


41-41: Enhance changelog entry with more details.

Consider expanding the changelog entry to better describe the codec package's capabilities. For example, mention its support for binary and JSON encoding/decoding interfaces.

-* [#22326](https://github.com/cosmos/cosmos-sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK dependency in modules. 
+* [#22326](https://github.com/cosmos/cosmos-sdk/pull/22326) Introduce codec package to facilitate removal of Cosmos SDK dependency in modules. The package provides interfaces for binary and JSON encoding/decoding operations.
🧰 Tools
🪛 LanguageTool

[style] ~41-~41: Consider a shorter alternative to avoid wordiness.
Context: ...sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK depend...

(IN_ORDER_TO_PREMIUM)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eb5c4bf and f1330c8.

📒 Files selected for processing (1)
  • core/CHANGELOG.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
core/CHANGELOG.md (1)

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

🪛 LanguageTool
core/CHANGELOG.md

[style] ~41-~41: Consider a shorter alternative to avoid wordiness.
Context: ...sdk/pull/22326) Introduce codec package in order to facilitate removal of Cosmos SDK depend...

(IN_ORDER_TO_PREMIUM)

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 (2)
.github/workflows/test.yml (2)

613-613: Consider using Go version 1.20 for consistency.

The job specifies Go version "1.23" which appears to be inconsistent with some other jobs in the workflow that use "1.20". Consider aligning the Go version with other jobs unless there's a specific requirement for this version.


Go version inconsistency requires update

The schema package is using Go 1.12 which is significantly outdated compared to the rest of the codebase. Most packages use Go 1.23.x, with a few using 1.20 or 1.21. Notably:

  • schema/go.mod: Go 1.12
  • indexer/postgres/go.mod: Go 1.12
  • Most other packages: Go 1.23.x
  • Some core packages (math, log, errors): Go 1.20
  • api, depinject: Go 1.21

The schema package should be updated to at least Go 1.20 to maintain consistency with the minimum Go version used in the codebase.

🔗 Analysis chain

Line range hint 1012-1012: Review Go version for schema package.

The schema job uses Go version "1.12" which is significantly older than the versions used in other jobs (1.20 and 1.23). This might be intentional but should be verified to ensure it's not a typo.


Let me gather more information about Go version requirements across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if schema package has specific Go version requirements
# Test: Look for Go version constraints in go.mod
rg -A 5 "^go \d+\.\d+" schema/go.mod

Length of output: 46


Script:

#!/bin/bash
# Check Go version requirements across all go.mod files
fd go.mod --exec sh -c 'echo "=== {} ===" && rg "^go \d+\.\d+" {}'

# Check if there are any specific version constraints in schema package
rg -g "*.go" "requires.*go" schema/

Length of output: 2155

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f1330c8 and d89f56c.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/test.yml (1)

607-637: LGTM on the new test job structure.

The new test-collections-protocodec job follows the established pattern of other test jobs in the workflow, including proper setup of Go environment, dependency caching, change detection, test execution with coverage reporting, and SonarCloud integration.

@tac0turtle tac0turtle added this pull request to the merge queue Oct 28, 2024
Merged via the queue into main with commit 6e3b2df Oct 28, 2024
72 of 74 checks passed
@tac0turtle tac0turtle deleted the marko/propose_codecs branch October 28, 2024 13:13
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.

7 participants