go-ethereum/node/grpcstack.go
Jordan Oroshiba f91e86a130
Adding features to mempool to support our pre-ordered txs (#2)
* Adding features to mempool to support our pre-ordered txs

* Add framing for gRPC to execute blocks

* Remove public engine API call

* Fix circular dependencies

* Updated to use new Init, and fill out starting attributes

* Add clear astriaordered, cleanup

* readme fix

* add bash and jq to final docker image

* make txpool interface

* no more panics, update DoBlock to also update state + store block

* cleanup

* set post-merge at genesis

* cleanup

* doc update

* remove txpool interface changes

* cleanup

* cleanup

* build and push images wih tags defined by git tags

* build for multiple architectures. use docker-metadata action for semver

* add push: true

* only build arm for git tags/releases

---------

Co-authored-by: Jesse Snyder <jessetsnyder@gmail.com>
Co-authored-by: elizabeth <elizabethjbinks@gmail.com>
2023-04-10 12:21:41 -05:00

69 lines
1.7 KiB
Go

package node
import (
"net"
"sync"
executionv1 "github.com/ethereum/go-ethereum/grpc/gen/proto/execution/v1"
"github.com/ethereum/go-ethereum/log"
"google.golang.org/grpc"
)
// GRPCServerHandler is the gRPC server handler.
// It gives us a way to attach the gRPC server to the node so it can be stopped on shutdown.
type GRPCServerHandler struct {
mu sync.Mutex
endpoint string
server *grpc.Server
executionServiceServer *executionv1.ExecutionServiceServer
}
// NewServer creates a new gRPC server.
// It registers the execution service server.
// It registers the gRPC server with the node so it can be stopped on shutdown.
func NewGRPCServerHandler(node *Node, execService executionv1.ExecutionServiceServer, cfg *Config) error {
server := grpc.NewServer()
log.Info("gRPC server enabled", "endpoint", cfg.GRPCEndpoint())
serverHandler := &GRPCServerHandler{
endpoint: cfg.GRPCEndpoint(),
server: server,
executionServiceServer: &execService,
}
executionv1.RegisterExecutionServiceServer(server, execService)
node.RegisterGRPCServer(serverHandler)
return nil
}
// Start starts the gRPC server if it is enabled.
func (handler *GRPCServerHandler) Start() error {
handler.mu.Lock()
defer handler.mu.Unlock()
if handler.endpoint == "" {
return nil
}
// Start the gRPC server
lis, err := net.Listen("tcp", handler.endpoint)
if err != nil {
return err
}
go handler.server.Serve(lis)
log.Info("gRPC server started", "endpoint", handler.endpoint)
return nil
}
// Stop stops the gRPC server.
func (handler *GRPCServerHandler) Stop() error {
handler.mu.Lock()
defer handler.mu.Unlock()
handler.server.Stop()
log.Info("gRPC server stopped", "endpoint", handler.endpoint)
return nil
}