From 41d8908ed6265d8aad1a37b338f81718477da4b3 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 27 Feb 2024 17:57:48 +0200 Subject: [PATCH 01/41] added script to create local-testnet with docker. --- .github/workflows/build_local_tesnet.yml | 54 ++++++ docker/node/Dockerfile | 4 +- scripts/docker-testnet/clean.sh | 16 ++ scripts/docker-testnet/helpers.sh | 153 +++++++++++++++++ scripts/docker-testnet/start.sh | 38 +++++ scripts/docker-testnet/variables.sh | 199 +++++++++++++++++++++++ 6 files changed, 461 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build_local_tesnet.yml create mode 100755 scripts/docker-testnet/clean.sh create mode 100755 scripts/docker-testnet/helpers.sh create mode 100755 scripts/docker-testnet/start.sh create mode 100644 scripts/docker-testnet/variables.sh diff --git a/.github/workflows/build_local_tesnet.yml b/.github/workflows/build_local_tesnet.yml new file mode 100644 index 00000000000..edd77fe9026 --- /dev/null +++ b/.github/workflows/build_local_tesnet.yml @@ -0,0 +1,54 @@ +name: Build local testnet + +on: + pull_request: + branches: [ master, rc/* ] + types: [opened, ready_for_review] + push: + workflow_dispatch: + +jobs: + build: + strategy: + matrix: + runs-on: [ubuntu-latest] + runs-on: ${{ matrix.runs-on }} + name: Build + steps: + - name: Set up Go 1.20.7 + uses: actions/setup-go@v3 + with: + go-version: 1.20.7 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Check out mx-deploy-go + uses: actions/checkout@v4 + with: + repository: multiversx/mx-chain-deploy-go + path: mx-chain-deploy-go + + - name: Check out mx-chain-proxy-go + uses: actions/checkout@v4 + with: + repository: multiversx/mx-chain-proxy-go + path: mx-chain-proxy-go + + - name: Build images + run: | + docker build -f docker/node/Dockerfile . -t node:dev + docker build -f docker/seednode/Dockerfile . -t seednode:dev + + - name: Start localnet + id: generate-config + run: | + cd ${GITHUB_WORKSPACE}/scripts/docker-testnet + export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet + export CI_RUN=1 + ./start.sh + echo "Check everything is alright. Remove once confirmed" + docker ps + sleep 1m + curl http://localhost:7950 diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index cf6a8955c76..2513f789dc8 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -10,12 +10,10 @@ RUN go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirt RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib/libvmexeccapi.so -WORKDIR /go/mx-chain-go/cmd/node - # ===== SECOND STAGE ====== FROM ubuntu:22.04 RUN apt-get update && apt-get upgrade -y -COPY --from=builder "/go/mx-chain-go/cmd/node" "/go/mx-chain-go/cmd/node/" +COPY --from=builder "/go/mx-chain-go/cmd/node/node" "/go/mx-chain-go/cmd/node/" COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so" COPY --from=builder "/lib/libvmexeccapi.so" "/lib/libvmexeccapi.so" WORKDIR /go/mx-chain-go/cmd/node/ diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh new file mode 100755 index 00000000000..a872ed57f13 --- /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 -f + +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/start.sh b/scripts/docker-testnet/start.sh new file mode 100755 index 00000000000..0181ac3c3a9 --- /dev/null +++ b/scripts/docker-testnet/start.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e + +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" + +source "$DOCKERTESTNETDIR/variables.sh" +source "$DOCKERTESTNETDIR/helpers.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" + +prepareFolders + +buildConfigGenerator + +generateConfig + +copyConfig + +copySeednodeConfig +updateSeednodeConfig + +copyNodeConfig +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 new file mode 100644 index 00000000000..f4afd395c41 --- /dev/null +++ b/scripts/docker-testnet/variables.sh @@ -0,0 +1,199 @@ +# These paths must be absolute + +# METASHARD_ID will be used to identify a shard ID as metachain +export METASHARD_ID=4294967295 + +# Path to mx-chain-go. Determined automatically. Do not change. +export MULTIVERSXDIR=$(dirname $(dirname $MULTIVERSXTESTNETSCRIPTSDIR)) + +# Enable the MultiversX Proxy. Note that this is a private repository +# (mx-chain-proxy-go). +export USE_PROXY=1 + +# Enable the MultiversX Transaction Generator. Note that this is a private +# repository (mx-chain-txgen-go). +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="$HOME/MultiversX/testnet" + + +# Path to mx-chain-deploy-go, branch: master. Default: near mx-chain-go. + +if [[ -n $CI_RUN ]]; then + export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-deploy-go/cmd/filegen" +else + export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" +fi + +export CONFIGGENERATOR="$CONFIGGENERATORDIR/filegen" # Leave unchanged. +export CONFIGGENERATOROUTPUTDIR="output" + +# Path to the executable node. Leave unchanged unless well justified. +export NODEDIR="$MULTIVERSXDIR/cmd/node" +export NODE="$NODEDIR/node" # Leave unchanged + +# Path to the executable seednode. Leave unchanged unless well justified. +export SEEDNODEDIR="$MULTIVERSXDIR/cmd/seednode" +export SEEDNODE="$SEEDNODEDIR/seednode" # Leave unchanged. + +# Niceness value of the Seednode, Observer Nodes and Validator Nodes. Leave +# blank to not adjust niceness. +export NODE_NICENESS=10 + +# Start a watcher daemon for each validator node, which restarts the node if it +# is suffled out of its shard. +export NODE_WATCHER=0 + +# Delays after running executables. +export SEEDNODE_DELAY=5 +export GENESIS_DELAY=30 +export HARDFORK_DELAY=900 #15 minutes enough to take export and gracefully close +export NODE_DELAY=60 + +export GENESIS_STAKE_TYPE="direct" #'delegated' or 'direct' as in direct stake + +#if set to 1, each observer will turn off the antiflooding capability, allowing spam in our network +export OBSERVERS_ANTIFLOOD_DISABLE=0 + +# Shard structure +export SHARDCOUNT=2 +export SHARD_VALIDATORCOUNT=3 +export SHARD_OBSERVERCOUNT=1 +export SHARD_CONSENSUS_SIZE=3 + +# Metashard structure +export META_VALIDATORCOUNT=3 +export META_OBSERVERCOUNT=1 +export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT + +# MULTI_KEY_NODES if set to 1, one observer will be generated on each shard that will handle all generated keys +export MULTI_KEY_NODES=0 + +# EXTRA_KEYS if set to 1, extra keys will be added to the generated keys +export EXTRA_KEYS=1 + +# ALWAYS_NEW_CHAINID will generate a fresh new chain ID each time start.sh/config.sh is called +export ALWAYS_NEW_CHAINID=1 + +# ROUNDS_PER_EPOCH represents the number of rounds per epoch. If set to 0, it won't override the node's config +export ROUNDS_PER_EPOCH=0 + +# HYSTERESIS defines the hysteresis value for number of nodes in shard +export HYSTERESIS=0.0 + +# ALWAYS_NEW_APP_VERSION will set a new version each time the node will be compiled +export ALWAYS_NEW_APP_VERSION=0 + +# ALWAYS_UPDATE_CONFIGS will re-generate configs (toml + json) each time ./start.sh +# Set this variable to 0 when testing bootstrap from storage or other edge cases where you do not want a fresh new config +# each time. +export ALWAYS_UPDATE_CONFIGS=1 + +# IP of the seednode +export SEEDNODE_IP="172.17.0.2" + +# Ports used by the Nodes +export PORT_SEEDNODE="9999" +export PORT_ORIGIN_OBSERVER="21100" +export PORT_ORIGIN_OBSERVER_REST="10000" +export PORT_ORIGIN_VALIDATOR="21500" +export PORT_ORIGIN_VALIDATOR_REST="9500" + +# UI configuration profiles + +# Use tmux or not. If set to 1, only 2 terminal windows will be opened, and +# tmux will be used to display the running executables using split windows. +# Recommended. Tmux needs to be installed. +export USETMUX=1 + +# Log level for the logger in the Node. +export LOGLEVEL="*:INFO" + + +if [ "$TESTNETMODE" == "debug" ]; then + LOGLEVEL="*:DEBUG,api:INFO" +fi + +if [ "$TESTNETMODE" == "trace" ]; then + LOGLEVEL="*:TRACE" +fi + +######################################################################## +# Proxy configuration + +# Path to mx-chain-proxy-go, branch: master. Default: near mx-chain-go. +if [[ -n $CI_RUN ]]; then + export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-proxy-go/cmd/proxy" +else + export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-proxy-go/cmd/proxy" +fi +export PROXY=$PROXYDIR/proxy # Leave unchanged. + +export PORT_PROXY="7950" +export PROXY_DELAY=10 + + + +######################################################################## +# TxGen configuration + +# Path to mx-chain-txgen-go. Default: near mx-chain-go. +export TXGENDIR="$(dirname $MULTIVERSXDIR)/mx-chain-txgen-go/cmd/txgen" +export TXGEN=$TXGENDIR/txgen # Leave unchanged. + +export PORT_TXGEN="7951" + +export TXGEN_SCENARIOS_LINE='Scenarios = ["basic", "erc20", "esdt"]' + +# Number of accounts to be generated by txgen +export NUMACCOUNTS="250" + +# Whether txgen should regenerate its accounts when starting, or not. +# Recommended value is 1, but 0 is useful to run the txgen a second time, to +# continue a testing session on the same accounts. +export TXGEN_REGENERATE_ACCOUNTS=0 + +# COPY_BACK_CONFIGS when set to 1 will copy back the configs and keys to the ./cmd/node/config directory +# in order to have a node in the IDE that can run a node in debug mode but in the same network with the rest of the nodes +# this option greatly helps the debugging process when running a small system test +export COPY_BACK_CONFIGS=0 +# SKIP_VALIDATOR_IDX when setting a value greater than -1 will not launch the validator with the provided index +export SKIP_VALIDATOR_IDX=-1 +# SKIP_OBSERVER_IDX when setting a value greater than -1 will not launch the observer with the provided index +export SKIP_OBSERVER_IDX=-1 + +# USE_HARDFORK will prepare the nodes to run the hardfork process, if needed +export USE_HARDFORK=1 + +# Load local overrides, .gitignored +LOCAL_OVERRIDES="$MULTIVERSXTESTNETSCRIPTSDIR/local.sh" +if [ -f "$LOCAL_OVERRIDES" ]; then + source "$MULTIVERSXTESTNETSCRIPTSDIR/local.sh" +fi + +# Leave unchanged. +let "total_observer_count = $SHARD_OBSERVERCOUNT * $SHARDCOUNT + $META_OBSERVERCOUNT" +export TOTAL_OBSERVERCOUNT=$total_observer_count + +# to enable the full archive feature on the observers, please use the --full-archive flag +export EXTRA_OBSERVERS_FLAGS="-operation-mode db-lookup-extension" + +if [[ $MULTI_KEY_NODES -eq 1 ]]; then + EXTRA_OBSERVERS_FLAGS="--no-key" +fi + +# Leave unchanged. +let "total_node_count = $SHARD_VALIDATORCOUNT * $SHARDCOUNT + $META_VALIDATORCOUNT + $TOTAL_OBSERVERCOUNT" +export TOTAL_NODECOUNT=$total_node_count + +# VALIDATOR_KEY_PEM_FILE is the pem file name when running single key mode, with all nodes' keys +export VALIDATOR_KEY_PEM_FILE="validatorKey.pem" + +# MULTI_KEY_PEM_FILE is the pem file name when running multi key mode, with all managed +export MULTI_KEY_PEM_FILE="allValidatorsKeys.pem" + +# EXTRA_KEY_PEM_FILE is the pem file name when running multi key mode, with all extra managed +export EXTRA_KEY_PEM_FILE="extraValidatorsKeys.pem" From 29367f37e3a771c6286d88bfad909e9b86c0009b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:14:32 +0200 Subject: [PATCH 02/41] remove CI to build local testnet. --- .github/workflows/build_local_tesnet.yml | 54 ------------------------ 1 file changed, 54 deletions(-) delete mode 100644 .github/workflows/build_local_tesnet.yml diff --git a/.github/workflows/build_local_tesnet.yml b/.github/workflows/build_local_tesnet.yml deleted file mode 100644 index edd77fe9026..00000000000 --- a/.github/workflows/build_local_tesnet.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Build local testnet - -on: - pull_request: - branches: [ master, rc/* ] - types: [opened, ready_for_review] - push: - workflow_dispatch: - -jobs: - build: - strategy: - matrix: - runs-on: [ubuntu-latest] - runs-on: ${{ matrix.runs-on }} - name: Build - steps: - - name: Set up Go 1.20.7 - uses: actions/setup-go@v3 - with: - go-version: 1.20.7 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Check out mx-deploy-go - uses: actions/checkout@v4 - with: - repository: multiversx/mx-chain-deploy-go - path: mx-chain-deploy-go - - - name: Check out mx-chain-proxy-go - uses: actions/checkout@v4 - with: - repository: multiversx/mx-chain-proxy-go - path: mx-chain-proxy-go - - - name: Build images - run: | - docker build -f docker/node/Dockerfile . -t node:dev - docker build -f docker/seednode/Dockerfile . -t seednode:dev - - - name: Start localnet - id: generate-config - run: | - cd ${GITHUB_WORKSPACE}/scripts/docker-testnet - export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet - export CI_RUN=1 - ./start.sh - echo "Check everything is alright. Remove once confirmed" - docker ps - sleep 1m - curl http://localhost:7950 From d13ca146479cb5cd380551753719eac2bdf3796b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:49:05 +0200 Subject: [PATCH 03/41] cosmetic changes. --- scripts/docker-testnet/{helpers.sh => functions.sh} | 3 +-- scripts/docker-testnet/start.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) rename scripts/docker-testnet/{helpers.sh => functions.sh} (98%) diff --git a/scripts/docker-testnet/helpers.sh b/scripts/docker-testnet/functions.sh similarity index 98% rename from scripts/docker-testnet/helpers.sh rename to scripts/docker-testnet/functions.sh index c7967c8c408..d16c7977866 100755 --- a/scripts/docker-testnet/helpers.sh +++ b/scripts/docker-testnet/functions.sh @@ -82,8 +82,7 @@ updateProxyConfigDocker() { generateProxyObserverListDocker config_edit.toml fi - cp config_edit.toml config.toml - rm config_edit.toml + mv config_edit.toml config.toml echo "Updated configuration for the Proxy." popd diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 0181ac3c3a9..1a9e2f84fc7 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -7,7 +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 "$DOCKERTESTNETDIR/functions.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" From 42d2b78cff3452f2a807ce740aba860c2d8c4def Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:52:54 +0200 Subject: [PATCH 04/41] added build.sh --- scripts/docker-testnet/build.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts/docker-testnet/build.sh diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh new file mode 100644 index 00000000000..5ca3246742d --- /dev/null +++ b/scripts/docker-testnet/build.sh @@ -0,0 +1,5 @@ +pushd ../.. + +docker build -f docker/seednode/Dockerfile . -t seednode:dev + +ocker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file From a77aef731abc837e63982f172e13afbe9ee1cd9f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:58:02 +0200 Subject: [PATCH 05/41] fixed typo. --- scripts/docker-testnet/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 5ca3246742d..34fdbc5b717 100644 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,4 +2,4 @@ pushd ../.. docker build -f docker/seednode/Dockerfile . -t seednode:dev -ocker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file +docker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file From b8cf3725dbdf887ced035b1f6046080fc7670f5e Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 11:10:33 +0200 Subject: [PATCH 06/41] added execution permissions on build.sh --- scripts/docker-testnet/build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/docker-testnet/build.sh diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh old mode 100644 new mode 100755 From 4f5330331dcf6358f1ff1e99133a0fb02243760c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 13:13:46 +0200 Subject: [PATCH 07/41] changed containers name for better visibility. --- scripts/docker-testnet/build.sh | 3 +- scripts/docker-testnet/functions.sh | 48 ++++++++++++++++++++--------- scripts/docker-testnet/start.sh | 2 ++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 34fdbc5b717..605db92580a 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,4 +2,5 @@ pushd ../.. docker build -f docker/seednode/Dockerfile . -t seednode:dev -docker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file +docker build -f docker/node/Dockerfile . -t node:dev + diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index d16c7977866..601707218ef 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -1,5 +1,18 @@ #!/usr/bin/env bash +IP_BIT=3 + +cloneRepositories() { + if [[ -n $CI_RUN ]]; then + echo "Repositories have been cloned in the CI" + else + cd $(dirname $MULTIVERSXDIR) + + git clone git@github.com:multiversx/mx-chain-deploy-go.git || true + git clone git@github.com:multiversx/mx-chain-proxy-go.git || true + fi +} + 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 @@ -13,14 +26,17 @@ startObservers() { # Your commands or code to be executed in each iteration KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}" \ + docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ -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} \ + $EXTRA_OBSERVERS_FLAGS + + (( IP_BIT++ )) ((observerIdx++)) || true done done @@ -28,14 +44,16 @@ startObservers() { for ((i = 0; i < META_OBSERVERCOUNT; i++)); do KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}" \ + docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-metachain" \ -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} \ + $EXTRA_OBSERVERS_FLAGS + (( IP_BIT++ )) ((observerIdx++)) || true done } @@ -46,25 +64,27 @@ startValidators() { for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do - docker run -d --name "validator${validatorIdx}" \ + docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ -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} \ + (( IP_BIT++ )) ((validatorIdx++)) || true done done for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - docker run -d --name "validator${validatorIdx}" \ + docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-metachain" \ -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} \ + (( IP_BIT++ )) ((validatorIdx++)) || true done } @@ -89,7 +109,7 @@ updateProxyConfigDocker() { } generateProxyObserverListDocker() { - IP_BIT=3 + local ipBit=3 OUTPUTFILE=$! @@ -98,25 +118,25 @@ generateProxyObserverListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true 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 " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true done } generateProxyValidatorListDocker() { - IP_BIT=3 + local ipBit=3 OUTPUTFILE=$! @@ -125,22 +145,22 @@ generateProxyValidatorListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true 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 " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true done } diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 1a9e2f84fc7..02e107c4229 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -11,6 +11,8 @@ source "$DOCKERTESTNETDIR/functions.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" +cloneRepositories + prepareFolders buildConfigGenerator From 092ef5505ff27d0b3091981a07de45db1c7f3a95 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 15 Mar 2024 17:20:13 +0200 Subject: [PATCH 08/41] removed hardcoded ips and added dedicated network for docker local-testnet. --- scripts/docker-testnet/clean.sh | 3 ++ scripts/docker-testnet/functions.sh | 66 ++++++++++++++++++++--------- scripts/docker-testnet/start.sh | 3 ++ scripts/docker-testnet/variables.sh | 16 +++++-- 4 files changed, 63 insertions(+), 25 deletions(-) mode change 100644 => 100755 scripts/docker-testnet/variables.sh diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh index a872ed57f13..b0dd59a6961 100755 --- a/scripts/docker-testnet/clean.sh +++ b/scripts/docker-testnet/clean.sh @@ -12,5 +12,8 @@ docker stop $(docker ps -a -q) echo "Removing all containers..." docker container prune -f +echo "Removing network..." +docker network rm ${DOCKER_NETWORK_NAME} + echo "Removing $TESTNETDIR..." rm -rf $TESTNETDIR diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index 601707218ef..3a6be5003a8 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash -IP_BIT=3 +# Starts from 3, if the DOCKER_NETWORK_SUBNET ends with a 0. The first IP address is reserved for the gateway and the +# second one is allocated to the seednode. Therefore the counting starts from 3. If you modify the DOCKER_NETWORK_SUBNET +# variable, make sure to change this one accordingly too. +IP_HOST_BYTE=3 cloneRepositories() { if [[ -n $CI_RUN ]]; then @@ -13,8 +16,18 @@ cloneRepositories() { fi } +createDockerNetwork() { + docker network create -d bridge --subnet=${DOCKER_NETWORK_SUBNET} ${DOCKER_NETWORK_NAME} + + # this variable is used to keep track of the allocated IP addresses in the network, by removing the last byte + # of the DOCKER_NETWORK_SUBNET. One can consider this the host network address without the last byte at the end. + export NETWORK_ADDRESS=$(echo "$DOCKER_NETWORK_SUBNET" | rev | cut -d. -f2- | rev) +} + startSeedNode() { - docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config seednode:dev \ + docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ + --network ${DOCKER_NETWORK_NAME} \ + seednode:dev \ --rest-api-interface=0.0.0.0:10000 } @@ -26,8 +39,9 @@ startObservers() { # Your commands or code to be executed in each iteration KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --destination-shard-as-observer $i \ --rest-api-interface=0.0.0.0:10200 \ @@ -36,7 +50,7 @@ startObservers() { $EXTRA_OBSERVERS_FLAGS - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((observerIdx++)) || true done done @@ -44,8 +58,9 @@ startObservers() { for ((i = 0; i < META_OBSERVERCOUNT; i++)); do KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-metachain" \ + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --destination-shard-as-observer "metachain" \ --rest-api-interface=0.0.0.0:10200 \ @@ -53,7 +68,7 @@ startObservers() { --sk-index=${KEY_INDEX} \ $EXTRA_OBSERVERS_FLAGS - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((observerIdx++)) || true done } @@ -64,27 +79,29 @@ startValidators() { for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do - docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_validator.toml \ --sk-index=${validatorIdx} \ - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((validatorIdx++)) || true done done for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-metachain" \ + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${validatorIdx} \ - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((validatorIdx++)) || true done } @@ -109,7 +126,7 @@ updateProxyConfigDocker() { } generateProxyObserverListDocker() { - local ipBit=3 + local ipByte=3 OUTPUTFILE=$! @@ -118,25 +135,25 @@ generateProxyObserverListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true 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.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true done } generateProxyValidatorListDocker() { - local ipBit=3 + local ipByte=3 OUTPUTFILE=$! @@ -145,28 +162,35 @@ generateProxyValidatorListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true 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.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true done } +buildProxyImage() { + pushd ${PROXYDIR} + cd ../.. + docker build -f docker/Dockerfile . -t proxy:dev +} + 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 + --network ${DOCKER_NETWORK_NAME} \ + proxy:dev } diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 02e107c4229..c32d7ac0523 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -27,11 +27,14 @@ updateSeednodeConfig copyNodeConfig updateNodeConfig +createDockerNetwork + startSeedNode startObservers startValidators if [ $USE_PROXY -eq 1 ]; then + buildProxyImage prepareFolders_Proxy copyProxyConfig updateProxyConfigDocker diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh old mode 100644 new mode 100755 index f4afd395c41..69c0e90d195 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -1,5 +1,14 @@ # These paths must be absolute +######################################################################## +# Docker network configuration + +# Don't change the subnet, unless you know what you are doing. Prone to errors. +export DOCKER_NETWORK_SUBNET="172.18.0.0/24" +export DOCKER_NETWORK_NAME="local-testnet" +######################################################################## + + # METASHARD_ID will be used to identify a shard ID as metachain export METASHARD_ID=4294967295 @@ -92,8 +101,9 @@ export ALWAYS_NEW_APP_VERSION=0 # each time. export ALWAYS_UPDATE_CONFIGS=1 -# IP of the seednode -export SEEDNODE_IP="172.17.0.2" +# IP of the seednode. This should be the first IP allocated in the local testnet network. If you modify the default +# DOCKER_NETWORK_SUBNET, you will need to edit this one accordingly too. +export SEEDNODE_IP="$(echo "$DOCKER_NETWORK_SUBNET" | rev | cut -d. -f2- | rev).2" # Ports used by the Nodes export PORT_SEEDNODE="9999" @@ -135,8 +145,6 @@ export PROXY=$PROXYDIR/proxy # Leave unchanged. export PORT_PROXY="7950" export PROXY_DELAY=10 - - ######################################################################## # TxGen configuration From 01e02fd0d49f7e3ba58972c0435b03fd2a4a48b4 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 15 Mar 2024 17:20:51 +0200 Subject: [PATCH 09/41] Removed executable permissions for variables.sh --- scripts/docker-testnet/variables.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 scripts/docker-testnet/variables.sh diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh old mode 100755 new mode 100644 From 24c1ac41b0c374b0ab58a82e9d2e210f2f9a6878 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 18 Mar 2024 10:33:43 +0200 Subject: [PATCH 10/41] fixes after review. --- scripts/docker-testnet/build.sh | 6 ++- scripts/docker-testnet/clean.sh | 14 ++++-- scripts/docker-testnet/functions.sh | 69 +++++++++++++++-------------- scripts/docker-testnet/start.sh | 2 +- scripts/docker-testnet/variables.sh | 46 ++++++++----------- 5 files changed, 69 insertions(+), 68 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 605db92580a..5bc11887fce 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -1,4 +1,8 @@ -pushd ../.. +#!/usr/bin/env bash + +set -eux + +cd ${MULTIVERSXDIR} docker build -f docker/seednode/Dockerfile . -t seednode:dev diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh index b0dd59a6961..b8cfe1ea2d7 100755 --- a/scripts/docker-testnet/clean.sh +++ b/scripts/docker-testnet/clean.sh @@ -1,16 +1,22 @@ #!/usr/bin/env bash +set -eux + # 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) +# Get the IDs of containers attached to the network +CONTAINER_IDS=$(docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' "$DOCKER_NETWORK_NAME") -echo "Removing all containers..." -docker container prune -f +# Stop each container +echo "Removing containers..." +for CONTAINER_ID in $CONTAINER_IDS; do + docker stop "$CONTAINER_ID" + docker rm "$CONTAINER_ID" +done echo "Removing network..." docker network rm ${DOCKER_NETWORK_NAME} diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index 3a6be5003a8..0a79c8de751 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -6,14 +6,18 @@ IP_HOST_BYTE=3 cloneRepositories() { - if [[ -n $CI_RUN ]]; then - echo "Repositories have been cloned in the CI" - else - cd $(dirname $MULTIVERSXDIR) - - git clone git@github.com:multiversx/mx-chain-deploy-go.git || true - git clone git@github.com:multiversx/mx-chain-proxy-go.git || true - fi + cd $(dirname $MULTIVERSXDIR) + + git clone git@github.com:multiversx/mx-chain-deploy-go.git || true + git clone git@github.com:multiversx/mx-chain-proxy-go.git || true +} + +buildNodeImages() { + cd $MULTIVERSXDIR + + docker build -f docker/seednode/Dockerfile . -t seednode:dev + + docker build -f docker/node/Dockerfile . -t node:dev } createDockerNetwork() { @@ -25,10 +29,11 @@ createDockerNetwork() { } startSeedNode() { - docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ - --network ${DOCKER_NETWORK_NAME} \ - seednode:dev \ - --rest-api-interface=0.0.0.0:10000 + docker run -d --name seednode \ + -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ + --network ${DOCKER_NETWORK_NAME} \ + seednode:dev \ + --rest-api-interface=0.0.0.0:10000 } startObservers() { @@ -40,14 +45,14 @@ startObservers() { KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --destination-shard-as-observer $i \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_observer.toml \ - --sk-index=${KEY_INDEX} \ - $EXTRA_OBSERVERS_FLAGS + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + node:dev \ + --destination-shard-as-observer $i \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + $EXTRA_OBSERVERS_FLAGS (( IP_HOST_BYTE++ )) @@ -80,12 +85,12 @@ startValidators() { for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_validator.toml \ - --sk-index=${validatorIdx} \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_validator.toml \ + --sk-index=${validatorIdx} \ (( IP_HOST_BYTE++ )) ((validatorIdx++)) || true @@ -127,8 +132,6 @@ updateProxyConfigDocker() { generateProxyObserverListDocker() { local ipByte=3 - OUTPUTFILE=$! - for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do @@ -154,8 +157,6 @@ generateProxyObserverListDocker() { generateProxyValidatorListDocker() { local ipByte=3 - OUTPUTFILE=$! - for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do @@ -189,8 +190,8 @@ buildProxyImage() { startProxyDocker() { docker run -d --name "proxy" \ - -p $PORT_PROXY:8080 \ - -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ - --network ${DOCKER_NETWORK_NAME} \ - proxy:dev + -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ + --network ${DOCKER_NETWORK_NAME} \ + -p $PORT_PROXY:8080 \ + proxy:dev } diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index c32d7ac0523..c96f071251d 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -eux export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index 69c0e90d195..90ef56a4fa4 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -28,14 +28,8 @@ export USE_TXGEN=0 # anyway. export TESTNETDIR="$HOME/MultiversX/testnet" - # Path to mx-chain-deploy-go, branch: master. Default: near mx-chain-go. - -if [[ -n $CI_RUN ]]; then - export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-deploy-go/cmd/filegen" -else - export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" -fi +export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" export CONFIGGENERATOR="$CONFIGGENERATORDIR/filegen" # Leave unchanged. export CONFIGGENERATOROUTPUTDIR="output" @@ -114,32 +108,28 @@ export PORT_ORIGIN_VALIDATOR_REST="9500" # UI configuration profiles -# Use tmux or not. If set to 1, only 2 terminal windows will be opened, and -# tmux will be used to display the running executables using split windows. -# Recommended. Tmux needs to be installed. -export USETMUX=1 - -# Log level for the logger in the Node. -export LOGLEVEL="*:INFO" - - -if [ "$TESTNETMODE" == "debug" ]; then - LOGLEVEL="*:DEBUG,api:INFO" -fi - -if [ "$TESTNETMODE" == "trace" ]; then - LOGLEVEL="*:TRACE" -fi +## Use tmux or not. If set to 1, only 2 terminal windows will be opened, and +## tmux will be used to display the running executables using split windows. +## Recommended. Tmux needs to be installed. +#export USETMUX=1 +# +## Log level for the logger in the Node. +#export LOGLEVEL="*:INFO" +# +# +#if [ "$TESTNETMODE" == "debug" ]; then +# LOGLEVEL="*:DEBUG,api:INFO" +#fi +# +#if [ "$TESTNETMODE" == "trace" ]; then +# LOGLEVEL="*:TRACE" +#fi ######################################################################## # Proxy configuration # Path to mx-chain-proxy-go, branch: master. Default: near mx-chain-go. -if [[ -n $CI_RUN ]]; then - export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-proxy-go/cmd/proxy" -else - export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-proxy-go/cmd/proxy" -fi +export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-proxy-go/cmd/proxy" export PROXY=$PROXYDIR/proxy # Leave unchanged. export PORT_PROXY="7950" From ecd2a344db1d23d4b5349babc2676a02a739ef03 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 18 Mar 2024 10:39:22 +0200 Subject: [PATCH 11/41] Added README.md --- scripts/docker-testnet/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 scripts/docker-testnet/README.md diff --git a/scripts/docker-testnet/README.md b/scripts/docker-testnet/README.md new file mode 100644 index 00000000000..630393774eb --- /dev/null +++ b/scripts/docker-testnet/README.md @@ -0,0 +1,10 @@ +# Setting up a local-testnet with Docker + +First and foremost, one needs to build the **seednode** & **node** images. Hence, the **_build.sh_** +script is provided. This can be done, by invoking the script or building the images manually. + +``` +./build.sh # (Optional) Can be ignored if you already have the images stored in the local registry. +./start.sh # Will start the local-testnet. +./clean.sh # Will stop and remove the containers related to the local-testnet. +``` \ No newline at end of file From 9bf2d7cfa0c679be8a7e90dd4e0ababa8b565165 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 18 Mar 2024 12:57:04 +0200 Subject: [PATCH 12/41] cosmetic changes. --- scripts/docker-testnet/build.sh | 2 +- scripts/docker-testnet/variables.sh | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 5bc11887fce..22babc04c84 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,7 +2,7 @@ set -eux -cd ${MULTIVERSXDIR} +pushd ../.. docker build -f docker/seednode/Dockerfile . -t seednode:dev diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index 90ef56a4fa4..dfd45bc7b5a 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -106,25 +106,6 @@ export PORT_ORIGIN_OBSERVER_REST="10000" export PORT_ORIGIN_VALIDATOR="21500" export PORT_ORIGIN_VALIDATOR_REST="9500" -# UI configuration profiles - -## Use tmux or not. If set to 1, only 2 terminal windows will be opened, and -## tmux will be used to display the running executables using split windows. -## Recommended. Tmux needs to be installed. -#export USETMUX=1 -# -## Log level for the logger in the Node. -#export LOGLEVEL="*:INFO" -# -# -#if [ "$TESTNETMODE" == "debug" ]; then -# LOGLEVEL="*:DEBUG,api:INFO" -#fi -# -#if [ "$TESTNETMODE" == "trace" ]; then -# LOGLEVEL="*:TRACE" -#fi - ######################################################################## # Proxy configuration From 7a9b96a68f8b8a4b1fbb8e0dd03384b22b32f1b1 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 20 Mar 2024 13:35:00 +0200 Subject: [PATCH 13/41] - added more files in the overridable configs options --- cmd/node/config/prefs.toml | 3 +- config/overridableConfig/configOverriding.go | 43 +++++++++++--- .../configOverriding_test.go | 56 ++++++++++++++++++- 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/cmd/node/config/prefs.toml b/cmd/node/config/prefs.toml index 42e16624ab8..47a439222d0 100644 --- a/cmd/node/config/prefs.toml +++ b/cmd/node/config/prefs.toml @@ -40,7 +40,8 @@ # configuration of the node has the false value) # The Path indicates what value to change, while Value represents the new value in string format. The node operator must make sure # to follow the same type of the original value (ex: uint32: "37", float32: "37.0", bool: "true") - # File represents the file name that holds the configuration. Currently, the supported files are: config.toml, external.toml, p2p.toml and enableEpochs.toml + # File represents the file name that holds the configuration. Currently, the supported files are: + # api.toml, config.toml, economics.toml, enableEpochs.toml, enableRounds.toml, external.toml, fullArchiveP2P.toml, p2p.toml, ratings.toml, systemSmartContractsConfig.toml # ------------------------------- # Un-comment and update the following section in order to enable config values overloading # ------------------------------- diff --git a/config/overridableConfig/configOverriding.go b/config/overridableConfig/configOverriding.go index 7e9f3a153de..84b823738fe 100644 --- a/config/overridableConfig/configOverriding.go +++ b/config/overridableConfig/configOverriding.go @@ -10,16 +10,32 @@ import ( ) const ( + apiTomlFile = "api.toml" configTomlFile = "config.toml" + economicsTomlFile = "economics.toml" enableEpochsTomlFile = "enableEpochs.toml" - p2pTomlFile = "p2p.toml" - fullArchiveP2PTomlFile = "fullArchiveP2P.toml" + enableRoundsTomlFile = "enableRounds.toml" externalTomlFile = "external.toml" + fullArchiveP2PTomlFile = "fullArchiveP2P.toml" + p2pTomlFile = "p2p.toml" + ratingsTomlFile = "ratings.toml" + systemSCTomlFile = "systemSmartContractsConfig.toml" ) var ( - availableConfigFilesForOverriding = []string{configTomlFile, enableEpochsTomlFile, p2pTomlFile, externalTomlFile} - log = logger.GetOrCreate("config") + availableConfigFilesForOverriding = []string{ + apiTomlFile, + configTomlFile, + economicsTomlFile, + enableEpochsTomlFile, + enableRoundsTomlFile, + externalTomlFile, + fullArchiveP2PTomlFile, + p2pTomlFile, + ratingsTomlFile, + systemSCTomlFile, + } + log = logger.GetOrCreate("config") ) // OverrideConfigValues will override config values for the specified configurations @@ -27,16 +43,27 @@ func OverrideConfigValues(newConfigs []config.OverridableConfig, configs *config var err error for _, newConfig := range newConfigs { switch newConfig.File { + case apiTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ApiRoutesConfig, newConfig.Path, newConfig.Value) case configTomlFile: err = reflectcommon.AdaptStructureValueBasedOnPath(configs.GeneralConfig, newConfig.Path, newConfig.Value) + case economicsTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EconomicsConfig, newConfig.Path, newConfig.Value) case enableEpochsTomlFile: err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EpochConfig, newConfig.Path, newConfig.Value) - case p2pTomlFile: - err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value) - case fullArchiveP2PTomlFile: - err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value) + case enableRoundsTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.RoundConfig, newConfig.Path, newConfig.Value) case externalTomlFile: err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ExternalConfig, newConfig.Path, newConfig.Value) + case fullArchiveP2PTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value) + case p2pTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value) + case ratingsTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.RatingsConfig, newConfig.Path, newConfig.Value) + case systemSCTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.SystemSCConfig, newConfig.Path, newConfig.Value) + default: err = fmt.Errorf("invalid config file <%s>. Available options are %s", newConfig.File, strings.Join(availableConfigFilesForOverriding, ",")) } diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index b15cf8e5c5c..c6cac7bef94 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -22,7 +22,8 @@ func TestOverrideConfigValues(t *testing.T) { t.Parallel() err := OverrideConfigValues([]config.OverridableConfig{{File: "invalid.toml"}}, &config.Configs{}) - require.Equal(t, "invalid config file . Available options are config.toml,enableEpochs.toml,p2p.toml,external.toml", err.Error()) + availableOptionsString := "api.toml,config.toml,economics.toml,enableEpochs.toml,enableRounds.toml,external.toml,fullArchiveP2P.toml,p2p.toml,ratings.toml,systemSmartContractsConfig.toml" + require.Equal(t, "invalid config file . Available options are "+availableOptionsString, err.Error()) }) t.Run("nil config, should error", func(t *testing.T) { @@ -81,4 +82,57 @@ func TestOverrideConfigValues(t *testing.T) { require.NoError(t, err) require.Equal(t, uint32(37), configs.EpochConfig.EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch) }) + + t.Run("should work for api.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{ApiRoutesConfig: &config.ApiRoutesConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: "true", File: "api.toml"}}, configs) + require.NoError(t, err) + require.True(t, configs.ApiRoutesConfig.Logging.LoggingEnabled) + }) + + t.Run("should work for economics.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{EconomicsConfig: &config.EconomicsConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "GlobalSettings.GenesisTotalSupply", Value: "37", File: "economics.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, "37", configs.EconomicsConfig.GlobalSettings.GenesisTotalSupply) + }) + + t.Run("should work for enableRounds.toml", func(t *testing.T) { + // TODO: fix this test + t.Skip("skipped, as this test requires the fix from this PR: https://github.com/multiversx/mx-chain-go/pull/5851") + + t.Parallel() + + configs := &config.Configs{RoundConfig: &config.RoundConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "RoundActivations.DisableAsyncCallV1.Round", Value: "37", File: "enableRounds.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, uint32(37), configs.RoundConfig.RoundActivations["DisableAsyncCallV1"]) + }) + + t.Run("should work for ratings.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{RatingsConfig: &config.RatingsConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: "37", File: "ratings.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, uint32(37), configs.RatingsConfig.General.StartRating) + }) + + t.Run("should work for systemSmartContractsConfig.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{SystemSCConfig: &config.SystemSmartContractsConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: "37", File: "systemSmartContractsConfig.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, uint64(37), configs.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod) + }) } From 96adb1fb233a6ebbc75a2efac1518ddf321e6e7b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 20 Mar 2024 16:06:47 +0200 Subject: [PATCH 14/41] Added publish ports argument and formatting changes. --- scripts/docker-testnet/functions.sh | 152 +++++++++++++++++----------- scripts/docker-testnet/variables.sh | 8 ++ 2 files changed, 101 insertions(+), 59 deletions(-) diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index 0a79c8de751..c075793030a 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -29,105 +29,139 @@ createDockerNetwork() { } startSeedNode() { + local publishPortArgs="" + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + (( DOCKER_PUBLISH_PORT_RANGE++ )) + fi + docker run -d --name seednode \ -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ 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 + local observerIdx=0 + local publishPortArgs="" + + # 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)) + + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi + + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ + node:dev \ + --destination-shard-as-observer $i \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + $EXTRA_OBSERVERS_FLAGS + + + (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) + ((observerIdx++)) || true + done + done + + for ((i = 0; i < META_OBSERVERCOUNT; i++)); do KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi + + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ node:dev \ - --destination-shard-as-observer $i \ + --destination-shard-as-observer "metachain" \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${KEY_INDEX} \ $EXTRA_OBSERVERS_FLAGS - (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) ((observerIdx++)) || true - done - done - - for ((i = 0; i < META_OBSERVERCOUNT; i++)); do - KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - - docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --destination-shard-as-observer "metachain" \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_observer.toml \ - --sk-index=${KEY_INDEX} \ - $EXTRA_OBSERVERS_FLAGS - - (( IP_HOST_BYTE++ )) - ((observerIdx++)) || true - done + 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 + local validatorIdx=0 + local publishPortArgs="" + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi + + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_validator.toml \ + --sk-index=${validatorIdx} \ + + (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) + ((validatorIdx++)) || true + done + done - docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_validator.toml \ - --sk-index=${validatorIdx} \ + for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - (( IP_HOST_BYTE++ )) - ((validatorIdx++)) || true - done - done + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi - for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${validatorIdx} \ - (( IP_HOST_BYTE++ )) - ((validatorIdx++)) || true + (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) + ((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 + pushd $TESTNETDIR/proxy/config + cp config.toml config_edit.toml - if [ "$SHARD_OBSERVERCOUNT" -le 0 ]; then - generateProxyValidatorListDocker config_edit.toml - else - generateProxyObserverListDocker config_edit.toml - fi + # Truncate config.toml before the [[Observers]] list + sed -i -n '/\[\[Observers\]\]/q;p' config_edit.toml - mv config_edit.toml config.toml + if [ "$SHARD_OBSERVERCOUNT" -le 0 ]; then + generateProxyValidatorListDocker config_edit.toml + else + generateProxyObserverListDocker config_edit.toml + fi - echo "Updated configuration for the Proxy." - popd + mv config_edit.toml config.toml + echo "Updated configuration for the Proxy." + popd } generateProxyObserverListDocker() { diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index dfd45bc7b5a..bdcb26662fd 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -6,6 +6,14 @@ # Don't change the subnet, unless you know what you are doing. Prone to errors. export DOCKER_NETWORK_SUBNET="172.18.0.0/24" export DOCKER_NETWORK_NAME="local-testnet" + +# By default ports won't be published. If set to 1, all containers will port-forward to host network. +export DOCKER_PUBLISH_PORTS=1 + +if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + export DOCKER_PUBLISH_PORT_RANGE=30000 +fi + ######################################################################## From e3cd364ed9baa52af57f6364b2fbd42298c3d99c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 20 Mar 2024 16:52:34 +0200 Subject: [PATCH 15/41] Added start/stop mechanism along with comsetic changes. --- scripts/docker-testnet/README.md | 6 +++- scripts/docker-testnet/setup.sh | 43 +++++++++++++++++++++++++++++ scripts/docker-testnet/start.sh | 47 ++++++++------------------------ scripts/docker-testnet/stop.sh | 21 ++++++++++++++ 4 files changed, 80 insertions(+), 37 deletions(-) create mode 100755 scripts/docker-testnet/setup.sh create mode 100755 scripts/docker-testnet/stop.sh diff --git a/scripts/docker-testnet/README.md b/scripts/docker-testnet/README.md index 630393774eb..04b4de89631 100644 --- a/scripts/docker-testnet/README.md +++ b/scripts/docker-testnet/README.md @@ -5,6 +5,10 @@ script is provided. This can be done, by invoking the script or building the ima ``` ./build.sh # (Optional) Can be ignored if you already have the images stored in the local registry. -./start.sh # Will start the local-testnet. +./setup.sh # Will setup the local-testnet. ./clean.sh # Will stop and remove the containers related to the local-testnet. + +Optionally +./stop.sh # Will stop all the containers in the local-testnet. +./start.sh # Will start all stopped containers from the initial local-testnet. ``` \ No newline at end of file diff --git a/scripts/docker-testnet/setup.sh b/scripts/docker-testnet/setup.sh new file mode 100755 index 00000000000..c96f071251d --- /dev/null +++ b/scripts/docker-testnet/setup.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -eux + +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" + +source "$DOCKERTESTNETDIR/variables.sh" +source "$DOCKERTESTNETDIR/functions.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" + +cloneRepositories + +prepareFolders + +buildConfigGenerator + +generateConfig + +copyConfig + +copySeednodeConfig +updateSeednodeConfig + +copyNodeConfig +updateNodeConfig + +createDockerNetwork + +startSeedNode +startObservers +startValidators + +if [ $USE_PROXY -eq 1 ]; then + buildProxyImage + prepareFolders_Proxy + copyProxyConfig + updateProxyConfigDocker + startProxyDocker +fi + diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index c96f071251d..1bf10af1840 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -2,42 +2,17 @@ set -eux -export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +file_path="./tmp/stopped_containers" -MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" - -source "$DOCKERTESTNETDIR/variables.sh" -source "$DOCKERTESTNETDIR/functions.sh" -source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" -source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" - -cloneRepositories - -prepareFolders - -buildConfigGenerator - -generateConfig - -copyConfig - -copySeednodeConfig -updateSeednodeConfig - -copyNodeConfig -updateNodeConfig - -createDockerNetwork - -startSeedNode -startObservers -startValidators - -if [ $USE_PROXY -eq 1 ]; then - buildProxyImage - prepareFolders_Proxy - copyProxyConfig - updateProxyConfigDocker - startProxyDocker +# Check if the file exists +if [ ! -f "$file_path" ]; then + echo "File $file_path not found." + exit 1 fi +# Read the file line by line +while IFS= read -r line; do + docker start $line +done < "$file_path" + +rmdir ./tmp \ No newline at end of file diff --git a/scripts/docker-testnet/stop.sh b/scripts/docker-testnet/stop.sh new file mode 100755 index 00000000000..89486f82044 --- /dev/null +++ b/scripts/docker-testnet/stop.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -eux + +# 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" + +# Get the IDs of containers attached to the network +export CONTAINER_IDS=$(docker network inspect -f '{{range $k, $v := .Containers}}{{printf "%s\n" $k}}{{end}}' "$DOCKER_NETWORK_NAME") + +mkdir -p ./tmp + +# Stop each container +echo "Stopping containers..." +for CONTAINER_ID in $CONTAINER_IDS; do + docker stop "$CONTAINER_ID" + echo "$CONTAINER_ID" >> ./tmp/stopped_containers +done \ No newline at end of file From d3cf4f8692199f7c3026615e9bfbd87a079e7c8f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 20 Mar 2024 17:18:18 +0200 Subject: [PATCH 16/41] Fixed paths. --- scripts/docker-testnet/build.sh | 8 +++++++- scripts/docker-testnet/start.sh | 6 ++++-- scripts/docker-testnet/stop.sh | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 22babc04c84..0b038e17e4b 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,7 +2,13 @@ set -eux -pushd ../.. +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" + +source "$DOCKERTESTNETDIR/variables.sh" + +cd ${MULTIVERSXDIR} docker build -f docker/seednode/Dockerfile . -t seednode:dev diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 1bf10af1840..f68e49d62d4 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -2,7 +2,9 @@ set -eux -file_path="./tmp/stopped_containers" +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +file_path="${DOCKERTESTNETDIR}/tmp/stopped_containers" # Check if the file exists if [ ! -f "$file_path" ]; then @@ -15,4 +17,4 @@ while IFS= read -r line; do docker start $line done < "$file_path" -rmdir ./tmp \ No newline at end of file +rm -rf "${DOCKERTESTNETDIR}/tmp" \ No newline at end of file diff --git a/scripts/docker-testnet/stop.sh b/scripts/docker-testnet/stop.sh index 89486f82044..6c5054570dc 100755 --- a/scripts/docker-testnet/stop.sh +++ b/scripts/docker-testnet/stop.sh @@ -11,11 +11,11 @@ source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh" # Get the IDs of containers attached to the network export CONTAINER_IDS=$(docker network inspect -f '{{range $k, $v := .Containers}}{{printf "%s\n" $k}}{{end}}' "$DOCKER_NETWORK_NAME") -mkdir -p ./tmp +mkdir -p "$MULTIVERSXTESTNETSCRIPTSDIR/tmp" # Stop each container echo "Stopping containers..." for CONTAINER_ID in $CONTAINER_IDS; do docker stop "$CONTAINER_ID" - echo "$CONTAINER_ID" >> ./tmp/stopped_containers + echo "$CONTAINER_ID" >> "$MULTIVERSXTESTNETSCRIPTSDIR/tmp/stopped_containers" done \ No newline at end of file From a9975e61799f78e8576aada839980f062cdf66bb Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 20 Mar 2024 21:00:32 +0200 Subject: [PATCH 17/41] - fixed the configs changes in chain simulator --- .../chainSimulator/staking/jail_test.go | 4 ++-- .../staking/stakeAndUnStake_test.go | 10 ++++++---- node/chainSimulator/configs/configs.go | 20 ++++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail_test.go index 185365912b1..2802ff94e8a 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail_test.go @@ -77,7 +77,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4JailUnJailStep1EnableEpoch) newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) configs.SetQuickJailRatingConfig(cfg) }, }) @@ -179,7 +179,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { configs.SetQuickJailRatingConfig(cfg) newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 1 - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) }, }) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go index b4c3fb6cf70..9ac5b86be20 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go @@ -69,7 +69,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) }, }) require.Nil(t, err) @@ -200,8 +200,10 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { AlterConfigsFunction: func(cfg *config.Configs) { cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 cfg.GeneralConfig.ValidatorStatistics.CacheRefreshIntervalInSec = 1 - newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + eligibleNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + // 8 nodes until new nodes will be placed on queue + waitingNodes := uint32(8) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(eligibleNodes), waitingNodes, numOfShards) }, }) require.Nil(t, err) @@ -328,7 +330,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod = 1 cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriodInEpochs = 1 newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 10 - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) }, }) require.Nil(t, err) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index 731f8078eef..3334f470fa3 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -103,10 +103,10 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi configs.GeneralConfig.SmartContractsStorageForSCQuery.DB.Type = string(storageunit.MemoryDB) configs.GeneralConfig.SmartContractsStorageSimulate.DB.Type = string(storageunit.MemoryDB) - maxNumNodes := uint64((args.MinNodesPerShard+args.NumNodesWaitingListShard)*args.NumOfShards) + - uint64(args.MetaChainMinNodes+args.NumNodesWaitingListMeta) + eligibleNodes := args.MinNodesPerShard*args.NumOfShards + args.MetaChainMinNodes + waitingNodes := args.NumNodesWaitingListShard*args.NumOfShards + args.NumNodesWaitingListMeta - SetMaxNumberOfNodesInConfigs(configs, maxNumNodes, args.NumOfShards) + SetMaxNumberOfNodesInConfigs(configs, eligibleNodes, waitingNodes, args.NumOfShards) // set compatible trie configs configs.GeneralConfig.StateTriesConfig.SnapshotsEnabled = false @@ -141,17 +141,23 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi } // SetMaxNumberOfNodesInConfigs will correctly set the max number of nodes in configs -func SetMaxNumberOfNodesInConfigs(cfg *config.Configs, maxNumNodes uint64, numOfShards uint32) { - cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake = maxNumNodes +func SetMaxNumberOfNodesInConfigs(cfg *config.Configs, eligibleNodes uint32, waitingNodes uint32, numOfShards uint32) { + cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake = uint64(eligibleNodes + waitingNodes) numMaxNumNodesEnableEpochs := len(cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch) for idx := 0; idx < numMaxNumNodesEnableEpochs-1; idx++ { - cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[idx].MaxNumNodes = uint32(maxNumNodes) + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[idx].MaxNumNodes = eligibleNodes + waitingNodes } cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].EpochEnable = cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch prevEntry := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-2] cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].NodesToShufflePerShard = prevEntry.NodesToShufflePerShard - cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].MaxNumNodes = prevEntry.MaxNumNodes - (numOfShards+1)*prevEntry.NodesToShufflePerShard + + stakingV4NumNodes := eligibleNodes + waitingNodes + if stakingV4NumNodes-(numOfShards+1)*prevEntry.NodesToShufflePerShard >= eligibleNodes { + // prevent the case in which we are decreasing the eligible number of nodes because we are working with 0 waiting list size + stakingV4NumNodes -= (numOfShards + 1) * prevEntry.NodesToShufflePerShard + } + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].MaxNumNodes = stakingV4NumNodes } // SetQuickJailRatingConfig will set the rating config in a way that leads to rapid jailing of a node From 71d48d403494bbade60c7c4eb564eb5cb17ed310 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 21 Mar 2024 09:59:26 +0200 Subject: [PATCH 18/41] fixed ports for nodes. --- scripts/docker-testnet/functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index c075793030a..74d39bf71dc 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -54,7 +54,7 @@ startObservers() { KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ @@ -79,7 +79,7 @@ startObservers() { KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ @@ -107,7 +107,7 @@ startValidators() { for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ @@ -128,7 +128,7 @@ startValidators() { for ((i = 0; i < META_VALIDATORCOUNT; i++)); do if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ From e7dac66bf179e3f4669970c9336bd9a9767c5426 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 22 Mar 2024 14:35:17 +0200 Subject: [PATCH 19/41] - exposed function ForceResetValidatorStatisticsCache in the chain simulator --- integrationTests/chainSimulator/interface.go | 1 + .../chainSimulator/staking/delegation_test.go | 2 +- integrationTests/chainSimulator/staking/jail_test.go | 2 +- .../chainSimulator/staking/simpleStake_test.go | 4 ++-- .../chainSimulator/staking/stakeAndUnStake_test.go | 4 ++-- node/chainSimulator/chainSimulator.go | 10 ++++++++++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index 6d66b9d62c0..eff1aac7874 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -21,4 +21,5 @@ type ChainSimulator interface { GenerateAndMintWalletAddress(targetShardID uint32, value *big.Int) (dtos.WalletAddress, error) GetInitialWalletKeys() *dtos.InitialWalletKeys GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) + ForceResetValidatorStatisticsCache() error } diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 1ed12f29fd9..baa138f4430 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -277,7 +277,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi delegationAddressBech32 := metachainNode.GetCoreComponents().AddressPubKeyConverter().SilentEncode(delegationAddress, log) log.Info("generated delegation address", "address", delegationAddressBech32) - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail_test.go index 2802ff94e8a..4251ece6bf4 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail_test.go @@ -248,7 +248,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { } func checkValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { - err := cs.GetNodeHandler(core.MetachainShardId).GetProcessComponents().ValidatorsProvider().ForceUpdate() + err := cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() diff --git a/integrationTests/chainSimulator/staking/simpleStake_test.go b/integrationTests/chainSimulator/staking/simpleStake_test.go index f738b2c7ff6..83039942189 100644 --- a/integrationTests/chainSimulator/staking/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/simpleStake_test.go @@ -212,7 +212,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { require.Nil(t, err) // In step 1, only the previously staked node should be in auction list - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) @@ -229,7 +229,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { require.Nil(t, err) // after the re-stake process, the node should be in auction list - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) auctionList, err = metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go index 9ac5b86be20..0e91ef2a2c5 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go @@ -152,7 +152,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) validatorStatistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) @@ -264,7 +264,7 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) results, err := metachainNode.GetFacadeHandler().AuctionListApi() require.Nil(t, err) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index a5292d72e40..8bffcb6c63a 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -212,6 +212,16 @@ func (s *simulator) GenerateBlocksUntilEpochIsReached(targetEpoch int32) error { return fmt.Errorf("exceeded rounds to generate blocks") } +// ForceResetValidatorStatisticsCache will force the reset of the cache used for the validators statistics endpoint +func (s *simulator) ForceResetValidatorStatisticsCache() error { + metachainNode := s.GetNodeHandler(core.MetachainShardId) + if check.IfNil(metachainNode) { + return errNilMetachainNode + } + + return metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() +} + func (s *simulator) isTargetEpochReached(targetEpoch int32) (bool, error) { metachainNode := s.nodes[core.MetachainShardId] metachainEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() From f81d1df14b0b4a1f840d368b210849c65ece925c Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Fri, 22 Mar 2024 16:19:42 +0200 Subject: [PATCH 20/41] enable host driver chain simulator --- .../components/statusComponents.go | 41 ++++++++++++++++--- .../components/statusComponents_test.go | 17 ++++---- .../components/testOnlyProcessingNode.go | 1 + 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index 65f9dbb7667..67738499216 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -9,12 +9,14 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/appStatusPolling" "github.com/multiversx/mx-chain-core-go/core/check" - outportCfg "github.com/multiversx/mx-chain-core-go/data/outport" + factoryMarshalizer "github.com/multiversx/mx-chain-core-go/marshal/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/statistics" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/outport" + "github.com/multiversx/mx-chain-go/outport/factory" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" ) @@ -32,7 +34,7 @@ type statusComponentsHolder struct { } // CreateStatusComponents will create a new instance of status components holder -func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int) (*statusComponentsHolder, error) { +func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig) (*statusComponentsHolder, error) { if check.IfNil(appStatusHandler) { return nil, core.ErrNilAppStatusHandler } @@ -44,9 +46,16 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl statusPollingIntervalSec: statusPollingIntervalSec, } - // TODO add drivers to index data - instance.outportHandler, err = outport.NewOutport(100*time.Millisecond, outportCfg.OutportConfig{ - ShardID: shardID, + hostDriverArgs, err := makeHostDriversArgs(external) + if err != nil { + return nil, err + } + instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ + IsImportDB: false, + ShardID: shardID, + RetrialInterval: 100 * time.Millisecond, + HostDriversArgs: hostDriverArgs, + EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, }) if err != nil { return nil, err @@ -59,6 +68,28 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl return instance, nil } +func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriverFactory, error) { + argsHostDriverFactorySlice := make([]factory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig)) + for idx := 0; idx < len(external.HostDriversConfig); idx++ { + hostConfig := external.HostDriversConfig[idx] + if !hostConfig.Enabled { + continue + } + + marshaller, err := factoryMarshalizer.NewMarshalizer(hostConfig.MarshallerType) + if err != nil { + return argsHostDriverFactorySlice, err + } + + argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, factory.ArgsHostDriverFactory{ + Marshaller: marshaller, + HostConfig: hostConfig, + }) + } + + return argsHostDriverFactorySlice, nil +} + // OutportHandler will return the outport handler func (s *statusComponentsHolder) OutportHandler() outport.OutportHandler { return s.outportHandler diff --git a/node/chainSimulator/components/statusComponents_test.go b/node/chainSimulator/components/statusComponents_test.go index 0e83e435003..b6e2e296fbb 100644 --- a/node/chainSimulator/components/statusComponents_test.go +++ b/node/chainSimulator/components/statusComponents_test.go @@ -7,6 +7,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" mxErrors "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/process" @@ -20,7 +21,7 @@ func TestCreateStatusComponents(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) require.NotNil(t, comp) @@ -30,7 +31,7 @@ func TestCreateStatusComponents(t *testing.T) { t.Run("nil app status handler should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, nil, 5) + comp, err := CreateStatusComponents(0, nil, 5, config.ExternalConfig{}) require.Equal(t, core.ErrNilAppStatusHandler, err) require.Nil(t, comp) }) @@ -42,7 +43,7 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) { var comp *statusComponentsHolder require.True(t, comp.IsInterfaceNil()) - comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.False(t, comp.IsInterfaceNil()) require.Nil(t, comp.Close()) } @@ -50,7 +51,7 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) { func TestStatusComponentsHolder_Getters(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) require.NotNil(t, comp.OutportHandler()) @@ -64,7 +65,7 @@ func TestStatusComponentsHolder_Getters(t *testing.T) { func TestStatusComponentsHolder_SetForkDetector(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) err = comp.SetForkDetector(nil) @@ -82,7 +83,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { t.Run("nil fork detector should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) err = comp.StartPolling() @@ -91,7 +92,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { t.Run("NewAppStatusPolling failure should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0, config.ExternalConfig{}) require.NoError(t, err) err = comp.SetForkDetector(&mock.ForkDetectorStub{}) @@ -113,7 +114,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { wasSetUInt64ValueCalled.SetValue(true) }, } - comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec) + comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec, config.ExternalConfig{}) require.NoError(t, err) forkDetector := &mock.ForkDetectorStub{ diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 07c8561c73f..ff1466ffba8 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -146,6 +146,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces selfShardID, instance.StatusCoreComponents.AppStatusHandler(), args.Configs.GeneralConfig.GeneralSettings.StatusPollingIntervalSec, + *args.Configs.ExternalConfig, ) if err != nil { return nil, err From 3994d89ba5c5c91df92b9750a4159103180e084d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 27 Mar 2024 13:48:35 +0200 Subject: [PATCH 21/41] updated dependencies --- go.mod | 24 ++++++++++++------------ go.sum | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 86225522dcc..d441c0f17eb 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 - github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 - github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a - github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c - github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 + github.com/multiversx/mx-chain-communication-go v1.0.13 + github.com/multiversx/mx-chain-core-go v1.2.19 + github.com/multiversx/mx-chain-crypto-go v1.2.10 + github.com/multiversx/mx-chain-es-indexer-go v1.4.19 + github.com/multiversx/mx-chain-logger-go v1.0.14 + github.com/multiversx/mx-chain-scenario-go v1.4.3 + github.com/multiversx/mx-chain-storage-go v1.0.15 + github.com/multiversx/mx-chain-vm-common-go v1.5.12 + github.com/multiversx/mx-chain-vm-go v1.5.28 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index f12ab723392..8089a226704 100644 --- a/go.sum +++ b/go.sum @@ -385,30 +385,30 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 h1:WQoVgQG9YWiYM5Q3MmnbnxeoQkfHr63iFJZScFYsMxk= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 h1:sBH1Zf5jdMqS+1LDfXBmsIdmol8CFloPzjDCtmBZGEc= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a h1:QvIC6R5sf0koeSwAs+Ye8J+CjNkAdaosTMSNTVBB8sA= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a/go.mod h1:Xs0xFsPv+c1p8pwurLV7VBS7bEpIN/0jZrCwXVU26zw= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 h1:aLJhYiDBtWW4yjizhvQgTU00KfkK3oL3GnEh7pVUPRs= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34/go.mod h1:8uugq3HUeDiE6G4AS3F8/B3zA1Pabzbl7SSD6Cebwz8= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b h1:iDDarqnGFZBXxqpaPWp8ePOqhG5G3DeAoopGgRLteu0= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b/go.mod h1:4uezxguZiX42kUaYMK/x46LLbgpYqn/iQXbcGM7zdM0= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 h1:yRfY/Mj1CXPoGd21F3y84cqBIKsktSgPuxz/5a7FA3w= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35/go.mod h1:Nvanb5BZVhqnFFlWUtn7PQ/GIsl72zPVcMEw/ZvYiQA= +github.com/multiversx/mx-chain-communication-go v1.0.13 h1:Iou1fB3VAZMl9ghFULHjsAa3m+voKrrW7ESviKI1QRQ= +github.com/multiversx/mx-chain-communication-go v1.0.13/go.mod h1:WY3tQP1Vrb822ZsuQU+ICd8+rgC7Op6eKb0I00Sav8k= +github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= +github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.10 h1:wFfTPh0kmfoMDu4iKVRWOB5N6jJwMmgxyymqoA/U5CY= +github.com/multiversx/mx-chain-crypto-go v1.2.10/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= +github.com/multiversx/mx-chain-es-indexer-go v1.4.19 h1:nuyqW5fsm22Wl0lNZNW1WviGGpAZhdgaKwi9XcTJisA= +github.com/multiversx/mx-chain-es-indexer-go v1.4.19/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js= +github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= +github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= +github.com/multiversx/mx-chain-scenario-go v1.4.3 h1:9xeVB8TOsolXS4YEr1CZ/VZr5Qk0X+nde8nRGnxJICo= +github.com/multiversx/mx-chain-scenario-go v1.4.3/go.mod h1:Bd7/Xs3mWM6pX/REHK5dfpf3MUfjMZ7li09cfCxg2ac= +github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdReD/tKBJj10JbxXvaE= +github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= +github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= +github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= +github.com/multiversx/mx-chain-vm-go v1.5.28 h1:iJ8aUF1GZ6KSfvwogOpck+dfAywn+nL3n2B0yzK4nis= +github.com/multiversx/mx-chain-vm-go v1.5.28/go.mod h1:5yiy54xE54u6jYOn7yLfgYtwl9oYf+WZDpCPi7/P7SI= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 h1:Of6I3lWp0P0F5hmw3aqvtgqFK5N9yjqdAuncM2aM1kg= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66/go.mod h1:YSB5/GnMklBPGBdk4bMTGD0DN1sPPUybE1sFCyaMVN8= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 h1:A8uVD0KqaVUISws7eqb6u3VGe1keMuZtOXAb+zwx/+0= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67/go.mod h1:/qrbL58Jb/hbN8uyf9a4DVjC36lEfkzroI5MiSPPDSY= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 h1:h+s8CMizwP1C99+oveNllzDsqjtI2LTzdfMOfs4q5yw= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96/go.mod h1:QiERt54tiyMlECVbHXyB+22aSOIJyseedjJdnufRPA8= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= From 720648adb135f0bb0e212ea52b279f0e7511d4a7 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 27 Mar 2024 14:01:39 +0200 Subject: [PATCH 22/41] fix test processor node --- node/chainSimulator/components/testOnlyProcessingNode.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index ff1466ffba8..e08f4fc1367 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -285,6 +285,14 @@ func (node *testOnlyProcessingNode) createNodesCoordinator(pref config.Preferenc return err } + shardID := node.BootstrapComponentsHolder.ShardCoordinator().SelfId() + shardIDStr := fmt.Sprintf("%d", shardID) + if shardID == core.MetachainShardId { + shardIDStr = "metachain" + } + + pref.DestinationShardAsObserver = shardIDStr + node.NodesCoordinator, err = bootstrapComp.CreateNodesCoordinator( nodesShufflerOut, node.CoreComponentsHolder.GenesisNodesSetup(), From 600a1bce9eb3577ddee0255ff3553add652a3902 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 27 Mar 2024 14:26:52 +0200 Subject: [PATCH 23/41] updated dependencies 2 --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index d441c0f17eb..c8c982dc127 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13 + github.com/multiversx/mx-chain-communication-go v1.0.14 github.com/multiversx/mx-chain-core-go v1.2.19 - github.com/multiversx/mx-chain-crypto-go v1.2.10 + github.com/multiversx/mx-chain-crypto-go v1.2.11 github.com/multiversx/mx-chain-es-indexer-go v1.4.19 github.com/multiversx/mx-chain-logger-go v1.0.14 github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.28 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 + github.com/multiversx/mx-chain-vm-go v1.5.29 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 8089a226704..9067c3ebf3b 100644 --- a/go.sum +++ b/go.sum @@ -385,12 +385,12 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.0.13 h1:Iou1fB3VAZMl9ghFULHjsAa3m+voKrrW7ESviKI1QRQ= -github.com/multiversx/mx-chain-communication-go v1.0.13/go.mod h1:WY3tQP1Vrb822ZsuQU+ICd8+rgC7Op6eKb0I00Sav8k= +github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= +github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10 h1:wFfTPh0kmfoMDu4iKVRWOB5N6jJwMmgxyymqoA/U5CY= -github.com/multiversx/mx-chain-crypto-go v1.2.10/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= +github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= +github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.19 h1:nuyqW5fsm22Wl0lNZNW1WviGGpAZhdgaKwi9XcTJisA= github.com/multiversx/mx-chain-es-indexer-go v1.4.19/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= @@ -401,14 +401,14 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.28 h1:iJ8aUF1GZ6KSfvwogOpck+dfAywn+nL3n2B0yzK4nis= -github.com/multiversx/mx-chain-vm-go v1.5.28/go.mod h1:5yiy54xE54u6jYOn7yLfgYtwl9oYf+WZDpCPi7/P7SI= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 h1:Of6I3lWp0P0F5hmw3aqvtgqFK5N9yjqdAuncM2aM1kg= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66/go.mod h1:YSB5/GnMklBPGBdk4bMTGD0DN1sPPUybE1sFCyaMVN8= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 h1:A8uVD0KqaVUISws7eqb6u3VGe1keMuZtOXAb+zwx/+0= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67/go.mod h1:/qrbL58Jb/hbN8uyf9a4DVjC36lEfkzroI5MiSPPDSY= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 h1:h+s8CMizwP1C99+oveNllzDsqjtI2LTzdfMOfs4q5yw= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96/go.mod h1:QiERt54tiyMlECVbHXyB+22aSOIJyseedjJdnufRPA8= +github.com/multiversx/mx-chain-vm-go v1.5.29 h1:Ovz5/WM9KbD3YKRafdKI4RwtsNN36AGeNw81LZAhE70= +github.com/multiversx/mx-chain-vm-go v1.5.29/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68/go.mod h1:sIXRCenIR6FJtr3X/gDc60N6+v99Ai4hDsn6R5TKGnk= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 h1:fbYYqollxbIArcrC161Z9Qh5yJGW0Ax60m83Gz8+H1w= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97/go.mod h1:56WJQio8SzOt3vWibaNkuGpqLlmTOGUSJqs3wMK69zw= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= From 99ac996965c56874c913c001d5d929e0e959d63d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 27 Mar 2024 15:40:46 +0200 Subject: [PATCH 24/41] updated indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c8c982dc127..aafbc51ec02 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.14 github.com/multiversx/mx-chain-core-go v1.2.19 github.com/multiversx/mx-chain-crypto-go v1.2.11 - github.com/multiversx/mx-chain-es-indexer-go v1.4.19 + github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.14 github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 diff --git a/go.sum b/go.sum index 9067c3ebf3b..09c6f9ea503 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0 github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19 h1:nuyqW5fsm22Wl0lNZNW1WviGGpAZhdgaKwi9XcTJisA= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js= +github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= +github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= github.com/multiversx/mx-chain-scenario-go v1.4.3 h1:9xeVB8TOsolXS4YEr1CZ/VZr5Qk0X+nde8nRGnxJICo= From e06b2d577e92a7e0163d673db5519261938abffc Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 27 Mar 2024 16:23:47 +0200 Subject: [PATCH 25/41] small fix --- node/chainSimulator/components/statusComponents.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index 67738499216..fa0027ca967 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -53,7 +53,7 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ IsImportDB: false, ShardID: shardID, - RetrialInterval: 100 * time.Millisecond, + RetrialInterval: time.Second, HostDriversArgs: hostDriverArgs, EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, }) From 99c9793df2e82c06f614ac83cae71de7ccf3afca Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 29 Mar 2024 10:35:24 +0200 Subject: [PATCH 26/41] fixed unstaked list on delegation when nodes are unstaked from queue --- vm/systemSmartContracts/delegation.go | 3 +- vm/systemSmartContracts/eei.go | 4 +++ vm/systemSmartContracts/stakingWaitingList.go | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/vm/systemSmartContracts/delegation.go b/vm/systemSmartContracts/delegation.go index ac33ba81da2..ab5c97cfce0 100644 --- a/vm/systemSmartContracts/delegation.go +++ b/vm/systemSmartContracts/delegation.go @@ -2322,7 +2322,8 @@ func (d *delegation) deleteDelegatorIfNeeded(address []byte, delegator *Delegato } func (d *delegation) unStakeAtEndOfEpoch(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { - if !bytes.Equal(args.CallerAddr, d.endOfEpochAddr) { + if !bytes.Equal(args.CallerAddr, d.endOfEpochAddr) && + !bytes.Equal(args.CallerAddr, d.stakingSCAddr) { d.eei.AddReturnMessage("can be called by end of epoch address only") return vmcommon.UserError } diff --git a/vm/systemSmartContracts/eei.go b/vm/systemSmartContracts/eei.go index 55f554d11b0..3f251a6cca4 100644 --- a/vm/systemSmartContracts/eei.go +++ b/vm/systemSmartContracts/eei.go @@ -144,6 +144,8 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte if value, isInMap := storageAdrMap[string(key)]; isInMap { return value } + } else { + storageAdrMap = make(map[string][]byte) } data, _, err := host.blockChainHook.GetStorageData(address, key) @@ -151,6 +153,8 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte return nil } + storageAdrMap[string(key)] = data + return data } diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index e1d0ff00cb4..1ab917a9269 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-core-go/core" "math" "math/big" "strconv" @@ -824,6 +825,8 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v return vmcommon.Ok } + orderedListOwners := make([]string, 0) + mapOwnerKeys := make(map[string][][]byte) for i, blsKey := range waitingListData.blsKeys { registrationData := waitingListData.stakedDataList[i] @@ -835,11 +838,42 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v // delete element from waiting list inWaitingListKey := createWaitingListKey(blsKey) s.eei.SetStorage(inWaitingListKey, nil) + + ownerAddr := string(registrationData.OwnerAddress) + _, exists := mapOwnerKeys[ownerAddr] + if !exists { + mapOwnerKeys[ownerAddr] = make([][]byte, 0) + orderedListOwners = append(orderedListOwners, ownerAddr) + } + + mapOwnerKeys[ownerAddr] = append(mapOwnerKeys[ownerAddr], blsKey) } // delete waiting list head element s.eei.SetStorage([]byte(waitingListHeadKey), nil) + // call unStakeAtEndOfEpoch from the delegation contracts to compute the new unStaked list + for _, owner := range orderedListOwners { + listOfKeys := mapOwnerKeys[owner] + + if s.eei.BlockChainHook().GetShardOfAddress([]byte(owner)) != core.MetachainShardId { + continue + } + + unStakeCall := "unStakeAtEndOfEpoch" + for _, key := range listOfKeys { + unStakeCall += "@" + hex.EncodeToString(key) + } + vmOutput, err := s.eei.ExecuteOnDestContext([]byte(owner), args.RecipientAddr, big.NewInt(0), []byte(unStakeCall)) + if err != nil { + s.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + if vmOutput.ReturnCode != vmcommon.Ok { + return vmOutput.ReturnCode + } + } + return vmcommon.Ok } From 60782049181eb301a5ba08a8db8383f58e8ac8c9 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 29 Mar 2024 11:59:51 +0200 Subject: [PATCH 27/41] fixed unstaked list on delegation when nodes are unstaked from queue --- vm/systemSmartContracts/stakingWaitingList.go | 27 +++-- vm/systemSmartContracts/staking_test.go | 104 ++++++++++++++++++ 2 files changed, 122 insertions(+), 9 deletions(-) diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index 1ab917a9269..e08b16b3cde 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -4,11 +4,11 @@ import ( "bytes" "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-core-go/core" "math" "math/big" "strconv" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/vm" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -829,7 +829,6 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v mapOwnerKeys := make(map[string][][]byte) for i, blsKey := range waitingListData.blsKeys { registrationData := waitingListData.stakedDataList[i] - result := s.doUnStake(blsKey, registrationData) if result != vmcommon.Ok { return result @@ -864,19 +863,29 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v for _, key := range listOfKeys { unStakeCall += "@" + hex.EncodeToString(key) } - vmOutput, err := s.eei.ExecuteOnDestContext([]byte(owner), args.RecipientAddr, big.NewInt(0), []byte(unStakeCall)) - if err != nil { - s.eei.AddReturnMessage(err.Error()) - return vmcommon.UserError - } - if vmOutput.ReturnCode != vmcommon.Ok { - return vmOutput.ReturnCode + returnCode := s.executeOnStakeAtEndOfEpoch([]byte(owner), listOfKeys, args.RecipientAddr) + if returnCode != vmcommon.Ok { + return returnCode } } return vmcommon.Ok } +func (s *stakingSC) executeOnStakeAtEndOfEpoch(destinationAddress []byte, listOfKeys [][]byte, senderAddress []byte) vmcommon.ReturnCode { + unStakeCall := "unStakeAtEndOfEpoch" + for _, key := range listOfKeys { + unStakeCall += "@" + hex.EncodeToString(key) + } + vmOutput, err := s.eei.ExecuteOnDestContext(destinationAddress, senderAddress, big.NewInt(0), []byte(unStakeCall)) + if err != nil { + s.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + + return vmOutput.ReturnCode +} + func (s *stakingSC) cleanAdditionalQueue(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { if !s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { s.eei.AddReturnMessage("invalid method to call") diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index 53d78208cf1..68bc5c0b7f8 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3706,3 +3706,107 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") } + +func TestStakingSc_UnStakeAllFromQueueWithDelegationContracts(t *testing.T) { + t.Parallel() + + blockChainHook := &mock.BlockChainHookStub{} + blockChainHook.GetStorageDataCalled = func(accountsAddress []byte, index []byte) ([]byte, uint32, error) { + return nil, 0, nil + } + blockChainHook.GetShardOfAddressCalled = func(address []byte) uint32 { + return core.MetachainShardId + } + + eei := createDefaultEei() + eei.blockChainHook = blockChainHook + eei.SetSCAddress([]byte("addr")) + + delegationSC, _ := createDelegationContractAndEEI() + delegationSC.eei = eei + + systemSCContainerStub := &mock.SystemSCContainerStub{GetCalled: func(key []byte) (vm.SystemSmartContract, error) { + return delegationSC, nil + }} + _ = eei.SetSystemSCContainer(systemSCContainerStub) + + stakingAccessAddress := vm.ValidatorSCAddress + args := createMockStakingScArguments() + args.StakingAccessAddr = stakingAccessAddress + args.StakingSCConfig.MaxNumberOfNodesForStake = 1 + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + args.Eei = eei + args.StakingSCConfig.UnBondPeriod = 100 + stakingSmartContract, _ := NewStakingSmartContract(args) + + stakerAddress := []byte("stakerAddr") + + blockChainHook.CurrentNonceCalled = func() uint64 { + return 1 + } + + enableEpochsHandler.AddActiveFlags(common.StakingV2Flag) + enableEpochsHandler.AddActiveFlags(common.StakeFlag) + + // do stake should work + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firstKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("secondKey")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) + assert.Equal(t, len(waitingReturn), 9) + + dStatus := &DelegationContractStatus{ + StakedKeys: make([]*NodesData, 4), + NotStakedKeys: nil, + UnStakedKeys: nil, + NumUsers: 0, + } + dStatus.StakedKeys[0] = &NodesData{BLSKey: []byte("firstKey ")} + dStatus.StakedKeys[1] = &NodesData{BLSKey: []byte("secondKey")} + dStatus.StakedKeys[2] = &NodesData{BLSKey: []byte("thirdKey ")} + dStatus.StakedKeys[3] = &NodesData{BLSKey: []byte("fourthKey")} + + marshaledData, _ := delegationSC.marshalizer.Marshal(dStatus) + eei.SetStorageForAddress(stakerAddress, []byte(delegationStatusKey), marshaledData) + + arguments := CreateVmContractCallInput() + arguments.RecipientAddr = vm.StakingSCAddress + validatorData := &ValidatorDataV2{ + TotalStakeValue: big.NewInt(400), + TotalUnstaked: big.NewInt(0), + RewardAddress: stakerAddress, + BlsPubKeys: [][]byte{[]byte("firstKey "), []byte("secondKey"), []byte("thirdKey "), []byte("fourthKey")}, + } + arguments.CallerAddr = stakingSmartContract.endOfEpochAccessAddr + marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) + eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) + + enableEpochsHandler.AddActiveFlags(common.StakingV4Step1Flag) + enableEpochsHandler.AddActiveFlags(common.StakingV4StartedFlag) + + arguments.Function = "unStakeAllNodesFromQueue" + retCode := stakingSmartContract.Execute(arguments) + fmt.Println(eei.returnMessage) + assert.Equal(t, retCode, vmcommon.Ok) + + assert.Equal(t, len(eei.GetStorage([]byte(waitingListHeadKey))), 0) + newHead, _ := stakingSmartContract.getWaitingListHead() + assert.Equal(t, uint32(0), newHead.Length) // no entries in the queue list + + marshaledData = eei.GetStorageFromAddress(stakerAddress, []byte(delegationStatusKey)) + _ = stakingSmartContract.marshalizer.Unmarshal(dStatus, marshaledData) + assert.Equal(t, len(dStatus.UnStakedKeys), 3) + assert.Equal(t, len(dStatus.StakedKeys), 1) + + doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "unStaked") + + // stake them again - as they were deleted from waiting list + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + // surprisingly, the queue works again as we did not activate the staking v4 + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") +} From 1e79ea7f4614cae0a0dfefdf3b4d2c1821f6cb6a Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:19:16 +0200 Subject: [PATCH 28/41] staking provider with node scenario --- .../stakingProviderWithNodesinQueue_test.go | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go new file mode 100644 index 00000000000..6bf887840c1 --- /dev/null +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -0,0 +1,130 @@ +package staking + +import ( + "encoding/hex" + "fmt" + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/vm" + "github.com/stretchr/testify/require" + "math/big" + "testing" + "time" +) + +func TestStakingProviderWithNodes(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + stakingV4ActivationEpoch := uint32(2) + + t.Run("staking ph 4 step 1 active", func(t *testing.T) { + testStakingProviderWithNodesReStakeUnStaked(t, stakingV4ActivationEpoch) + }) + + t.Run("staking ph 4 step 2 active", func(t *testing.T) { + testStakingProviderWithNodesReStakeUnStaked(t, stakingV4ActivationEpoch+1) + }) + + t.Run("staking ph 4 step 3 active", func(t *testing.T) { + testStakingProviderWithNodesReStakeUnStaked(t, stakingV4ActivationEpoch+2) + }) +} + +func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4ActivationEpoch uint32) { + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + configs.SetStakingV4ActivationEpochs(cfg, stakingV4ActivationEpoch) + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + defer cs.Close() + + mintValue := big.NewInt(0).Mul(big.NewInt(5000), oneEGLD) + validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) + require.Nil(t, err) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(1) + require.Nil(t, err) + + // create delegation contract + stakeValue, _ := big.NewInt(0).SetString("4250000000000000000000", 10) + dataField := "createNewDelegationContract@00@0ea1" + txStake := generateTransaction(validatorOwner.Bytes, getNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTx) + + delegationAddress := stakeTx.Logs.Events[2].Address + delegationAddressBytes, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(delegationAddress) + + // add nodes in queue + _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + + txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], mockBLSSignature+"02") + ownerNonce := getNonce(t, cs, validatorOwner) + txAddNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, gasLimitForStakeOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, addNodesTx) + + txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s", blsKeys[0]) + ownerNonce = getNonce(t, cs, validatorOwner) + txStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, gasLimitForStakeOperation) + + stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.Equal(t, 1, len(stakeNodesTxs)) + + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) + status := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, "queued", status) + + // activate staking v4 + err = cs.GenerateBlocksUntilEpochIsReached(int32(stakingV4ActivationEpoch)) + require.Nil(t, err) + + status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, "unStaked", status) + + ownerNonce = getNonce(t, cs, validatorOwner) + reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) + reStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, gasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, reStakeTx) + + status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, "staked", status) + + err = cs.GenerateBlocks(20) + + checkValidatorStatus(t, cs, blsKeys[0], "auction") +} From bb090cebe542f89d152764b7709f30a358d41456 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:21:20 +0200 Subject: [PATCH 29/41] fix linter --- .../staking/stakingProviderWithNodesinQueue_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go index 6bf887840c1..db417bbee1f 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -125,6 +125,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati require.Equal(t, "staked", status) err = cs.GenerateBlocks(20) + require.Nil(t, err) checkValidatorStatus(t, cs, blsKeys[0], "auction") } From 1f2fae1e7239aed9d6a392db483124724623e669 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:37:58 +0200 Subject: [PATCH 30/41] fixes after review --- .../staking/stakingProviderWithNodesinQueue_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go index db417bbee1f..57377c47bd6 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -3,6 +3,10 @@ package staking import ( "encoding/hex" "fmt" + "math/big" + "testing" + "time" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" @@ -11,9 +15,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/vm" "github.com/stretchr/testify/require" - "math/big" - "testing" - "time" ) func TestStakingProviderWithNodes(t *testing.T) { @@ -124,6 +125,10 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "staked", status) + result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + require.NotNil(t, result) + require.Equal(t, "staked", result[blsKeys[0]]) + err = cs.GenerateBlocks(20) require.Nil(t, err) From 028f6a379467d28fb0f79870fe8cb93b111f1386 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:41:15 +0200 Subject: [PATCH 31/41] extra check --- .../staking/stakingProviderWithNodesinQueue_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go index 57377c47bd6..af50d56c821 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -115,6 +115,10 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "unStaked", status) + result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + require.NotNil(t, result) + require.Equal(t, "unStaked", result[blsKeys[0]]) + ownerNonce = getNonce(t, cs, validatorOwner) reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) reStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, gasLimitForStakeOperation) @@ -125,7 +129,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "staked", status) - result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + result = getAllNodeStates(t, metachainNode, delegationAddressBytes) require.NotNil(t, result) require.Equal(t, "staked", result[blsKeys[0]]) From c227dd5091341af24887b610a4b4eefcdeaed878 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 12:13:50 +0300 Subject: [PATCH 32/41] extend unit test and fixes --- vm/systemSmartContracts/staking_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index 68bc5c0b7f8..fb92a574945 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3755,7 +3755,7 @@ func TestStakingSc_UnStakeAllFromQueueWithDelegationContracts(t *testing.T) { doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) - assert.Equal(t, len(waitingReturn), 9) + requireSliceContains(t, waitingReturn, [][]byte{[]byte("secondKey"), []byte("thirdKey "), []byte("fourthKey")}) dStatus := &DelegationContractStatus{ StakedKeys: make([]*NodesData, 4), @@ -3801,12 +3801,19 @@ func TestStakingSc_UnStakeAllFromQueueWithDelegationContracts(t *testing.T) { assert.Equal(t, len(dStatus.StakedKeys), 1) doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "unStaked") + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "unStaked") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "unStaked") // stake them again - as they were deleted from waiting list doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) - // surprisingly, the queue works again as we did not activate the staking v4 doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") } + +func requireSliceContains(t *testing.T, s1, s2 [][]byte) { + for _, elemInS2 := range s2 { + require.Contains(t, s1, elemInS2) + } +} From b0e9ead8fbdd42a047f3835194d0c601ebcc2bed Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 13:04:50 +0300 Subject: [PATCH 33/41] extend unit test and fixes --- .../chainSimulator/staking/helpers.go | 112 ++++++ .../staking/{ => jail}/jail_test.go | 66 ++-- .../staking/{ => stake}/simpleStake_test.go | 43 +-- .../{ => stake}/stakeAndUnStake_test.go | 282 +++++++-------- .../{ => stakingProvider}/delegation_test.go | 324 +++++++----------- .../stakingProviderWithNodesinQueue_test.go | 46 +-- 6 files changed, 454 insertions(+), 419 deletions(-) create mode 100644 integrationTests/chainSimulator/staking/helpers.go rename integrationTests/chainSimulator/staking/{ => jail}/jail_test.go (74%) rename integrationTests/chainSimulator/staking/{ => stake}/simpleStake_test.go (83%) rename integrationTests/chainSimulator/staking/{ => stake}/stakeAndUnStake_test.go (87%) rename integrationTests/chainSimulator/staking/{ => stakingProvider}/delegation_test.go (84%) rename integrationTests/chainSimulator/staking/{ => stakingProvider}/stakingProviderWithNodesinQueue_test.go (68%) diff --git a/integrationTests/chainSimulator/staking/helpers.go b/integrationTests/chainSimulator/staking/helpers.go new file mode 100644 index 00000000000..550e227a7f2 --- /dev/null +++ b/integrationTests/chainSimulator/staking/helpers.go @@ -0,0 +1,112 @@ +package staking + +import ( + "encoding/hex" + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/vm" + "github.com/stretchr/testify/require" + "math/big" + "testing" +) + +const ( + minGasPrice = 1000000000 + txVersion = 1 + mockTxSignature = "sig" + + OkReturnCode = "ok" + UnStakedStatus = "unStaked" + MockBLSSignature = "010101" + GasLimitForStakeOperation = 50_000_000 + GasLimitForUnBond = 12_000_000 + MaxNumOfBlockToGenerateWhenExecutingTx = 7 + + QueuedStatus = "queued" + StakedStatus = "staked" + NotStakedStatus = "notStaked" + AuctionStatus = "auction" +) + +var InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) +var ZeroValue = big.NewInt(0) + +var MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) +var OneEGLD = big.NewInt(1000000000000000000) + +func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 { + account, err := cs.GetAccount(address) + require.Nil(t, err) + + return account.Nonce +} + +func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { + return &transaction.Transaction{ + Nonce: nonce, + Value: value, + SndAddr: sender, + RcvAddr: receiver, + Data: []byte(data), + GasLimit: gasLimit, + GasPrice: minGasPrice, + ChainID: []byte(configs.ChainID), + Version: txVersion, + Signature: []byte(mockTxSignature), + } +} + +func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { + scQuery := &process.SCQuery{ + ScAddress: vm.StakingSCAddress, + FuncName: "getBLSKeyStatus", + CallerAddr: vm.StakingSCAddress, + CallValue: big.NewInt(0), + Arguments: [][]byte{blsKey}, + } + result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, OkReturnCode, result.ReturnCode) + + return string(result.ReturnData[0]) +} + +func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string { + scQuery := &process.SCQuery{ + ScAddress: address, + FuncName: "getAllNodeStates", + CallerAddr: vm.StakingSCAddress, + CallValue: big.NewInt(0), + } + result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, OkReturnCode, result.ReturnCode) + + m := make(map[string]string) + status := "" + for _, resultData := range result.ReturnData { + if len(resultData) != 96 { + // not a BLS key + status = string(resultData) + continue + } + + m[hex.EncodeToString(resultData)] = status + } + + return m +} + +func CheckValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { + err := cs.ForceResetValidatorStatisticsCache() + require.Nil(t, err) + + validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() + require.Nil(t, err) + require.Equal(t, expectedStatus, validatorsStatistics[blsKey].ValidatorStatus) +} diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go similarity index 74% rename from integrationTests/chainSimulator/staking/jail_test.go rename to integrationTests/chainSimulator/staking/jail/jail_test.go index 4251ece6bf4..c16d3c60df2 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -1,8 +1,9 @@ -package staking +package jail import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -11,7 +12,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" - chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" @@ -21,6 +21,7 @@ import ( const ( stakingV4JailUnJailStep1EnableEpoch = 5 + defaultPathToInitialConfig = "../../../../cmd/node/config/" epochWhenNodeIsJailed = 4 ) @@ -92,13 +93,13 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -107,18 +108,18 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus require.Nil(t, err) decodedBLSKey, _ := hex.DecodeString(blsKeys[0]) - status := getBLSKeyStatus(t, metachainNode, decodedBLSKey) + status := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey) require.Equal(t, "jailed", status) // do an unjail transaction unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := generateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, gasLimitForStakeOperation) + txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch) require.Nil(t, err) - unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, maxNumOfBlockToGenerateWhenExecutingTx) + unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unJailTx) require.Equal(t, transaction.TxStatusSuccess, unJailTx.Status) @@ -126,20 +127,20 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus err = cs.GenerateBlocks(1) require.Nil(t, err) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey) require.Equal(t, "staked", status) - checkValidatorStatus(t, cs, blsKeys[0], nodeStatusAfterUnJail) + staking.CheckValidatorStatus(t, cs, blsKeys[0], nodeStatusAfterUnJail) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - checkValidatorStatus(t, cs, blsKeys[0], "waiting") + staking.CheckValidatorStatus(t, cs, blsKeys[0], "waiting") err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 2) require.Nil(t, err) - checkValidatorStatus(t, cs, blsKeys[0], "eligible") + staking.CheckValidatorStatus(t, cs, blsKeys[0], "eligible") } // Test description @@ -196,13 +197,13 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { err = cs.AddValidatorKeys([][]byte{privateKeys[1]}) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(6000)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(6000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -211,47 +212,38 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { require.Nil(t, err) decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) - status := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "jailed", status) // add one more node - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) decodedBLSKey1, _ := hex.DecodeString(blsKeys[1]) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey1) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey1) require.Equal(t, "staked", status) // unJail the first node unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := generateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, gasLimitForStakeOperation) + txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) - unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, maxNumOfBlockToGenerateWhenExecutingTx) + unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unJailTx) require.Equal(t, transaction.TxStatusSuccess, unJailTx.Status) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "queued", status) err = cs.GenerateBlocksUntilEpochIsReached(stakingV4JailUnJailStep1EnableEpoch) require.Nil(t, err) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) - require.Equal(t, unStakedStatus, status) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, staking.UnStakedStatus, status) - checkValidatorStatus(t, cs, blsKeys[0], string(common.InactiveList)) -} - -func checkValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { - err := cs.ForceResetValidatorStatisticsCache() - require.Nil(t, err) - - validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() - require.Nil(t, err) - require.Equal(t, expectedStatus, validatorsStatistics[blsKey].ValidatorStatus) + staking.CheckValidatorStatus(t, cs, blsKeys[0], string(common.InactiveList)) } diff --git a/integrationTests/chainSimulator/staking/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go similarity index 83% rename from integrationTests/chainSimulator/staking/simpleStake_test.go rename to integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 83039942189..4bbaa1ef74c 100644 --- a/integrationTests/chainSimulator/staking/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -1,8 +1,9 @@ -package staking +package stake import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -83,7 +84,7 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) wallet1, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) wallet2, err := cs.GenerateAndMintWalletAddress(0, mintValue) @@ -97,18 +98,18 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch) require.Nil(t, err) - dataFieldTx1 := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - tx1Value := big.NewInt(0).Mul(big.NewInt(2499), oneEGLD) - tx1 := generateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, gasLimitForStakeOperation) + dataFieldTx1 := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + tx1Value := big.NewInt(0).Mul(big.NewInt(2499), staking.OneEGLD) + tx1 := staking.GenerateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, staking.GasLimitForStakeOperation) - dataFieldTx2 := fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - tx2 := generateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, dataFieldTx2, gasLimitForStakeOperation) + dataFieldTx2 := fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + tx2 := staking.GenerateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, dataFieldTx2, staking.GasLimitForStakeOperation) - dataFieldTx3 := fmt.Sprintf("stake@01@%s@%s", blsKeys[2], mockBLSSignature) - tx3Value := big.NewInt(0).Mul(big.NewInt(2501), oneEGLD) - tx3 := generateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, gasLimitForStakeOperation) + dataFieldTx3 := fmt.Sprintf("stake@01@%s@%s", blsKeys[2], staking.MockBLSSignature) + tx3Value := big.NewInt(0).Mul(big.NewInt(2501), staking.OneEGLD) + tx3 := staking.GenerateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, staking.GasLimitForStakeOperation) - results, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx1, tx2, tx3}, maxNumOfBlockToGenerateWhenExecutingTx) + results, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx1, tx2, tx3}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 3, len(results)) require.NotNil(t, results) @@ -123,16 +124,16 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus bls1, _ := hex.DecodeString(blsKeys[1]) bls2, _ := hex.DecodeString(blsKeys[2]) - blsKeyStatus := getBLSKeyStatus(t, metachainNode, bls1) + blsKeyStatus := staking.GetBLSKeyStatus(t, metachainNode, bls1) require.Equal(t, nodesStatus, blsKeyStatus) - blsKeyStatus = getBLSKeyStatus(t, metachainNode, bls2) + blsKeyStatus = staking.GetBLSKeyStatus(t, metachainNode, bls2) require.Equal(t, nodesStatus, blsKeyStatus) } else { // tx2 -- validator should be in queue - checkValidatorStatus(t, cs, blsKeys[1], nodesStatus) + staking.CheckValidatorStatus(t, cs, blsKeys[1], nodesStatus) // tx3 -- validator should be in queue - checkValidatorStatus(t, cs, blsKeys[2], nodesStatus) + staking.CheckValidatorStatus(t, cs, blsKeys[2], nodesStatus) } } @@ -194,14 +195,14 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { err = cs.AddValidatorKeys(privateKey) require.Nil(t, err) - mintValue := big.NewInt(0).Add(minimumStakeValue, oneEGLD) + mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) // Stake a new validator that should end up in auction in step 1 - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -220,8 +221,8 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { // re-stake the node txDataField = fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - txReStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, gasLimitForStakeOperation) - reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, maxNumOfBlockToGenerateWhenExecutingTx) + txReStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, staking.GasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go similarity index 87% rename from integrationTests/chainSimulator/staking/stakeAndUnStake_test.go rename to integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 0e91ef2a2c5..712f7ed5824 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -1,8 +1,9 @@ -package staking +package stake import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -26,8 +27,7 @@ import ( ) const ( - defaultPathToInitialConfig = "../../../cmd/node/config/" - maxNumOfBlockToGenerateWhenExecutingTx = 7 + defaultPathToInitialConfig = "../../../../cmd/node/config/" ) var log = logger.GetOrCreate("integrationTests/chainSimulator") @@ -115,7 +115,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -144,7 +144,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) // Step 6 --- generate 8 epochs to get rewards @@ -256,7 +256,7 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { Version: 1, } - txFromNetwork, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + txFromNetwork, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txFromNetwork) @@ -346,43 +346,43 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { err = cs.AddValidatorKeys(privateKeys) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) walletAddressShardID := uint32(0) walletAddress, err := cs.GenerateAndMintWalletAddress(walletAddressShardID, mintValue) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) metachainNode := cs.GetNodeHandler(core.MetachainShardId) bls0, _ := hex.DecodeString(blsKeys[0]) - blsKeyStatus := getBLSKeyStatus(t, metachainNode, bls0) + blsKeyStatus := staking.GetBLSKeyStatus(t, metachainNode, bls0) require.Equal(t, "staked", blsKeyStatus) // do unStake - txUnStake := generateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, zeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) - blsKeyStatus = getBLSKeyStatus(t, metachainNode, bls0) + blsKeyStatus = staking.GetBLSKeyStatus(t, metachainNode, bls0) require.Equal(t, "unStaked", blsKeyStatus) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) // do unBond - txUnBond := generateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, zeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), gasLimitForStakeOperation) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) // do claim - txClaim := generateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, zeroValue, "unBondTokens", gasLimitForStakeOperation) - claimTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txClaim, maxNumOfBlockToGenerateWhenExecutingTx) + txClaim := staking.GenerateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, "unBondTokens", staking.GasLimitForStakeOperation) + claimTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txClaim, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, claimTx) @@ -393,7 +393,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { walletAccount, _, err := cs.GetNodeHandler(walletAddressShardID).GetFacadeHandler().GetAccount(walletAddress.Bech32, coreAPI.AccountQueryOptions{}) require.Nil(t, err) walletBalanceBig, _ := big.NewInt(0).SetString(walletAccount.Balance, 10) - require.True(t, walletBalanceBig.Cmp(minimumStakeValue) > 0) + require.True(t, walletBalanceBig.Cmp(staking.MinimumStakeValue) > 0) } func checkTotalQualified(t *testing.T, auctionList []*common.AuctionListValidatorAPIResponse, expected int) { @@ -576,25 +576,25 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumStakeValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - stakeValue = big.NewInt(0).Set(minimumStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -606,10 +606,10 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul log.Info("Step 2. Create from the owner of the staked nodes a tx to stake 1 EGLD") - stakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1)) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(1)) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -624,7 +624,7 @@ func checkExpectedStakedValue(t *testing.T, metachainNode chainSimulatorProcess. totalStaked := getTotalStaked(t, metachainNode, blsKey) expectedStaked := big.NewInt(expectedValue) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(totalStaked)) } @@ -638,7 +638,7 @@ func getTotalStaked(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -804,15 +804,15 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumStakeValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -821,10 +821,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(minimumStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -839,10 +839,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -855,7 +855,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Wait for change of epoch and check the outcome") @@ -875,7 +875,7 @@ func getUnStakedTokensList(t *testing.T, metachainNode chainSimulatorProcess.Nod } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -885,16 +885,16 @@ func checkOneOfTheNodesIsUnstaked(t *testing.T, blsKeys []string, ) { decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) - keyStatus0 := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + keyStatus0 := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) log.Info("Key info", "key", blsKeys[0], "status", keyStatus0) - isNotStaked0 := keyStatus0 == unStakedStatus + isNotStaked0 := keyStatus0 == staking.UnStakedStatus decodedBLSKey1, _ := hex.DecodeString(blsKeys[1]) - keyStatus1 := getBLSKeyStatus(t, metachainNode, decodedBLSKey1) + keyStatus1 := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey1) log.Info("Key info", "key", blsKeys[1], "status", keyStatus1) - isNotStaked1 := keyStatus1 == unStakedStatus + isNotStaked1 := keyStatus1 == staking.UnStakedStatus require.True(t, isNotStaked0 != isNotStaked1) } @@ -912,14 +912,14 @@ func testBLSKeyStaked(t *testing.T, activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { - require.Equal(t, stakedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.StakedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) return } // in staking ph 2/3.5 we do not find the bls key on the validator statistics _, found := validatorStatistics[blsKey] require.False(t, found) - require.Equal(t, queuedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.QueuedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) } // Test description: @@ -1085,15 +1085,15 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(6000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumStakeValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1102,10 +1102,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(minimumStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1120,10 +1120,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1136,16 +1136,16 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Create from the owner of staked nodes a transaction to stake 10 EGLD and send it to the network") newStakeValue := big.NewInt(10) - newStakeValue = newStakeValue.Mul(oneEGLD, newStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + newStakeValue = newStakeValue.Mul(staking.OneEGLD, newStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1315,15 +1315,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1340,10 +1340,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi log.Info("Step 1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1354,8 +1354,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi testBLSKeyStaked(t, metachainNode, blsKeys[0]) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1373,10 +1373,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) // the owner balance should decrease only with the txs fee @@ -1549,15 +1549,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1572,10 +1572,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. balanceBeforeUnbonding, _ := big.NewInt(0).SetString(accountValidatorOwner.Balance, 10) unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1594,10 +1594,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) log.Info("Step 1. Wait for the unbonding epoch to start") @@ -1608,8 +1608,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. log.Info("Step 2. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1627,10 +1627,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2590) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) // the owner balance should increase with the (10 EGLD - tx fee) @@ -1820,15 +1820,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1848,10 +1848,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 2. Send the transactions in consecutive epochs, one TX in each epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(oneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1862,10 +1862,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(oneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1874,10 +1874,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(oneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1897,10 +1897,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -1912,10 +1912,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -1927,8 +1927,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1963,8 +1963,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = generateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1991,8 +1991,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = generateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2176,15 +2176,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2204,28 +2204,28 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 2. Send the transactions in consecutively in same epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(oneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) unStakeTxFee, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(oneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(oneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -2241,10 +2241,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11 + 12 + 13) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -2256,10 +2256,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -2271,8 +2271,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go similarity index 84% rename from integrationTests/chainSimulator/staking/delegation_test.go rename to integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index baa138f4430..4b2354eb0fe 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -1,9 +1,11 @@ -package staking +package stakingProvider import ( "crypto/rand" "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + logger "github.com/multiversx/mx-chain-logger-go" "math/big" "strings" "testing" @@ -21,7 +23,6 @@ import ( chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" @@ -30,33 +31,19 @@ import ( "github.com/stretchr/testify/require" ) -const mockBLSSignature = "010101" -const gasLimitForStakeOperation = 50_000_000 +var log = logger.GetOrCreate("stakingProvider") + const gasLimitForConvertOperation = 510_000_000 const gasLimitForDelegationContractCreationOperation = 500_000_000 const gasLimitForAddNodesOperation = 500_000_000 const gasLimitForUndelegateOperation = 500_000_000 const gasLimitForMergeOperation = 600_000_000 const gasLimitForDelegate = 12_000_000 -const gasLimitForUnBond = 12_000_000 -const minGasPrice = 1000000000 -const txVersion = 1 -const mockTxSignature = "sig" -const queuedStatus = "queued" -const stakedStatus = "staked" -const notStakedStatus = "notStaked" -const unStakedStatus = "unStaked" -const auctionStatus = "auction" -const okReturnCode = "ok" + const maxCap = "00" // no cap const hexServiceFee = "0ea1" // 37.45% const walletAddressBytesLen = 32 -var initialDelegationValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1250)) -var zeroValue = big.NewInt(0) -var oneEGLD = big.NewInt(1000000000000000000) -var minimumStakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(2500)) - // Test description: // Test that delegation contract created with MakeNewContractFromValidatorData works properly // Also check that delegate and undelegate works properly and the top-up remain the same if every delegator undelegates. @@ -237,7 +224,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 2. Set the initial state for the owner and the 2 delegators") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -252,12 +239,12 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi "newValidatorOwner", validatorOwner.Bech32, "delegator1", delegator1.Bech32, "delegator2", delegator2.Bech32) log.Info("Step 3. Do a stake transaction for the validator key and test that the new key is on queue / auction list and the correct topup") - stakeValue := big.NewInt(0).Set(minimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) stakeValue.Add(stakeValue, addedStakedValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -268,8 +255,8 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue / auction list and the correct topup") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := generateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForConvertOperation) - convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, maxNumOfBlockToGenerateWhenExecutingTx) + txConvert := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -283,35 +270,35 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700") - delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) - txDelegate1 := generateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) - delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + txDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - txDelegate2 := generateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) - delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp := big.NewInt(0).Mul(oneEGLD, big.NewInt(700)) + expectedTopUp := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(700)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) log.Info("6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500") - unDelegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) + unDelegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate1 := generateTransaction(delegator1.Bytes, 1, delegationAddress, zeroValue, txDataField, gasLimitForDelegate) - unDelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + txUnDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + unDelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate1Tx) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate2 := generateTransaction(delegator2.Bytes, 1, delegationAddress, zeroValue, txDataField, gasLimitForDelegate) - unDelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txUnDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + unDelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate2Tx) - expectedTopUp = big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) + expectedTopUp = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) } @@ -332,7 +319,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc // in staking ph 2/3.5 we do not find the bls key on the validator statistics _, found := statistics[blsKey] require.False(t, found) - require.Equal(t, queuedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.QueuedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) } func testBLSKeyIsInAuction( @@ -346,7 +333,7 @@ func testBLSKeyIsInAuction( numNodes int, owner []byte, ) { - require.Equal(t, stakedStatus, getBLSKeyStatus(t, metachainNode, blsKeyBytes)) + require.Equal(t, staking.StakedStatus, staking.GetBLSKeyStatus(t, metachainNode, blsKeyBytes)) err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) @@ -387,7 +374,7 @@ func testBLSKeyIsInAuction( // in staking ph 4 we should find the key in the validators statics validatorInfo, found := validatorStatistics[blsKey] require.True(t, found) - require.Equal(t, auctionStatus, validatorInfo.ValidatorStatus) + require.Equal(t, staking.AuctionStatus, validatorInfo.ValidatorStatus) } func testBLSKeysAreInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte, blsKeys []string, totalTopUp *big.Int, actionListSize int) { @@ -411,7 +398,7 @@ func testBLSKeysAreInQueueOrAuction(t *testing.T, metachainNode chainSimulatorPr // in staking ph 2/3.5 we do not find the bls key on the validator statistics _, found := statistics[blsKey] require.False(t, found) - require.Equal(t, queuedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.QueuedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) } } @@ -567,7 +554,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 2. Set the initial state for 2 owners") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwnerA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -580,15 +567,15 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 3. Do 2 stake transactions and test that the new keys are on queue / auction list and have the correct topup") - topupA := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) - stakeValueA := big.NewInt(0).Add(minimumStakeValue, topupA) + topupA := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + stakeValueA := big.NewInt(0).Add(staking.MinimumStakeValue, topupA) txStakeA := generateStakeTransaction(t, cs, validatorOwnerA, blsKeys[0], stakeValueA) - topupB := big.NewInt(0).Mul(oneEGLD, big.NewInt(200)) - stakeValueB := big.NewInt(0).Add(minimumStakeValue, topupB) + topupB := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) + stakeValueB := big.NewInt(0).Add(staking.MinimumStakeValue, topupB) txStakeB := generateStakeTransaction(t, cs, validatorOwnerB, blsKeys[1], stakeValueB) - stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeA, txStakeB}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeA, txStakeB}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 2, len(stakeTxs)) @@ -603,7 +590,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * txConvertA := generateConvertToStakingProviderTransaction(t, cs, validatorOwnerA) txConvertB := generateConvertToStakingProviderTransaction(t, cs, validatorOwnerB) - convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvertA, txConvertB}, maxNumOfBlockToGenerateWhenExecutingTx) + convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvertA, txConvertB}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 2, len(convertTxs)) @@ -689,7 +676,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() // unbond succeeded because the nodes were on queue - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 1, notStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 1, staking.NotStakedStatus) }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -721,7 +708,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 2, unStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 2, staking.UnStakedStatus) }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -753,7 +740,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 3, unStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 3, staking.UnStakedStatus) }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -785,7 +772,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 4, unStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 4, staking.UnStakedStatus) }) } @@ -808,7 +795,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 2. Set the initial state for 1 owner and 1 delegator") mintValue := big.NewInt(10001) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) owner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -821,11 +808,11 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 3. Do a stake transaction and test that the new key is on queue / auction list and has the correct topup") - topup := big.NewInt(0).Mul(oneEGLD, big.NewInt(99)) - stakeValue := big.NewInt(0).Add(minimumStakeValue, topup) + topup := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(99)) + stakeValue := big.NewInt(0).Add(staking.MinimumStakeValue, topup) txStake := generateStakeTransaction(t, cs, owner, blsKeys[0], stakeValue) - stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStake}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStake}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(stakeTxs)) @@ -838,7 +825,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta txConvert := generateConvertToStakingProviderTransaction(t, cs, owner) - convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvert}, maxNumOfBlockToGenerateWhenExecutingTx) + convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvert}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(convertTxs)) @@ -850,30 +837,30 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], topup, 1) log.Info("Step 5. Add 2 nodes in the staking contract") - txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s@%s@%s", blsKeys[1], mockBLSSignature+"02", blsKeys[2], mockBLSSignature+"03") - ownerNonce := getNonce(t, cs, owner) - txAddNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, gasLimitForStakeOperation) + txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s@%s@%s", blsKeys[1], staking.MockBLSSignature+"02", blsKeys[2], staking.MockBLSSignature+"03") + ownerNonce := staking.GetNonce(t, cs, owner) + txAddNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) - addNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txAddNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + addNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txAddNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(addNodesTxs)) log.Info("Step 6. Delegate 5000 EGLD to the contract") - delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(5000)) + delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(5000)) txDataFieldDelegate := "delegate" - delegatorNonce := getNonce(t, cs, delegator) - txDelegate := generateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, gasLimitForStakeOperation) + delegatorNonce := staking.GetNonce(t, cs, delegator) + txDelegate := staking.GenerateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, staking.GasLimitForStakeOperation) - delegateTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txDelegate}, maxNumOfBlockToGenerateWhenExecutingTx) + delegateTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txDelegate}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(delegateTxs)) log.Info("Step 7. Stake the 2 nodes") txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s@%s", blsKeys[1], blsKeys[2]) - ownerNonce = getNonce(t, cs, owner) - txStakeNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, owner) + txStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) - stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(stakeNodesTxs)) @@ -886,10 +873,10 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 8. UnStake 2 nodes (latest staked)") txDataFieldUnStakeNodes := fmt.Sprintf("unStakeNodes@%s@%s", blsKeys[1], blsKeys[2]) - ownerNonce = getNonce(t, cs, owner) - txUnStakeNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, owner) + txUnStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, staking.GasLimitForStakeOperation) - unStakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + unStakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(unStakeNodesTxs)) @@ -904,58 +891,25 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 9. Unbond the 2 nodes (that were un staked)") txDataFieldUnBondNodes := fmt.Sprintf("unBondNodes@%s@%s", blsKeys[1], blsKeys[2]) - ownerNonce = getNonce(t, cs, owner) - txUnBondNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, owner) + txUnBondNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, staking.GasLimitForStakeOperation) - unBondNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnBondNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + unBondNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnBondNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(unBondNodesTxs)) err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the nodes assert.Nil(t, err) - keyStatus := getAllNodeStates(t, metachainNode, delegationAddress) + keyStatus := staking.GetAllNodeStates(t, metachainNode, delegationAddress) require.Equal(t, len(blsKeys), len(keyStatus)) // key[0] should be staked - require.Equal(t, stakedStatus, keyStatus[blsKeys[0]]) + require.Equal(t, staking.StakedStatus, keyStatus[blsKeys[0]]) // key[1] and key[2] should be unstaked (unbond was not executed) require.Equal(t, nodesStatusAfterUnBondTx, keyStatus[blsKeys[1]]) require.Equal(t, nodesStatusAfterUnBondTx, keyStatus[blsKeys[2]]) } -func getNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 { - account, err := cs.GetAccount(address) - require.Nil(t, err) - - return account.Nonce -} - -func getAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string { - scQuery := &process.SCQuery{ - ScAddress: address, - FuncName: "getAllNodeStates", - CallerAddr: vm.StakingSCAddress, - CallValue: big.NewInt(0), - } - result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) - require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) - - m := make(map[string]string) - status := "" - for _, resultData := range result.ReturnData { - if len(resultData) != 96 { - // not a BLS key - status = string(resultData) - continue - } - - m[hex.EncodeToString(resultData)] = status - } - - return m -} - func generateStakeTransaction( t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, @@ -966,8 +920,8 @@ func generateStakeTransaction( account, err := cs.GetAccount(owner) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeyHex, mockBLSSignature) - return generateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeyHex, staking.MockBLSSignature) + return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) } func generateConvertToStakingProviderTransaction( @@ -979,7 +933,7 @@ func generateConvertToStakingProviderTransaction( require.Nil(t, err) txDataField := fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - return generateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForConvertOperation) + return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) } // Test description @@ -1174,7 +1128,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat delegator1, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator1Bytes) delegator2Bytes := generateWalletAddressBytes() delegator2, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator2Bytes) - initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each + initialFunds := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each addresses := []*dtos.AddressState{ {Address: validatorOwner, Balance: initialFunds.String()}, {Address: delegator1, Balance: initialFunds.String()}, @@ -1184,11 +1138,11 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) // Step 3: Create a new delegation contract - maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(51000)) // 51000 EGLD cap - txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, initialDelegationValue, + maxDelegationCap := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap + txCreateDelegationContract := staking.GenerateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), gasLimitForDelegationContractCreationOperation) - createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) + createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, createDelegationContractTx) @@ -1217,12 +1171,12 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) signatures := getSignatures(delegationContractAddressBytes, validatorSecretKeysBytes) - txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddressBytes, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) - addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + txAddNodes := staking.GenerateTransaction(validatorOwnerBytes, 1, delegationContractAddressBytes, staking.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys := getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) @@ -1230,8 +1184,8 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, blsKeys[0], hex.EncodeToString(notStakedKeys[0])) require.Equal(t, 0, len(unStakedKeys)) - expectedTopUp := big.NewInt(0).Set(initialDelegationValue) - expectedTotalStaked := big.NewInt(0).Set(initialDelegationValue) + expectedTopUp := big.NewInt(0).Set(staking.InitialDelegationValue) + expectedTotalStaked := big.NewInt(0).Set(staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1239,16 +1193,16 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{validatorOwnerBytes}) require.Nil(t, err) - require.Equal(t, initialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - txDelegate1 := generateTransaction(delegator1Bytes, 0, delegationContractAddressBytes, initialDelegationValue, "delegate", gasLimitForDelegate) - delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + txDelegate1 := staking.GenerateTransaction(delegator1Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, initialDelegationValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, initialDelegationValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, staking.InitialDelegationValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1256,15 +1210,15 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) require.Nil(t, err) - require.Equal(t, initialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - txDelegate2 := generateTransaction(delegator2Bytes, 0, delegationContractAddressBytes, initialDelegationValue, "delegate", gasLimitForDelegate) - delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txDelegate2 := staking.GenerateTransaction(delegator2Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, initialDelegationValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, initialDelegationValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, staking.InitialDelegationValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1272,20 +1226,20 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) require.Nil(t, err) - require.Equal(t, initialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 4: Perform stakeNodes - txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddressBytes, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForStakeOperation) - stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + txStakeNodes := staking.GenerateTransaction(validatorOwnerBytes, 2, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, initialDelegationValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, initialDelegationValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1303,13 +1257,13 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the staked state // The total active stake should be reduced by the amount undelegated - txUndelegate1 := generateTransaction(delegator1Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(initialDelegationValue.Bytes())), gasLimitForUndelegateOperation) - undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + txUndelegate1 := staking.GenerateTransaction(delegator1Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate1Tx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, initialDelegationValue) - expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, initialDelegationValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) + expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1317,9 +1271,9 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) require.Nil(t, err) - require.Equal(t, zeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1331,22 +1285,22 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the unStaked state // The total active stake should be reduced by the amount undelegated - txUndelegate2 := generateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(initialDelegationValue.Bytes())), gasLimitForUndelegateOperation) - undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txUndelegate2 := staking.GenerateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate2Tx) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, "1250000000000000000000", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) - require.Equal(t, zeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) + require.Equal(t, staking.ZeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) require.Nil(t, err) require.Equal(t, "0", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) // still staked until epoch change - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1357,7 +1311,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) @@ -1420,21 +1374,6 @@ func getNodesFromContract(returnData [][]byte) ([][]byte, [][]byte, [][]byte) { return stakedKeys, notStakedKeys, unStakedKeys } -func getBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { - scQuery := &process.SCQuery{ - ScAddress: vm.StakingSCAddress, - FuncName: "getBLSKeyStatus", - CallerAddr: vm.StakingSCAddress, - CallValue: big.NewInt(0), - Arguments: [][]byte{blsKey}, - } - result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) - require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) - - return string(result.ReturnData[0]) -} - func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) *big.Int { scQuery := &process.SCQuery{ ScAddress: vm.ValidatorSCAddress, @@ -1445,7 +1384,7 @@ func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHand } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) if len(result.ReturnData[0]) == 0 { return big.NewInt(0) @@ -1454,21 +1393,6 @@ func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHand return big.NewInt(0).SetBytes(result.ReturnData[0]) } -func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - return &transaction.Transaction{ - Nonce: nonce, - Value: value, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } -} - // Test description: // Test that merging delegation with whiteListForMerge and mergeValidatorToDelegationWithWhitelist contracts still works properly // Test that their topups will merge too and will be used by auction list computing. @@ -1632,7 +1556,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(3000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -1641,12 +1565,12 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat require.Nil(t, err) log.Info("Step 1. User A: - stake 1 node to have 100 egld more than minimum stake value") - stakeValue := big.NewInt(0).Set(minimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1658,8 +1582,8 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 2. Execute MakeNewContractFromValidatorData for User A") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := generateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForConvertOperation) - convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, maxNumOfBlockToGenerateWhenExecutingTx) + txConvert := staking.GenerateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -1671,12 +1595,12 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 3. User B: - stake 1 node to have 100 egld more") - stakeValue = big.NewInt(0).Set(minimumStakeValue) - addedStakedValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + addedStakedValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1694,8 +1618,8 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 4. User A : whitelistForMerge@addressB") txDataField = fmt.Sprintf("whitelistForMerge@%s", hex.EncodeToString(validatorB.Bytes)) - whitelistForMerge := generateTransaction(validatorA.Bytes, 2, delegationAddress, zeroValue, txDataField, gasLimitForDelegate) - whitelistForMergeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(whitelistForMerge, maxNumOfBlockToGenerateWhenExecutingTx) + whitelistForMerge := staking.GenerateTransaction(validatorA.Bytes, 2, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + whitelistForMergeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(whitelistForMerge, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, whitelistForMergeTx) @@ -1705,8 +1629,8 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 5. User A : mergeValidatorToDelegationWithWhitelist") txDataField = fmt.Sprintf("mergeValidatorToDelegationWithWhitelist@%s", hex.EncodeToString(delegationAddress)) - txConvert = generateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForMergeOperation) - convertTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, maxNumOfBlockToGenerateWhenExecutingTx) + txConvert = staking.GenerateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForMergeOperation) + convertTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -1719,7 +1643,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat decodedBLSKey1, _ = hex.DecodeString(blsKeys[1]) require.Equal(t, delegationAddress, getBLSKeyOwner(t, metachainNode, decodedBLSKey1)) - expectedTopUpValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(200)) + expectedTopUpValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) require.Equal(t, expectedTopUpValue, getBLSTopUpValue(t, metachainNode, delegationAddress)) } @@ -1733,7 +1657,7 @@ func getBLSKeyOwner(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go similarity index 68% rename from integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go rename to integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index af50d56c821..1b197493ef4 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -1,8 +1,10 @@ -package staking +package stakingProvider import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "math/big" "testing" "time" @@ -17,6 +19,10 @@ import ( "github.com/stretchr/testify/require" ) +const ( + defaultPathToInitialConfig = "../../../../cmd/node/config/" +) + func TestStakingProviderWithNodes(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -65,7 +71,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(big.NewInt(5000), oneEGLD) + mintValue := big.NewInt(0).Mul(big.NewInt(5000), staking.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) require.Nil(t, err) @@ -76,8 +82,8 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati // create delegation contract stakeValue, _ := big.NewInt(0).SetString("4250000000000000000000", 10) dataField := "createNewDelegationContract@00@0ea1" - txStake := generateTransaction(validatorOwner.Bytes, getNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, staking.GetNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -88,53 +94,53 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) - txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], mockBLSSignature+"02") - ownerNonce := getNonce(t, cs, validatorOwner) - txAddNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, gasLimitForStakeOperation) - addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], staking.MockBLSSignature+"02") + ownerNonce := staking.GetNonce(t, cs, validatorOwner) + txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s", blsKeys[0]) - ownerNonce = getNonce(t, cs, validatorOwner) - txStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, validatorOwner) + txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) - stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(stakeNodesTxs)) metachainNode := cs.GetNodeHandler(core.MetachainShardId) decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) - status := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "queued", status) // activate staking v4 err = cs.GenerateBlocksUntilEpochIsReached(int32(stakingV4ActivationEpoch)) require.Nil(t, err) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "unStaked", status) - result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + result := staking.GetAllNodeStates(t, metachainNode, delegationAddressBytes) require.NotNil(t, result) require.Equal(t, "unStaked", result[blsKeys[0]]) - ownerNonce = getNonce(t, cs, validatorOwner) + ownerNonce = staking.GetNonce(t, cs, validatorOwner) reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - reStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, gasLimitForStakeOperation) - reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + reStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, staking.GasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "staked", status) - result = getAllNodeStates(t, metachainNode, delegationAddressBytes) + result = staking.GetAllNodeStates(t, metachainNode, delegationAddressBytes) require.NotNil(t, result) require.Equal(t, "staked", result[blsKeys[0]]) err = cs.GenerateBlocks(20) require.Nil(t, err) - checkValidatorStatus(t, cs, blsKeys[0], "auction") + staking.CheckValidatorStatus(t, cs, blsKeys[0], "auction") } From 5b6ccb927cb6aa21314e1915081409f02f9acd79 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 13:21:13 +0300 Subject: [PATCH 34/41] fix test --- .../staking/stakingProvider/delegation_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 4b2354eb0fe..4b44f2077e2 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -1176,7 +1176,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) require.NotNil(t, addNodesTx) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys := getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) @@ -1239,7 +1239,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1273,7 +1273,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) require.Equal(t, staking.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1300,7 +1300,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, "0", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) // still staked until epoch change - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1311,7 +1311,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) From d9ef2e90306e215cb4db88754d1747cce049f2e6 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 13:37:40 +0300 Subject: [PATCH 35/41] fixes --- .../chainSimulator/staking/helpers.go | 21 ++++++++++++------- .../chainSimulator/staking/jail/jail_test.go | 3 ++- .../staking/stake/simpleStake_test.go | 2 +- .../staking/stake/stakeAndUnStake_test.go | 2 +- .../stakingProvider/delegation_test.go | 2 +- .../stakingProviderWithNodesinQueue_test.go | 3 +-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/integrationTests/chainSimulator/staking/helpers.go b/integrationTests/chainSimulator/staking/helpers.go index 550e227a7f2..ed42733f5a4 100644 --- a/integrationTests/chainSimulator/staking/helpers.go +++ b/integrationTests/chainSimulator/staking/helpers.go @@ -2,6 +2,9 @@ package staking import ( "encoding/hex" + "math/big" + "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -11,8 +14,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" "github.com/stretchr/testify/require" - "math/big" - "testing" ) const ( @@ -33,12 +34,14 @@ const ( AuctionStatus = "auction" ) -var InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) -var ZeroValue = big.NewInt(0) - -var MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) -var OneEGLD = big.NewInt(1000000000000000000) +var ( + ZeroValue = big.NewInt(0) + InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) + MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) + OneEGLD = big.NewInt(1000000000000000000) +) +// GetNonce will return the nonce of the provided address func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 { account, err := cs.GetAccount(address) require.Nil(t, err) @@ -46,6 +49,7 @@ func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, ad return account.Nonce } +// GenerateTransaction will generate a transaction based on input data func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { return &transaction.Transaction{ Nonce: nonce, @@ -61,6 +65,7 @@ func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi } } +// GetBLSKeyStatus will return the bls key status func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { scQuery := &process.SCQuery{ ScAddress: vm.StakingSCAddress, @@ -76,6 +81,7 @@ func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandl return string(result.ReturnData[0]) } +// GetAllNodeStates will return the status of all the nodes that belong to the provided address func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string { scQuery := &process.SCQuery{ ScAddress: address, @@ -102,6 +108,7 @@ func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHand return m } +// CheckValidatorStatus will compare the status of the provided bls key with the provided expected status func CheckValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { err := cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index c16d3c60df2..496db236d2c 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -3,7 +3,7 @@ package jail import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "math/big" "testing" "time" @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 4bbaa1ef74c..a4f63e44f28 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -3,7 +3,6 @@ package stake import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -12,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 712f7ed5824..2b2246df713 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -3,7 +3,6 @@ package stake import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -15,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 4b44f2077e2..3c7edc79fee 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" logger "github.com/multiversx/mx-chain-logger-go" "math/big" "strings" @@ -21,6 +20,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 1b197493ef4..99cc7a66518 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -3,8 +3,6 @@ package stakingProvider import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" - "math/big" "testing" "time" @@ -12,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" From 7b5677b67274a1efb124c8433f39ceac030bc58a Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 3 Apr 2024 09:15:39 +0300 Subject: [PATCH 36/41] fixes after review --- .../staking/{helpers.go => common.go} | 26 +++++++++++++------ .../stakingProvider/delegation_test.go | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) rename integrationTests/chainSimulator/staking/{helpers.go => common.go} (79%) diff --git a/integrationTests/chainSimulator/staking/helpers.go b/integrationTests/chainSimulator/staking/common.go similarity index 79% rename from integrationTests/chainSimulator/staking/helpers.go rename to integrationTests/chainSimulator/staking/common.go index ed42733f5a4..d358c0c966d 100644 --- a/integrationTests/chainSimulator/staking/helpers.go +++ b/integrationTests/chainSimulator/staking/common.go @@ -21,17 +21,27 @@ const ( txVersion = 1 mockTxSignature = "sig" - OkReturnCode = "ok" - UnStakedStatus = "unStaked" - MockBLSSignature = "010101" - GasLimitForStakeOperation = 50_000_000 - GasLimitForUnBond = 12_000_000 + // OkReturnCode the const for the ok return code + OkReturnCode = "ok" + // MockBLSSignature the const for a mocked bls signature + MockBLSSignature = "010101" + // GasLimitForStakeOperation the const for the gas limit value for the stake operation + GasLimitForStakeOperation = 50_000_000 + // GasLimitForUnBond the const for the gas limit value for the unBond operation + GasLimitForUnBond = 12_000_000 + // MaxNumOfBlockToGenerateWhenExecutingTx the const for the maximum number of block to generate when execute a transaction MaxNumOfBlockToGenerateWhenExecutingTx = 7 - QueuedStatus = "queued" - StakedStatus = "staked" + // QueuedStatus the const for the queued status of a validators + QueuedStatus = "queued" + // StakedStatus the const for the staked status of a validators + StakedStatus = "staked" + // NotStakedStatus the const for the notStaked status of a validators NotStakedStatus = "notStaked" - AuctionStatus = "auction" + // AuctionStatus the const for the action status of a validators + AuctionStatus = "auction" + // UnStakedStatus the const for the unStaked status of a validators + UnStakedStatus = "unStaked" ) var ( diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 3c7edc79fee..653ab74f031 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/hex" "fmt" - logger "github.com/multiversx/mx-chain-logger-go" "math/big" "strings" "testing" @@ -27,6 +26,7 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) From 669f0e715e96d55eb143964dbcf0ac3b48e83826 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 3 Apr 2024 10:35:28 +0300 Subject: [PATCH 37/41] missing comments --- integrationTests/chainSimulator/staking/common.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/staking/common.go b/integrationTests/chainSimulator/staking/common.go index d358c0c966d..a8500a05995 100644 --- a/integrationTests/chainSimulator/staking/common.go +++ b/integrationTests/chainSimulator/staking/common.go @@ -45,10 +45,14 @@ const ( ) var ( - ZeroValue = big.NewInt(0) + // ZeroValue the variable for the zero big int + ZeroValue = big.NewInt(0) + // OneEGLD the variable for one egld value + OneEGLD = big.NewInt(1000000000000000000) + //InitialDelegationValue the variable for the initial delegation value InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) - MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) - OneEGLD = big.NewInt(1000000000000000000) + // MinimumStakeValue the variable for the minimum stake value + MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) ) // GetNonce will return the nonce of the provided address From bd41b675cd97acae0e0f5ab8a060d7178376238d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 8 Apr 2024 10:46:18 +0300 Subject: [PATCH 38/41] - added block timestamp + scripts update for the round duration --- common/constants.go | 3 +++ dataRetriever/blockchain/blockchain.go | 1 + dataRetriever/blockchain/metachain.go | 1 + node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 1 + scripts/testnet/include/config.sh | 3 ++- scripts/testnet/variables.sh | 2 ++ statusHandler/persister/persistentHandler.go | 1 + statusHandler/statusMetricsProvider.go | 1 + statusHandler/statusMetricsProvider_test.go | 4 ++++ 10 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index 5d4e15e9fc5..0476f1aa5e5 100644 --- a/common/constants.go +++ b/common/constants.go @@ -100,6 +100,9 @@ const MetricCurrentRound = "erd_current_round" // MetricNonce is the metric for monitoring the nonce of a node const MetricNonce = "erd_nonce" +// MetricBlockTimestamp is the metric for monitoring the timestamp of the last synchronized block +const MetricBlockTimestamp = "erd_block_timestamp" + // MetricProbableHighestNonce is the metric for monitoring the max speculative nonce received by the node by listening on the network const MetricProbableHighestNonce = "erd_probable_highest_nonce" diff --git a/dataRetriever/blockchain/blockchain.go b/dataRetriever/blockchain/blockchain.go index bf18ad64402..f8d011e5a08 100644 --- a/dataRetriever/blockchain/blockchain.go +++ b/dataRetriever/blockchain/blockchain.go @@ -69,6 +69,7 @@ func (bc *blockChain) SetCurrentBlockHeaderAndRootHash(header data.HeaderHandler bc.appStatusHandler.SetUInt64Value(common.MetricNonce, h.GetNonce()) bc.appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, h.GetRound()) + bc.appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, h.GetTimeStamp()) bc.mut.Lock() bc.currentBlockHeader = h.ShallowClone() diff --git a/dataRetriever/blockchain/metachain.go b/dataRetriever/blockchain/metachain.go index 179b1b84b0a..0ef4b1247c2 100644 --- a/dataRetriever/blockchain/metachain.go +++ b/dataRetriever/blockchain/metachain.go @@ -71,6 +71,7 @@ func (mc *metaChain) SetCurrentBlockHeaderAndRootHash(header data.HeaderHandler, mc.appStatusHandler.SetUInt64Value(common.MetricNonce, currHead.Nonce) mc.appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, currHead.Round) + mc.appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, currHead.GetTimeStamp()) mc.mut.Lock() mc.currentBlockHeader = currHead.ShallowClone() diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index ca2cd4e910a..94c61a4aeb0 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -30,6 +30,7 @@ func InitBaseMetrics(appStatusHandler core.AppStatusHandler) error { appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, initUint) appStatusHandler.SetUInt64Value(common.MetricNonce, initUint) + appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, initUint) appStatusHandler.SetUInt64Value(common.MetricCountConsensus, initUint) appStatusHandler.SetUInt64Value(common.MetricCountLeader, initUint) appStatusHandler.SetUInt64Value(common.MetricCountAcceptedBlocks, initUint) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 7da1a582626..f10707c64f0 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -23,6 +23,7 @@ func TestInitBaseMetrics(t *testing.T) { expectedKeys := []string{ common.MetricSynchronizedRound, common.MetricNonce, + common.MetricBlockTimestamp, common.MetricCountConsensus, common.MetricCountLeader, common.MetricCountAcceptedBlocks, diff --git a/scripts/testnet/include/config.sh b/scripts/testnet/include/config.sh index 8fa1d11b3db..25f836a84b7 100644 --- a/scripts/testnet/include/config.sh +++ b/scripts/testnet/include/config.sh @@ -20,7 +20,8 @@ generateConfig() { -num-of-observers-in-metachain $TMP_META_OBSERVERCOUNT \ -metachain-consensus-group-size $META_CONSENSUS_SIZE \ -stake-type $GENESIS_STAKE_TYPE \ - -hysteresis $HYSTERESIS + -hysteresis $HYSTERESIS \ + -round-duration $ROUND_DURATION_IN_MS popd } diff --git a/scripts/testnet/variables.sh b/scripts/testnet/variables.sh index f3fb44c5866..c5a5b013523 100644 --- a/scripts/testnet/variables.sh +++ b/scripts/testnet/variables.sh @@ -62,6 +62,8 @@ export META_VALIDATORCOUNT=3 export META_OBSERVERCOUNT=1 export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT +export ROUND_DURATION_IN_MS=6000 + # MULTI_KEY_NODES if set to 1, one observer will be generated on each shard that will handle all generated keys export MULTI_KEY_NODES=0 diff --git a/statusHandler/persister/persistentHandler.go b/statusHandler/persister/persistentHandler.go index b2d9c750082..93561363247 100644 --- a/statusHandler/persister/persistentHandler.go +++ b/statusHandler/persister/persistentHandler.go @@ -58,6 +58,7 @@ func (psh *PersistentStatusHandler) initMap() { psh.persistentMetrics.Store(common.MetricNumProcessedTxs, initUint) psh.persistentMetrics.Store(common.MetricNumShardHeadersProcessed, initUint) psh.persistentMetrics.Store(common.MetricNonce, initUint) + psh.persistentMetrics.Store(common.MetricBlockTimestamp, initUint) psh.persistentMetrics.Store(common.MetricCurrentRound, initUint) psh.persistentMetrics.Store(common.MetricNonceAtEpochStart, initUint) psh.persistentMetrics.Store(common.MetricRoundAtEpochStart, initUint) diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index 99f15ad1bf6..d0f841468b8 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -340,6 +340,7 @@ func (sm *statusMetrics) saveUint64NetworkMetricsInMap(networkMetrics map[string currentNonce := sm.uint64Metrics[common.MetricNonce] nonceAtEpochStart := sm.uint64Metrics[common.MetricNonceAtEpochStart] networkMetrics[common.MetricNonce] = currentNonce + networkMetrics[common.MetricBlockTimestamp] = sm.uint64Metrics[common.MetricBlockTimestamp] networkMetrics[common.MetricHighestFinalBlock] = sm.uint64Metrics[common.MetricHighestFinalBlock] networkMetrics[common.MetricCurrentRound] = currentRound networkMetrics[common.MetricRoundAtEpochStart] = roundNumberAtEpochStart diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index 5572b1754f8..fbf74ad26fc 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -231,6 +231,7 @@ func TestStatusMetrics_NetworkMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricCurrentRound, 200) sm.SetUInt64Value(common.MetricRoundAtEpochStart, 100) sm.SetUInt64Value(common.MetricNonce, 180) + sm.SetUInt64Value(common.MetricBlockTimestamp, 18000) sm.SetUInt64Value(common.MetricHighestFinalBlock, 181) sm.SetUInt64Value(common.MetricNonceAtEpochStart, 95) sm.SetUInt64Value(common.MetricEpochNumber, 1) @@ -240,6 +241,7 @@ func TestStatusMetrics_NetworkMetrics(t *testing.T) { "erd_current_round": uint64(200), "erd_round_at_epoch_start": uint64(100), "erd_nonce": uint64(180), + "erd_block_timestamp": uint64(18000), "erd_highest_final_nonce": uint64(181), "erd_nonce_at_epoch_start": uint64(95), "erd_epoch_number": uint64(1), @@ -270,6 +272,7 @@ func TestStatusMetrics_StatusMetricsMapWithoutP2P(t *testing.T) { sm.SetUInt64Value(common.MetricCurrentRound, 100) sm.SetUInt64Value(common.MetricRoundAtEpochStart, 200) sm.SetUInt64Value(common.MetricNonce, 300) + sm.SetUInt64Value(common.MetricBlockTimestamp, 30000) sm.SetStringValue(common.MetricAppVersion, "400") sm.SetUInt64Value(common.MetricRoundsPassedInCurrentEpoch, 95) sm.SetUInt64Value(common.MetricNoncesPassedInCurrentEpoch, 1) @@ -281,6 +284,7 @@ func TestStatusMetrics_StatusMetricsMapWithoutP2P(t *testing.T) { require.Equal(t, uint64(100), res[common.MetricCurrentRound]) require.Equal(t, uint64(200), res[common.MetricRoundAtEpochStart]) require.Equal(t, uint64(300), res[common.MetricNonce]) + require.Equal(t, uint64(30000), res[common.MetricBlockTimestamp]) require.Equal(t, "400", res[common.MetricAppVersion]) require.NotContains(t, res, common.MetricRoundsPassedInCurrentEpoch) require.NotContains(t, res, common.MetricNoncesPassedInCurrentEpoch) From 5afe305f43530adfb5bf98a31a6fa37f4dc467ae Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 12:13:48 +0300 Subject: [PATCH 39/41] fix after merge --- cmd/node/config/prefs.toml | 4 ++-- config/overridableConfig/configOverriding_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/node/config/prefs.toml b/cmd/node/config/prefs.toml index 42e16508608..8f3a2343a79 100644 --- a/cmd/node/config/prefs.toml +++ b/cmd/node/config/prefs.toml @@ -38,8 +38,8 @@ # so that certain config values need to remain the same during upgrades. # (for example, an Elasticsearch user wants external.toml->ElasticSearchConnector.Enabled to remain true all the time during upgrades, while the default # configuration of the node has the false value) - # The Path indicates what value to change, while Value represents the new value in string format. The node operator must make sure - # to follow the same type of the original value (ex: uint32: "37", float32: "37.0", bool: "true") + # The Path indicates what value to change, while Value represents the new value. The node operator must make sure + # to follow the same type of the original value (ex: uint32: 37, float32: 37.0, bool: true) # Also, the Value can be a struct (ex: { StartEpoch = 0, Version = "1.5" }) or an array (ex: [{ StartEpoch = 0, Version = "1.4" }, { StartEpoch = 1, Version = "1.5" }]) # File represents the file name that holds the configuration. Currently, the supported files are: # api.toml, config.toml, economics.toml, enableEpochs.toml, enableRounds.toml, external.toml, fullArchiveP2P.toml, p2p.toml, ratings.toml, systemSmartContractsConfig.toml diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index a15a1b6a4ad..5e23a2bacda 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -88,7 +88,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{ApiRoutesConfig: &config.ApiRoutesConfig{}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: "true", File: "api.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: true, File: "api.toml"}}, configs) require.NoError(t, err) require.True(t, configs.ApiRoutesConfig.Logging.LoggingEnabled) }) @@ -121,7 +121,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{RatingsConfig: &config.RatingsConfig{}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: "37", File: "ratings.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: 37, File: "ratings.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint32(37), configs.RatingsConfig.General.StartRating) }) @@ -131,7 +131,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{SystemSCConfig: &config.SystemSmartContractsConfig{}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: "37", File: "systemSmartContractsConfig.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: 37, File: "systemSmartContractsConfig.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint64(37), configs.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod) }) From ec0a7251a631c5283b8c85a9b877a9edb58d0bcc Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 13:23:07 +0300 Subject: [PATCH 40/41] golangci-lint fix --- .github/workflows/golangci-lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 611fadc3d08..47044a12169 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -5,6 +5,8 @@ on: - master pull_request: branches: [ master, feat/*, rc/* ] + workflow_dispatch: + branches: [ master, feat/*, rc/* ] permissions: contents: read From d9412ac23f8d1dca2e27a3ee93c5754e99f76fac Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 13:28:56 +0300 Subject: [PATCH 41/41] small fix --- .github/workflows/golangci-lint.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 47044a12169..1cc46af26c8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -6,7 +6,6 @@ on: pull_request: branches: [ master, feat/*, rc/* ] workflow_dispatch: - branches: [ master, feat/*, rc/* ] permissions: contents: read