From e0013df3f5052d05facbe3d43f70a243b141a1cc Mon Sep 17 00:00:00 2001 From: Mikhail Wall Date: Mon, 23 Dec 2024 01:37:24 +0500 Subject: [PATCH] feat: added releasers only, without mev-commit changes --- .github/workflows/goreleaser.yaml | 35 ++++ .goreleaser.yml | 78 +++++++++ deploy_create2.sh | 77 +++++++++ entrypoint.sh | 277 ++++++++++++++++++++++++++++++ 4 files changed, 467 insertions(+) create mode 100644 .github/workflows/goreleaser.yaml create mode 100644 .goreleaser.yml create mode 100644 deploy_create2.sh create mode 100644 entrypoint.sh diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml new file mode 100644 index 0000000000..2ccc284a94 --- /dev/null +++ b/.github/workflows/goreleaser.yaml @@ -0,0 +1,35 @@ +name: goreleaser + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + packages: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - if: ${{ !startsWith(github.ref, 'refs/tags/v') }} + run: echo "flags=--snapshot" >> $GITHUB_ENV + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: 1.21 + cache: true + - name: GHCR Docker Login + run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean ${{ env.flags }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..af48e23fba --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,78 @@ +version: 1 + +project_name: mev-commit-go-ethereum +dist: /tmp/dist/mev-commit-go-ethereum + +builds: + - env: + - CGO_ENABLED=0 + - GOWORK=off + ldflags: + - -checklinkname=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 7 + ignore: + - goos: windows + goarch: arm64 + dir: ./external/geth-pos + main: ./cmd/geth + binary: "{{ .ProjectName }}" + +archives: + - format: tar.gz + name_template: >- + {{- .Binary }}_ + {{- with index .Env "RELEASE_VERSION" -}} + {{ . }} + {{- else -}} + {{- if .IsSnapshot }}{{ .ShortCommit }} + {{- else }}{{ .Version }} + {{- end }} + {{- end -}} + {{- with index .Env "DIRTY_SUFFIX" -}} + {{ . }} + {{- end -}}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }} + {{- end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + format_overrides: + - goos: windows + format: zip + files: + - src: ./external/geth-pos/entrypoint.sh + dst: ./ + strip_parent: true + - src: ./external/geth-pos/deploy_create2.sh + dst: ./ + strip_parent: true + +checksum: + name_template: >- + {{ .ProjectName }}_ + {{- with index .Env "RELEASE_VERSION" -}} + {{ . }} + {{- else -}} + {{- if .IsSnapshot }}{{ .ShortCommit }} + {{- else }}{{ .Version }} + {{- end }} + {{- end -}} + {{- with index .Env "DIRTY_SUFFIX" -}} + {{ . }} + {{- end -}} + _checksums.txt +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/deploy_create2.sh b/deploy_create2.sh new file mode 100644 index 0000000000..5e9ca90c66 --- /dev/null +++ b/deploy_create2.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +set -ex + +# Deploys create2 proxy according to https://github.com/primev/deterministic-deployment-proxy + +PROXY_ADDRESS="0x4e59b44847b379578588920ca78fbf26c0b4956c" +SIGNER_ADDRESS="0x3fab184622dc19b6109349b94811493bf2a45362" +# The following transaction string contains fixed from address corresponding to the signer address: 0x3fab184622dc19b6109349b94811493bf2a45362 +TRANSACTION="0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222" + +help() { + echo "Usage: $0 " + echo " RPC_URL: URL of the JSON RPC endpoint" + exit 1 +} + +RPC_URL="${1:-$RPC_URL}" +if [ -z "${RPC_URL}" ]; then + help +fi + +RESPONSE=$( + curl \ + --silent \ + --request POST \ + --header "Content-Type: application/json" \ + --data '{ + "jsonrpc": "2.0", + "method": "eth_getCode", + "params": ["'"${PROXY_ADDRESS}"'", "latest"], + "id": 1 + }' \ + "${RPC_URL}") +if [ -z "${RESPONSE}" ] || [ "${RESPONSE}" = "null" ]; then + echo "Error: No response from JSON RPC at ${RPC_URL}" + exit 1 +fi +if [ "$(echo "${RESPONSE}" | jq -r '.result')" != "0x" ]; then + echo "Contract already deployed at ${PROXY_ADDRESS}" + exit 0 +fi + +echo "No contract deployed at ${PROXY_ADDRESS}, deploying..." +curl \ + --silent "${RPC_URL}" \ + --request 'POST' \ + --header 'Content-Type: application/json' \ + --data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "eth_sendRawTransaction", + "params": ["'"${TRANSACTION}"'"] + }' +sleep 5 + +# For prod we'll have to set gas params s.t. no ether is leftover here. For now we warn +RESPONSE=$( + curl \ + --silent \ + --request POST \ + --header "Content-Type: application/json" \ + --data '{ + "jsonrpc": "2.0", + "method": "eth_getBalance", + "params": ["'"${SIGNER_ADDRESS}"'", "latest"], + "id": 1 + }' \ + "${RPC_URL}") +if [ -z "${RESPONSE}" ] || [ "${RESPONSE}" = "null" ]; then + echo "Error: No response from JSON RPC at ${RPC_URL}" + exit 1 +fi +RESULT="$(echo "${RESPONSE}" | jq -r '.result')" +if [ "${RESULT}" != "0x0" ]; then + echo "WARNING: Deployment signer (${SIGNER_ADDRESS}) has leftover balance of ${RESULT} wei." +fi diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000000..b0717b9139 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,277 @@ +#!/bin/sh +set -exu + +GETH_BIN_PATH=${GETH_BIN_PATH:-geth} +GENESIS_L1_PATH=${GENESIS_L1_PATH:-/genesis_pos.json} +GETH_VERBOSITY=${GETH_VERBOSITY:-3} +GETH_LOG_FORMAT=${GETH_LOG_FORMAT:-terminal} +GETH_SYNC_MODE=${GETH_SYNC_MODE:-snap} +GETH_STATE_SCHEME=${GETH_STATE_SCHEME:-path} +GETH_DATA_DIR=${GETH_DATA_DIR:-/data} +GETH_CHAINDATA_DIR="$GETH_DATA_DIR/geth/chaindata" +GETH_KEYSTORE_DIR="$GETH_DATA_DIR/keystore" +GETH_KEYSTORE_PASSWORD=${GETH_KEYSTORE_PASSWORD:-"primev"} +GETH_ZERO_FEE_ADDRESSES=${GETH_ZERO_FEE_ADDRESSES:-} +CHAIN_ID=$(cat "$GENESIS_L1_PATH" | jq -r .config.chainId) +RPC_PORT="${RPC_PORT:-8545}" +WS_PORT="${WS_PORT:-8546}" +RPC_ENGINE_PORT="${RPC_ENGINE_PORT:-8551}" +BLOCK_SIGNER_PRIVATE_KEY=${BLOCK_SIGNER_PRIVATE_KEY:-""} +JWT_SECRET=${JWT_SECRET:-"13373d9a0257983ad150392d7ddb2f9172c9396b4c450e26af469d123c7aaa5c"} + +if [ -n "$GETH_ZERO_FEE_ADDRESSES" ]; then + ZERO_FEE_ADDRESSES="--zero-fee-addresses=$GETH_ZERO_FEE_ADDRESSES" +else + ZERO_FEE_ADDRESSES="" +fi + +# Generate signer key if needed +if [ "$GETH_NODE_TYPE" = "signer" ]; then + if [ ! -f "$GETH_DATA_DIR/password" ]; then + echo -n "$GETH_KEYSTORE_PASSWORD" > "$GETH_DATA_DIR"/password + fi + if [ ! -d "$GETH_KEYSTORE_DIR" ]; then + if [ -n "$BLOCK_SIGNER_PRIVATE_KEY" ]; then + echo "$GETH_KEYSTORE_DIR missing, running account import" + echo -n "$BLOCK_SIGNER_PRIVATE_KEY" | sed 's/0x//' > "$GETH_DATA_DIR"/block-signer-key + "$GETH_BIN_PATH" \ + --verbosity="$GETH_VERBOSITY" \ + --log.format="$GETH_LOG_FORMAT" \ + --nousb \ + account import \ + --datadir="$GETH_DATA_DIR" \ + --password="$GETH_DATA_DIR"/password \ + "$GETH_DATA_DIR"/block-signer-key + fi + else + echo "$GETH_KEYSTORE_DIR exists." + if [ -z "$BLOCK_SIGNER_PRIVATE_KEY" ]; then + GETH_ACCOUNT_LIST=$("$GETH_BIN_PATH" --verbosity="$GETH_VERBOSITY" account list --datadir "$GETH_DATA_DIR") + BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX=$(echo "$GETH_ACCOUNT_LIST" | grep -oE '[0-9a-fA-F]{40}$') + BLOCK_SIGNER_ADDRESS="0x$BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX" + echo "Block signer address with 0x prefix: $BLOCK_SIGNER_ADDRESS" + fi + fi +fi + +# Init geth if needed +if [ ! -d "$GETH_CHAINDATA_DIR" ]; then + echo "$GETH_CHAINDATA_DIR missing, running init" + echo "Initializing genesis." + "$GETH_BIN_PATH" \ + --verbosity="$GETH_VERBOSITY" \ + --log.format="$GETH_LOG_FORMAT" \ + --nousb \ + --state.scheme="$GETH_STATE_SCHEME" \ + --datadir="$GETH_DATA_DIR" init \ + "$GENESIS_L1_PATH" +else + echo "$GETH_CHAINDATA_DIR exists." +fi + +# Obtain assigned container IP for p2p +NODE_IP=${NODE_IP:-$(hostname -i)} +echo "NODE_IP is set to: $NODE_IP" + +PUBLIC_NODE_IP=${PUBLIC_NODE_IP:-""} +echo "EXTERNAL_NODE_IP is set to: $PUBLIC_NODE_IP" + +# Set NAT_FLAG based on whether PUBLIC_NODE_IP is empty or not +if [ -n "$PUBLIC_NODE_IP" ]; then + NAT_FLAG="--nat=extip:$PUBLIC_NODE_IP" +else + NAT_FLAG="--nat=none" +fi + +# (Optional) Echo the values for verification + +if [ "$GETH_NODE_TYPE" = "bootnode" ]; then + echo "Starting bootnode" + echo "$NODE_KEY" > $GETH_DATA_DIR/nodekey + + exec "$GETH_BIN_PATH" \ + --verbosity="$GETH_VERBOSITY" \ + --log.format="$GETH_LOG_FORMAT" \ + $ZERO_FEE_ADDRESSES \ + --datadir="$GETH_DATA_DIR" \ + --port 30301 \ + --http \ + --http.corsdomain="*" \ + --http.vhosts="*" \ + --http.addr="$NODE_IP" \ + --http.port="$RPC_PORT" \ + --http.api=web3,debug,eth,txpool,net,engine \ + --ws \ + --ws.addr="$NODE_IP" \ + --ws.port="$WS_PORT" \ + --ws.origins="*" \ + --ws.api=debug,eth,txpool,net,engine \ + --syncmode="${GETH_SYNC_MODE}" \ + --gcmode=full \ + --state.scheme="$GETH_STATE_SCHEME" \ + --networkid=$CHAIN_ID \ + --nousb \ + --metrics \ + --metrics.addr="$NODE_IP" \ + --metrics.port=6060 \ + --pprof \ + --pprof.addr="$NODE_IP" \ + --pprof.port=60601 \ + --nodekey $GETH_DATA_DIR/nodekey \ + --netrestrict $NET_RESTRICT \ + "$NAT_FLAG" \ + --txpool.accountqueue=512 \ + --rpc.allow-unprotected-txs \ + --miner.gasprice=1000000000 \ + --miner.recommit=300ms \ + --gpo.maxprice=500000000000 \ + --authrpc.addr="$NODE_IP" \ + --authrpc.jwtsecret $GETH_DATA_DIR/jwt.hex + +elif [ "$GETH_NODE_TYPE" = "signer" ]; then + echo "Starting signer node" + echo "$NODE_KEY" > $GETH_DATA_DIR/nodekey + echo "$JWT_SECRET" > $GETH_DATA_DIR/jwt.hex + + GETH_PORT="${GETH_PORT:-30311}" + + exec "$GETH_BIN_PATH" \ + --verbosity="$GETH_VERBOSITY" \ + --log.format="$GETH_LOG_FORMAT" \ + $ZERO_FEE_ADDRESSES \ + --datadir="$GETH_DATA_DIR" \ + --port="$GETH_PORT" \ + --syncmode="${GETH_SYNC_MODE}" \ + --gcmode=full \ + --state.scheme="$GETH_STATE_SCHEME" \ + --http \ + --http.corsdomain="*" \ + --http.vhosts="*" \ + --http.addr="$NODE_IP" \ + --http.port="$RPC_PORT" \ + --http.api=web3,debug,eth,txpool,net,engine \ + --networkid=$CHAIN_ID \ + --unlock=$BLOCK_SIGNER_ADDRESS \ + --password="$GETH_DATA_DIR"/password \ + --mine \ + --miner.etherbase=$BLOCK_SIGNER_ADDRESS \ + --allow-insecure-unlock \ + --nousb \ + --nodekey $GETH_DATA_DIR/nodekey \ + --netrestrict $NET_RESTRICT \ + --metrics \ + --metrics.addr="$NODE_IP" \ + --metrics.port=6060 \ + --pprof \ + --pprof.addr="$NODE_IP" \ + --pprof.port=60601 \ + --ws \ + --ws.addr="$NODE_IP" \ + --ws.port="$WS_PORT" \ + --ws.origins="*" \ + --ws.api=debug,eth,txpool,net,engine \ + --rpc.allow-unprotected-txs \ + --authrpc.addr="$NODE_IP" \ + --authrpc.port="$RPC_ENGINE_PORT" \ + --authrpc.vhosts="*" \ + --txpool.accountqueue=512 \ + --miner.gasprice=1000000000 \ + --miner.recommit=300ms \ + --gpo.maxprice=500000000000 \ + --authrpc.jwtsecret $GETH_DATA_DIR/jwt.hex \ + "$NAT_FLAG" + +elif [ "$GETH_NODE_TYPE" = "member" ]; then + echo "Starting member node" + echo "$NODE_KEY" > $GETH_DATA_DIR/nodekey + echo "BOOTNODE_ENDPOINT is set to: $BOOTNODE_ENDPOINT" + GETH_PORT="${GETH_PORT:-30311}" + + exec "$GETH_BIN_PATH" \ + --verbosity="$GETH_VERBOSITY" \ + --log.format="$GETH_LOG_FORMAT" \ + $ZERO_FEE_ADDRESSES \ + --datadir="$GETH_DATA_DIR" \ + --port="$GETH_PORT" \ + --syncmode="${GETH_SYNC_MODE}" \ + --gcmode=full \ + --state.scheme="$GETH_STATE_SCHEME" \ + --db.engine=pebble \ + --http \ + --http.corsdomain="*" \ + --http.vhosts="*" \ + --http.addr="$NODE_IP" \ + --http.port="$RPC_PORT" \ + --http.api=web3,debug,eth,txpool,net,engine \ + --bootnodes $BOOTNODE_ENDPOINT \ + --networkid=$CHAIN_ID \ + --password="$GETH_DATA_DIR"/password \ + --nodekey $GETH_DATA_DIR/nodekey \ + --metrics \ + --metrics.addr="$NODE_IP" \ + --metrics.port=6060 \ + --pprof \ + --pprof.addr="$NODE_IP" \ + --pprof.port=60601 \ + --ws \ + --ws.addr="$NODE_IP" \ + --ws.port="$WS_PORT" \ + --ws.origins="*" \ + --ws.api=debug,eth,txpool,net,engine \ + --rpc.allow-unprotected-txs \ + --authrpc.addr="$NODE_IP" \ + --authrpc.port="$RPC_ENGINE_PORT" \ + --authrpc.vhosts="*" \ + --txpool.accountqueue=512 \ + --miner.gasprice=1000000000 \ + --miner.recommit=300ms \ + --gpo.maxprice=500000000000 \ + "$NAT_FLAG" +elif [ "$GETH_NODE_TYPE" = "archive" ]; then + echo "Starting archive node" + echo "BOOTNODE_ENDPOINT is set to: $BOOTNODE_ENDPOINT" + GETH_PORT="${GETH_PORT:-30311}" + + exec "$GETH_BIN_PATH" \ + --verbosity="$GETH_VERBOSITY" \ + --log.format="$GETH_LOG_FORMAT" \ + --datadir="$GETH_DATA_DIR" \ + --port="$GETH_PORT" \ + --syncmode="${GETH_SYNC_MODE}" \ + --gcmode=archive \ + --history.state=0 \ + --history.transactions=0 \ + --state.scheme="$GETH_STATE_SCHEME" \ + --db.engine=pebble \ + --http \ + --http.corsdomain="*" \ + --http.vhosts="*" \ + --http.addr="$NODE_IP" \ + --http.port="$RPC_PORT" \ + --http.api=web3,debug,eth,txpool,net,engine \ + --bootnodes $BOOTNODE_ENDPOINT \ + --networkid=$CHAIN_ID \ + --password="$GETH_DATA_DIR"/password \ + --metrics \ + --metrics.addr="$NODE_IP" \ + --metrics.port=6060 \ + --pprof \ + --pprof.addr="$NODE_IP" \ + --pprof.port=60601 \ + --ws \ + --ws.addr="$NODE_IP" \ + --ws.port="$WS_PORT" \ + --ws.origins="*" \ + --ws.api=debug,eth,txpool,net,engine \ + --rpc.allow-unprotected-txs \ + --authrpc.addr="$NODE_IP" \ + --authrpc.port="$RPC_ENGINE_PORT" \ + --authrpc.vhosts="*" \ + --txpool.accountqueue=512 \ + --miner.gasprice=1000000000 \ + --miner.recommit=300ms \ + --gpo.maxprice=500000000000 \ + "$NAT_FLAG" +else + echo "Invalid GETH_NODE_TYPE specified" +fi