Skip to content

Commit

Permalink
feat: simple command to start go-execution-evm as server
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Nov 20, 2024
1 parent 1403e27 commit 0a2b882
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 20 deletions.
75 changes: 75 additions & 0 deletions cmd/evm-middleware/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"errors"
"github.com/ethereum/go-ethereum/common"

Check failure on line 5 in cmd/evm-middleware/main.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `goimports`-ed with -local github.com/rollkit (goimports)
"google.golang.org/grpc"
"log"
"net"
"os"
"sync"
"time"

"github.com/ethereum/go-ethereum/core"

grpcproxy "github.com/rollkit/go-execution/proxy/grpc"
pb "github.com/rollkit/go-execution/types/pb/execution"

evm "github.com/rollkit/go-execution-evm"
)

const bufSize = 1024 * 1024

func main() {
jwtSecret := ""
if len(os.Args) == 2 {
jwtSecret = os.Args[1]
}

config := &grpcproxy.Config{
DefaultTimeout: 5 * time.Second,
MaxRequestSize: bufSize,
}

listener, err := net.Listen("tcp4", "0.0.0.0:40041")
if err != nil {
log.Fatalf("error while creating listener: %v\n", err)
}
defer func() {
_ = listener.Close()
}()

// TODO(tzdybal): initialize from genesis file?
var genesisHash common.Hash
var feeRecipient common.Address

genesis := core.DefaultGenesisBlock()
genesisHash = genesis.ToBlock().Hash()

evmClient, err := evm.NewEngineAPIExecutionClient("http://:8545", "http://8551", jwtSecret, genesisHash, feeRecipient)
if err != nil {
log.Fatalf("failed to create Engine API client middleware: %v", err)
}
_ = evmClient.Start()
defer evmClient.Stop()

log.Println("Starting server...")
server := grpcproxy.NewServer(evmClient, config)
s := grpc.NewServer()
pb.RegisterExecutionServiceServer(s, server)

wg := sync.WaitGroup{}
wg.Add(1)

go func() {
log.Println("Serving...")
if err := s.Serve(listener); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
log.Fatalf("Server exited with error: %v\n", err)
}
wg.Done()
}()
defer s.Stop()

wg.Wait()
log.Println("Server stopped")
}
12 changes: 2 additions & 10 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/golang-jwt/jwt/v5"

Check failure on line 19 in execution.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `goimports`-ed with -local github.com/rollkit (goimports)
execution "github.com/rollkit/go-execution"
proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
execution_types "github.com/rollkit/go-execution/types"
)

Expand All @@ -32,7 +31,6 @@ var _ execution.Executor = (*EngineAPIExecutionClient)(nil)

// EngineAPIExecutionClient implements the execution.Execute interface
type EngineAPIExecutionClient struct {
proxyClient *proxy_json_rpc.Client
engineClient *rpc.Client // engine api
ethClient *ethclient.Client
genesisHash common.Hash
Expand All @@ -41,16 +39,12 @@ type EngineAPIExecutionClient struct {

// NewEngineAPIExecutionClient creates a new instance of EngineAPIExecutionClient
func NewEngineAPIExecutionClient(
proxyConfig *proxy_json_rpc.Config,
ethURL,
engineURL string,
jwtSecret string,
genesisHash common.Hash,
feeRecipient common.Address,
) (*EngineAPIExecutionClient, error) {
proxyClient := proxy_json_rpc.NewClient()
proxyClient.SetConfig(proxyConfig)

ethClient, err := ethclient.Dial(ethURL)
if err != nil {
return nil, err
Expand Down Expand Up @@ -88,7 +82,6 @@ func NewEngineAPIExecutionClient(
}

return &EngineAPIExecutionClient{
proxyClient: proxyClient,
engineClient: engineClient,
ethClient: ethClient,
genesisHash: genesisHash,
Expand All @@ -97,13 +90,12 @@ func NewEngineAPIExecutionClient(
}

// Start starts the execution client
func (c *EngineAPIExecutionClient) Start(url string) error {
return c.proxyClient.Start(url)
func (c *EngineAPIExecutionClient) Start() error {
return nil
}

// Stop stops the execution client and closes all connections
func (c *EngineAPIExecutionClient) Stop() {
c.proxyClient.Stop()

if c.engineClient != nil {
c.engineClient.Close()
Expand Down
5 changes: 0 additions & 5 deletions execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

Check failure on line 16 in execution_test.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `goimports`-ed with -local github.com/rollkit (goimports)
"github.com/rollkit/go-execution-evm/mocks"
proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
execution_types "github.com/rollkit/go-execution/types"
"github.com/stretchr/testify/require"
)
Expand All @@ -39,7 +38,6 @@ func TestEngineAPIExecutionClient_InitChain(t *testing.T) {

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
jwtSecret,
Expand Down Expand Up @@ -78,7 +76,6 @@ func TestEngineAPIExecutionClient_ExecuteTxs(t *testing.T) {

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
jwtSecret,
Expand Down Expand Up @@ -129,7 +126,6 @@ func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
jwtSecret,
Expand Down Expand Up @@ -197,7 +193,6 @@ func TestEngineAPIExecutionClient_SetFinal(t *testing.T) {

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
jwtSecret,
Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ require (
require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/bits-and-blooms/bitset v1.15.0 // indirect
github.com/celestiaorg/go-header v0.6.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/consensys/bavard v0.1.22 // indirect
github.com/consensys/gnark-crypto v0.14.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
Expand All @@ -34,8 +37,10 @@ require (
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
Expand Down Expand Up @@ -84,9 +89,10 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
google.golang.org/protobuf v1.35.2 // indirect
Expand All @@ -101,4 +107,5 @@ require (
github.com/docker/go-connections v0.5.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.67.1
)
10 changes: 9 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand All @@ -19,7 +21,7 @@ github.com/celestiaorg/go-header v0.6.3 h1:VI+fsNxFLeUS7cNn0LgHP6Db66uslnKp/fgMg
github.com/celestiaorg/go-header v0.6.3/go.mod h1:Az4S4NxMOJ1eAzOaF8u5AZt5UzsSzg92uqpdXS3yOZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
Expand All @@ -44,6 +46,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
Expand Down Expand Up @@ -106,6 +110,9 @@ github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQg
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand Down Expand Up @@ -418,6 +425,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
3 changes: 0 additions & 3 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
rollkit_types "github.com/rollkit/go-execution/types"
)

Expand Down Expand Up @@ -132,7 +131,6 @@ func TestExecutionClientLifecycle(t *testing.T) {
require.NoError(t, err)

executionClient, err := NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
TEST_ETH_URL,
TEST_ENGINE_URL,
JWT_SECRET,
Expand Down Expand Up @@ -213,7 +211,6 @@ func TestExecutionClient_InitChain_InvalidPayloadTimestamp(t *testing.T) {
blockTime := time.Date(2024, 3, 13, 13, 54, 0, 0, time.UTC) // pre-cancun timestamp not supported

executionClient, err := NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
TEST_ETH_URL,
TEST_ENGINE_URL,
JWT_SECRET,
Expand Down

0 comments on commit 0a2b882

Please sign in to comment.