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

use grpcAccess Client option in Gateway #45

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
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
18 changes: 8 additions & 10 deletions gateway/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
grpcAccess "github.com/onflow/flow-go-sdk/access/grpc"
"github.com/onflow/flow-go/utils/grpcutils"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/onflow/flowkit/v2/config"
)
Expand All @@ -45,18 +44,17 @@ type GrpcGateway struct {

// NewGrpcGateway returns a new gRPC gateway.

func NewGrpcGateway(network config.Network, opts ...grpc.DialOption) (*GrpcGateway, error) {
options := []grpc.DialOption{
func NewGrpcGateway(network config.Network, opts ...grpcAccess.ClientOption) (*GrpcGateway, error) {
opts = append(
Copy link
Member

@turbolent turbolent May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't equivalent to the previous version: Before, the default was insecure, and the options passed to the function were appended, allowing to override this default. Now, the insecure option is appended to the given options, overriding options passed by the user.

Ideally also add a test that ensures this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? Isn't it done where the defaults are set first, then any additonal options are appended to override the default?

https://github.com/onflow/flow-go-sdk/blob/master/access/grpc/client.go#L56-L58

Here the default is set as grpc.WithTransportCredentials(insecure.NewCredentials()), then any additional options are appended here:

https://github.com/onflow/flow-go-sdk/blob/master/access/grpc/client.go#L66-L70

meaning, shouldn't the final result be

dialOptions = []grpc.DialOptions{
grpc.WithTransportCredentials(insecure.NewCredentials()), // from the Default
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxGRPCMessageSize) // added from flowkit
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, i just understood what you meant 👍 let me fix this

opts,
grpcAccess.WithGRPCDialOptions(
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxGRPCMessageSize),
),
))

grpc.WithTransportCredentials(insecure.NewCredentials()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already defaulted

grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxGRPCMessageSize)),
}
options = append(options, opts...)
gClient, err := grpcAccess.NewClient(
network.Host,
grpcAccess.WithGRPCDialOptions(
options...,
),
opts...,
)

if err != nil || gClient == nil {
Expand Down
Loading