mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-04 02:52:07 +00:00
Closes #7073 As part of the 0.36 cycle we've discussed and decided to remove the mutex in tendermint that protects the ABCI application. First, applications should be able to be responsible for their own concurrency control, and can make more fine-grained decisions about concurrent use than tendermint ever could. Second, I've observed in recent weeks as we've been making this change that the mutex wasn't applied particularly consistently in many cases (e.g. multiple "local" connections to the application had multiple locks, etc.) so this will give more consistent experiences across ABCI execution environments, and simplifies the tendermint ABCI handling code.
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
tmnet "github.com/tendermint/tendermint/libs/net"
|
|
"github.com/tendermint/tendermint/libs/service"
|
|
)
|
|
|
|
type GRPCServer struct {
|
|
service.BaseService
|
|
logger log.Logger
|
|
|
|
proto string
|
|
addr string
|
|
server *grpc.Server
|
|
|
|
app types.ABCIApplicationServer
|
|
}
|
|
|
|
// NewGRPCServer returns a new gRPC ABCI server
|
|
func NewGRPCServer(logger log.Logger, protoAddr string, app types.ABCIApplicationServer) service.Service {
|
|
proto, addr := tmnet.ProtocolAndAddress(protoAddr)
|
|
s := &GRPCServer{
|
|
logger: logger,
|
|
proto: proto,
|
|
addr: addr,
|
|
app: app,
|
|
}
|
|
s.BaseService = *service.NewBaseService(logger, "ABCIServer", s)
|
|
return s
|
|
}
|
|
|
|
// OnStart starts the gRPC service.
|
|
func (s *GRPCServer) OnStart(ctx context.Context) error {
|
|
ln, err := net.Listen(s.proto, s.addr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
s.server = grpc.NewServer()
|
|
types.RegisterABCIApplicationServer(s.server, s.app)
|
|
|
|
s.logger.Info("Listening", "proto", s.proto, "addr", s.addr)
|
|
go func() {
|
|
go func() {
|
|
<-ctx.Done()
|
|
s.server.GracefulStop()
|
|
}()
|
|
|
|
if err := s.server.Serve(ln); err != nil {
|
|
s.logger.Error("error serving gRPC server", "err", err)
|
|
}
|
|
}()
|
|
return nil
|
|
}
|
|
|
|
// OnStop stops the gRPC server.
|
|
func (s *GRPCServer) OnStop() { s.server.Stop() }
|