Skip to content

Commit

Permalink
Replace blst with gnark-crypto, simplify builds (flashbots#479)
Browse files Browse the repository at this point in the history
* replace blst library with Go impl, remove portable builds

* CGO_ENABLED=0

* Clean up build flags & add more cgo=0

* Enable cgo for test-race

* Remove -race from test-coverage

* Remove double build instruction

* Update goreleaser

* update to gnark-crypto / go-boost-utils v1.4.1

* Fix windows/arm64 build issue

* Force gnark-crypto v0.7.1

* golangci-lint ignore gomoddirectives

* remove broken arm/v6 docker build

* Enable gomoddirectives and add gnark to replace-allow-list

* Use latest version of gnark-crypto

* Revert changes to golangci.yml

---------

Co-authored-by: Justin Traglia <[email protected]>
  • Loading branch information
metachris and jtraglia authored Mar 29, 2023
1 parent 01a2431 commit c106467
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 236 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest
env:
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
CGO_CFLAGS: "-O -D__BLST_PORTABLE__"
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
84 changes: 11 additions & 73 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ jobs:
tags: |
type=sha
type=semver,pattern={{version}}
type=raw,value=latest,enable=false
- name: Extract metadata (tags, labels) for portable Docker images
id: meta-portable
uses: docker/metadata-action@v4
with:
images: flashbots/mev-boost
tags: |
type=sha
type=semver,pattern={{version}},suffix=-portable
type=raw,value=latest,enable=${{ !contains(env.RELEASE_VERSION, '-') }}
- name: Set up QEMU
Expand All @@ -64,56 +54,12 @@ jobs:
push: true
build-args: |
VERSION=${{ env.RELEASE_VERSION }}
CGO_CFLAGS=
platforms: linux/amd64,linux/arm64,linux/arm/v6
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push portable
uses: docker/build-push-action@v3
with:
context: .
push: true
build-args: |
VERSION=${{ env.RELEASE_VERSION }}
CGO_CFLAGS=-O -D__BLST_PORTABLE__
platforms: linux/amd64,linux/arm64,linux/arm/v6
tags: ${{ steps.meta-portable.outputs.tags }}
labels: ${{ steps.meta-portable.outputs.labels }}

build-linux-windows:
build-all:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.20
- name: Install cross-compiler for linux/arm64 and windows
run: sudo apt-get -y install gcc-aarch64-linux-gnu gcc-mingw-w64
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --skip-publish --config .goreleaser-linux_windows.yaml --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload
uses: actions/upload-artifact@v3
with:
name: mev-boost-linux_windows
path: |
dist/mev-boost*.tar.gz
dist/mev-boost*.txt
build-darwin:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -130,19 +76,19 @@ jobs:
with:
distribution: goreleaser
version: latest
args: release --skip-publish --config .goreleaser-darwin.yaml --rm-dist
args: release --skip-publish --config .goreleaser-build.yaml --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload
uses: actions/upload-artifact@v3
with:
name: mev-boost-darwin
name: mev-boost-build
path: |
dist/mev-boost*.tar.gz
dist/mev-boost*.txt
release:
needs: [build-linux-windows, build-darwin]
needs: build-all
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -157,25 +103,17 @@ jobs:
go-version: ^1.20
- name: Make directories
run: |
mkdir -p ./build/linux_windows
mkdir -p ./build/darwin
- name: Download Linux and Windows binaries
uses: actions/download-artifact@v3
with:
name: mev-boost-linux_windows
path: ./build/linux_windows
- name: Download Darwin binaries
mkdir -p ./build
- name: Download binaries
uses: actions/download-artifact@v3
with:
name: mev-boost-darwin
path: ./build/darwin
name: mev-boost-build
path: ./build
- name: Merge checksum file
run: |
cd ./build
cat ./darwin/mev-boost*checksums.txt >> checksums.txt
cat ./linux_windows/mev-boost*checksums.txt >> checksums.txt
rm ./darwin/mev-boost*checksums.txt
rm ./linux_windows/mev-boost*checksums.txt
cat ./mev-boost*checksums.txt >> checksums.txt
rm ./mev-boost*checksums.txt
- name: Release
uses: goreleaser/goreleaser-action@v3
with:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
CGO_CFLAGS: "-O -D__BLST_PORTABLE__"
steps:
- name: Set up Go
uses: actions/setup-go@v3
Expand Down
24 changes: 24 additions & 0 deletions .goreleaser-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://goreleaser.com/customization/builds/
project_name: mev-boost
builds:
- id: mev-boost
env:
# Force build to be all Go.
- CGO_ENABLED=0
flags:
# Remove all file system paths from the executable.
- -trimpath
ldflags:
# Disables DWARF debugging information.
- -w
# Disables symbol table information.
- -s
# Sets the value of the symbol.
- -X github.com/flashbots/mev-boost/config.Version={{.Version}}
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
20 changes: 0 additions & 20 deletions .goreleaser-darwin.yaml

This file was deleted.

49 changes: 0 additions & 49 deletions .goreleaser-linux_windows.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions .goreleaser-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ builds:
release:
draft: true
extra_files:
- glob: ./build/**/*
- glob: ./build/checksums.txt
- glob: ./build/*
header: |
# 🚀 Features
# 🎄 Enhancements
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ go run . -goerli -relay-check -relays https://0xafa4c6985aa049fb79dd37010438cfeb

Note that you'll need to set the correct genesis fork version (either manually with `-genesis-fork-version` or a helper flag `-mainnet`/`-goerli`/`-sepolia`).

If the test or target application crashes with an "illegal instruction" exception, run/rebuild with CGO_CFLAGS environment variable set to `-O -D__BLST_PORTABLE__`. This error also happens if you are on an ARM-based system, including the Apple M1/M2 chip.

## Test

```bash
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# syntax=docker/dockerfile:1
FROM golang:1.20 as builder
ARG VERSION
ARG CGO_CFLAGS
WORKDIR /build

COPY go.mod ./
Expand All @@ -10,11 +9,10 @@ COPY go.sum ./
RUN go mod download

ADD . .
RUN --mount=type=cache,target=/root/.cache/go-build CGO_CFLAGS="$CGO_CFLAGS" GOOS=linux go build \
-tags osusergo,netgo \
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux go build \
-trimpath \
-ldflags "-extldflags=-static -w -s -X 'github.com/flashbots/mev-boost/config.Version=$VERSION'" \
-v \
-ldflags "-w -s -X 'github.com/flashbots/mev-boost/config.Version=$VERSION'" \
-o mev-boost .

FROM alpine
Expand Down
50 changes: 13 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
VERSION ?= $(shell git describe --tags --always --dirty="-dev")
DOCKER_REPO := flashbots/mev-boost

# Force os/user & net to be pure Go.
GO_BUILD_FLAGS += -tags osusergo,netgo
# Remove all file system paths from the executable.
GO_BUILD_FLAGS += -trimpath
# Make the build more verbose.
GO_BUILD_FLAGS += -v

# Set linker flags to:
# -w: disables DWARF debugging information.
GO_BUILD_LDFLAGS += -w
Expand All @@ -16,6 +9,11 @@ GO_BUILD_LDFLAGS += -s
# -X: sets the value of the symbol.
GO_BUILD_LDFLAGS += -X 'github.com/flashbots/mev-boost/config.Version=$(VERSION)'

# Remove all file system paths from the executable.
GO_BUILD_FLAGS += -trimpath
# Add linker flags to build flags.
GO_BUILD_FLAGS += -ldflags "$(GO_BUILD_LDFLAGS)"

.PHONY: all
all: build

Expand All @@ -25,32 +23,19 @@ v:

.PHONY: build
build:
$(EXTRA_ENV) go build $(GO_BUILD_FLAGS) -ldflags "$(GO_BUILD_LDFLAGS)" -o mev-boost .

.PHONY: build-portable
build-portable: EXTRA_ENV = CGO_CFLAGS="-O -D__BLST_PORTABLE__"
build-portable: build

.PHONY: build-static
build-static: GO_BUILD_LDFLAGS += "-extldflags=-static"
build-static: build

.PHONY: build-portable-static
build-portable-static: EXTRA_ENV = CGO_CFLAGS="-O -D__BLST_PORTABLE__"
build-portable-static: GO_BUILD_LDFLAGS += -extldflags=-static
build-portable-static: build
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o mev-boost

.PHONY: build-testcli
build-testcli:
go build $(GO_BUILD_FLAGS) -ldflags "$(GO_BUILD_LDFLAGS)" -o test-cli ./cmd/test-cli
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o test-cli ./cmd/test-cli

.PHONY: test
test:
go test ./...
CGO_ENABLED=0 go test ./...

.PHONY: test-race
test-race:
go test -race ./...
CGO_ENABLED=1 go test -race ./...

.PHONY: lint
lint:
Expand All @@ -61,18 +46,18 @@ lint:

.PHONY: test-coverage
test-coverage:
go test -race -v -covermode=atomic -coverprofile=coverage.out ./...
CGO_ENABLED=0 go test -v -covermode=atomic -coverprofile=coverage.out ./...
go tool cover -func coverage.out

.PHONY: cover
cover:
go test -coverprofile=coverage.out ./...
CGO_ENABLED=0 go test -coverprofile=coverage.out ./...
go tool cover -func coverage.out
unlink coverage.out

.PHONY: cover-html
cover-html:
go test -coverprofile=coverage.out ./...
CGO_ENABLED=0 go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
unlink coverage.out

Expand All @@ -82,19 +67,10 @@ run-mergemock-integration: build

.PHONY: docker-image
docker-image:
DOCKER_BUILDKIT=1 docker build --platform linux/amd64 --build-arg CGO_CFLAGS="" --build-arg VERSION=${VERSION} . -t mev-boost
DOCKER_BUILDKIT=1 docker build --platform linux/amd64 --build-arg VERSION=${VERSION} . -t mev-boost
docker tag mev-boost:latest ${DOCKER_REPO}:${VERSION}
docker tag mev-boost:latest ${DOCKER_REPO}:latest

.PHONY: docker-image-portable
docker-image-portable:
DOCKER_BUILDKIT=1 docker build --platform linux/amd64 --build-arg CGO_CFLAGS="-O -D__BLST_PORTABLE__" --build-arg VERSION=${VERSION} . -t mev-boost
docker tag mev-boost:latest ${DOCKER_REPO}:${VERSION}

.PHONY: docker-push-version
docker-push-version:
docker push ${DOCKER_REPO}:${VERSION}

.PHONY: clean
clean:
git clean -fdx
Loading

0 comments on commit c106467

Please sign in to comment.