diff --git a/.gitignore b/.gitignore index 74356d86b8fa7939aa9dc08effc5b9e05641cb5c..f4d1ac83ecd4a5875ec87c06720738c58dff0078 100644 --- a/.gitignore +++ b/.gitignore @@ -170,3 +170,5 @@ terraform.rc # /script-inputs/custom_dune_flags contains a local choice and must not be committed. /script-inputs/custom_dune_flags + +etherlink/scripts/docker-compose/mainnet-docker-compose/.etherlink-mainnet-data/ diff --git a/etherlink/scripts/docker-compose/mainnet-docker-compose/.env b/etherlink/scripts/docker-compose/mainnet-docker-compose/.env new file mode 100644 index 0000000000000000000000000000000000000000..55f8293d4bdb014ab93644699e1a92791449d3e6 --- /dev/null +++ b/etherlink/scripts/docker-compose/mainnet-docker-compose/.env @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +## This script is not meant to be executed interactively. Instead it +## is meant to be used in the init script to provide variables. + +# network to use +# warning: date dependent variables won't be correctly interpreted in compose.yml + +# tag to use for the tezos docker. default to `master` +OCTEZ_TAG=octez-v20.2 +ROLLUP_OCTEZ_TAG=master_3f7d4e39_20240716203446 +# EVM node is not published yet in release and so it must uses a more +# recent commit (on master branch). +EVM_OCTEZ_TAG=master_3f7d4e39_20240716203446 + +# exposed port of the evm-node container +EVM_OCTEZ_PORT=8545 + +# directory where all data dir are placed, default to `./.etherlink-${TZNETWORK}-data` +HOST_TEZOS_DATA_DIR=${HOST_TEZOS_DATA_DIR:-$PWD/.etherlink-mainnet-data} + +# snapshot to use to start the octez node +SNAPSHOT_URL=${SNAPSHOT_URL:-"https://snapshots.eu.tzinit.org/mainnet/rolling"} + +# snapshot to use to start the octez node +ROLLUP_SNAPSHOT_URL=${ROLLUP_SNAPSHOT_URL:-"https://snapshots.eu.tzinit.org/etherlink-mainnet/eth-mainnet.full"} + +## Rollup options +ROLLUP_ADDRESS="sr1Ghq66tYK9y3r8CC1Tf8i8m5nxh8nTvZEf" +# the used mode for the rollup node +ROLLUP_NODE_MODE="observer" +# the used endpoint for the preimages of the rollup +PREIMAGES_ENDPOINT=${PREIMAGES_ENDPOINT:-"https://snapshots.eu.tzinit.org/etherlink-mainnet/wasm_2_0_0"} + +# ----- Internal use (not intended to be modified by users) + +#by default it's the address of the octez node run in the docker +#compose. It's only available in the network +OCTEZ_NODE_ENDPOINT=${OCTEZ_NODE_ENDPOINT:-"http://octez-node:8732"} + +# When bootstraping the rollup node an archive node is necessary. In +# order to not have to setup an archive node, the init.sh script uses +# that node instead. +ARCHIVE_OCTEZ_NODE_ENDPOINT=${ARCHIVE_OCTEZ_NODE_ENDPOINT:-"https://rpc.tzkt.io/mainnet"} diff --git a/etherlink/scripts/docker-compose/mainnet-docker-compose/README.md b/etherlink/scripts/docker-compose/mainnet-docker-compose/README.md new file mode 100644 index 0000000000000000000000000000000000000000..29eb05dd4157957f25cca39f71fa38a1013cdcae --- /dev/null +++ b/etherlink/scripts/docker-compose/mainnet-docker-compose/README.md @@ -0,0 +1,21 @@ +This directory contains a script and docker compose file to be used to +start an EVM node in proxy mode. + +This document does not explain how smart rollup, smart rollup node, +evm node and the kernel works. + +The following directory allows to initialise an octez-node on a +specified network, a rollup node using a snapshot and start an evm +node based on the rollup node data dir. + +The script `init.sh` is here to take care of every necessary steps to +initialised all the node states. It can be called with +`./init.sh`. This call will bootstrap the 3 necessary nodes: +- octez-node, that follows the tezos chain +- octez-smart-rollup-node, that follows the rollup 'etherlink' +- octez-evm-node, that follows the evm chain 'etherlink' + +The `.env` file defines the default value necessary to run the docker +compose. By default it sets the data of all nodes in the directory +`$PWD/.etherlink-mainnet-data`, but this can be parameterized +with the environment variable `HOST_TEZOS_DATA_DIR`. diff --git a/etherlink/scripts/docker-compose/mainnet-docker-compose/compose.yml b/etherlink/scripts/docker-compose/mainnet-docker-compose/compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..c868e52b7aba6a2c40e9d842fd10a80069efa29e --- /dev/null +++ b/etherlink/scripts/docker-compose/mainnet-docker-compose/compose.yml @@ -0,0 +1,40 @@ +services: + octez-node: + container_name: octez-node + image: tezos/tezos-bare:${OCTEZ_TAG} + volumes: + - ${HOST_TEZOS_DATA_DIR}:/home/tezos + expose: + - 8732 + entrypoint: /usr/local/bin/octez-node + command: run --rpc-addr=0.0.0.0:8732 --allow-all-rpc 0.0.0.0 + + rollup-node: + container_name: rollup-node + image: tezos/tezos-bare:${ROLLUP_OCTEZ_TAG} + restart: always + volumes: + - ${HOST_TEZOS_DATA_DIR}:/home/tezos + expose: + - 8932 + entrypoint: /usr/local/bin/octez-smart-rollup-node + command: --endpoint ${OCTEZ_NODE_ENDPOINT} run + + proxy: + container_name: evm-proxy + image: tezos/tezos-bare:${EVM_OCTEZ_TAG} + restart: always + volumes: + - ${HOST_TEZOS_DATA_DIR}:/home/tezos + ports: + - ${EVM_OCTEZ_PORT}:8545 + entrypoint: /usr/local/bin/octez-evm-node + command: run proxy --finalized-view --read-only --keep-alive + + curl-runner: + container_name: curl-runner + image: curlimages/curl:latest + +networks: + default: + name: etherlink-net diff --git a/etherlink/scripts/docker-compose/mainnet-docker-compose/init.sh b/etherlink/scripts/docker-compose/mainnet-docker-compose/init.sh new file mode 100755 index 0000000000000000000000000000000000000000..4858fe8dca1642da42593b7a2dd2802036d59fac --- /dev/null +++ b/etherlink/scripts/docker-compose/mainnet-docker-compose/init.sh @@ -0,0 +1,154 @@ +#!/usr/bin/env bash + +set -e + +script_dir=$(dirname "$0") + +#shellcheck source=etherlink/scripts/docker-compose/.env +. "${script_dir}/.env" + +docker_compose() { + if (command -v "docker-compose" &> /dev/null); then + docker-compose "$@" + else + docker compose "$@" + fi +} + +run_in_docker_compose() { + service="$1" + shift 1 + docker_compose run "${service}" "$@" +} + +docker_update_images() { + # pull latest version + docker pull tezos/tezos-bare:"${OCTEZ_TAG}" + docker pull tezos/tezos-bare:"${ROLLUP_OCTEZ_TAG}" + docker pull tezos/tezos-bare:"${EVM_OCTEZ_TAG}" +} + +# fallback function to say which datadir to delete. This allows to recall the +# script if it fails at some point +script_failed() { + dirs="$1" + docker_compose down + echo "Script failed, please delete following datadir to restart the script from scratch ${HOST_TEZOS_DATA_DIR}/${dirs}." +} + +assert_init_can_run() { + if [[ -d "${HOST_TEZOS_DATA_DIR}" ]]; then + echo "${HOST_TEZOS_DATA_DIR} already exists. To run, please remove it." + exit 1 + fi +} + +init_octez_node() { + trap 'script_failed ".tezos-node"' ERR + mkdir -p "$HOST_TEZOS_DATA_DIR" + # init octez node storage + if [[ -n ${TZNETWORK_ADDRESS} ]]; then + run_in_docker_compose octez-node config init --network "${TZNETWORK_ADDRESS}" + fi + # download snapshot and import it. + if [[ -n ${SNAPSHOT_URL} ]]; then + # Do not download the snapshot if it already exists. + if [ ! -e "${HOST_TEZOS_DATA_DIR}/snapshot" ]; then + wget -O "${HOST_TEZOS_DATA_DIR}/snapshot" "${SNAPSHOT_URL}" + else + echo "Snapshot ${HOST_TEZOS_DATA_DIR}/snapshot already exists, using it." + fi + echo "importing snapshot ${HOST_TEZOS_DATA_DIR}/snapshot" + run_in_docker_compose octez-node snapshot import /home/tezos/snapshot + fi +} + +init_rollup_node() { + trap 'script_failed "{.tezos-node, .tezos-smart-rollup-node}"' ERR + echo "creating rollup node config" + run_in_docker_compose rollup-node init "${ROLLUP_NODE_MODE}" config for "${ROLLUP_ADDRESS}" \ + with operators "${OPERATOR_ALIAS}" \ + --rpc-addr 0.0.0.0 --rpc-port 8932 --cors-origins '*' \ + --cors-headers '*' \ + --pre-images-endpoint "${PREIMAGES_ENDPOINT}" \ + --acl-override allow-all + # download snapshot and import it. + if [[ -n ${ROLLUP_SNAPSHOT_URL} ]]; then + # Do not download the snapshot if it already exists. + if [ ! -e "${HOST_TEZOS_DATA_DIR}/rollup-snapshot" ]; then + wget -O "${HOST_TEZOS_DATA_DIR}/rollup-snapshot" "${ROLLUP_SNAPSHOT_URL}" + else + echo "Snapshot ${HOST_TEZOS_DATA_DIR}/rollup-snapshot already exists, using it." + fi + echo "importing snapshot ${HOST_TEZOS_DATA_DIR}/rollup-snapshot" + run_in_docker_compose rollup-node --endpoint "${ARCHIVE_OCTEZ_NODE_ENDPOINT}" snapshot import /home/tezos/rollup-snapshot + fi +} + +init_evm_node() { + trap 'script_failed "{.tezos-node, .tezos-smart-rollup-node, .tezos-evm-node}"' ERR + echo "creating evm node config" + run_in_docker_compose proxy init config --rollup-node-endpoint http://rollup-node:8932 --cors-origins '*' --cors-headers '*' --rpc-addr 0.0.0.0 --rpc-port 8545 --keep-alive +} + +init() { + docker_update_images + init_octez_node + docker_compose up octez-node -d + echo "waiting for the octez-node to be bootstrapped" + # The while loop allows to ignore the possible first iteration where + # the endpoint is not up yet (while the container starts). + while ! run_in_docker_compose curl-runner --max-time 1200 http://octez-node:8732/monitor/bootstrapped; do + sleep 5. + done + init_rollup_node + OCTEZ_NODE_ENDPOINT="${ARCHIVE_OCTEZ_NODE_ENDPOINT}" docker_compose up rollup-node -d + echo "waiting for the rollup-node to be bootstrapped" + # The while loop allows to ignore the possible first iteration where + # the endpoint is not up yet (while the container starts). + while ! run_in_docker_compose curl-runner --max-time 1200 http://rollup-node:8932/local/synchronized; do + sleep 5. + done + + init_evm_node + docker_compose stop +} + +command="${1:-init}" +# Perform a safe shift +if [ "$#" -ge 1 ]; then + shift 1 +fi + +case $command in +init_octez_node) + init_octez_node + ;; +init_rollup_node) + init_rollup_node + ;; +init_evm_node) + init_evm_node + ;; +init) + assert_init_can_run + init + ;; +run) + docker_compose up -d + ;; +restart) + docker_compose restart + ;; +*) + cat << EOF +Available commands: + - init: + initialize the full stack + - run + execute docker compose up + - restart + execute docker compose restart +EOF + ;; +esac