Skip to content

Commit

Permalink
Unify gRPC Gateways into Single, Shared lib (#8799)
Browse files Browse the repository at this point in the history
* moved validator/rpc/gateway under shared,  validator/rpc/web is not visiable to the new shared gateway

* decided to have one lib with two methods if needed, status and stop are the same, however New and Start are not

* moved beacon's gateway to shared and moved the main func to its own /server folder

* goftm

* gofmt

* removed the extra loggin

* reduce visibility

* tighter visibilty of the shared lib for beacon and validator only for now

* fix patterns , ctx needs to be first param

* fix comments

* gofmt

* added enum for the caller id

* added unit test for gateway

* deprecated .WithDialer to .WithContextDialer

* changed the string callerId to uint8, and rearranged the Gateway struct based on the compiler

* fix 1 based on comment

* iota type

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
  • Loading branch information
ahadda5 and rauljordan authored May 4, 2021
1 parent 3c9b9e7 commit 8dd2915
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 333 deletions.
20 changes: 0 additions & 20 deletions beacon-chain/gateway/cors.go

This file was deleted.

26 changes: 0 additions & 26 deletions beacon-chain/gateway/handlers.go

This file was deleted.

50 changes: 0 additions & 50 deletions beacon-chain/gateway/server/BUILD.bazel

This file was deleted.

2 changes: 1 addition & 1 deletion beacon-chain/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ go_library(
"//beacon-chain/db/kv:go_default_library",
"//beacon-chain/forkchoice:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/gateway:go_default_library",
"//beacon-chain/interop-cold-start:go_default_library",
"//beacon-chain/node/registration:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
Expand All @@ -41,6 +40,7 @@ go_library(
"//shared/debug:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/gateway:go_default_library",
"//shared/params:go_default_library",
"//shared/prereq:go_default_library",
"//shared/prometheus:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
interopcoldstart "github.com/prysmaticlabs/prysm/beacon-chain/interop-cold-start"
"github.com/prysmaticlabs/prysm/beacon-chain/node/registration"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
Expand All @@ -42,6 +41,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/gateway"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/prereq"
"github.com/prysmaticlabs/prysm/shared/prometheus"
Expand Down Expand Up @@ -650,7 +650,7 @@ func (b *BeaconNode) registerGRPCGateway() error {
enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name)
selfCert := b.cliCtx.String(flags.CertFlag.Name)
return b.services.RegisterService(
gateway.New(
gateway.NewBeacon(
b.ctx,
selfAddress,
selfCert,
Expand Down
24 changes: 24 additions & 0 deletions beacon-chain/server/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@prysm//tools/go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"log.go",
"main.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/server",
visibility = ["//visibility:private"],
deps = [
"//shared/gateway:go_default_library",
"//shared/maxprocs:go_default_library",
"@com_github_joonix_log//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

go_binary(
name = "server",
embed = [":go_default_library"],
visibility = ["//visibility:private"],
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

joonix "github.com/joonix/log"
"github.com/prysmaticlabs/prysm/beacon-chain/gateway"
"github.com/prysmaticlabs/prysm/shared/gateway"
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
"github.com/sirupsen/logrus"
)
Expand All @@ -36,7 +36,7 @@ func main() {
}

mux := http.NewServeMux()
gw := gateway.New(
gw := gateway.NewBeacon(
context.Background(),
*beaconRPC,
"", // remoteCert
Expand Down
1 change: 1 addition & 0 deletions cmd/beacon-chain/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
visibility = [
"//beacon-chain:__subpackages__",
"//cmd/beacon-chain:__subpackages__",
"//shared/gateway:__pkg__",
],
deps = [
"//shared/cmd:go_default_library",
Expand Down
25 changes: 19 additions & 6 deletions beacon-chain/gateway/BUILD.bazel → shared/gateway/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# gazelle:ignore
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@prysm//tools/go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"cors.go",
"gateway.go",
"handlers.go",
"log.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/gateway",
importpath = "github.com/prysmaticlabs/prysm/shared/gateway",
visibility = [
"//beacon-chain/gateway/server:__pkg__",
"//beacon-chain/node:__pkg__",
"//beacon-chain:__subpackages__",
"//validator:__subpackages__",
],
deps = [
"//proto/beacon/rpc/v1:go_grpc_gateway_library",
"//proto/validator/accounts/v2:ethereum_validator_account_gateway_proto",
"//shared:go_default_library",
"//validator/web:go_default_library",
"@com_github_grpc_ecosystem_grpc_gateway//runtime:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_grpc_gateway_library",
Expand All @@ -27,3 +28,15 @@ go_library(
"@org_golang_google_grpc//credentials:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["gateway_test.go"],
embed = [":go_default_library"],
deps = [
"//cmd/beacon-chain/flags:go_default_library",
"//shared/testutil/require:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)
Loading

0 comments on commit 8dd2915

Please sign in to comment.