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

chore: fix linter issues #13

Merged
merged 2 commits into from
Nov 26, 2024
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
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ run:

linters:
enable:
- deadcode
- errcheck
- gofmt
- goimports
Expand All @@ -15,10 +14,8 @@ linters:
- misspell
- revive
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

issues:
exclude-use-default: false
Expand Down
9 changes: 9 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html
extends: default

rules:
# 120 chars should be enough, but don't fail if a line is longer
line-length:
max: 120
level: warning
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Architecture
# Architecture

```mermaid
graph LR
Expand Down Expand Up @@ -64,7 +64,7 @@ The architecture consists of several key components:
## Development

```bash
$ cd docker
$ docker compose up -d
$ docker compose down
cd docker
docker compose up -d
docker compose down
```
10 changes: 5 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ services:
timeout: 5s
retries: 3
command: >
/bin/sh -c "mkdir -p /jwt &&
if [ ! -f /jwt/jwt.hex ]; then
/bin/sh -c "mkdir -p /jwt &&
if [ ! -f /jwt/jwt.hex ]; then
apk add --no-cache openssl &&
openssl rand -hex 32 | tr -d '\n' > /jwt/jwt.hex;
openssl rand -hex 32 | tr -d '\n' > /jwt/jwt.hex;
fi"

reth:
Expand All @@ -38,8 +38,8 @@ services:
- ./jwttoken:/root/jwt:ro
- ./chain:/root/chain:ro
pid: host
entrypoint: /bin/sh -c
command:
entrypoint: /bin/sh -c
command:
- |
reth init --chain /root/chain/genesis.json
reth node \
Expand Down
25 changes: 12 additions & 13 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import (
"net/http"
"time"

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

"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"

"github.com/golang-jwt/jwt/v5"
execution "github.com/rollkit/go-execution"
"github.com/rollkit/go-execution"
proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
execution_types "github.com/rollkit/go-execution/types"
)

var (
ErrNilPayloadStatus = errors.New("nil payload status")
// ErrNilPayloadStatus indicates that PayloadID returned by EVM was nil
ErrNilPayloadStatus = errors.New("nil payload status")
// ErrInvalidPayloadStatus indicates that EVM returned status != VALID
ErrInvalidPayloadStatus = errors.New("invalid payload status")
)

Expand All @@ -32,7 +35,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 Down Expand Up @@ -88,7 +90,6 @@ func NewEngineAPIExecutionClient(
}

return &EngineAPIExecutionClient{
proxyClient: proxyClient,
engineClient: engineClient,
ethClient: ethClient,
genesisHash: genesisHash,
Expand All @@ -97,14 +98,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 All @@ -124,7 +123,7 @@ func (c *EngineAPIExecutionClient) InitChain(ctx context.Context, genesisTime ti
FinalizedBlockHash: c.genesisHash,
},
engine.PayloadAttributes{
Timestamp: uint64(genesisTime.Unix()),
Timestamp: uint64(genesisTime.Unix()), //nolint:gosec // disable G115
Random: common.Hash{},
SuggestedFeeRecipient: c.feeRecipient,
BeaconRoot: &c.genesisHash,
Expand Down Expand Up @@ -222,7 +221,7 @@ func (c *EngineAPIExecutionClient) ExecuteTxs(ctx context.Context, txs []executi
FinalizedBlockHash: c.genesisHash,
},
&engine.PayloadAttributes{
Timestamp: uint64(timestamp.Unix()),
Timestamp: uint64(timestamp.Unix()), //nolint:gosec // disable G115
Random: c.derivePrevRandao(height),
SuggestedFeeRecipient: c.feeRecipient,
Withdrawals: []*types.Withdrawal{},
Expand Down Expand Up @@ -264,7 +263,7 @@ func (c *EngineAPIExecutionClient) ExecuteTxs(ctx context.Context, txs []executi

// SetFinal marks a block at the given height as final
func (c *EngineAPIExecutionClient) SetFinal(ctx context.Context, height uint64) error {
block, err := c.ethClient.BlockByNumber(ctx, big.NewInt(int64(height)))
block, err := c.ethClient.BlockByNumber(ctx, big.NewInt(int64(height))) //nolint:gosec // disable G115
if err != nil {
return fmt.Errorf("failed to get block at height %d: %w", height, err)
}
Expand Down Expand Up @@ -293,5 +292,5 @@ func (c *EngineAPIExecutionClient) SetFinal(ctx context.Context, height uint64)

// derivePrevRandao generates a deterministic prevRandao value based on block height
func (c *EngineAPIExecutionClient) derivePrevRandao(blockHeight uint64) common.Hash {
return common.BigToHash(big.NewInt(int64(blockHeight)))
return common.BigToHash(big.NewInt(int64(blockHeight))) //nolint:gosec // disable G115
}
36 changes: 19 additions & 17 deletions execution_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package execution
package execution_test

import (
"context"
"encoding/hex"
"encoding/json"
"io"
"math/big"
Expand All @@ -10,14 +11,14 @@ import (
"testing"
"time"

"encoding/hex"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/rollkit/go-execution-evm/mocks"

"github.com/rollkit/go-execution-evm"
proxy_json_rpc "github.com/rollkit/go-execution/proxy/jsonrpc"
execution_types "github.com/rollkit/go-execution/types"
"github.com/stretchr/testify/require"
)

// Helper function to generate a test JWT secret
Expand All @@ -31,14 +32,14 @@ func generateTestJWTSecret() string {
}

func TestEngineAPIExecutionClient_InitChain(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down Expand Up @@ -70,16 +71,16 @@ func TestEngineAPIExecutionClient_InitChain(t *testing.T) {
}

func TestEngineAPIExecutionClient_ExecuteTxs(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
prevStateRoot := execution_types.Hash(common.Hex2Bytes("111122223333444455556666777788889999aaaabbbbccccddddeeeeffff0000"))

client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down Expand Up @@ -119,14 +120,14 @@ func TestEngineAPIExecutionClient_ExecuteTxs(t *testing.T) {
}

func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down Expand Up @@ -172,11 +173,12 @@ func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {
}
}

json.NewEncoder(w).Encode(map[string]interface{}{
err = json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0",
"id": req["id"],
"result": resp,
})
require.NoError(t, err)
}))

ctx := context.Background()
Expand All @@ -187,14 +189,14 @@ func TestEngineAPIExecutionClient_GetTxs(t *testing.T) {
}

func TestEngineAPIExecutionClient_SetFinal(t *testing.T) {
mockEngine := mocks.NewMockEngineAPI(t)
mockEngine := NewMockEngineAPI(t)
defer mockEngine.Close()

mockEth := mocks.NewMockEthAPI(t)
mockEth := NewMockEthAPI(t)
defer mockEth.Close()

jwtSecret := generateTestJWTSecret()
client, err := NewEngineAPIExecutionClient(
client, err := execution.NewEngineAPIExecutionClient(
&proxy_json_rpc.Config{},
mockEth.URL,
mockEngine.URL,
Expand Down
16 changes: 8 additions & 8 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"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 All @@ -25,7 +26,7 @@ import (
const (
TEST_ETH_URL = "http://localhost:8545"
TEST_ENGINE_URL = "http://localhost:8551"
JWT_SECRET = "09a23c010d96caaebb21c193b85d30bbb62a9bac5bd0a684e9e91c77c811ca65"
JWT_SECRET = "09a23c010d96caaebb21c193b85d30bbb62a9bac5bd0a684e9e91c77c811ca65" //nolint:gosec

CHAIN_ID = "1234"
GENESIS_HASH = "0x8bf225d50da44f60dee1c4ee6f810fe5b44723c76ac765654b6692d50459f216"
Expand All @@ -34,7 +35,7 @@ const (
TEST_TO_ADDRESS = "0x944fDcD1c868E3cC566C78023CcB38A32cDA836E"

DOCKER_CHAIN_PATH = "./docker/chain" // path relative to the test file
DOCKER_JWTSECRET_PATH = "./docker/jwttoken/" // path relative to the test file
DOCKER_JWTSECRET_PATH = "./docker/jwttoken/" //nolint:gosec // path relative to the test file
DOCKER_JWT_SECRET_FILE = "testsecret.hex"
)

Expand All @@ -47,7 +48,7 @@ func setupTestRethEngine(t *testing.T) {
jwtSecretPath, err := filepath.Abs(DOCKER_JWTSECRET_PATH)
require.NoError(t, err)

err = os.WriteFile(DOCKER_JWTSECRET_PATH+DOCKER_JWT_SECRET_FILE, []byte(JWT_SECRET), 0644)
err = os.WriteFile(DOCKER_JWTSECRET_PATH+DOCKER_JWT_SECRET_FILE, []byte(JWT_SECRET), 0600)
require.NoError(t, err)

cli, err := client.NewClientWithOpts()
Expand Down Expand Up @@ -105,9 +106,8 @@ func setupTestRethEngine(t *testing.T) {
err = cli.ContainerStart(context.Background(), rethContainer.ID, container.StartOptions{})
require.NoError(t, err)

// a reasonable time to wait for the container to start!
// do we want a more predictable elaborate code to wait for the container to be running?
time.Sleep(50 * time.Millisecond)
// TODO: check container status instead of sleeping
time.Sleep(5 * time.Second)
tzdybal marked this conversation as resolved.
Show resolved Hide resolved

t.Cleanup(func() {
err = cli.ContainerStop(context.Background(), rethContainer.ID, container.StopOptions{})
Expand Down
Loading
Loading