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: only overwrite context chainID when necessary #22568

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

damiannolan
Copy link
Member

@damiannolan damiannolan commented Nov 20, 2024

Description

Fixes some weird test failure behaviour in ibc-go. Without the change in this PR we have to reorder context API calls in test file. See diff. With this change we no longer need to modify the test code.

diff --git a/modules/core/02-client/types/height_test.go b/modules/core/02-client/types/height_test.go
index f9638c6b4..68fccb50a 100644
--- a/modules/core/02-client/types/height_test.go
+++ b/modules/core/02-client/types/height_test.go
@@ -147,14 +147,14 @@ func (suite *TypesTestSuite) TestSelfHeight() {
        ctx := suite.chainA.GetContext()

        // Test default revision
-       ctx = ctx.WithBlockHeight(10)
        ctx = ctx.WithChainID("gaiamainnet")
+       ctx = ctx.WithBlockHeight(10)
        height := types.GetSelfHeight(ctx)
        suite.Require().Equal(types.NewHeight(0, 10), height, "default self height failed")

        // Test successful revision format
-       ctx = ctx.WithBlockHeight(18)
        ctx = ctx.WithChainID("gaiamainnet-3")
+       ctx = ctx.WithBlockHeight(18)
        height = types.GetSelfHeight(ctx)
        suite.Require().Equal(types.NewHeight(3, 18), height, "valid self height failed")
 }
(END)

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

  • Bug Fixes
    • Improved validation for the chainID field to prevent overwriting existing values if they are already set or contain only whitespace.

@damiannolan damiannolan requested a review from a team as a code owner November 20, 2024 10:38
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

📝 Walkthrough

Walkthrough

The changes introduced in this pull request involve an update to the WithBlockHeader method in types/context.go. A new import for the strings package is added, and a conditional check is implemented to ensure that the chainID field is only updated if it is currently empty or consists solely of whitespace. This adjustment modifies the control flow to prevent overwriting an existing chainID.

Changes

File Path Change Summary
types/context.go Added import for strings package; modified WithBlockHeader to check if chainID is empty or whitespace before updating.

Possibly related PRs

  • fix(systemtest): upgrade test #21877: This PR modifies the TestChainUpgrade function in the upgrade_test.go file, which may relate to the control flow changes in the WithBlockHeader method in context.go regarding how the chain ID is handled during upgrades.
  • test(systemtests): fix failing tests #22145: This PR addresses failing tests in the cometbft_client_test.go, which may involve similar context handling as the changes in context.go, particularly in how the context is set up for tests.
  • fix(baseapp): populate header info in NewUncachedContext #22557: This PR enhances the NewUncachedContext method to ensure proper header information is populated, which is relevant to the changes in context.go that involve managing context and header information.

Suggested labels

C:x/accounts/base, backport/v0.52.x

Suggested reviewers

  • testinginprod
  • sontrinh16
  • akhilkumarpilli

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6351dc3 and 92a3034.

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

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

🔇 Additional comments (2)
types/context.go (2)

5-5: LGTM: Import addition is necessary

The addition of the strings package import is required for the new TrimSpace functionality.


166-169: LGTM: Conditional chainID update is well implemented

The change ensures that the chainID is only overwritten when it's empty or contains only whitespace, which:

  1. Fixes the test failures mentioned in the PR description
  2. Maintains backward compatibility
  3. Follows the principle of least surprise

The implementation is clean and follows Go best practices.


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

@damiannolan your pull request is missing a changelog!

@damiannolan
Copy link
Member Author

damiannolan commented Nov 20, 2024

I will add changelog. Can we put in v52?

edit: actually probably don't need changelog if it does go to v52.. i'll let you guys decide

@julienrbrt
Copy link
Member

I will add changelog. Can we put in v52?

edit: actually probably don't need changelog if it does go to v52.. i'll let you guys decide

No changelog needed yeah

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Nov 20, 2024
@julienrbrt julienrbrt enabled auto-merge November 20, 2024 10:42
@julienrbrt julienrbrt added this pull request to the merge queue Nov 20, 2024
Merged via the queue into main with commit 50c5963 Nov 20, 2024
73 of 76 checks passed
@julienrbrt julienrbrt deleted the damian/context-chain-id branch November 20, 2024 10:57
mergify bot pushed a commit that referenced this pull request Nov 20, 2024
julienrbrt pushed a commit that referenced this pull request Nov 20, 2024
…22569)

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
alpe added a commit that referenced this pull request Nov 21, 2024
* main:
  build(deps): Bump cosmossdk.io/math from 1.3.0 to 1.4.0 (#22580)
  fix(server/v2/api/telemetry): enable global metrics  (#22571)
  refactor(server/v2/cometbft): add `codec.Codec` and clean-up APIs (#22566)
  feat(core/coretesting): make memDB satisfy db.Db interface (#22570)
  Merge commit from fork
  fix(server(/v2)): fix fallback genesis path (#22564)
  fix: only overwrite context chainID when necessary (#22568)
  docs(client): Update setFeeGranter and setFeePayer comments (#22526)
  fix(baseapp): populate header info in `NewUncachedContext` (#22557)
  build(deps): Bump buf.build/gen/go/cometbft/cometbft/protocolbuffers/go from 1.35.1-20240701160653-fedbb9acfd2f.1 to 1.35.2-20240701160653-fedbb9acfd2f.1 in /api (#22551)
  build(deps): Bump github.com/creachadair/atomicfile from 0.3.5 to 0.3.6 in /tools/confix (#22552)
  docs: Update reference of Approximation (#22550)
  fix(server/v2/comebft): wire missing services + fix simulation (#21964)
  ci: fix permissions for GITHUB_TOKEN on dependabot workflows (#22547)
  ci: fix permissions for GITHUB_TOKEN in spell check workflow (#22545)
  build(deps): Bump google.golang.org/protobuf from 1.35.1 to 1.35.2 (#22537)
  fix(cosmovisor): premature upgrade on restart (#22528)
  fix(store/v2/pebble): handle version 0 in keys (#22524)
  refactor(server/v2/telemetry): swap redirects (#22520)
  docs: Update content in  CODE_OF_CONDUCT.md (#22518)
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants