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

Feature/grpc execution api #1

Merged
merged 8 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
utils.RegisterGraphQLService(stack, backend, filterSystem, &cfg.Node)
}

// Configure gRPC if requested.
if ctx.IsSet(utils.GRPCEnabledFlag.Name) {
utils.RegisterGRPCService(stack, backend, &cfg.Node)
}

// Add the Ethereum Stats daemon if requested.
if cfg.Ethstats.URL != "" {
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ var (
utils.RPCGlobalEVMTimeoutFlag,
utils.RPCGlobalTxFeeCapFlag,
utils.AllowUnprotectedTxs,
utils.GRPCEnabledFlag,
utils.GRPCHostFlag,
utils.GRPCPortFlag,
}

metricsFlags = []cli.Flag{
Expand Down
40 changes: 40 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,24 @@ var (
Usage: "Enables the (deprecated) personal namespace",
Category: flags.APICategory,
}
// grpc
GRPCEnabledFlag = &cli.BoolFlag{
Name: "grpc",
Usage: "Enable the gRPC server",
Category: flags.APICategory,
}
GRPCHostFlag = &cli.StringFlag{
Name: "grpc.addr",
Usage: "gRPC server listening interface",
Value: node.DefaultGRPCHost,
Category: flags.APICategory,
}
GRPCPortFlag = &cli.IntFlag{
Name: "grpc.port",
Usage: "gRPC server listening port",
Value: node.DefaultGRPCPort,
Category: flags.APICategory,
}

// Network Settings
MaxPeersFlag = &cli.IntFlag{
Expand Down Expand Up @@ -1211,6 +1229,19 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
}
}

// setGRCP creates the gRPC RPC listener interface string from the set command
// line flags, returning empty if the gRPC endpoint is disabled.
func setGRCP(ctx *cli.Context, cfg *node.Config) {
if ctx.Bool(GRPCEnabledFlag.Name) {
if ctx.IsSet(GRPCHostFlag.Name) {
cfg.GRPCHost = ctx.String(GRPCHostFlag.Name)
}
if ctx.IsSet(GRPCPortFlag.Name) {
cfg.GRPCPort = ctx.Int(GRPCPortFlag.Name)
}
}
}

// setGraphQL creates the GraphQL listener interface string from the set
// command line flags, returning empty if the GraphQL endpoint is disabled.
func setGraphQL(ctx *cli.Context, cfg *node.Config) {
Expand Down Expand Up @@ -1460,6 +1491,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
SetP2PConfig(ctx, &cfg.P2P)
setIPC(ctx, cfg)
setHTTP(ctx, cfg)
setGRCP(ctx, cfg)
setGraphQL(ctx, cfg)
setWS(ctx, cfg)
setNodeUserIdent(ctx, cfg)
Expand Down Expand Up @@ -2032,6 +2064,14 @@ func RegisterGraphQLService(stack *node.Node, backend ethapi.Backend, filterSyst
}
}

// RegisterGRPCService adds the gRPC API to the node.
// It was done this way so that our grpc execution server can access the ethapi.Backend
func RegisterGRPCService(stack *node.Node, backend ethapi.Backend, cfg *node.Config) {
if err := node.NewGRPCServerHandler(stack, backend, cfg); err != nil {
Fatalf("Failed to register the gRPC service: %v", err)
}
}

// RegisterFilterAPI adds the eth log filtering RPC API to the node.
func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconfig.Config) *filters.FilterSystem {
isLightClient := ethcfg.SyncMode == downloader.LightSync
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ require (
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,16 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc=
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
15 changes: 15 additions & 0 deletions grpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This package provides a gRPC server as an entrypoint to the EVM.

Helpful commands (MacOS):
```bash
# install necessary dependencies
brew install leveldb

# build geth
make geth

# TODO - run beacon?

# run geth
./build/bin/geth --grpc --grpc.addr "[::1]" --grpc.port 50051
```
22 changes: 22 additions & 0 deletions grpc/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# buf.gen.yaml
version: v1
managed:
enabled: true
go_package_prefix:
# <module_name> : name in go.mod
# <relative_path> : where generated code should be output
# default: <module_name>/<relative_path>
default: github.com/ethereum/go-ethereum/grpc
# Remove `except` field if googleapis is not used
# except:
# - buf.build/googleapis/googleapis
plugins:
- plugin: buf.build/grpc/go
out: gen
opt:
- paths=source_relative
# dependencies
- plugin: buf.build/protocolbuffers/go
out: gen
opt:
- paths=source_relative
64 changes: 64 additions & 0 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Package execution provides the gRPC server for the execution layer.
//
// Its procedures will be called from the conductor. It is responsible
// for immediately executing lists of ordered transactions that come from the shared sequencer.
package execution

import (
"context"

"github.com/ethereum/go-ethereum/core/types"
executionv1 "github.com/ethereum/go-ethereum/grpc/gen/proto/execution/v1"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
)

// executionServiceServer is the implementation of the ExecutionServiceServer interface.
type ExecutionServiceServer struct {
// NOTE - from the generated code:
// All implementations must embed UnimplementedExecutionServiceServer
// for forward compatibility
executionv1.UnimplementedExecutionServiceServer

// TODO - will need access to the consensus api to call functions for building a block
// e.g. getPayload, newPayload, forkchoiceUpdated

Backend ethapi.Backend

// TODO - will need access to forkchoice on first run.
// this will probably be passed in when calling NewServer
}

// FIXME - how do we know which hash to start with? will probably need another api function like
// GetHeadHash() to get the head hash of the forkchoice

func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.DoBlockRequest) (*executionv1.DoBlockResponse, error) {
log.Info("DoBlock called request", "request", req)

// NOTE - Request.Header.ParentHash needs to match forkchoice head hash
// ParentHash should be the forkchoice head of the last block

// TODO - need to call consensus api to build a block

// txs := bytesToTransactions(req.Transactions)
// for _, tx := range txs {
// s.Backend.SendTx(ctx, tx)
// }

res := &executionv1.DoBlockResponse{
// TODO - get state root from last block
StateRoot: []byte{0x00},
}
return res, nil
}

// convert bytes to transactions
func bytesToTransactions(b [][]byte) []*types.Transaction {
txs := []*types.Transaction{}
for _, txBytes := range b {
tx := &types.Transaction{}
tx.UnmarshalBinary(txBytes)
txs = append(txs, tx)
}
return txs
}
Loading