Skip to content

Commit

Permalink
fix(server): allow align block header with skip check heaader in grpc…
Browse files Browse the repository at this point in the history
… server

ensure overwrite with latest header under grpc only or pruned node
  • Loading branch information
mmsqe committed Jan 8, 2025
1 parent c6327ea commit 3d50d82
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (query) [23002](https://github.com/cosmos/cosmos-sdk/pull/23002) Fix collection filtered pagination.
* (x/auth/tx) [23144](https://github.com/cosmos/cosmos-sdk/pull/23144) Add missing CacheWithValue for ExtensionOptions.
* (x/auth/tx) [#23148](https://github.com/cosmos/cosmos-sdk/pull/23148) Avoid panic from intoAnyV2 when v1.PublicKey is optional.
* (server) [#23244](https://github.com/cosmos/cosmos-sdk/pull/23244) Allow align block header with skip check heaader in grpc server.

### Deprecated

Expand Down
8 changes: 7 additions & 1 deletion baseapp/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// RegisterGRPCServer registers gRPC services directly with the gRPC server.
func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
app.RegisterGRPCServerWithSkipCheckHeader(server, false)
}

// RegisterGRPCServerWithSkipCheckHeader registers gRPC services with the specified gRPC server
// and bypass check header flag.
func (app *BaseApp) RegisterGRPCServerWithSkipCheckHeader(server gogogrpc.Server, skipCheckHeader bool) {
// Define an interceptor for all gRPC queries: this interceptor will create
// a new sdk.Context, and pass it into the query handler.
interceptor := func(grpcCtx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
Expand All @@ -48,7 +54,7 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {

// Create the sdk.Context. Passing false as 2nd arg, as we can't
// actually support proofs with gRPC right now.
sdkCtx, err := app.CreateQueryContext(height, false)
sdkCtx, err := app.CreateQueryContextWithCheckHeader(height, false, !skipCheckHeader)
if err != nil {
return nil, err
}
Expand Down
12 changes: 8 additions & 4 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ type GRPCConfig struct {
// MaxSendMsgSize defines the max message size in bytes the server can send.
// The default value is math.MaxInt32.
MaxSendMsgSize int `mapstructure:"max-send-msg-size"`

// SkipCheckHeader defines if the gRPC server should bypass check header.
SkipCheckHeader bool `mapstructure:"skip-check-header"`
}

// StateSyncConfig defines the state sync snapshot configuration.
Expand Down Expand Up @@ -237,10 +240,11 @@ func DefaultConfig() *Config {
RPCMaxBodyBytes: 1000000,
},
GRPC: GRPCConfig{
Enable: true,
Address: DefaultGRPCAddress,
MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize,
MaxSendMsgSize: DefaultGRPCMaxSendMsgSize,
Enable: true,
Address: DefaultGRPCAddress,
MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize,
MaxSendMsgSize: DefaultGRPCMaxSendMsgSize,
SkipCheckHeader: false,
},
StateSync: StateSyncConfig{
SnapshotInterval: 0,
Expand Down
3 changes: 3 additions & 0 deletions server/config/config.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}"
# The default value is math.MaxInt32.
max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}"

# SkipCheckHeader defines if the gRPC server should bypass check header.
skip-check-header = {{ .GRPC.SkipCheckHeader }}

###############################################################################
### State Sync Configuration ###
###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewGRPCServer(clientCtx client.Context, app types.Application, cfg config.G
grpc.MaxRecvMsgSize(maxRecvMsgSize),
)

app.RegisterGRPCServer(grpcSrv)
app.RegisterGRPCServerWithSkipCheckHeader(grpcSrv, cfg.SkipCheckHeader)

// Reflection allows consumers to build dynamic clients that can write to any
// Cosmos SDK application without relying on application packages at compile
Expand Down
6 changes: 3 additions & 3 deletions server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type (

RegisterAPIRoutes(*api.Server, config.APIConfig)

// RegisterGRPCServer registers gRPC services directly with the gRPC
// server.
RegisterGRPCServer(grpc.Server)
// RegisterGRPCServerWithSkipCheckHeader registers gRPC services directly with the gRPC
// server and bypass check header flag.
RegisterGRPCServerWithSkipCheckHeader(grpc.Server, bool)

// RegisterTxService registers the gRPC Query service for tx (such as tx
// simulation, fetching txs by hash...).
Expand Down
3 changes: 3 additions & 0 deletions tools/confix/data/v0.52-app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ max-recv-msg-size = "10485760"
# The default value is math.MaxInt32.
max-send-msg-size = "2147483647"

# SkipCheckHeader defines if the gRPC server should bypass check header.
skip-check-header = false

###############################################################################
### State Sync Configuration ###
###############################################################################
Expand Down
4 changes: 4 additions & 0 deletions tools/confix/data/v2-app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ max-recv-msg-size = 10485760
# MaxSendMsgSize defines the max message size in bytes the server can send.
# The default value is math.MaxInt32.
max-send-msg-size = 2147483647
# SkipCheckHeader defines if the gRPC server should bypass check header.
skip-check-header = false
# SkipCheckHeader defines if the gRPC server should bypass check header.
skip-check-header = false

[grpc-gateway]
# Enable defines if the gRPC-gateway should be enabled.
Expand Down

0 comments on commit 3d50d82

Please sign in to comment.