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: v2 system tests #20896

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c0ddc0
refactor grpc query handlers
testinginprod Jul 23, 2024
9162065
add make unknown service handler
testinginprod Jul 23, 2024
cdbd164
refactors left and right
testinginprod Jul 23, 2024
8ab8b26
add height header handling
testinginprod Jul 23, 2024
a83f470
Merge remote-tracking branch 'origin/tip/serverv2/grpc' into tip/serv…
testinginprod Jul 23, 2024
a161d7a
v2 system tests
tac0turtle Jul 5, 2024
74377a4
changes
tac0turtle Jul 5, 2024
2dc6114
system tests failing
tac0turtle Jul 5, 2024
d3b5c45
fix simapp v2 init shell
tac0turtle Jul 5, 2024
ad50d8d
turn simapp v2 tests into a systemtest
tac0turtle Jul 16, 2024
a874125
fix gRPC handlers being overriden each time
testinginprod Jul 16, 2024
b5eca3e
remove unused flag from grpc
tac0turtle Jul 16, 2024
dd909c9
chore(core): sync changelog (#21025)
julienrbrt Jul 23, 2024
27876af
refactor(schema)!: move bech32 address prefixes to a higher level (#2…
aaronc Jul 23, 2024
9fb5833
fixes from reabse
tac0turtle Jul 27, 2024
c427155
fix flag
tac0turtle Jul 28, 2024
969f62e
Merge branch 'main' into marko/system_v2
tac0turtle Jul 30, 2024
16a0a87
fix import
tac0turtle Jul 30, 2024
9d296ee
fix ci
tac0turtle Jul 30, 2024
261c4be
erge branch 'main' into marko/system_v2
tac0turtle Aug 4, 2024
233b7cf
Merge branch 'main' into marko/system_v2
tac0turtle Aug 6, 2024
84fd6f8
++
tac0turtle Aug 6, 2024
8ae4591
++
tac0turtle Aug 6, 2024
3308f99
++
tac0turtle Aug 7, 2024
6881520
Merge branch 'main' into marko/system_v2
tac0turtle Aug 7, 2024
43fa607
test
tac0turtle Aug 8, 2024
7aa637d
Merge branch 'main' into marko/system_v2
tac0turtle Aug 20, 2024
c14511f
Merge branch 'main' into marko/system_v2
tac0turtle Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add height header handling
  • Loading branch information
testinginprod committed Jul 23, 2024
commit 8ab8b26ad90cd0e46a046d0d7a3c5309962624b4
51 changes: 40 additions & 11 deletions server/v2/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"fmt"
"io"
"net"
"strconv"

"github.com/cosmos/gogoproto/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"cosmossdk.io/core/transaction"
Expand All @@ -19,7 +21,9 @@ import (
"cosmossdk.io/server/v2/api/grpc/gogoreflection"
)

type GRPCServer[T transaction.Tx] struct {
const BlockHeightHeader = "x-cosmos-block-height"

type Server[T transaction.Tx] struct {
logger log.Logger
config *Config
cfgOptions []CfgOption
Expand All @@ -28,15 +32,15 @@ type GRPCServer[T transaction.Tx] struct {
}

// New creates a new grpc server.
func New[T transaction.Tx](cfgOptions ...CfgOption) *GRPCServer[T] {
return &GRPCServer[T]{
func New[T transaction.Tx](cfgOptions ...CfgOption) *Server[T] {
return &Server[T]{
cfgOptions: cfgOptions,
}
}

// Init returns a correctly configured and initialized gRPC server.
// Note, the caller is responsible for starting the server.
func (s *GRPCServer[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error {
func (s *Server[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logger) error {
cfg := s.Config().(*Config)
if v != nil {
if err := serverv2.UnmarshalSubConfig(v, s.Name(), &cfg); err != nil {
Expand Down Expand Up @@ -84,9 +88,12 @@ func makeUnknownServiceHandler(messageMap map[string]func() proto.Message, queri
}

// extract height header
height := uint64(0)

resp, err := querier.Query(stream.Context(), height, req)
ctx := stream.Context()
height, err := getHeightFromCtx(ctx)
if err != nil {
return status.Errorf(codes.InvalidArgument, "invalid get height from context: %v", err)
}
resp, err := querier.Query(ctx, height, req)
if err != nil {
return err
}
Expand All @@ -98,11 +105,33 @@ func makeUnknownServiceHandler(messageMap map[string]func() proto.Message, queri
}
}

func (s *GRPCServer[T]) Name() string {
func getHeightFromCtx(ctx context.Context) (uint64, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return 0, nil
}
values := md.Get(BlockHeightHeader)
if len(values) == 0 {
return 0, nil
}
if len(values) != 1 {
return 0, fmt.Errorf("gRPC height metadata must be of lenght 1, got: %d", len(values))
}

heightStr := values[0]
height, err := strconv.ParseUint(heightStr, 10, 64)
if err != nil {
return 0, fmt.Errorf("unable to parse height string from gRPC metadata %s: %v", heightStr, err)
}

return height, nil
}

func (s *Server[T]) Name() string {
return "grpc"
}

func (s *GRPCServer[T]) Config() any {
func (s *Server[T]) Config() any {
if s.config == nil || s.config == (&Config{}) {
cfg := DefaultConfig()
// overwrite the default config with the provided options
Expand All @@ -116,7 +145,7 @@ func (s *GRPCServer[T]) Config() any {
return s.config
}

func (s *GRPCServer[T]) Start(ctx context.Context) error {
func (s *Server[T]) Start(ctx context.Context) error {
if !s.config.Enable {
return nil
}
Expand All @@ -143,7 +172,7 @@ func (s *GRPCServer[T]) Start(ctx context.Context) error {
return err
}

func (s *GRPCServer[T]) Stop(ctx context.Context) error {
func (s *Server[T]) Stop(ctx context.Context) error {
if !s.config.Enable {
return nil
}
Expand Down