-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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(server/v2/grpcgateway): register grpcgateway server and module endpoints #22701
Changes from 9 commits
453e50c
4fbc2be
251c05a
05d2bf4
dbd93ac
be03c92
0eb853d
af260f2
c1f48b4
332d9a4
e251733
cb6063e
6bc8be3
51cd316
da3da66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,10 @@ func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { | |
return flags | ||
} | ||
|
||
func (s *Server[T]) GrpcServer() *grpc.Server { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See other comment, if we don't need the grpc server, let's not expose this |
||
return s.grpcSrv | ||
} | ||
|
||
func makeUnknownServiceHandler( | ||
handlers map[string]appmodulev2.Handler, | ||
queryable func(ctx context.Context, version uint64, msg transaction.Msg) (transaction.Msg, error), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ type Server[T transaction.Tx] struct { | |
|
||
server *http.Server | ||
gRPCSrv *grpc.Server | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like |
||
gRPCGatewayRouter *runtime.ServeMux | ||
GRPCGatewayRouter *runtime.ServeMux | ||
} | ||
|
||
// New creates a new gRPC-gateway server. | ||
|
@@ -53,7 +53,7 @@ func New[T transaction.Tx]( | |
|
||
s := &Server[T]{ | ||
gRPCSrv: grpcSrv, | ||
gRPCGatewayRouter: runtime.NewServeMux( | ||
GRPCGatewayRouter: runtime.NewServeMux( | ||
// Custom marshaler option is required for gogo proto | ||
runtime.WithMarshalerOption(runtime.MIMEWildcard, marshalerOption), | ||
|
||
|
@@ -83,6 +83,13 @@ func New[T transaction.Tx]( | |
return s, nil | ||
} | ||
|
||
// NewWithConfigOptions creates a new gRPC-gateway server with the provided config options. | ||
func NewWithConfigOptions[T transaction.Tx](opts ...CfgOption) *Server[T] { | ||
return &Server[T]{ | ||
cfgOptions: opts, | ||
} | ||
} | ||
|
||
func (s *Server[T]) Name() string { | ||
return ServerName | ||
} | ||
|
@@ -108,7 +115,7 @@ func (s *Server[T]) Start(ctx context.Context) error { | |
} | ||
|
||
mux := http.NewServeMux() | ||
mux.Handle("/", s.gRPCGatewayRouter) | ||
mux.Handle("/", s.GRPCGatewayRouter) | ||
|
||
s.server = &http.Server{ | ||
Addr: s.config.Address, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
runtimev2 "cosmossdk.io/runtime/v2" | ||
serverv2 "cosmossdk.io/server/v2" | ||
grpcserver "cosmossdk.io/server/v2/api/grpc" | ||
"cosmossdk.io/server/v2/api/grpcgateway" | ||
"cosmossdk.io/server/v2/api/rest" | ||
"cosmossdk.io/server/v2/api/telemetry" | ||
"cosmossdk.io/server/v2/cometbft" | ||
|
@@ -20,6 +21,7 @@ | |
confixcmd "cosmossdk.io/tools/confix/cmd" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
sdkclient "github.com/cosmos/cosmos-sdk/client" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid duplicate imports of the same package The package Apply the following diff to remove the duplicate import: - "github.com/cosmos/cosmos-sdk/client"
🧰 Tools🪛 golangci-lint (1.62.2)24-24: ST1019(related information): other import of "github.com/cosmos/cosmos-sdk/client" (stylecheck) |
||
"github.com/cosmos/cosmos-sdk/client/config" | ||
"github.com/cosmos/cosmos-sdk/client/debug" | ||
"github.com/cosmos/cosmos-sdk/client/keys" | ||
|
@@ -31,8 +33,13 @@ | |
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" | ||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2/cli" | ||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
) | ||
|
||
type ModuleWithGRPCGateway interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to delete |
||
RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwruntime.ServeMux) | ||
} | ||
|
||
// CommandDependencies is a struct that contains all the dependencies needed to initialize the root command. | ||
// an alternative design could fetch these even later from the command context | ||
type CommandDependencies[T transaction.Tx] struct { | ||
|
@@ -83,6 +90,7 @@ | |
&serverstore.Server[T]{}, | ||
&telemetry.Server[T]{}, | ||
&rest.Server[T]{}, | ||
&grpcgateway.Server[T]{}, | ||
) | ||
} | ||
|
||
|
@@ -140,6 +148,24 @@ | |
return nil, err | ||
} | ||
|
||
grpcSrv := grpcServer.GrpcServer() | ||
|
||
grpcgatewayServer, err := grpcgateway.New[T]( | ||
logger, | ||
deps.GlobalConfig, | ||
grpcSrv, | ||
simApp.InterfaceRegistry(), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, mod := range deps.ModuleManager.Modules() { | ||
if gmod, ok := mod.(ModuleWithGRPCGateway); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use module.HasGRPCGateway (from types/modules), and can you add a |
||
gmod.RegisterGRPCGatewayRoutes(deps.ClientContext, grpcgatewayServer.GRPCGatewayRouter) | ||
} | ||
} | ||
|
||
|
||
// wire server commands | ||
return serverv2.AddCommands[T]( | ||
rootCmd, | ||
|
@@ -152,6 +178,7 @@ | |
storeComponent, | ||
telemetryServer, | ||
restServer, | ||
grpcgatewayServer, | ||
) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,3 +167,5 @@ require ( | |
pgregory.net/rapid v1.1.0 // indirect | ||
sigs.k8s.io/yaml v1.4.0 // indirect | ||
) | ||
|
||
replace cosmossdk.io/systemtests => ../../systemtests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove local The Please remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove that replace? We have rc.2 tagged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no changelog needed, thanks!