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

Remove capella types (flashbots#650) #3

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
30 changes: 19 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

permissions:
contents: write
packages: write

jobs:
docker-image:
Expand All @@ -20,33 +21,38 @@ jobs:
- name: Get tag version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Get release date
run: |
echo "RELEASE_DATE=$(date --rfc-3339=date)" >> ${GITHUB_ENV}

- name: Print version
run: |
echo $RELEASE_VERSION
echo ${{ env.RELEASE_VERSION }}

- name: Extract metadata (tags, labels) for Docker images
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
with:
images: flashbots/mev-boost
images: ghcr.io/${{ github.event.repository.full_name }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=pep440,pattern={{version}}
type=pep440,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ !contains(env.RELEASE_VERSION, '-') }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
Expand All @@ -55,6 +61,8 @@ jobs:
push: true
build-args: |
VERSION=${{ env.RELEASE_VERSION }}
VCS_REF=${{ github.event.ref }}
BUILD_DATE=${{ env.RELEASE_DATE }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand All @@ -77,7 +85,7 @@ jobs:
with:
distribution: goreleaser
version: latest
args: release --skip-publish --config .goreleaser-build.yaml --rm-dist
args: release --skip=publish --config .goreleaser-build.yaml --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload
Expand Down Expand Up @@ -120,4 +128,4 @@ jobs:
with:
args: release --config .goreleaser-release.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 changes: 35 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,52 @@ on:
branches:
- develop
pull_request:
branches:
- develop

jobs:
test:
name: Test
name: Test on Go ${{ matrix.go-version }}
runs-on: ubuntu-latest

strategy:
matrix:
go-version: [1.20, 1.21, 1.22]

steps:
- name: Checkout sources
id: checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
id: setup-go
uses: actions/setup-go@v4
with:
go-version: ^1.22
id: go
go-version: ${{ matrix.go-version }}

- name: Cache Go modules
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-

- name: Checkout sources
uses: actions/checkout@v2
- name: Install dependencies
id: install-dependencies
run: go mod download

- name: Run unit tests and generate the coverage report
run: make test-coverage
id: test
run: go test -coverprofile=coverage-${{ matrix.go-version }}.out -json > TestResults-${{ matrix.go-version }}.json

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
id: upload-coverage
uses: codecov/codecov-action@v3
with:
files: ./coverage.out
files: coverage-${{ matrix.go-version }}.out
verbose: false
flags: unittests
flags: unittests-${{ matrix.go-version }}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax=docker/dockerfile:1
FROM golang:1.22 as builder
ARG VERSION
ARG VCS_REF
ARG BUILD_DATE
WORKDIR /build

COPY go.mod ./
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ Usage of mev-boost:
relay monitor urls - single entry or comma-separated list (scheme://host)
-relays string
relay urls - single entry or comma-separated list (scheme://pubkey@host)
-privileged-builder
a single privileged builder(relay pubkey), can be specified multiple times
-privileged-builders string
privileged builders(relay pubkey) - single entry or comma-separated list
-request-timeout-getheader int
timeout for getHeader requests to the relay [ms] (default 950)
-request-timeout-getpayload int
Expand Down
54 changes: 35 additions & 19 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ var (
errInvalidLoglevel = errors.New("invalid loglevel")

// defaults
defaultLogJSON = os.Getenv("LOG_JSON") != ""
defaultLogLevel = common.GetEnv("LOG_LEVEL", "info")
defaultListenAddr = common.GetEnv("BOOST_LISTEN_ADDR", "localhost:18550")
defaultRelayCheck = os.Getenv("RELAY_STARTUP_CHECK") != ""
defaultRelayMinBidEth = common.GetEnvFloat64("MIN_BID_ETH", 0)
defaultDisableLogVersion = os.Getenv("DISABLE_LOG_VERSION") == "1" // disables adding the version to every log entry
defaultDebug = os.Getenv("DEBUG") != ""
defaultLogServiceTag = os.Getenv("LOG_SERVICE_TAG")
defaultRelays = os.Getenv("RELAYS")
defaultRelayMonitors = os.Getenv("RELAY_MONITORS")
defaultMaxRetries = common.GetEnvInt("REQUEST_MAX_RETRIES", 5)
defaultLogJSON = os.Getenv("LOG_JSON") != ""
defaultLogLevel = common.GetEnv("LOG_LEVEL", "info")
defaultListenAddr = common.GetEnv("BOOST_LISTEN_ADDR", "localhost:18550")
defaultRelayCheck = os.Getenv("RELAY_STARTUP_CHECK") != ""
defaultRelayMinBidEth = common.GetEnvFloat64("MIN_BID_ETH", 0)
defaultDisableLogVersion = os.Getenv("DISABLE_LOG_VERSION") == "1" // disables adding the version to every log entry
defaultDebug = os.Getenv("DEBUG") != ""
defaultLogServiceTag = os.Getenv("LOG_SERVICE_TAG")
defaultRelays = os.Getenv("RELAYS")
defaultRelayMonitors = os.Getenv("RELAY_MONITORS")
defaultMaxRetries = common.GetEnvInt("REQUEST_MAX_RETRIES", 5)
defaultPrivilegedBuilders = os.Getenv("PRIVILEGED_BUILDERS")

defaultGenesisForkVersion = common.GetEnv("GENESIS_FORK_VERSION", "")
defaultGenesisTime = common.GetEnvInt("GENESIS_TIMESTAMP", -1)
Expand All @@ -55,8 +56,9 @@ var (
defaultTimeoutMsGetPayload = common.GetEnvInt("RELAY_TIMEOUT_MS_GETPAYLOAD", 4000) // timeout for getPayload requests
defaultTimeoutMsRegisterValidator = common.GetEnvInt("RELAY_TIMEOUT_MS_REGVAL", 3000) // timeout for registerValidator requests

relays relayList
relayMonitors relayMonitorList
relays relayList
relayMonitors relayMonitorList
privilegedBuilders privilegedBuilderList

// cli flags
printVersion = flag.Bool("version", false, "only print version")
Expand All @@ -66,11 +68,12 @@ var (
logService = flag.String("log-service", defaultLogServiceTag, "add a 'service=...' tag to all log messages")
logNoVersion = flag.Bool("log-no-version", defaultDisableLogVersion, "disables adding the version to every log entry")

listenAddr = flag.String("addr", defaultListenAddr, "listen-address for mev-boost server")
relayURLs = flag.String("relays", defaultRelays, "relay urls - single entry or comma-separated list (scheme://pubkey@host)")
relayCheck = flag.Bool("relay-check", defaultRelayCheck, "check relay status on startup and on the status API call")
relayMinBidEth = flag.Float64("min-bid", defaultRelayMinBidEth, "minimum bid to accept from a relay [eth]")
relayMonitorURLs = flag.String("relay-monitors", defaultRelayMonitors, "relay monitor urls - single entry or comma-separated list (scheme://host)")
listenAddr = flag.String("addr", defaultListenAddr, "listen-address for mev-boost server")
relayURLs = flag.String("relays", defaultRelays, "relay urls - single entry or comma-separated list (scheme://pubkey@host)")
relayCheck = flag.Bool("relay-check", defaultRelayCheck, "check relay status on startup and on the status API call")
relayMinBidEth = flag.Float64("min-bid", defaultRelayMinBidEth, "minimum bid to accept from a relay [eth]")
relayMonitorURLs = flag.String("relay-monitors", defaultRelayMonitors, "relay monitor urls - single entry or comma-separated list (scheme://host)")
privilegedBuilderKeys = flag.String("privileged-builders", defaultPrivilegedBuilders, "single entry or comma-separated list of relay username (pubkey)")

relayTimeoutMsGetHeader = flag.Int("request-timeout-getheader", defaultTimeoutMsGetHeader, "timeout for getHeader requests to the relay [ms]")
relayTimeoutMsGetPayload = flag.Int("request-timeout-getpayload", defaultTimeoutMsGetPayload, "timeout for getPayload requests to the relay [ms]")
Expand All @@ -95,6 +98,7 @@ func Main() {
// process repeatable flags
flag.Var(&relays, "relay", "a single relay, can be specified multiple times")
flag.Var(&relayMonitors, "relay-monitor", "a single relay monitor, can be specified multiple times")
flag.Var(&privilegedBuilders, "privileged-builder", "a single privileged builder, can be specified multiple times")

// parse flags and get started
flag.Parse()
Expand Down Expand Up @@ -149,13 +153,24 @@ func Main() {
}
}

// set relay priorities
if *privilegedBuilderKeys != "" {
for _, builderKey := range strings.Split(*privilegedBuilderKeys, ",") {
err := privilegedBuilders.Set(strings.TrimSpace(builderKey))
if err != nil {
log.WithError(err).WithField("privilegedBuilder", builderKey).Fatal("Invalid privileged builder")
}
}
}

if len(relays) == 0 {
flag.Usage()
log.Fatal("no relays specified")
}
log.Infof("using %d relays", len(relays))
for index, relay := range relays {
log.Infof("relay #%d: %s", index+1, relay.String())
isPrivileged := privilegedBuilders.Contains(relay.PublicKey)
log.Infof("relay #%d: %s, privileged %t", index+1, relay.String(), isPrivileged)
}

// For backwards compatibility with the -relay-monitors flag.
Expand Down Expand Up @@ -188,6 +203,7 @@ func Main() {
ListenAddr: *listenAddr,
Relays: relays,
RelayMonitors: relayMonitors,
PrivilegedBuilders: privilegedBuilders,
GenesisForkVersionHex: genesisForkVersionHex,
GenesisTime: genesisTime,
RelayCheck: *relayCheck,
Expand Down
34 changes: 34 additions & 0 deletions cli/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cli

import (
"bytes"
"errors"
"net/url"
"strings"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/flashbots/go-boost-utils/utils"
"github.com/flashbots/mev-boost/server/types"
)

Expand Down Expand Up @@ -67,3 +70,34 @@ func (rm *relayMonitorList) Set(value string) error {
*rm = append(*rm, relayMonitor)
return nil
}

type privilegedBuilderList []phase0.BLSPubKey

func (pb *privilegedBuilderList) String() string {
privilegedBuilders := []string{}
for _, privilegedBuilder := range *pb {
privilegedBuilders = append(privilegedBuilders, privilegedBuilder.String())
}
return strings.Join(privilegedBuilders, ",")
}

func (pb *privilegedBuilderList) Contains(privilegedBuilder phase0.BLSPubKey) bool {
for _, entry := range *pb {
if bytes.Equal(entry[:], privilegedBuilder[:]) {
return true
}
}
return false
}

func (pb *privilegedBuilderList) Set(value string) error {
privilegedBuilder, err := utils.HexToPubkey(value)
if err != nil {
return err
}
if pb.Contains(privilegedBuilder) {
return errDuplicateEntry
}
*pb = append(*pb, privilegedBuilder)
return nil
}
23 changes: 9 additions & 14 deletions server/mock/mock_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
"github.com/stretchr/testify/require"
)

const (
mockRelaySecretKeyHex = "0x4e343a647c5a5c44d76c2c58b63f02cdf3a9a0ec40f102ebc26363b4b1b95033"
)

var (
skBytes, _ = hexutil.Decode(mockRelaySecretKeyHex)
mockRelaySecretKey, _ = bls.SecretKeyFromBytes(skBytes)
mockRelayPublicKey, _ = bls.PublicKeyFromSecretKey(mockRelaySecretKey)
)

// Relay is used to fake a relay's behavior.
// You can override each of its handler by setting the instance's HandlerOverride_METHOD_TO_OVERRIDE to your own
// handler.
Expand Down Expand Up @@ -72,15 +62,19 @@
// A secret key must be provided to sign default and custom response messages
func NewRelay(t *testing.T) *Relay {
t.Helper()
relay := &Relay{t: t, secretKey: mockRelaySecretKey, publicKey: mockRelayPublicKey, requestCount: make(map[string]int)}

relay := &Relay{t: t, requestCount: make(map[string]int)}

relay.secretKey, _, _ = bls.GenerateNewKeypair()
relay.publicKey, _ = bls.PublicKeyFromSecretKey(relay.secretKey)

// Initialize server
relay.Server = httptest.NewServer(relay.getRouter())

// Create the RelayEntry with correct pubkey
url, err := url.Parse(relay.Server.URL)
require.NoError(t, err)
urlWithKey := fmt.Sprintf("%s://%s@%s", url.Scheme, hexutil.Encode(bls.PublicKeyToBytes(mockRelayPublicKey)), url.Host)
urlWithKey := fmt.Sprintf("%s://%s@%s", url.Scheme, hexutil.Encode(bls.PublicKeyToBytes(relay.publicKey)), url.Host)
relay.RelayEntry, err = types.NewRelayEntry(urlWithKey)
require.NoError(t, err)
return relay
Expand Down Expand Up @@ -224,8 +218,9 @@
12345,
"0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7",
"0xe28385e7bd68df656cd0042b74b69c3104b5356ed1f20eb69f1f925df47a3ab7",
"0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249",
spec.DataVersionDeneb,
"0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249",
m.RelayEntry.PublicKey.String(),
spec.DataVersionCapella,

Check failure on line 223 in server/mock/mock_relay.go

View workflow job for this annotation

GitHub Actions / Lint

too many arguments in call to m.MakeGetHeaderResponse

Check failure on line 223 in server/mock/mock_relay.go

View workflow job for this annotation

GitHub Actions / Lint

too many arguments in call to m.MakeGetHeaderResponse

Check failure on line 223 in server/mock/mock_relay.go

View workflow job for this annotation

GitHub Actions / Lint

too many arguments in call to m.MakeGetHeaderResponse

Check failure on line 223 in server/mock/mock_relay.go

View workflow job for this annotation

GitHub Actions / Lint

too many arguments in call to m.MakeGetHeaderResponse
)
if m.GetHeaderResponse != nil {
response = m.GetHeaderResponse
Expand Down
Loading
Loading