mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Add grpc middleware to recover from panics (#1956)
This commit is contained in:
parent
e4588d9be0
commit
bdbc572f3f
@ -1046,3 +1046,9 @@ go_repository(
|
||||
commit = "a5947ffaace3e882f334c1750858b4a6a7e52422",
|
||||
importpath = "golang.org/x/xerrors",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_grpc_ecosystem_go_grpc_middleware",
|
||||
commit = "cfaf5686ec79ff8344257723b6f5ba1ae0ffeb4d",
|
||||
importpath = "github.com/grpc-ecosystem/go-grpc-middleware",
|
||||
)
|
||||
|
@ -24,6 +24,8 @@ go_library(
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library",
|
||||
"@com_github_grpc_ecosystem_go_grpc_middleware//recovery:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//plugin/ocgrpc:go_default_library",
|
||||
"@org_golang_google_grpc//:go_default_library",
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
@ -118,6 +120,15 @@ func (s *Service) Start() {
|
||||
s.listener = lis
|
||||
log.Infof("RPC server listening on port :%s", s.port)
|
||||
|
||||
opts := []grpc.ServerOption{
|
||||
grpc.StatsHandler(&ocgrpc.ServerHandler{}),
|
||||
grpc.StreamInterceptor(middleware.ChainStreamServer(
|
||||
recovery.StreamServerInterceptor(),
|
||||
)),
|
||||
grpc.UnaryInterceptor(middleware.ChainUnaryServer(
|
||||
recovery.UnaryServerInterceptor(),
|
||||
)),
|
||||
}
|
||||
// TODO(#791): Utilize a certificate for secure connections
|
||||
// between beacon nodes and validator clients.
|
||||
if s.withCert != "" && s.withKey != "" {
|
||||
@ -126,11 +137,11 @@ func (s *Service) Start() {
|
||||
log.Errorf("Could not load TLS keys: %s", err)
|
||||
s.credentialError = err
|
||||
}
|
||||
s.grpcServer = grpc.NewServer(grpc.Creds(creds), grpc.StatsHandler(&ocgrpc.ServerHandler{}))
|
||||
opts = append(opts, grpc.Creds(creds))
|
||||
} else {
|
||||
log.Warn("You are using an insecure gRPC connection! Provide a certificate and key to connect securely")
|
||||
s.grpcServer = grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
|
||||
}
|
||||
s.grpcServer = grpc.NewServer(opts...)
|
||||
|
||||
beaconServer := &BeaconServer{
|
||||
beaconDB: s.beaconDB,
|
||||
|
Loading…
Reference in New Issue
Block a user