Skip to content

Commit

Permalink
🧪 add CI workflows and lint progress
Browse files Browse the repository at this point in the history
  • Loading branch information
cairoeth committed Mar 24, 2024
1 parent 012256d commit 3b183be
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 109 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.20
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Install gofumpt
run: go install mvdan.cc/[email protected]

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/[email protected]

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/[email protected]

- name: Lint
run: make lint

- name: Ensure go mod tidy runs without changes
run: |
go mod tidy
git diff-index HEAD
git diff-index --quiet HEAD
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ run-anvil:
run-all:
make -j run-anvil run-share run-operator

# Run all in background and example (used by CI)
run-ci:
make run-all & && sleep 200 && python test_tx.py && exit 0

test:
go test ./...

Expand Down
4 changes: 2 additions & 2 deletions preconf-operator/cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func operatorMain(ctx_cli *cli.Context) error {
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
configJSON, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config:", string(configJson))
log.Println("Config:", string(configJSON))

log.Println("Initializing operator")
operator, err := operator.NewOperatorFromConfig(nodeConfig)
Expand Down
6 changes: 3 additions & 3 deletions preconf-operator/core/chainio/avs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func BuildAvsWriterFromConfig(c *config.Config) (*AvsWriter, error) {
return BuildAvsWriter(c.TxMgr, c.IncredibleSquaringRegistryCoordinatorAddr, c.OperatorStateRetrieverAddr, c.EthHttpClient, c.Logger)
}

func BuildAvsWriter(txMgr txmgr.TxManager, registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHttpClient eth.EthClient, logger logging.Logger) (*AvsWriter, error) {
avsServiceBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr, ethHttpClient, logger)
func BuildAvsWriter(txMgr txmgr.TxManager, registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethHTTPClient eth.EthClient, logger logging.Logger) (*AvsWriter, error) {
avsServiceBindings, err := NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr, ethHTTPClient, logger)
if err != nil {
logger.Error("Failed to create contract bindings", "err", err)
return nil, err
}
avsRegistryWriter, err := avsregistry.BuildAvsRegistryChainWriter(registryCoordinatorAddr, operatorStateRetrieverAddr, logger, ethHttpClient, txMgr)
avsRegistryWriter, err := avsregistry.BuildAvsRegistryChainWriter(registryCoordinatorAddr, operatorStateRetrieverAddr, logger, ethHTTPClient, txMgr)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions preconf-operator/core/chainio/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethcommon "github.com/ethereum/go-ethereum/common"

regcoord "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator"
erc20mock "github.com/cairoeth/preconfirmations/contracts/bindings/ERC20Mock"
Expand All @@ -21,7 +20,7 @@ type AvsManagersBindings struct {
logger logging.Logger
}

func NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr gethcommon.Address, ethclient eth.EthClient, logger logging.Logger) (*AvsManagersBindings, error) {
func NewAvsManagersBindings(registryCoordinatorAddr, operatorStateRetrieverAddr common.Address, ethclient eth.EthClient, logger logging.Logger) (*AvsManagersBindings, error) {
contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethclient)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions preconf-operator/receiverapi/receiverapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type ReceiveApi struct {
}

type ReceiveResponse struct {
jsonrpc string `json:"jsonrpc"`
id int `json:"id"`
jsonrpc string
id int
}

type ReceiveTx struct {
Expand Down
2 changes: 1 addition & 1 deletion preconf-operator/sse/client_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *Subscription) readEvents() {
for {
msg, err := s.pubsub.ReceiveMessage(context.Background())
if err != nil {
fmt.Printf("Error occured receiving message from Preconf-Share stream", err)
fmt.Printf("Error occured receiving message from preconf-share stream %v", err)
}

var event MatchMakerEvent
Expand Down
84 changes: 42 additions & 42 deletions preconf-share/preconshare/bundle_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,111 +18,111 @@ func TestMergeInclusionIntervals(t *testing.T) {
{
name: "same intervals",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
},
err: nil,
},
{
name: "overlap, top to the right",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(3),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(4),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
},
err: nil,
},
{
name: "overlap, top to the left",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(4),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(3),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
},
err: nil,
},
{
name: "overlap, bottom inside top",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(4),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
},
err: nil,
},
{
name: "overlap, top inside bottom",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(4),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
DesiredBlock: hexutil.Uint64(2),
MaxBlock: hexutil.Uint64(3),
},
},
{
name: "no overlap, top to the right",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(3),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(3),
MaxBlock: hexutil.Uint64(4),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
},
err: ErrInvalidInclusion,
},
{
name: "no overlap, top to the left",
top: RequestInclusion{
BlockNumber: hexutil.Uint64(3),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(3),
MaxBlock: hexutil.Uint64(4),
},
bottom: RequestInclusion{
BlockNumber: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
DesiredBlock: hexutil.Uint64(1),
MaxBlock: hexutil.Uint64(2),
},
expectedTop: RequestInclusion{
BlockNumber: hexutil.Uint64(3),
MaxBlock: hexutil.Uint64(4),
DesiredBlock: hexutil.Uint64(3),
MaxBlock: hexutil.Uint64(4),
},
err: ErrInvalidInclusion,
},
Expand Down
44 changes: 15 additions & 29 deletions preconf-share/preconshare/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package preconshare

import (
"context"
"math/big"
"database/sql"
"testing"
"time"

Expand All @@ -15,6 +15,18 @@ import (

var testPostgresDSN = cli.GetEnv("TEST_POSTGRES_DSN", "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable")

type DBSbundleBuilder struct {
Hash []byte `db:"hash"`
Cancelled bool `db:"cancelled"`
Block int64 `db:"block"`
MaxBlock int64 `db:"max_block"`
SimStateBlock sql.NullInt64 `db:"sim_state_block"`
SimEffGasPrice sql.NullString `db:"sim_eff_gas_price"`
SimProfit sql.NullString `db:"sim_profit"`
Body []byte `db:"body"`
InsertedAt time.Time `db:"inserted_at"`
}

func TestDBBackend_GetBundle(t *testing.T) {
b, err := NewDBBackend(testPostgresDSN)
require.NoError(t, err)
Expand Down Expand Up @@ -73,9 +85,8 @@ func TestDBBackend_InsertBundleForStats(t *testing.T) {
},
Body: []RequestBody{{Tx: (*hexutil.Bytes)(&tx)}},
Privacy: &RequestPrivacy{
Hints: HintHash,
Builders: nil,
WantRefund: nil,
Hints: HintHash,
Operators: nil,
},
Metadata: &RequestMetadata{
RequestHash: bundleHash,
Expand Down Expand Up @@ -212,31 +223,6 @@ func TestDBBackend_InsertBundleForBuilder(t *testing.T) {
_, err = b.db.Exec("DELETE FROM sbundle_builder WHERE hash = $1", bundleHash.Bytes())
require.NoError(t, err)

receivedAt := time.Now()
tx := common.Hex2Bytes("0x0102030405060708091011121314151617181920212223242526272829303132")
signer := common.HexToAddress("0x0102030405060708091011121314151617181920")

bundle := SendRequestArgs{
Version: "v0.1",
Inclusion: RequestInclusion{
DesiredBlock: 6,
MaxBlock: 8,
},
Body: []RequestBody{{Tx: (*hexutil.Bytes)(&tx)}},
Privacy: &RequestPrivacy{
Hints: HintHash,
Builders: nil,
WantRefund: nil,
},
Metadata: &RequestMetadata{
BundleHash: bundleHash,
BodyHashes: []common.Hash{bundleHash},
Signer: signer,
OriginID: "test-origin",
ReceivedAt: hexutil.Uint64(receivedAt.UnixMicro()),
},
}

var dbBundle DBSbundleBuilder
err = b.db.Get(&dbBundle, "SELECT * FROM sbundle_builder WHERE hash = $1", bundleHash.Bytes())
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion rpc/server/request_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (r *RpcRequest) writeRpcError(msg string, errCode int) {
r.jsonRes = &types.JsonRpcResponse{
Id: r.jsonReq.Id,
Version: "2.0",
Error: &types.JsonRpcError{
Error: &types.JSONRPCError{
Code: errCode,
Message: msg,
},
Expand Down
6 changes: 3 additions & 3 deletions rpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type RpcEndPointServer struct {
listenAddress string
logger *zap.Logger
proxyTimeoutSeconds int
proxyUrl string
proxyURL string
relaySigningKey *ecdsa.PrivateKey
relayUrl string
startTime time.Time
Expand Down Expand Up @@ -98,7 +98,7 @@ func NewRpcEndPointServer(cfg Configuration) (*RpcEndPointServer, error) {
listenAddress: cfg.ListenAddress,
logger: cfg.Logger,
proxyTimeoutSeconds: cfg.ProxyTimeoutSeconds,
proxyUrl: cfg.ProxyUrl,
proxyURL: cfg.ProxyUrl,
relaySigningKey: cfg.RelaySigningKey,
relayUrl: cfg.RelayUrl,
startTime: Now(),
Expand Down Expand Up @@ -237,7 +237,7 @@ func (s *RpcEndPointServer) HandleHttpRequest(respw http.ResponseWriter, req *ht
return
}

request := NewRpcRequestHandler(s.logger, &respw, req, s.proxyUrl, s.proxyTimeoutSeconds, s.relaySigningKey, s.relayUrl, s.db, s.builderNameProvider.BuilderNames(), s.chainID)
request := NewRpcRequestHandler(s.logger, &respw, req, s.proxyURL, s.proxyTimeoutSeconds, s.relaySigningKey, s.relayUrl, s.db, s.builderNameProvider.BuilderNames(), s.chainID)
request.process()
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/server/url_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func AuctionPreferenceErrorToJSONRPCResponse(jsonReq *types.JsonRpcRequest, err
message := fmt.Sprintf("Invalid auction preference in the rpc endpoint url. %s", err.Error())
return &types.JsonRpcResponse{
Id: jsonReq.Id,
Error: &types.JsonRpcError{Code: types.JsonRpcInvalidRequest, Message: message},
Error: &types.JSONRPCError{Code: types.JsonRpcInvalidRequest, Message: message},
Version: "2.0",
}
}
2 changes: 1 addition & 1 deletion rpc/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func respBytesToJsonRPCResponse(respBytes []byte) (*types.JsonRpcResponse, error
errorResp := new(types.RelayErrorResponse)
if err := json.Unmarshal(respBytes, errorResp); err == nil && errorResp.Error != "" {
// relay returned an error, convert to standard JSON-RPC error now
jsonRpcResp.Error = &types.JsonRpcError{Message: errorResp.Error}
jsonRpcResp.Error = &types.JSONRPCError{Message: errorResp.Error}
return jsonRpcResp, nil
}

Expand Down
Loading

0 comments on commit 3b183be

Please sign in to comment.