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

chore: split key and path functions in separate files #5670

Merged

Conversation

crodriguezvega
Copy link
Contributor

@crodriguezvega crodriguezvega commented Jan 20, 2024

Description

A quick low-hanging fruit PR to close a golden oldie issue. From all the points mentioned in the issue the only one that is still valid is splitting the ...Key and ...Path functions in separate files. If team prefers not to have separate files, that's also fine; I will then just close the PR and the corresponding issue.

closes: #28

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Refactor

    • Simplified channel, client, and connection key management by consolidating path and key generation functions.
    • Removed redundant path-related functions, streamlining the handling of IBC-related data.
  • New Features

    • Introduced new functionalities for generating paths related to channels, clients, connections, and packets, enhancing data management and accessibility within the IBC module.

@codecov-commenter
Copy link

Codecov Report

Attention: 44 lines in your changes are missing coverage. Please review.

Comparison is base (59ac9b2) 81.16% compared to head (c8a8ac2) 81.16%.
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #5670   +/-   ##
=======================================
  Coverage   81.16%   81.16%           
=======================================
  Files         199      203    +4     
  Lines       15278    15278           
=======================================
  Hits        12401    12401           
  Misses       2408     2408           
  Partials      469      469           
Files Coverage Δ
modules/core/24-host/channel_keys.go 0.00% <ø> (ø)
modules/core/24-host/client_keys.go 0.00% <ø> (-18.19%) ⬇️
modules/core/24-host/connection_keys.go 0.00% <ø> (ø)
modules/core/24-host/packet_keys.go 0.00% <ø> (ø)
modules/core/24-host/connection_paths.go 0.00% <0.00%> (ø)
modules/core/24-host/client_paths.go 40.00% <40.00%> (ø)
modules/core/24-host/channel_paths.go 0.00% <0.00%> (ø)
modules/core/24-host/packet_paths.go 0.00% <0.00%> (ø)

…rovements

# Conflicts:
#	modules/core/24-host/packet_keys.go
@crodriguezvega crodriguezvega added the type: code hygiene Clean up code but without changing functionality or interfaces label Jan 24, 2024
@colin-axner
Copy link
Contributor

An alternative would be to remove one of the two functions. I'd propose we remove the Path... functions. I believe these are primarily used by 03-connection for generating the path to verify (but having a whole function to cast from byte to string seems unnecessary). I guess the reason it was initially added is because we format as string, then cast as a byte and then it would be casted back as a string

I'm don't have much preference. Having in same file, splitting into two files or removing one of the funcs all seem fine to me

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

fine with this but wouldn't mind discussion from others on a more aggressive refactor re: removing one of em as Colin mentions.

Copy link
Contributor

coderabbitai bot commented Apr 23, 2024

Walkthrough

Walkthrough

The refactoring in the host package focuses on simplifying the handling of paths and keys for channels, clients, connections, and packets in the IBC module. This involved removing outdated functions and introducing new files to centralize path generation, enhancing clarity and maintainability.

Changes

Files Change Summary
channel_keys.go, client_keys.go, connection_keys.go, packet_keys.go Removed various functions for path and key generation, simplifying key management.
channel_paths.go, client_paths.go, connection_paths.go, packet_paths.go Introduced new files for centralized path generation for channels, clients, connections, and packets.

Possibly related issues


Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6ceba47 and 5f4334d.
Files selected for processing (8)
  • modules/core/24-host/channel_keys.go (2 hunks)
  • modules/core/24-host/channel_paths.go (1 hunks)
  • modules/core/24-host/client_keys.go (2 hunks)
  • modules/core/24-host/client_paths.go (1 hunks)
  • modules/core/24-host/connection_keys.go (1 hunks)
  • modules/core/24-host/connection_paths.go (1 hunks)
  • modules/core/24-host/packet_keys.go (1 hunks)
  • modules/core/24-host/packet_paths.go (1 hunks)
Files not reviewed due to errors (1)
  • modules/core/24-host/packet_paths.go (no review received)
Files skipped from review due to trivial changes (1)
  • modules/core/24-host/client_paths.go
Additional Context Used
Path-based Instructions (7)
modules/core/24-host/connection_keys.go (1)

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

modules/core/24-host/connection_paths.go (1)

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

modules/core/24-host/channel_keys.go (1)

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

modules/core/24-host/client_keys.go (1)

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

modules/core/24-host/packet_keys.go (1)

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

modules/core/24-host/channel_paths.go (1)

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

modules/core/24-host/packet_paths.go (1)

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

Additional comments not posted (27)
modules/core/24-host/connection_keys.go (2)

3-5: LGTM! The function ClientConnectionsKey correctly generates a byte array key for client connections.


7-9: LGTM! The function ConnectionKey correctly generates a byte array key for a specific connection.

modules/core/24-host/connection_paths.go (3)

5-5: LGTM! The constant KeyConnectionPrefix is appropriately defined and used consistently in path functions.


11-13: LGTM! The function ClientConnectionsPath correctly constructs a path for client connections using the defined prefix.


16-18: LGTM! The function ConnectionPath correctly constructs a path for a specific connection using the defined prefix.

modules/core/24-host/channel_keys.go (4)

3-5: LGTM! The function ChannelKey correctly generates a byte array key for a particular channel.


7-9: LGTM! The function ChannelUpgradeErrorKey correctly generates a byte array key for storing the ErrorReceipt in case of a failed channel upgrade.


11-13: LGTM! The function ChannelUpgradeKey correctly generates a byte array key for a particular channel upgrade attempt.


1-15: > 📝 NOTE

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

LGTM! The function ChannelCounterpartyUpgradeKey correctly generates a byte array key for the upgrade used on the counterparty channel.

modules/core/24-host/client_keys.go (6)

11-13: LGTM! The function FullClientKey correctly generates a full path key for specific client paths.


15-17: LGTM! The function PrefixedClientStoreKey correctly generates a key for prefixed key store iteration.


19-21: LGTM! The function FullClientStateKey correctly generates a store key for a particular client state.


Line range hint 23-25: LGTM! The function ClientStateKey correctly returns a store key for a particular client state stored in a client prefixed store.


29-40: > 📝 NOTE

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

LGTM! The function FullConsensusStateKey correctly generates a store key for the consensus state of a particular client.


31-33: LGTM! The function ConsensusStateKey correctly returns a store key for the consensus state of a particular client stored in a client prefixed store.

modules/core/24-host/packet_keys.go (8)

3-5: LGTM! The function NextSequenceSendKey correctly generates a store key for the send sequence of a particular channel.


7-9: LGTM! The function NextSequenceRecvKey correctly generates a store key for the receive sequence of a particular channel.


11-13: LGTM! The function NextSequenceAckKey correctly generates a store key for the acknowledgement sequence of a particular channel.


15-17: LGTM! The function PacketCommitmentKey correctly generates a store key for storing a packet commitment.


19-21: LGTM! The function PacketAcknowledgementKey correctly generates a store key for storing a packet acknowledgement.


23-25: LGTM! The function PacketReceiptKey correctly generates a store key for storing a packet receipt.


27-29: LGTM! The function PruningSequenceStartKey correctly generates a store key for the pruning sequence start of a particular channel.


31-33: LGTM! The function RecvStartSequenceKey correctly generates a store key for the recv start sequence of a particular channel.

modules/core/24-host/channel_paths.go (4)

5-13: LGTM! The constants for key prefixes are appropriately defined and used consistently in path functions.


19-21: LGTM! The function ChannelPath correctly constructs a path for channels using the defined prefix.


25-27: LGTM! The function ChannelCapabilityPath correctly constructs a path for channel capabilities using the defined prefix.


31-33: LGTM! The function ChannelUpgradeErrorPath correctly constructs a path for storing the ErrorReceipt in case of a failed channel upgrade.


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/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

sonarcloud bot commented Apr 23, 2024

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
9 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@crodriguezvega
Copy link
Contributor Author

Ok, since there's no strong opposition to splitting them in files, I will merge this for now, and we can tackle a more aggressive refactor later on.

@crodriguezvega crodriguezvega merged commit 4efbc8a into main Apr 23, 2024
76 checks passed
@crodriguezvega crodriguezvega deleted the carlos/28-ics24-spec-inconsistencies-and-improvements branch April 23, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code hygiene Clean up code but without changing functionality or interfaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICS24 Spec inconsistencies and improvements
4 participants