diff --git a/etherlink/scripts/docker-compose/.env b/etherlink/scripts/docker-compose/.env new file mode 100644 index 0000000000000000000000000000000000000000..2d0aca6003fb057c0c97fe95ea85b844fa22f0d1 --- /dev/null +++ b/etherlink/scripts/docker-compose/.env @@ -0,0 +1,32 @@ +#!/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. + +# tag to use for the tezos docker. default to `master` +OCTEZ_TAG=${OCTEZ_TAG:-master} + +# directory where all data dir are placed, default to `./data` +HOST_TEZOS_DATA_DIR=${HOST_TEZOS_DATA_DIR:-$PWD/data} + +# network used to initialize the octez node configuration +TZNETWORK=${TZNETWORK:-"ghostnet"} +# snapshot to use to start the octez node +SNAPSHOT_URL=${SNAPSHOT_URL-"https://snapshots.eu.tzinit.org/ghostnet/full"} +# endpoint to use to originate the smart rollup. +# it could be possible to use the local node but it +# would require then to first start the octez-node sepratatly from the docker compose. +ENDPOINT=${ENDPOINT:-"https://rpc.ghostnet.teztnets.com"} + +# alias to use for for rollup node operator default acount. +OPERATOR_ALIAS=${OPERATOR_ALIAS:-"operator"} +MINIMUM_OPERATOR_BALANCE=${MINIMUM_OPERATOR_BALANCE:-1000} +# alias to use for the address that originate the rollup. Different from +# the operator to prevent some failure with 1M when reseting the rollup node. +ORIGINATOR_ALIAS=${ORIGINATOR_ALIAS:-"originator"} +# alias to use for rollup. +ROLLUP_ALIAS=${ROLLUP_ALIAS:-"evm_rollup"} +# the used mode for the rollup node +ROLLUP_NODE_MODE=${ROLLUP_NODE_MODE:-"batcher"} +# the chain_id +EVM_CHAIN_ID=${EVM_CHAIN_ID:-123123} diff --git a/etherlink/scripts/docker-compose/README.md b/etherlink/scripts/docker-compose/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bbb5518c0ac34429e2ef6e9cfd432577455f479e --- /dev/null +++ b/etherlink/scripts/docker-compose/README.md @@ -0,0 +1,59 @@ +This directory contains some script and Dockerfile used to start a evm +sequencer rollup. + +This document does not explain how smart rollup, smart rollup node, +evm node and the sequencer kernel works. + +The following directory allows to initialise an octez-node on a +specified network, originate a new evm rollup and start a rollup and +sequencer node. + +The script assume the use of only 1 operator key for the rollup node. + +First step is to create an `.env` containing all necessary variables: + +``` +# tag to use for the tezos docker. default to `master` +OCTEZ_TAG=${OCTEZ_TAG:-"master"} + +# directory where all data dir are place, default to `./data` +HOST_TEZOS_DATA_DIR=${HOST_TEZOS_DATA_DIR:-$PWD/data} + +# network used to initialized the octez node configuration +TZNETWORK=${TZNETWORK:-"https://teztnets.xyz/ghostnet"} +# snapshot to use to start the rollup node +SNAPSHOT_URL=${SNAPSHOT_URL:-"https://snapshots.eu.tzinit.org/ghostnet/full"} +# endpoint to use to originate the smart rollup. +# it could be possible to use the local node but it +# would require then to first start the octez-node sepratatly from the docker compose. +ENDPOINT=${ENDPOINT:-"https://rpc.ghosnet.teztnets.xyz"} + +# alias to use for for rollup node operator default acount. +OPERATOR_ALIAS=${OPERATOR_ALIAS:-"operator"} +# alias to use for for rollup. +ROLLUP_ALIAS=${ROLLUP_ALIAS:-"evm_rollup"} +# the used mode for the rollup node +ROLLUP_NODE_MODE=${ROLLUP_NODE_MODE:-"operator"} +``` + +Then when the variables are defined, or default value is valid you can initialise the octez node with: +``` +./init.sh init_octez_node +``` + +This initialise the octez-node configuration, download the snapshot +and import it. + +Last step before running the docker compose is to bootstrap the rollup environment: +``` +./init.sh init_rollup +``` +This generate a new account, wait until the address has enough tz. +Then it build the evm kernel and originate a new rollup with it. +And finally initialise the rollup node configuration. + + +then start all node: +``` +docker compose up +``` diff --git a/etherlink/scripts/docker-compose/blockscout.env b/etherlink/scripts/docker-compose/blockscout.env new file mode 100644 index 0000000000000000000000000000000000000000..2a6fc5059f8c17aa8d0bec519506311a89b5996f --- /dev/null +++ b/etherlink/scripts/docker-compose/blockscout.env @@ -0,0 +1,207 @@ +# DOCKER_TAG= +ETHEREUM_JSONRPC_VARIANT=geth +ETHEREUM_JSONRPC_HTTP_URL=http://sequencer:8545 +# ETHEREUM_JSONRPC_FALLBACK_HTTP_URL= +DATABASE_URL=postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false +ETHEREUM_JSONRPC_TRACE_URL=http://host.docker.internal:8545/ +# ETHEREUM_JSONRPC_FALLBACK_TRACE_URL= +# ETHEREUM_JSONRPC_HTTP_TIMEOUT= +NETWORK= +SUBNETWORK=Awesome chain +LOGO=/images/blockscout_logo.svg +# ETHEREUM_JSONRPC_WS_URL= +ETHEREUM_JSONRPC_TRANSPORT=http +ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES=false +IPC_PATH= +NETWORK_PATH=/ +BLOCKSCOUT_HOST= +BLOCKSCOUT_PROTOCOL= +# SECRET_KEY_BASE= +# CHECK_ORIGIN= +PORT=4000 +COIN_NAME= +# METADATA_CONTRACT= +# VALIDATORS_CONTRACT= +# KEYS_MANAGER_CONTRACT= +# REWARDS_CONTRACT= +# TOKEN_BRIDGE_CONTRACT= +EMISSION_FORMAT=DEFAULT +# CHAIN_SPEC_PATH= +# SUPPLY_MODULE= +COIN= +EXCHANGE_RATES_COIN= +# EXCHANGE_RATES_SOURCE= +# EXCHANGE_RATES_COINGECKO_COIN_ID= +# EXCHANGE_RATES_COINGECKO_API_KEY= +# EXCHANGE_RATES_COINMARKETCAP_API_KEY= +POOL_SIZE=90 +# EXCHANGE_RATES_COINGECKO_PLATFORM_ID= +# TOKEN_EXCHANGE_RATE_INTERVAL= +# TOKEN_EXCHANGE_RATE_REFETCH_INTERVAL= +# TOKEN_EXCHANGE_RATE_MAX_BATCH_SIZE= +# DISABLE_TOKEN_EXCHANGE_RATE= +POOL_SIZE_API=10 +ECTO_USE_SSL=false +# DATADOG_HOST= +# DATADOG_PORT= +# SPANDEX_BATCH_SIZE= +# SPANDEX_SYNC_THRESHOLD= +HEART_BEAT_TIMEOUT=30 +# HEART_COMMAND= +#BLOCKSCOUT_VERSION= +RELEASE_LINK= +BLOCK_TRANSFORMER=base +# GRAPHIQL_TRANSACTION= +# BLOCK_RANGES= +# FIRST_BLOCK= +# LAST_BLOCK= +# TRACE_FIRST_BLOCK= +# TRACE_LAST_BLOCK= +# FOOTER_CHAT_LINK= +# FOOTER_FORUM_LINK_ENABLED= +# FOOTER_FORUM_LINK= +# FOOTER_TELEGRAM_LINK_ENABLED= +# FOOTER_TELEGRAM_LINK= +# FOOTER_GITHUB_LINK= +FOOTER_LOGO=/images/blockscout_logo.svg +FOOTER_LINK_TO_OTHER_EXPLORERS=false +FOOTER_OTHER_EXPLORERS={} +SUPPORTED_CHAINS={} +CACHE_BLOCK_COUNT_PERIOD=7200 +CACHE_TXS_COUNT_PERIOD=7200 +CACHE_ADDRESS_SUM_PERIOD=3600 +CACHE_TOTAL_GAS_USAGE_PERIOD=3600 +CACHE_ADDRESS_TRANSACTIONS_GAS_USAGE_COUNTER_PERIOD=1800 +CACHE_TOKEN_HOLDERS_COUNTER_PERIOD=3600 +CACHE_TOKEN_TRANSFERS_COUNTER_PERIOD=3600 +CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL=1800 +CACHE_AVERAGE_BLOCK_PERIOD=1800 +CACHE_MARKET_HISTORY_PERIOD=21600 +CACHE_ADDRESS_TRANSACTIONS_COUNTER_PERIOD=1800 +CACHE_ADDRESS_TOKENS_USD_SUM_PERIOD=3600 +CACHE_ADDRESS_TOKEN_TRANSFERS_COUNTER_PERIOD=1800 +TOKEN_METADATA_UPDATE_INTERVAL=172800 +CONTRACT_VERIFICATION_ALLOWED_SOLIDITY_EVM_VERSIONS=homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg,istanbul,berlin,london,paris,shanghai,default +CONTRACT_VERIFICATION_ALLOWED_VYPER_EVM_VERSIONS=byzantium,constantinople,petersburg,istanbul,berlin,paris,shanghai,default +# CONTRACT_VERIFICATION_MAX_LIBRARIES=10 +CONTRACT_MAX_STRING_LENGTH_WITHOUT_TRIMMING=2040 +# CONTRACT_DISABLE_INTERACTION= +UNCLES_IN_AVERAGE_BLOCK_TIME=false +DISABLE_WEBAPP=false +API_V1_READ_METHODS_DISABLED=false +API_V1_WRITE_METHODS_DISABLED=false +DISABLE_INDEXER=false +DISABLE_REALTIME_INDEXER=false +INDEXER_DISABLE_TOKEN_INSTANCE_REALTIME_FETCHER=false +INDEXER_DISABLE_TOKEN_INSTANCE_RETRY_FETCHER=false +INDEXER_DISABLE_TOKEN_INSTANCE_SANITIZE_FETCHER=false +INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER=false +INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false +# INDEXER_CATCHUP_BLOCKS_BATCH_SIZE= +# INDEXER_CATCHUP_BLOCKS_CONCURRENCY= +# INDEXER_CATCHUP_BLOCK_INTERVAL= +# INDEXER_INTERNAL_TRANSACTIONS_BATCH_SIZE= +# INDEXER_INTERNAL_TRANSACTIONS_CONCURRENCY= +# INDEXER_BLOCK_REWARD_BATCH_SIZE= +# INDEXER_BLOCK_REWARD_CONCURRENCY= +# INDEXER_TOKEN_INSTANCE_RETRY_REFETCH_INTERVAL= +# INDEXER_TOKEN_INSTANCE_RETRY_CONCURRENCY= +# INDEXER_TOKEN_INSTANCE_REALTIME_CONCURRENCY= +# INDEXER_TOKEN_INSTANCE_SANITIZE_CONCURRENCY= +# INDEXER_COIN_BALANCES_BATCH_SIZE= +# INDEXER_COIN_BALANCES_CONCURRENCY= +# INDEXER_RECEIPTS_BATCH_SIZE= +# INDEXER_RECEIPTS_CONCURRENCY= +# INDEXER_TOKEN_BALANCES_BATCH_SIZE= +# INDEXER_TX_ACTIONS_ENABLE= +# INDEXER_TX_ACTIONS_MAX_TOKEN_CACHE_SIZE= +# INDEXER_TX_ACTIONS_REINDEX_FIRST_BLOCK= +# INDEXER_TX_ACTIONS_REINDEX_LAST_BLOCK= +# INDEXER_TX_ACTIONS_REINDEX_PROTOCOLS= +# INDEXER_TX_ACTIONS_AAVE_V3_POOL_CONTRACT= +# INDEXER_REALTIME_FETCHER_MAX_GAP= +# INDEXER_DISABLE_WITHDRAWALS_FETCHER= +# WITHDRAWALS_FIRST_BLOCK= +# TOKEN_ID_MIGRATION_FIRST_BLOCK= +# TOKEN_ID_MIGRATION_CONCURRENCY= +# TOKEN_ID_MIGRATION_BATCH_SIZE= +# INDEXER_INTERNAL_TRANSACTIONS_TRACER_TYPE= +# WEBAPP_URL= +# API_URL= +SHOW_ADDRESS_MARKETCAP_PERCENTAGE=true +CHECKSUM_ADDRESS_HASHES=true +CHECKSUM_FUNCTION=eth +DISABLE_EXCHANGE_RATES=true +TXS_STATS_ENABLED=true +SHOW_PRICE_CHART=false +SHOW_PRICE_CHART_LEGEND=false +SHOW_TXS_CHART=true +TXS_HISTORIAN_INIT_LAG=0 +TXS_STATS_DAYS_TO_COMPILE_AT_INIT=10 +COIN_BALANCE_HISTORY_DAYS=90 +APPS_MENU=true +EXTERNAL_APPS=[] +# GAS_PRICE= +# RESTRICTED_LIST= +# RESTRICTED_LIST_KEY= +SHOW_MAINTENANCE_ALERT=false +MAINTENANCE_ALERT_MESSAGE= +SOURCIFY_INTEGRATION_ENABLED=false +SOURCIFY_SERVER_URL= +SOURCIFY_REPO_URL= +CHAIN_ID= +MAX_SIZE_UNLESS_HIDE_ARRAY=50 +HIDE_BLOCK_MINER=false +DISPLAY_TOKEN_ICONS=false +SHOW_TENDERLY_LINK=false +TENDERLY_CHAIN_PATH= +RE_CAPTCHA_SECRET_KEY= +RE_CAPTCHA_CLIENT_KEY= +RE_CAPTCHA_V3_SECRET_KEY= +RE_CAPTCHA_V3_CLIENT_KEY= +RE_CAPTCHA_DISABLED=false +JSON_RPC= +#API_RATE_LIMIT_DISABLED=true +API_RATE_LIMIT_TIME_INTERVAL=1s +API_RATE_LIMIT_BY_IP_TIME_INTERVAL=5m +API_RATE_LIMIT=50 +API_RATE_LIMIT_BY_KEY=50 +API_RATE_LIMIT_BY_WHITELISTED_IP=50 +API_RATE_LIMIT_WHITELISTED_IPS= +API_RATE_LIMIT_STATIC_API_KEY= +API_RATE_LIMIT_UI_V2_WITH_TOKEN=5 +API_RATE_LIMIT_BY_IP=3000 +# API_RATE_LIMIT_HAMMER_REDIS_URL=redis://redis_db:6379/1 +# API_RATE_LIMIT_IS_BLOCKSCOUT_BEHIND_PROXY=false +API_RATE_LIMIT_UI_V2_TOKEN_TTL_IN_SECONDS=18000 +FETCH_REWARDS_WAY=trace_block +MICROSERVICE_SC_VERIFIER_ENABLED=true +MICROSERVICE_SC_VERIFIER_URL=http://smart-contract-verifier:8050/ +MICROSERVICE_SC_VERIFIER_TYPE=sc_verifier +MICROSERVICE_ETH_BYTECODE_DB_INTERVAL_BETWEEN_LOOKUPS=10m +MICROSERVICE_VISUALIZE_SOL2UML_ENABLED=true +MICROSERVICE_VISUALIZE_SOL2UML_URL=http://visualizer:8050/ +MICROSERVICE_SIG_PROVIDER_ENABLED=true +MICROSERVICE_SIG_PROVIDER_URL=http://sig-provider:8050/ +DECODE_NOT_A_CONTRACT_CALLS=true +# DATABASE_READ_ONLY_API_URL= +# ACCOUNT_DATABASE_URL= +# ACCOUNT_POOL_SIZE= +# ACCOUNT_AUTH0_DOMAIN= +# ACCOUNT_AUTH0_CLIENT_ID= +# ACCOUNT_AUTH0_CLIENT_SECRET= +# ACCOUNT_PUBLIC_TAGS_AIRTABLE_URL= +# ACCOUNT_PUBLIC_TAGS_AIRTABLE_API_KEY= +# ACCOUNT_SENDGRID_API_KEY= +# ACCOUNT_SENDGRID_SENDER= +# ACCOUNT_SENDGRID_TEMPLATE= +ACCOUNT_CLOAK_KEY= +ACCOUNT_ENABLED=false +ACCOUNT_REDIS_URL=redis://redis_db:6379 +# MIXPANEL_TOKEN= +# MIXPANEL_URL= +# AMPLITUDE_API_KEY= +# AMPLITUDE_URL= +EIP_1559_ELASTICITY_MULTIPLIER=2 +# API_SENSITIVE_ENDPOINTS_KEY= +# ACCOUNT_VERIFICATION_EMAIL_RESEND_INTERVAL= diff --git a/etherlink/scripts/docker-compose/compose.yml b/etherlink/scripts/docker-compose/compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..abdebd81626ab223317dcbda19ec5b3176470783 --- /dev/null +++ b/etherlink/scripts/docker-compose/compose.yml @@ -0,0 +1,138 @@ +--- +version: '3.8' +services: + + _tezos_with_curl_build: + container_name: tezos_with_curl_build + image: tezos_with_curl:${OCTEZ_TAG} + logging: + driver: "json-file" + command: ['echo', 'build completed'] # any linux command which directly terminates. + build: + context: $PWD/tezos_with_curl + dockerfile: $PWD/tezos_with_curl/Dockerfile + args: + OCTEZ_TAG: ${OCTEZ_TAG} + + octez-node: + container_name: octez-node + depends_on: + - _tezos_with_curl_build + image: tezos_with_curl:${OCTEZ_TAG} + logging: + driver: "json-file" + healthcheck: + test: curl http://0.0.0.0:8732/monitor/bootstrapped + volumes: + - ${HOST_TEZOS_DATA_DIR}:/home/tezos + networks: + - etherlink-net + ports: + - 8732:8732 + entrypoint: /usr/local/bin/octez-node + command: run --rpc-addr=0.0.0.0:8732 --allow-all-rpc 0.0.0.0 + + smart-rollup-node: + container_name: rollup-node + image: tezos_with_curl:${OCTEZ_TAG} + logging: + driver: "json-file" + depends_on: + _tezos_with_curl_build: + condition: service_completed_successfully + octez-node: + condition: service_healthy + restart: always + volumes: + - ${HOST_TEZOS_DATA_DIR}:/home/tezos + ports: + - 8733:8733 + networks: + - etherlink-net + healthcheck: + test: curl http://0.0.0.0:8733/global/smart_rollup_address + entrypoint: /usr/local/bin/octez-smart-rollup-node + command: --endpoint http://octez-node:8732 run + + sequencer: + container_name: evm-sequencer + image: tezos/tezos-bare:${OCTEZ_TAG} + logging: + driver: "json-file" + depends_on: + smart-rollup-node: + condition: service_healthy + restart: always + volumes: + - ${HOST_TEZOS_DATA_DIR}:/home/tezos + networks: + - etherlink-net + ports: + - 8545:8545 + entrypoint: /usr/local/bin/octez-evm-node + command: run sequencer with endpoint http://rollup-node:8733 --rpc-addr 0.0.0.0 --rpc-port 8545 --kernel /home/tezos/kernel/sequencer.wasm --preimage-dir /home/tezos/kernel/_evm_installer_preimages --time-between-blocks 10 + + blockscout-redis-db: + image: 'redis:alpine' + container_name: blockscout-redis-db + logging: + driver: "json-file" + expose: + - 6379 + command: redis-server + networks: + - blockscout-net + + blockscout-db: + image: postgres:14 + container_name: blockscout-db + logging: + driver: "json-file" + restart: always + command: postgres -c 'max_connections=200' + environment: + POSTGRES_PASSWORD: '' + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 7432:5432 + networks: + - blockscout-net + + blockscout: + depends_on: + - blockscout-db + - blockscout-redis-db + image: blockscout/blockscout:${DOCKER_TAG:-latest} + logging: + driver: "json-file" + container_name: blockscout + restart: always + stop_grace_period: 5m + links: + - blockscout-db:database + command: sh -c "bin/blockscout eval \"Elixir.Explorer.ReleaseTasks.create_and_migrate()\" && bin/blockscout start" + extra_hosts: + - 'host.docker.internal:host-gateway' + env_file: + - ./blockscout.env + environment: + SUBNETWORK: Etherlink + CHAIN_ID: ${EVM_CHAIN_ID} + INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER: true + INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER: true + MICROSERVICE_SC_VERIFIER_ENABLED: false + MICROSERVICE_VISUALIZE_SOL2UML_ENABLED: false + MICROSERVICE_SIG_PROVIDER_ENABLED: false + DATABASE_URL: postgresql://postgres:@host.docker.internal:7432/blockscout?ssl=false + ACCOUNT_REDIS_URL: redis://blockscout-redis-db:6379 + ports: + - 4000:4000 + networks: + - etherlink-net + - blockscout-net + + +networks: + etherlink-net: + blockscout-net: diff --git a/etherlink/scripts/docker-compose/evm_kernel_builder/Dockerfile b/etherlink/scripts/docker-compose/evm_kernel_builder/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..1ca3af2f27f84eeba3fb50a0cdcf75390adc60f4 --- /dev/null +++ b/etherlink/scripts/docker-compose/evm_kernel_builder/Dockerfile @@ -0,0 +1,19 @@ +FROM rust:1.66.0 AS kernel_build +RUN apt-get update +RUN apt-get install -y \ + make \ + libc-dev \ + git \ + wabt \ + clang +RUN rustup target add wasm32-unknown-unknown +RUN git clone -b master --single-branch https://gitlab.com/tezos/tezos.git /tezos +WORKDIR /tezos +ARG EVM_CHAIN_ID_CONFIG +RUN echo "${EVM_CHAIN_ID_CONFIG}" >> /tezos/etherlink/kernel_evm/config/sequencer.yaml +RUN cat /tezos/etherlink/kernel_evm/config/sequencer.yaml +RUN make -f /tezos/kernels.mk build-deps sequencer.wasm + +FROM alpine:3.14 +COPY --from=kernel_build /tezos/sequencer.wasm /tezos/evm_kernel.wasm /kernel/ +COPY --from=kernel_build /tezos/_evm_installer_preimages/ /kernel/_evm_installer_preimages diff --git a/etherlink/scripts/docker-compose/init.sh b/etherlink/scripts/docker-compose/init.sh new file mode 100755 index 0000000000000000000000000000000000000000..7abb33246e38d7364c43bf51c03679e26ea10f86 --- /dev/null +++ b/etherlink/scripts/docker-compose/init.sh @@ -0,0 +1,189 @@ +#!/usr/bin/env bash + +set -e + +script_dir="$(dirname "$0")" + +#shellcheck source=etherlink/scripts/docker-compose/.env +. "${script_dir}/.env" + +run_in_docker() { + bin="$1" + shift 1 + docker_run=(docker run --log-driver=json-file -v "${HOST_TEZOS_DATA_DIR}":/home/tezos tezos/tezos-bare:"${OCTEZ_TAG}") + "${docker_run[@]}" "/usr/local/bin/${bin}" "$@" +} + +docker_update_images() { + # pull latest version + docker pull tezos/tezos-bare:"${OCTEZ_TAG}" + docker build -t tezos_with_curl:"${OCTEZ_TAG}" tezos_with_curl/ --build-arg OCTEZ_TAG="${OCTEZ_TAG}" +} + +create_chain_id() { + number="$1" + # Convert the number to hexadecimal and little endian format + hex_le=$(printf "%064x" "$number" | tac -rs ..) + + # Pad to 256 bits (64 hex characters) + padded_hex_le=$(printf "%064s" "$hex_le") + echo "$padded_hex_le" +} + +build_kernel() { + docker build -t etherlink_kernel:"${OCTEZ_TAG}" evm_kernel_builder/ --build-arg OCTEZ_TAG="${OCTEZ_TAG}" + evm_chain_id=$(create_chain_id "${EVM_CHAIN_ID}") + evm_chain_id_config=" - set:\n # Chain ID: ${EVM_CHAIN_ID}\n value: ${evm_chain_id}\n to: /evm/chain_id\n" + # build kernel in an image (e.g. tezos/tezos-bare:master) with new chain id + docker build -t etherlink_kernel:"${OCTEZ_TAG}" evm_kernel_builder/ --build-arg OCTEZ_TAG="${OCTEZ_TAG}" --build-arg EVM_CHAIN_ID_CONFIG="${evm_chain_id_config}" + container_name=$(docker create etherlink_kernel:"${OCTEZ_TAG}") + docker cp "${container_name}":/kernel/ "${HOST_TEZOS_DATA_DIR}/" +} + +generate_key() { + alias=$1 + echo "Generate a ${alias} key. Nothing happens if key already exists" + # if next command fails it's because the alias already + # exists. Don't override it. + run_in_docker octez-client --endpoint "${ENDPOINT}" gen keys "${alias}" || echo "${alias} already exists" + echo "You can now top up the balance for ${alias}" +} + +balance_account_is_enough() { + address="$1" + alias="$2" + minimum="$3" + balance=$(run_in_docker octez-client --endpoint "${ENDPOINT}" get balance for "${alias}") + balance=${balance%" ꜩ"} # remove ꜩ + balance=${balance%.*} # remove floating part + echo "balance of ${alias} is ${balance} ꜩ (truncated)." + if [[ "${balance}" -ge "${minimum}" ]]; then + return 0 + else + echo "Top up the balance for ${address} at least with ${minimum}" + return 1 + fi +} + +originate_evm_rollup() { + source="$1" + rollup_alias="$2" + kernel_path="$3" + echo "originate a new evm rollup '${rollup_alias}' with '${source}', and kernel '${kernel_path}'" + kernel="$(xxd -p "${kernel_path}" | tr -d '\n')" + run_in_docker octez-client --endpoint "${ENDPOINT}" \ + originate smart rollup "${rollup_alias}" \ + from "${source}" \ + of kind wasm_2_0_0 of type "(or (or (pair bytes (ticket (pair nat (option bytes)))) bytes) bytes)" \ + with kernel "${kernel}" \ + --burn-cap 999 --force +} + +init_rollup_node_config() { + mode="$1" + rollup_alias="$2" + operators="$3" + echo "create rollup node config and copy kernel preimage" + run_in_docker octez-smart-rollup-node init "${mode}" config for "${rollup_alias}" with operators "${operators[@]}" --rpc-addr 0.0.0.0 --rpc-port 8733 + cp -R "${HOST_TEZOS_DATA_DIR}"/kernel/_evm_installer_preimages/ "${HOST_TEZOS_DATA_DIR}"/.tezos-smart-rollup-node/wasm_2_0_0 +} + +init_octez_node() { + docker_update_images + + # init octez node storage + docker run --log-driver=json-file -v "${HOST_TEZOS_DATA_DIR}":/home/tezos tezos/tezos-bare:"${OCTEZ_TAG}" /usr/local/bin/octez-node config init --network "${TZNETWORK}" --data-dir /home/tezos/.tezos-node + # download snapshot + if [[ -n ${SNAPSHOT_URL} ]]; then + wget -O "${HOST_TEZOS_DATA_DIR}/snapshot" "${SNAPSHOT_URL}" + docker run --log-driver=json-file -v "${HOST_TEZOS_DATA_DIR}":/home/tezos tezos/tezos-bare:"${OCTEZ_TAG}" /usr/local/bin/octez-node snapshot import /home/tezos/snapshot --data-dir /home/tezos/.tezos-node + fi + +} + +# this function: +# 1/ updates the docker images/ +# 2/ build the kernel based on latest octez master version. +# kernels and pre-images are copied into "${HOST_TEZOS_DATA_DIR}/kernel" +# 3/ originate a new rollup with the build kernel +# 4/ initialise the octez-smart-rollup-node configuration +init_rollup() { + docker_update_images + + build_kernel + + KERNEL="${HOST_TEZOS_DATA_DIR}"/kernel/sequencer.wasm + originate_evm_rollup "${ORIGINATOR_ALIAS}" "${ROLLUP_ALIAS}" "${KERNEL}" + + init_rollup_node_config "${ROLLUP_NODE_MODE}" "${ROLLUP_ALIAS}" "${OPERATOR_ALIAS}" +} + +loop_until_balance_is_enough() { + alias=$1 + minimum_balance=$2 + address=$(run_in_docker octez-client --endpoint "${ENDPOINT}" show address "${alias}" | grep Hash | grep -oE "tz.*") + echo "loop until ${alias} (e.g. ${address}) as at last a balance of ${minimum_balance}" + until balance_account_is_enough "${address}" "${alias}" "${minimum_balance}"; do + sleep 10. + done +} + +command=$1 +shift 1 + +case $command in +generate_key) + generate_key "$@" + ;; +check_balance) + loop_until_balance_is_enough "$@" + ;; +originate_rollup) + originate_evm_rollup "$@" + ;; +init_rollup_node_config) + init_rollup_node_config "$@" + ;; +init_octez_node) + init_octez_node + ;; +init_rollup) + if [[ -n ${OPERATOR_ALIAS} ]]; then + generate_key "${OPERATOR_ALIAS}" + loop_until_balance_is_enough "${OPERATOR_ALIAS}" "${MINIMUM_OPERATOR_BALANCE}" + fi + generate_key "${ORIGINATOR_ALIAS}" + loop_until_balance_is_enough "${ORIGINATOR_ALIAS}" 100 + init_rollup + echo "You can now start the docker with \"docker compose up -d\"" + ;; +reset_rollup) + docker-compose stop smart-rollup-node sequencer blockscout blockscout-db blockscout-redis-db + + rm -r "${HOST_TEZOS_DATA_DIR}/.tezos-smart-rollup-node" "${HOST_TEZOS_DATA_DIR}/.octez-evm-node" "${HOST_TEZOS_DATA_DIR}/kernel" + + init_rollup + + docker-compose up -d --remove-orphans + ;; +*) + cat << EOF +Available commands: + - generate_key + - check_balance + - originate_rollup + - init_rollup_node_config + - init_octez_node: + download snapshot, and init octez-node config + - init_rollup: + build lastest evm kernel, originate the rollup, create operator, wait until operator balance + is topped then create rollup node config. + - reset_rollup: + remove rollup node data dir, sequencer data dir, blockscout data dir, + and existing kernel. + Then build lastest evm kernel, originate a new rollup with it and + initialise the rollup node config in: + "${HOST_TEZOS_DATA_DIR}". +EOF + ;; +esac diff --git a/etherlink/scripts/docker-compose/tezos_with_curl/Dockerfile b/etherlink/scripts/docker-compose/tezos_with_curl/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..f483eece55bb72319b9ba060263a0dbe7105bd5f --- /dev/null +++ b/etherlink/scripts/docker-compose/tezos_with_curl/Dockerfile @@ -0,0 +1,5 @@ +ARG OCTEZ_TAG +FROM tezos/tezos-bare:${OCTEZ_TAG} AS tezos_with_curl +USER root +RUN apk add curl +USER tezos