diff --git a/.github/workflows/build_local_tesnet.yml b/.github/workflows/build_local_tesnet.yml index 480ca51c22e..6b2029c012c 100644 --- a/.github/workflows/build_local_tesnet.yml +++ b/.github/workflows/build_local_tesnet.yml @@ -28,19 +28,19 @@ jobs: uses: actions/checkout@v4 with: repository: multiversx/mx-chain-deploy-go - path: mx-chain-deploy-go + path: ../mx-chain-deploy-go - - name: Generate config - id: generate-config - run: | - cd ${GITHUB_WORKSPACE}/scripts/docker-testnet - export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet - ./prepare.sh - - - name: Deploy local testnet - run: | - export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet - echo ${TESTNETDIR} - docker compose up -d - docker ps -a - docker logs seednode +# - name: Generate config +# id: generate-config +# run: | +# cd ${GITHUB_WORKSPACE}/scripts/docker-testnet +# export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet +# ./prepare.sh +# +# - name: Deploy local testnet +# run: | +# export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet +# echo ${TESTNETDIR} +# docker compose up -d +# docker ps -a +# docker logs seednode diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 7efb0fd28e6..00000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,162 +0,0 @@ -version: "3.0" -services: - seednode: - image: seednode:dev - container_name: seednode - build: - context: . - dockerfile: docker/seednode/Dockerfile - command: "--rest-api-interface=0.0.0.0:10000" - networks: - local-testnet: - ipv4_address: 172.18.0.2 - volumes: - - ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config - - validator00: - image: node:dev - container_name: validator00 - build: - context: . - dockerfile: docker/node/Dockerfile - command: ["--rest-api-interface=0.0.0.0:10200", "--sk-index=0", "--config=./config/config_validator.toml"] - networks: - local-testnet: - ipv4_address: 172.18.0.3 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [seednode] - - validator01: - image: node:dev - container_name: validator01 - build: - context: . - dockerfile: docker/node/Dockerfile - command: ["--rest-api-interface=0.0.0.0:10201", "--sk-index=1", "--config=./config/config_validator.toml"] - networks: - local-testnet: - ipv4_address: 172.18.0.4 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [seednode] - - validator02: - image: node:dev - container_name: validator02 - build: - context: . - dockerfile: docker/node/Dockerfile - command: ["--rest-api-interface=0.0.0.0:10202", "--sk-index=2", "--config=./config/config_validator.toml"] - networks: - local-testnet: - ipv4_address: 172.18.0.5 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [seednode] - - validator03: - image: node:dev - container_name: validator03 - build: - context: . - dockerfile: docker/node/Dockerfile - command: [ "--rest-api-interface=0.0.0.0:10203", "--sk-index=3", "--config=./config/config_validator.toml" ] - networks: - local-testnet: - ipv4_address: 172.18.0.6 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [ seednode ] - - validator04: - image: node:dev - container_name: validator04 - build: - context: . - dockerfile: docker/node/Dockerfile - command: [ "--rest-api-interface=0.0.0.0:10204", "--sk-index=4", "--config=./config/config_validator.toml" ] - networks: - local-testnet: - ipv4_address: 172.18.0.7 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [ seednode ] - - validator05: - image: node:dev - container_name: validator05 - build: - context: . - dockerfile: docker/node/Dockerfile - command: [ "--rest-api-interface=0.0.0.0:10205", "--sk-index=5", "--config=./config/config_validator.toml" ] - networks: - local-testnet: - ipv4_address: 172.18.0.8 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [ seednode ] - - - validator06: - image: node:dev - container_name: validator06 - build: - context: . - dockerfile: docker/node/Dockerfile - command: [ "--rest-api-interface=0.0.0.0:10206", "--sk-index=6", "--config=./config/config_validator.toml" ] - networks: - local-testnet: - ipv4_address: 172.18.0.9 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [ seednode ] - - validator07: - image: node:dev - container_name: validator07 - build: - context: . - dockerfile: docker/node/Dockerfile - command: [ "--rest-api-interface=0.0.0.0:10207", "--sk-index=7", "--config=./config/config_validator.toml" ] - networks: - local-testnet: - ipv4_address: 172.18.0.10 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [ seednode ] - - validator08: - image: node:dev - container_name: validator08 - build: - context: . - dockerfile: docker/node/Dockerfile - command: [ "--rest-api-interface=0.0.0.0:10208", "--sk-index=8", "--config=./config/config_validator.toml" ] - networks: - local-testnet: - ipv4_address: 172.18.0.11 - volumes: - - ${TESTNETDIR}/node/config:/go/mx-chain-go/cmd/node/config - depends_on: [ seednode ] - - - proxy: - image: multiversx/chain-proxy:v1.1.45-sp4 - container_name: chain-proxy - ports: - - "7950:7950" - depends_on: [validator00, validator01, validator02] - networks: - local-testnet: - volumes: - - ${TESTNETDIR}/proxy/config:/mx-chain-proxy-go/cmd/proxy/config - -networks: - local-testnet: - driver: bridge - ipam: - driver: default - config: - - subnet: 172.18.0.0/16 - gateway: 172.18.0.1 \ No newline at end of file diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh new file mode 100755 index 00000000000..aa5cbda7e72 --- /dev/null +++ b/scripts/docker-testnet/clean.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Delete the entire testnet folder, which includes configuration, executables and logs. + +export MULTIVERSXTESTNETSCRIPTSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh" + +echo "Stopping all containers" +docker stop $(docker ps -a -q) + +echo "Removing all containers" +docker container prune + +echo "Removing $TESTNETDIR..." +rm -rf $TESTNETDIR diff --git a/scripts/docker-testnet/helpers.sh b/scripts/docker-testnet/helpers.sh new file mode 100755 index 00000000000..c7967c8c408 --- /dev/null +++ b/scripts/docker-testnet/helpers.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash + +startSeedNode() { + docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config seednode:dev \ + --rest-api-interface=0.0.0.0:10000 +} + +startObservers() { + local observerIdx=0 + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do + # Your commands or code to be executed in each iteration + KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) + + docker run -d --name "observer${observerIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --destination-shard-as-observer $i \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + + ((observerIdx++)) || true + done + done + + for ((i = 0; i < META_OBSERVERCOUNT; i++)); do + KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) + + docker run -d --name "observer${observerIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --destination-shard-as-observer "metachain" \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + + ((observerIdx++)) || true + done +} + +startValidators() { + validatorIdx=0 + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + + docker run -d --name "validator${validatorIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_validator.toml \ + --sk-index=${validatorIdx} \ + + ((validatorIdx++)) || true + done + done + + for ((i = 0; i < META_VALIDATORCOUNT; i++)); do + docker run -d --name "validator${validatorIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${validatorIdx} \ + + ((validatorIdx++)) || true + done +} + +updateProxyConfigDocker() { + pushd $TESTNETDIR/proxy/config + cp config.toml config_edit.toml + + # Truncate config.toml before the [[Observers]] list + sed -i -n '/\[\[Observers\]\]/q;p' config_edit.toml + + if [ "$SHARD_OBSERVERCOUNT" -le 0 ]; then + generateProxyValidatorListDocker config_edit.toml + else + generateProxyObserverListDocker config_edit.toml + fi + + cp config_edit.toml config.toml + rm config_edit.toml + + echo "Updated configuration for the Proxy." + popd +} + +generateProxyObserverListDocker() { + IP_BIT=3 + OUTPUTFILE=$! + + + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do + + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $i" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done + done + + for META_OBSERVER in $(seq $META_OBSERVERCOUNT); do + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $METASHARD_ID" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done +} + +generateProxyValidatorListDocker() { + IP_BIT=3 + OUTPUTFILE=$! + + + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $i" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Type = \"Validator\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done + done + + for META_OBSERVER in $(seq $META_VALIDATORCOUNT); do + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $METASHARD_ID" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Type = \"Validator\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done +} + +startProxyDocker() { + docker run -d --name "proxy" \ + -p $PORT_PROXY:8080 \ + -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ + multiversx/chain-proxy:v1.1.45-sp4 +} diff --git a/scripts/docker-testnet/prepare.sh b/scripts/docker-testnet/start.sh similarity index 67% rename from scripts/docker-testnet/prepare.sh rename to scripts/docker-testnet/start.sh index 1ae7268418e..0181ac3c3a9 100755 --- a/scripts/docker-testnet/prepare.sh +++ b/scripts/docker-testnet/start.sh @@ -7,6 +7,7 @@ export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>& MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" source "$DOCKERTESTNETDIR/variables.sh" +source "$DOCKERTESTNETDIR/helpers.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" @@ -22,4 +23,16 @@ copySeednodeConfig updateSeednodeConfig copyNodeConfig -updateNodeConfig \ No newline at end of file +updateNodeConfig + +startSeedNode +startObservers +startValidators + +if [ $USE_PROXY -eq 1 ]; then + prepareFolders_Proxy + copyProxyConfig + updateProxyConfigDocker + startProxyDocker +fi + diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index cddbcb92b0e..09f5d3eca43 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -17,10 +17,10 @@ export USE_TXGEN=0 # Path where the testnet will be instantiated. This folder is assumed to not # exist, but it doesn't matter if it already does. It will be created if not, # anyway. -export TESTNETDIR="$MULTIVERSXDIR/MultiversX/testnet" +export TESTNETDIR="$HOME/MultiversX/testnet" # Path to mx-chain-deploy-go, branch: master. Default: near mx-chain-go. -export CONFIGGENERATORDIR="$MULTIVERSXDIR/mx-chain-deploy-go/cmd/filegen" +export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" export CONFIGGENERATOR="$CONFIGGENERATORDIR/filegen" # Leave unchanged. export CONFIGGENERATOROUTPUTDIR="output" @@ -54,7 +54,7 @@ export OBSERVERS_ANTIFLOOD_DISABLE=0 # Shard structure export SHARDCOUNT=2 export SHARD_VALIDATORCOUNT=3 -export SHARD_OBSERVERCOUNT=1 +export SHARD_OBSERVERCOUNT=0 export SHARD_CONSENSUS_SIZE=3 # Metashard structure @@ -86,7 +86,7 @@ export ALWAYS_NEW_APP_VERSION=0 export ALWAYS_UPDATE_CONFIGS=1 # IP of the seednode -export SEEDNODE_IP="172.18.0.2" +export SEEDNODE_IP="172.17.0.2" # Ports used by the Nodes export PORT_SEEDNODE="9999"