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(server): allow align block header with skip check header in grpc server #23244

Open
wants to merge 5 commits into
base: release/v0.52.x
Choose a base branch
from

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Jan 8, 2025

ensure overwrite with latest header under grpc only or pruned node

Description

Closes: #XXXX


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

    • Added option to align block header with skip check header in gRPC server
    • Introduced SkipCheckHeader configuration to bypass header checks in gRPC server
  • Configuration

    • New skip-check-header option added to gRPC configuration files
    • Default value set to false
  • Improvements

    • Enhanced gRPC server registration flexibility
    • Updated server interfaces to support new header check configuration

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • main

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request introduces a new feature in the Cosmos SDK that allows aligning block headers with skip check headers in the gRPC server. The changes span multiple files across the server configuration and implementation, adding a new SkipCheckHeader configuration option. This boolean flag enables developers to optionally bypass header checks during gRPC server registration and context creation, providing more flexibility in how gRPC services are handled.

Changes

File Change Summary
CHANGELOG.md Added feature entry for block header alignment in gRPC server
baseapp/grpcserver.go Added RegisterGRPCServerWithSkipCheckHeader method to allow skipping header checks
server/config/config.go Introduced SkipCheckHeader boolean field in GRPCConfig struct
server/config/config.toml.tpl Added skip-check-header configuration option
server/grpc/server.go Updated NewGRPCServer method signature to support skip header configuration
server/types/app.go Replaced RegisterGRPCServer with RegisterGRPCServerWithSkipCheckHeader in Application interface
server/v2/api/grpc/config.go Added SkipCheckHeader field to Config struct
Configuration files Added skip-check-header = false in various TOML configuration files

Sequence Diagram

sequenceDiagram
    participant Client
    participant GRPCServer
    participant Application
    participant Context

    Client->>GRPCServer: Request with configuration
    GRPCServer->>Application: RegisterGRPCServerWithSkipCheckHeader(server, skipCheckHeader)
    Application->>Context: CreateQueryContextWithCheckHeader(!skipCheckHeader)
    Context-->>GRPCServer: Return context
    GRPCServer-->>Client: Process request
Loading

Possibly Related PRs

Suggested Labels

C:server/v2 appmanager, C:server/v2 cometbft

Suggested Reviewers

  • kocubinski
  • julienrbrt
  • hieuvubk
  • tac0turtle
  • sontrinh16
  • akhilkumarpilli

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.

@github-actions github-actions bot added C:Confix Issues and PR related to Confix C:server/v2 Issues related to server/v2 C:server/v2 api labels Jan 8, 2025
@mmsqe mmsqe marked this pull request as ready for review January 8, 2025 02:02
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: 2

🧹 Nitpick comments (6)
baseapp/grpcserver.go (1)

29-31: Consider adding error handling for edge cases

The implementation should consider handling edge cases where the context creation fails specifically due to header validation. This would help in distinguishing between different types of failures and provide better error messages.

 func (app *BaseApp) RegisterGRPCServerWithSkipCheckHeader(server gogogrpc.Server, skipCheckHeader bool) {
+    if skipCheckHeader {
+        app.logger.Info("header validation is disabled for gRPC server")
+    }
     // ... rest of the implementation ...
     sdkCtx, err := app.CreateQueryContextWithCheckHeader(height, false, !skipCheckHeader)
     if err != nil {
+        if !skipCheckHeader && errors.Is(err, sdkerrors.ErrInvalidHeader) {
+            return nil, errorsmod.Wrapf(err, "header validation failed")
+        }
         return nil, err
     }

Also applies to: 57-57

server/config/config.toml.tpl (1)

174-176: Enhance the configuration documentation.

The comment for skip-check-header could be more descriptive. Consider explaining:

  • The purpose and impact of bypassing header checks
  • When this option should be enabled/disabled
  • Any security implications
-# SkipCheckHeader defines if the gRPC server should bypass check header.
+# SkipCheckHeader defines if the gRPC server should bypass header checks.
+# Enable this option only for pruned nodes or when running under gRPC.
+# Note: Disabling header checks may affect chain security guarantees.
 skip-check-header = {{ .GRPC.SkipCheckHeader }}
CHANGELOG.md (4)

Line range hint 1-1: Add version links to release headers

The version headers in the changelog should include links to the corresponding GitHub releases/tags for easier navigation.

- ## [v0.47.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.0) - 2023-03-14
+ ## [v0.47.0]

48-48: Fix typo in changelog entry

There's a typo in "heaader" which should be "header".

- * (server) [#23244](https://github.com/cosmos/cosmos-sdk/pull/23244) Allow align block header with skip check heaader in grpc server.
+ * (server) [#23244](https://github.com/cosmos/cosmos-sdk/pull/23244) Allow align block header with skip check header in grpc server.

Line range hint 1-2000: Improve changelog organization

The changelog is well-maintained but could benefit from:

  1. A table of contents for easier navigation
  2. Consistent formatting for PR references
  3. Clearer migration instructions with code examples

Line range hint 1-2000: Add deprecation notices more prominently

Consider adding a dedicated "Deprecation Notices" section at the top of each release to highlight important deprecations that require user attention.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b0031a1 and fe8268c.

📒 Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • baseapp/grpcserver.go (2 hunks)
  • server/config/config.go (1 hunks)
  • server/config/config.toml.tpl (1 hunks)
  • server/grpc/server.go (2 hunks)
  • server/types/app.go (1 hunks)
  • server/v2/api/grpc/config.go (1 hunks)
  • server/v2/testdata/app.toml (1 hunks)
  • tools/confix/data/v2-app.toml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
server/config/config.go (1)

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

server/grpc/server.go (1)

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

server/v2/api/grpc/config.go (1)

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

server/types/app.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"

baseapp/grpcserver.go (1)

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

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: repo-analysis
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (5)
server/types/app.go (1)

38-40: Breaking Change: Interface Method Modification

The removal of RegisterGRPCServer and addition of RegisterGRPCServerWithSkipCheckHeader is a breaking change that will require updates in all implementations of the Application interface. Consider providing a migration guide for users.

server/grpc/server.go (1)

23-26: LGTM: Clean implementation of the new interface

The changes correctly implement the new interface and properly pass the configuration option to the registration method.

Also applies to: 43-43

baseapp/grpcserver.go (1)

26-27: LGTM: Good backward compatibility

The default implementation maintains backward compatibility by calling the new method with skipCheckHeader set to false.

server/v2/testdata/app.toml (1)

12-13: LGTM!

The test configuration is consistent with the main configuration template and uses appropriate default values.

tools/confix/data/v2-app.toml (1)

47-48: LGTM!

The configuration is consistent across all files and follows a secure-by-default approach with skip-check-header = false.

server/v2/api/grpc/config.go Outdated Show resolved Hide resolved
server/config/config.go Show resolved Hide resolved
@julienrbrt
Copy link
Member

First and foremost, what is the use case?

Additionally, server is being killed from main (#22904 / #23238). I think this is the moment where the main branch diverges from release/v0.52.x, which will hold the last baseapp implementation. Could you target directly release/v0.52.x instead for the baseapp changes?

The v2 changes should still target main, so this is fine, however this PR doesn't implement the proposed functionality.

@mmsqe
Copy link
Contributor Author

mmsqe commented Jan 8, 2025

Noted thanks. This flag is used for case such as grpcOnly or prune node, where block header could be empty, which can't be returned if this check is not skipped by a false checkHeader.

mmsqe added 2 commits January 8, 2025 20:34
… server

ensure overwrite with latest header under grpc only or pruned node
@mmsqe mmsqe changed the base branch from main to release/v0.52.x January 8, 2025 12:36
@mmsqe mmsqe changed the title feat(server): allow align block header with skip check heaader in grpc server fix(server): allow align block header with skip check heaader in grpc server Jan 8, 2025
@github-actions github-actions bot removed C:server/v2 Issues related to server/v2 C:server/v2 api labels Jan 8, 2025
@mmsqe mmsqe changed the title fix(server): allow align block header with skip check heaader in grpc server fix(server): allow align block header with skip check header in grpc server Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Confix Issues and PR related to Confix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants