diff --git a/.envrc b/.envrc index aff4f86..ab7eee4 100644 --- a/.envrc +++ b/.envrc @@ -5,16 +5,24 @@ HOST_UID=$(id -u) HOST_GID=$(id -g) export HOST_UID HOST_GID -# Used by geth setup in docker-compose +# used by docker-compose to define data paths +export DOCKER_CONFIGS=${PRJ_ROOT}/docker/configs +export DOCKER_LOCAL_DATA=${PRJ_ROOT}/.local/docker/data + +# used by geth setup in docker-compose export GETH_NETWORK_ID=1214 export GETH_ACCOUNT_PASSWORD=!Pa55word -# Used by Avalanche -# AVALANCHEGO_EXEC_PATH - already defined in flake.nix -# export AVALANCHEGO_VERSION=$(avalanchego --version | awk -F' ' '{print $1}' | awk -F '/' '{print $2}') -# AVALANCHE_SUBNET_EVM_PATH - already defined in flake.nix -# export AVALANCHE_SUBNET_EVM_VERSION=$(subnet-cli --version | awk -F' ' '{print $3}') -# export AVALANCHE_CLI_DIR="$HOME/.avalanche-cli" # do NOT change this directory as avalanche-cli as this path is harcoded +# erigon +export ERIGON_DATA=${DOCKER_LOCAL_DATA}/erigon + +# prysm +export PRYSM_CHECKPOINT=${DOCKER_CONFIGS}/prysm/checkpoints +export PRYSM_DATA=${DOCKER_LOCAL_DATA}/prysm # allow local .envrc overrides [[ -f .envrc.local ]] && source_env .envrc.local + +# ensure local data directories exist +mkdir -p ${PRYSM_DATA} +mkdir -p ${ERIGON_DATA} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9bf6409..f7c3408 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,9 @@ node_modules/ ############################## ## Binaries ############################## -/out \ No newline at end of file +/out + +############################## +## Docker +############################## +/.local/ diff --git a/Justfile b/Justfile index e0ec6a7..fa3d488 100644 --- a/Justfile +++ b/Justfile @@ -53,5 +53,14 @@ nix-check: # Cleans all outputs clean: - rm -rf result* -alias c := clean \ No newline at end of file + rm -rf ./result* +alias c := clean + +# Alias docker-compose up +up: + mkdir -p $PRYSM_DATA $ERIGON_DATA + docker-compose up -d + +# Alias for docker-compose down +down: + docker-compose down --remove-orphans -v \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.eth1.yaml similarity index 95% rename from docker-compose.yml rename to docker-compose.eth1.yaml index eced725..0d75b40 100644 --- a/docker-compose.yml +++ b/docker-compose.eth1.yaml @@ -10,10 +10,9 @@ networks: services: nats: - image: nats:2.8.3-alpine container_name: nats - volumes: - - ./docker/nats/:/etc/nats:ro + build: + context: docker/images/nats ports: - "4222:4222" # client connections - "6222:6222" # routing port for clustering @@ -24,7 +23,7 @@ services: geth-bootnode: container_name: geth-bootnode build: - context: docker/geth + context: docker/images/geth args: - ACCOUNT_PASSWORD=${GETH_ACCOUNT_PASSWORD} command: @@ -39,7 +38,7 @@ services: geth-miner: container_name: geth-miner build: - context: docker/geth + context: docker/images/geth depends_on: - geth-bootnode command: @@ -54,7 +53,7 @@ services: geth-rpc-1: container_name: geth-rpc-1 build: - context: docker/geth + context: docker/images/geth depends_on: - geth-bootnode command: @@ -95,7 +94,7 @@ services: geth-rpc-2: container_name: geth-rpc-2 build: - context: docker/geth + context: docker/images/geth depends_on: - geth-bootnode command: @@ -133,7 +132,7 @@ services: geth-rpc-3: container_name: geth-rpc-3 build: - context: docker/geth + context: docker/images/geth depends_on: - geth-bootnode command: diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..2f951fa --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,116 @@ +version: "3.8" + +configs: + genesis.ssz: + file: ${PRYSM_CHECKPOINT}/genesis.ssz + +networks: + tethys: + name: tethys + driver: bridge + ipam: + config: + - subnet: 172.16.254.0/28 + +services: + prysm: + image: gcr.io/prysmaticlabs/prysm/beacon-chain:v3.0.0 + restart: unless-stopped + user: "${HOST_UID}:${HOST_GID}" + command: --datadir=/data/sepolia + --rpc-host=0.0.0.0 + --monitoring-host=0.0.0.0 + --execution-endpoint=http://erigon:8551 + --sepolia + --jwt-secret=/erigon-data/sepolia/jwt.hex + --accept-terms-of-use + --genesis-state=/genesis.ssz + --grpc-gateway-host="0.0.0.0" + --grpc-gateway-corsdomain='*' + --checkpoint-sync-url=https://sepolia.checkpoint-sync.ethdevops.io + --genesis-beacon-api-url=https://sepolia.checkpoint-sync.ethdevops.io + networks: + - tethys + ports: + - "3500:3500" + - "13000:13000" + - "12000:12000/udp" + volumes: + - type: bind + source: "${ERIGON_DATA}" + target: /erigon-data + - type: bind + source: "${PRYSM_DATA}" + target: /data + depends_on: + - "erigon" + mem_swappiness: 0 + configs: + - genesis.ssz + + erigon: + image: otterscan/erigon:v2022.08.03-otterscan + restart: unless-stopped + user: "${HOST_UID}:${HOST_GID}" + command: erigon + --chain=sepolia + --datadir=/erigon-data/sepolia + --torrent.download.slots=7 + --http.api="eth,web3,net,erigon,ots" + --ws + --http.corsdomain="*" + --http.addr="0.0.0.0" + --http.vhosts='*' + --authrpc.addr="erigon" + --authrpc.vhosts="erigon" + networks: + - tethys + ports: + - "8545:8545" + - "30303:30303/tcp" + - "30303:30303/udp" + - "42069:42069/tcp" + - "42069:42069/udp" + volumes: + - type: bind + source: "${ERIGON_DATA}" + target: /erigon-data + mem_swappiness: 0 + + otterscan: + image: otterscan/otterscan:v2022.04.01-otterscan + restart: unless-stopped + networks: + - tethys + ports: + - "3000:80" + depends_on: + - "prysm" + - "erigon" + + nats: + build: + context: docker/images/nats + ports: + - "4222:4222" # client connections + - "6222:6222" # routing port for clustering + - "8222:8222" # http management port for information reporting + networks: + - tethys + + proxy: + image: 41north/tethys-proxy:dev + restart: unless-stopped + depends_on: + - nats + networks: + - tethys + ports: + - "8080:8080" + command: + - eth + - --log-level=debug + environment: + NATS_URL: ns://nats:4222 + ETH_NETWORK_ID: 11155111 # sepolia + ETH_CHAIN_ID: 11155111 diff --git a/docker/configs/prysm/checkpoints/genesis.ssz b/docker/configs/prysm/checkpoints/genesis.ssz new file mode 100644 index 0000000..3edfc0a Binary files /dev/null and b/docker/configs/prysm/checkpoints/genesis.ssz differ diff --git a/docker/geth/Dockerfile b/docker/images/geth/Dockerfile similarity index 89% rename from docker/geth/Dockerfile rename to docker/images/geth/Dockerfile index de5bdf1..1e9e0bd 100644 --- a/docker/geth/Dockerfile +++ b/docker/images/geth/Dockerfile @@ -1,4 +1,4 @@ -FROM ethereum/client-go:v1.10.11 +FROM ethereum/client-go:v1.10.23 ARG ACCOUNT_PASSWORD diff --git a/docker/geth/genesis.json b/docker/images/geth/genesis.json similarity index 100% rename from docker/geth/genesis.json rename to docker/images/geth/genesis.json diff --git a/docker/images/nats/Dockerfile b/docker/images/nats/Dockerfile new file mode 100644 index 0000000..b7f97bd --- /dev/null +++ b/docker/images/nats/Dockerfile @@ -0,0 +1,3 @@ +FROM nats:2.8.4-alpine + +COPY nats-server.conf /etc/nats/nats-server.conf \ No newline at end of file diff --git a/docker/nats/nats-server.conf b/docker/images/nats/nats-server.conf similarity index 100% rename from docker/nats/nats-server.conf rename to docker/images/nats/nats-server.conf diff --git a/nix/pkgs/prysm/default.nix b/nix/pkgs/prysm/default.nix new file mode 100644 index 0000000..2c71294 --- /dev/null +++ b/nix/pkgs/prysm/default.nix @@ -0,0 +1,52 @@ +{ + lib, + buildGoModule, + fetchFromGitHub, +}: +buildGoModule rec { + pname = "prysm"; + version = "3.0.0"; + + src = fetchFromGitHub { + owner = "prysmaticlabs"; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-Rjg+dHd6MxHy+ZQcPIx18VCzIvxqP3crvU9nF6DG8rs="; + }; + + vendorSha256 = "sha256-aaWCj3bucb81P3GjspOiFgUOoL2bygy2lmwmnG/W2a8="; + + doCheck = false; + + ldflags = [ + "-s" + "-w" + "-X github.com/ava-labs/avalanchego/version.GitCommit=${src.rev}" + ]; + + postInstall = '' + # Build directory should have this structure: + # See: https://github.com/ava-labs/avalanchego/blob/acd07505cd701dbd3832ca7aa301865fc0737839/config/config.go#L84 + # + # build + # ├── avalanchego (the binary from compiling the app directory) + # └── plugins + # └── evm + mkdir -p $out/build/plugins + + # Store bin inside build/ folder + mv $out/bin/main $out/build/${pname} + + # For now, we symlink, but the idea is to give support to different plugins + ln -s $out/build/${pname} $out/bin/${pname} + ''; + + subPackages = ["main/main.go"]; + + meta = with lib; { + homepage = "https://www.avax.network/"; + description = "Go implementation of an Avalanche node"; + license = licenses.bsd3; + maintainers = with maintainers; [aldoborrero]; + }; +}