2023-10-21 03:24:04 +00:00
GO ?= go # if using docker, should not need to be installed/linked
2020-09-30 09:28:36 +00:00
GOBIN = $( CURDIR) /build/bin
2022-06-30 10:11:37 +00:00
UNAME = $( shell uname) # Supported: Darwin, Linux
DOCKER := $( shell command -v docker 2> /dev/null)
2015-11-20 14:06:35 +00:00
2020-10-30 08:43:24 +00:00
GIT_COMMIT ?= $( shell git rev-list -1 HEAD)
2021-04-11 04:23:50 +00:00
GIT_BRANCH ?= $( shell git rev-parse --abbrev-ref HEAD)
2022-05-25 01:12:40 +00:00
GIT_TAG ?= $( shell git describe --tags '--match=v*' --dirty)
2022-06-30 10:11:37 +00:00
ERIGON_USER ?= erigon
# if using volume-mounting data dir, then must exist on host OS
DOCKER_UID ?= $( shell id -u)
DOCKER_GID ?= $( shell id -g)
2022-06-16 14:50:59 +00:00
DOCKER_TAG ?= thorax/erigon:latest
2022-01-23 03:05:31 +00:00
2022-06-30 10:11:37 +00:00
# Variables below for building on host OS, and are ignored for docker
#
# Pipe error below to /dev/null since Makefile structure kind of expects
# Go to be available, but with docker it's not strictly necessary
CGO_CFLAGS := $( shell $( GO) env CGO_CFLAGS 2>/dev/null) # don't lose default
2022-07-19 03:54:44 +00:00
CGO_CFLAGS += -DMDBX_FORCE_ASSERTIONS= 0 # Enable MDBX's asserts by default in 'devel' branch and disable in releases
2023-01-28 09:39:16 +00:00
#CGO_CFLAGS += -DMDBX_DISABLE_VALIDATION=1 # This feature is not ready yet
#CGO_CFLAGS += -DMDBX_ENABLE_PROFGC=0 # Disabled by default, but may be useful for performance debugging
#CGO_CFLAGS += -DMDBX_ENABLE_PGOP_STAT=0 # Disabled by default, but may be useful for performance debugging
#CGO_CFLAGS += -DMDBX_ENV_CHECKPID=0 # Erigon doesn't do fork() syscall
2022-10-15 10:38:37 +00:00
CGO_CFLAGS += -O
CGO_CFLAGS += -D__BLST_PORTABLE__
2023-10-27 04:01:11 +00:00
CGO_CFLAGS += -Wno-unknown-warning-option -Wno-enum-int-mismatch -Wno-strict-prototypes -Wno-unused-but-set-variable
2022-01-23 03:05:31 +00:00
2023-12-06 04:02:54 +00:00
CGO_LDFLAGS := $( shell $( GO) env CGO_LDFLAGS 2> /dev/null)
i f e q ( $( shell uname -s ) , D a r w i n )
ifeq ( $( filter-out 13.%,$( shell sw_vers --productVersion) ) ,)
CGO_LDFLAGS += -mmacosx-version-min= 13.3
endif
e n d i f
2023-06-06 06:49:01 +00:00
# about netgo see: https://github.com/golang/go/issues/30310#issuecomment-471669125 and https://github.com/golang/go/issues/57757
BUILD_TAGS = nosqlite,noboltdb
2022-04-22 00:15:23 +00:00
PACKAGE = github.com/ledgerwatch/erigon
2020-09-06 11:35:32 +00:00
2022-04-22 03:56:44 +00:00
GO_FLAGS += -trimpath -tags $( BUILD_TAGS) -buildvcs= false
2022-04-22 00:15:23 +00:00
GO_FLAGS += -ldflags " -X ${ PACKAGE } /params.GitCommit= ${ GIT_COMMIT } -X ${ PACKAGE } /params.GitBranch= ${ GIT_BRANCH } -X ${ PACKAGE } /params.GitTag= ${ GIT_TAG } "
2023-12-06 04:02:54 +00:00
GOBUILD = CGO_CFLAGS = " $( CGO_CFLAGS) " CGO_LDFLAGS = " $( CGO_LDFLAGS) " $( GO) build $( GO_FLAGS)
GO_DBG_BUILD = CGO_CFLAGS = " $( CGO_CFLAGS) -DMDBX_DEBUG=1 " CGO_LDFLAGS = " $( CGO_LDFLAGS) " $( GO) build -tags $( BUILD_TAGS) ,debug -gcflags= all = "-N -l" # see delve docs
GOTEST = CGO_CFLAGS = " $( CGO_CFLAGS) " CGO_LDFLAGS = " $( CGO_LDFLAGS) " GODEBUG = cgocheck = 0 $( GO) test $( GO_FLAGS) ./... -p 2
2021-04-19 10:54:56 +00:00
2022-02-24 15:10:46 +00:00
default : all
2020-08-21 12:38:11 +00:00
2022-07-22 12:26:18 +00:00
## go-version: print and verify go version
2021-04-19 10:54:56 +00:00
go-version :
2023-10-16 23:52:28 +00:00
@if [ $( shell $( GO) version | cut -c 16-17) -lt 20 ] ; then \
echo "minimum required Golang version is 1.20" ; \
2021-04-19 10:54:56 +00:00
exit 1 ; \
fi
2022-07-22 12:26:18 +00:00
## validate_docker_build_args: ensure docker build args are valid
2022-06-30 10:11:37 +00:00
validate_docker_build_args :
@echo "Docker build args:"
@echo " DOCKER_UID: $( DOCKER_UID) "
@echo " DOCKER_GID: $( DOCKER_GID) \n "
@echo "Ensuring host OS user exists with specified UID/GID..."
@if [ " $( UNAME) " = "Darwin" ] ; then \
dscl . list /Users UniqueID | grep " $( DOCKER_UID) " ; \
elif [ " $( UNAME) " = "Linux" ] ; then \
cat /etc/passwd | grep " $( DOCKER_UID) : $( DOCKER_GID) " ; \
fi
@echo " ✔️ host OS user exists: $( shell id -nu $( DOCKER_UID) ) "
2022-07-22 12:26:18 +00:00
## docker: validate, update submodules and build with docker
2022-06-30 10:11:37 +00:00
docker : validate_docker_build_args git -submodules
DOCKER_BUILDKIT = 1 $( DOCKER) build -t ${ DOCKER_TAG } \
2022-08-23 05:38:02 +00:00
--build-arg " BUILD_DATE= $( shell date +"%Y-%m-%dT%H:%M:%S:%z" ) " \
2022-05-21 09:21:35 +00:00
--build-arg VCS_REF = ${ GIT_COMMIT } \
--build-arg VERSION = ${ GIT_TAG } \
2022-06-30 10:11:37 +00:00
--build-arg UID = ${ DOCKER_UID } \
--build-arg GID = ${ DOCKER_GID } \
2022-05-21 09:21:35 +00:00
${ DOCKER_FLAGS } \
.
2020-08-21 12:38:11 +00:00
2021-07-19 13:40:09 +00:00
xdg_data_home := ~/.local/share
i f d e f X D G _ D A T A _ H O M E
xdg_data_home = $( XDG_DATA_HOME)
e n d i f
2022-06-30 10:11:37 +00:00
xdg_data_home_subdirs = $( xdg_data_home) /erigon $( xdg_data_home) /erigon-grafana $( xdg_data_home) /erigon-prometheus
2022-07-22 12:26:18 +00:00
## setup_xdg_data_home: TODO
2022-07-08 06:11:07 +00:00
setup_xdg_data_home :
2022-06-30 10:11:37 +00:00
mkdir -p $( xdg_data_home_subdirs)
2022-07-25 04:29:34 +00:00
ls -aln $( xdg_data_home) | grep -E "472.*0.*erigon-grafana" || chown -R 472:0 $( xdg_data_home) /erigon-grafana
2022-07-08 06:11:07 +00:00
@echo "✔️ xdg_data_home setup"
@ls -al $( xdg_data_home)
2022-07-22 12:26:18 +00:00
## docker-compose: validate build args, setup xdg data home, and run docker-compose up
2022-07-08 06:11:07 +00:00
docker-compose : validate_docker_build_args setup_xdg_data_home
2023-06-17 03:27:58 +00:00
docker compose up
2019-05-27 13:51:49 +00:00
2022-07-22 12:26:18 +00:00
## dbg debug build allows see C stack traces, run it with GOTRACEBACK=crash. You don't need debug build for C pit for profiling. To profile C code use SETCGOTRCKEBACK=1
2021-06-19 20:30:12 +00:00
dbg :
2021-04-29 14:29:58 +00:00
$( GO_DBG_BUILD) -o $( GOBIN) / ./cmd/...
2022-07-20 10:23:12 +00:00
%.cmd :
2022-02-24 15:10:46 +00:00
@# Note: $* is replaced by the command name
@echo " Building $* "
2022-03-04 00:47:09 +00:00
@cd ./cmd/$* && $( GOBUILD) -o $( GOBIN) /$*
2022-02-24 15:10:46 +00:00
@echo " Run \" $( GOBIN) / $* \" to launch $* . "
2022-07-22 12:26:18 +00:00
## geth: run erigon (TODO: remove?)
2021-05-31 10:20:56 +00:00
geth : erigon
2015-04-18 21:21:45 +00:00
2022-07-22 12:26:18 +00:00
## erigon: build erigon
2022-02-24 15:10:46 +00:00
erigon : go -version erigon .cmd
2022-02-22 18:17:50 +00:00
@rm -f $( GOBIN) /tg # Remove old binary to prevent confusion where users still use it because of the scripts
2021-05-08 08:45:40 +00:00
2022-09-30 20:04:34 +00:00
COMMANDS += devnet
2023-10-18 22:53:03 +00:00
COMMANDS += capcli
2022-02-24 15:10:46 +00:00
COMMANDS += downloader
COMMANDS += hack
COMMANDS += integration
2022-04-22 11:02:12 +00:00
COMMANDS += observer
2022-02-24 15:10:46 +00:00
COMMANDS += pics
COMMANDS += rpcdaemon
COMMANDS += rpctest
COMMANDS += sentry
COMMANDS += state
COMMANDS += txpool
2022-09-02 13:45:30 +00:00
COMMANDS += verkle
2022-09-17 11:55:38 +00:00
COMMANDS += evm
2022-10-29 19:51:32 +00:00
COMMANDS += sentinel
2023-10-16 13:35:26 +00:00
COMMANDS += caplin
2023-06-07 18:01:32 +00:00
COMMANDS += caplin-regression
2023-11-16 19:59:43 +00:00
COMMANDS += tooling
2023-06-07 18:01:32 +00:00
2022-02-24 15:10:46 +00:00
# build each command using %.cmd rule
$(COMMANDS) : %: %.cmd
2022-07-22 12:26:18 +00:00
## all: run erigon with all commands
2022-02-24 15:10:46 +00:00
all : erigon $( COMMANDS )
2021-11-23 16:44:46 +00:00
2022-07-22 12:26:18 +00:00
## db-tools: build db tools
2022-09-17 11:55:38 +00:00
db-tools :
2021-06-19 20:30:12 +00:00
@echo "Building db-tools"
2021-12-15 09:07:57 +00:00
2022-09-17 11:55:38 +00:00
go mod vendor
2023-08-24 11:12:22 +00:00
cd vendor/github.com/erigontech/mdbx-go && MDBX_BUILD_TIMESTAMP = unknown make tools
2023-04-10 01:44:03 +00:00
mkdir -p $( GOBIN)
2023-08-24 11:12:22 +00:00
cd vendor/github.com/erigontech/mdbx-go/mdbxdist && cp mdbx_chk $( GOBIN) && cp mdbx_copy $( GOBIN) && cp mdbx_dump $( GOBIN) && cp mdbx_drop $( GOBIN) && cp mdbx_load $( GOBIN) && cp mdbx_stat $( GOBIN)
2022-09-17 11:55:38 +00:00
rm -rf vendor
2021-06-11 13:31:37 +00:00
@echo " Run \" $( GOBIN) /mdbx_stat -h\" to get info about mdbx db file. "
2020-10-08 07:11:36 +00:00
2023-11-01 10:44:01 +00:00
test-erigon-lib :
2023-09-21 11:50:59 +00:00
@cd erigon-lib && $( MAKE) test
2023-11-01 10:44:01 +00:00
test-erigon-ext :
@cd tests/erigon-ext-test && ./test.sh $( GIT_COMMIT)
## test: run unit tests with a 100s timeout
test : test -erigon -lib
2023-10-08 17:26:54 +00:00
$( GOTEST) --timeout 10m
2022-05-04 03:35:59 +00:00
2023-11-01 10:44:01 +00:00
test3 : test -erigon -lib
2023-10-08 17:26:54 +00:00
$( GOTEST) --timeout 10m -tags $( BUILD_TAGS) ,e3
2022-09-18 10:41:01 +00:00
2022-07-22 12:26:18 +00:00
## test-integration: run integration tests with a 30m timeout
2023-11-01 10:44:01 +00:00
test-integration : test -erigon -lib
2023-10-07 20:30:10 +00:00
$( GOTEST) --timeout 240m -tags $( BUILD_TAGS) ,integration
2020-06-12 09:31:21 +00:00
2023-11-01 10:44:01 +00:00
test3-integration : test -erigon -lib
2023-10-07 20:30:10 +00:00
$( GOTEST) --timeout 240m -tags $( BUILD_TAGS) ,integration,e3
2022-10-05 02:53:03 +00:00
2023-09-21 11:50:59 +00:00
## lint-deps: install lint dependencies
lint-deps :
@cd erigon-lib && $( MAKE) lint-deps
2019-05-27 13:51:49 +00:00
2023-09-21 11:50:59 +00:00
## lintci: run golangci-lint linters
2021-06-18 03:35:11 +00:00
lintci :
2023-09-21 11:50:59 +00:00
@cd erigon-lib && $( MAKE) lintci
@./erigon-lib/tools/golangci_lint.sh
2019-11-05 08:12:49 +00:00
2023-09-21 11:50:59 +00:00
## lint: run all linters
lint :
@cd erigon-lib && $( MAKE) lint
@./erigon-lib/tools/golangci_lint.sh
2023-09-22 07:04:25 +00:00
@./erigon-lib/tools/mod_tidy_check.sh
2018-04-17 22:53:50 +00:00
2022-07-22 12:26:18 +00:00
## clean: cleans the go cache, build dir, libmdbx db dir
2016-05-25 12:07:57 +00:00
clean :
2021-12-22 04:18:35 +00:00
go clean -cache
2020-10-28 03:18:10 +00:00
rm -fr build/*
2016-05-25 12:07:57 +00:00
2017-02-26 22:52:10 +00:00
# The devtools target installs tools required for 'go generate'.
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.
2022-07-22 12:26:18 +00:00
## devtools: installs dev tools (and checks for npm installation etc.)
2017-02-26 22:52:10 +00:00
devtools :
2020-10-02 03:56:13 +00:00
# Notice! If you adding new binary - add it also to cmd/hack/binary-deps/main.go file
$( GOBUILD) -o $( GOBIN) /gencodec github.com/fjl/gencodec
$( GOBUILD) -o $( GOBIN) /abigen ./cmd/abigen
2023-03-07 06:14:35 +00:00
$( GOBUILD) -o $( GOBIN) /codecgen github.com/ugorji/go/codec/codecgen
2020-10-02 03:56:13 +00:00
PATH = $( GOBIN) :$( PATH) go generate ./common
2023-03-07 06:14:35 +00:00
# PATH=$(GOBIN):$(PATH) go generate ./core/types
2023-06-14 03:43:29 +00:00
PATH = $( GOBIN) :$( PATH) cd ./cmd/rpcdaemon/graphql && go run github.com/99designs/gqlgen .
2021-06-25 18:13:40 +00:00
PATH = $( GOBIN) :$( PATH) go generate ./consensus/aura/...
2022-05-30 10:08:49 +00:00
#PATH=$(GOBIN):$(PATH) go generate ./eth/ethconfig/...
2018-01-08 12:15:57 +00:00
@type "npm" 2> /dev/null || echo 'Please install node.js and npm'
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'
2017-02-26 22:52:10 +00:00
2022-07-22 12:26:18 +00:00
## bindings: generate test contracts and core contracts
2019-05-27 13:51:49 +00:00
bindings :
2020-10-02 03:56:13 +00:00
PATH = $( GOBIN) :$( PATH) go generate ./tests/contracts/
PATH = $( GOBIN) :$( PATH) go generate ./core/state/contracts/
2020-09-03 07:51:19 +00:00
2022-07-22 12:26:18 +00:00
## prometheus: run prometheus and grafana with docker-compose
2020-04-29 10:51:07 +00:00
prometheus :
2023-06-17 03:27:58 +00:00
docker compose up prometheus grafana
2020-06-05 16:46:34 +00:00
2022-07-22 12:26:18 +00:00
## escape: run escape path={path} to check for memory leaks e.g. run escape path=cmd/erigon
2020-06-05 16:46:34 +00:00
escape :
2020-06-15 16:39:34 +00:00
cd $( path) && go test -gcflags "-m -m" -run none -bench= BenchmarkJumpdest* -benchmem -memprofile mem.out
2022-01-19 07:54:56 +00:00
2022-07-22 12:26:18 +00:00
## git-submodules: update git submodules
2022-01-19 07:54:56 +00:00
git-submodules :
2022-04-29 07:07:39 +00:00
@[ -d ".git" ] || ( echo "Not a git repository" && exit 1)
2022-02-22 18:17:50 +00:00
@echo "Updating git submodules"
@# Dockerhub using ./hooks/post-checkout to set submodules, so this line will fail on Dockerhub
2022-06-30 10:11:37 +00:00
@# these lines will also fail if ran as root in a non-root user' s checked out repository
@git submodule sync --quiet --recursive || true
2022-02-22 18:17:50 +00:00
@git submodule update --quiet --init --recursive --force || true
2022-06-30 10:11:37 +00:00
2022-08-27 09:22:28 +00:00
PACKAGE_NAME := github.com/ledgerwatch/erigon
2023-08-11 05:54:59 +00:00
GOLANG_CROSS_VERSION ?= v1.20.7
2022-08-27 09:22:28 +00:00
.PHONY : release -dry -run
release-dry-run : git -submodules
@docker run \
--rm \
--privileged \
-e CGO_ENABLED = 1 \
-e GITHUB_TOKEN \
-e DOCKER_USERNAME \
-e DOCKER_PASSWORD \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ` pwd ` :/go/src/$( PACKAGE_NAME) \
-w /go/src/$( PACKAGE_NAME) \
2023-02-10 06:02:00 +00:00
ghcr.io/goreleaser/goreleaser-cross:${ GOLANG_CROSS_VERSION } \
2023-02-10 12:12:18 +00:00
--clean --skip-validate --skip-publish
2022-08-27 09:22:28 +00:00
.PHONY : release
release : git -submodules
@docker run \
--rm \
--privileged \
-e CGO_ENABLED = 1 \
-e GITHUB_TOKEN \
-e DOCKER_USERNAME \
-e DOCKER_PASSWORD \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ` pwd ` :/go/src/$( PACKAGE_NAME) \
-w /go/src/$( PACKAGE_NAME) \
2023-02-10 06:02:00 +00:00
ghcr.io/goreleaser/goreleaser-cross:${ GOLANG_CROSS_VERSION } \
2023-02-10 12:12:18 +00:00
--clean --skip-validate
2022-08-27 09:22:28 +00:00
2023-02-08 09:31:32 +00:00
@docker image push --all-tags thorax/erigon
@docker image push --all-tags ghcr.io/ledgerwatch/erigon
2022-06-30 10:11:37 +00:00
# since DOCKER_UID, DOCKER_GID are default initialized to the current user uid/gid,
# we need separate envvars to facilitate creation of the erigon user on the host OS.
ERIGON_USER_UID ?= 3473
ERIGON_USER_GID ?= 3473
2022-07-22 12:26:18 +00:00
## user_linux: create "erigon" user (Linux)
2022-06-30 10:11:37 +00:00
user_linux :
i f d e f D O C K E R
sudo groupadd -f docker
e n d i f
sudo addgroup --gid $( ERIGON_USER_GID) $( ERIGON_USER) 2> /dev/null || true
sudo adduser --disabled-password --gecos '' --uid $( ERIGON_USER_UID) --gid $( ERIGON_USER_GID) $( ERIGON_USER) 2> /dev/null || true
sudo mkhomedir_helper $( ERIGON_USER)
echo 'export PATH=$$PATH:/usr/local/go/bin' | sudo -u $( ERIGON_USER) tee /home/$( ERIGON_USER) /.bash_aliases >/dev/null
i f d e f D O C K E R
sudo usermod -aG docker $( ERIGON_USER)
e n d i f
2023-09-06 02:49:08 +00:00
sudo -u $( ERIGON_USER) mkdir -p /home/$( ERIGON_USER) /.local/share
2022-06-30 10:11:37 +00:00
2022-07-22 12:26:18 +00:00
## user_macos: create "erigon" user (MacOS)
2022-06-30 10:11:37 +00:00
user_macos :
sudo dscl . -create /Users/$( ERIGON_USER)
sudo dscl . -create /Users/$( ERIGON_USER) UserShell /bin/bash
sudo dscl . -list /Users UniqueID | grep $( ERIGON_USER) | grep $( ERIGON_USER_UID) || sudo dscl . -create /Users/$( ERIGON_USER) UniqueID $( ERIGON_USER_UID)
sudo dscl . -create /Users/$( ERIGON_USER) PrimaryGroupID $( ERIGON_USER_GID)
sudo dscl . -create /Users/$( ERIGON_USER) NFSHomeDirectory /Users/$( ERIGON_USER)
sudo dscl . -append /Groups/admin GroupMembership $( ERIGON_USER)
2023-09-06 02:49:08 +00:00
sudo -u $( ERIGON_USER) mkdir -p /Users/$( ERIGON_USER) /.local/share
2022-07-22 12:26:18 +00:00
## coverage: run code coverage report and output total coverage %
2022-09-07 11:38:45 +00:00
.PHONY : coverage
2022-07-22 12:26:18 +00:00
coverage :
@go test -coverprofile= coverage.out ./... > /dev/null 2>& 1 && go tool cover -func coverage.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}'
2022-09-07 11:38:45 +00:00
## hive: run hive test suite locally using docker e.g. OUTPUT_DIR=~/results/hive SIM=ethereum/engine make hive
.PHONY : hive
hive :
DOCKER_TAG = thorax/erigon:ci-local make docker
2022-12-07 22:51:24 +00:00
docker pull thorax/hive:latest
2022-09-07 11:38:45 +00:00
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $( OUTPUT_DIR) :/work thorax/hive:latest --sim $( SIM) --results-root= /work/results --client erigon_ci-local # run erigon
2022-12-09 13:07:57 +00:00
## automated-tests run automated tests (BUILD_ERIGON=0 to prevent erigon build with local image tag)
.PHONY : automated -tests
automated-tests :
./tests/automated-testing/run.sh
2022-07-22 12:26:18 +00:00
## help: print commands help
help : Makefile
@sed -n 's/^##//p' $<