Skip to content

Commit

Permalink
Merge pull request #282 from nspcc-dev/feature/internal-consensus-wit…
Browse files Browse the repository at this point in the history
…h-autodeploy

Internal consensus mode of Inner Ring with Sidechain auto-deploy
  • Loading branch information
roman-khimov authored Dec 22, 2023
2 parents e78f577 + f54fdc7 commit 95acc4b
Show file tree
Hide file tree
Showing 28 changed files with 254 additions and 376 deletions.
1 change: 0 additions & 1 deletion .basic_services
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Services start/stop order
# Will start from top to bottom and stop in reverse
nats
ir
storage
2 changes: 1 addition & 1 deletion .bootstrap_services
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Will start from top to bottom and stop in reverse
basenet
chain
morph_chain
ir
14 changes: 5 additions & 9 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ NEO_GO_PLATFORM=linux-amd64
NEO_GO_URL=https://github.com/nspcc-dev/neo-go/releases/download/v${NEOGO_VERSION}/neo-go-${NEO_GO_PLATFORM}

# NeoFS InnerRing nodes
IR_VERSION=0.38.1
IR_VERSION=0.39.1
IR_IMAGE=nspccdev/neofs-ir

# NeoFS Storage nodes
NODE_VERSION=0.38.1
NODE_VERSION=0.39.1
NODE_IMAGE=nspccdev/neofs-storage

# NATS Server
Expand All @@ -44,21 +44,17 @@ S3_GW_IMAGE=nspccdev/neofs-s3-gw
COREDNS_VERSION=v016
COREDNS_IMAGE=nspccdev/coredns

# NeoFS LOCODE database
LOCODE_DB_URL=https://github.com/nspcc-dev/neofs-locode-db/releases/download/v0.3.0/locode_db.gz
#LOCODE_DB_PATH=/path/to/locode_db

# NeoFS CLI binary
NEOFS_CLI_URL=https://github.com/nspcc-dev/neofs-node/releases/download/v0.38.1/neofs-cli-amd64.tar.gz
NEOFS_CLI_URL=https://github.com/nspcc-dev/neofs-node/releases/download/v0.39.1/neofs-cli-amd64.tar.gz
#NEOFS_CLI_PATH=/path/to/neofs-cli-binary

# NeoFS ADM tool binary
NEOFS_ADM_VERSION=v0.38.1
NEOFS_ADM_VERSION=v0.39.1
NEOFS_ADM_URL=https://github.com/nspcc-dev/neofs-node/releases/download/${NEOFS_ADM_VERSION}/neofs-adm-amd64.tar.gz
#NEOFS_ADM_PATH=/path/to/neofs-adm-binary

# Compiled NeoFS Smart Contracts
NEOFS_CONTRACTS_VERSION=v0.17.0
NEOFS_CONTRACTS_VERSION=v0.19.1
NEOFS_CONTRACTS_URL=https://github.com/nspcc-dev/neofs-contract/releases/download/${NEOFS_CONTRACTS_VERSION}/neofs-contract-${NEOFS_CONTRACTS_VERSION}.tar.gz
#NEOFS_CONTRACTS_PATH=/path/to/unpacked/neofs-contracts-dir

Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PULL_SVCS = $(shell find ${ENABLED_SVCS_DIRS} -type f -name 'docker-compose.yml'
HOSTS_LINES = $(shell grep -Rl IPV4_PREFIX ./services/* | grep .hosts)

# Paths to protocol.privnet.yml
MORPH_CHAIN_PROTOCOL = './services/morph_chain/protocol.privnet.yml'
NEOFS_CHAIN_PROTOCOL = './services/ir/cfg/config.yml'
CHAIN_PROTOCOL = './services/chain/protocol.privnet.yml'

# List of grepped environment variables from *.env
Expand Down Expand Up @@ -125,10 +125,9 @@ up/bootstrap: get vendor/hosts
@./vendor/neo-go contract deploy --wallet-config wallets/config.yml --in vendor/contracts/neofs/neofs_contract.nef --manifest vendor/contracts/neofs/config.json --force -r http://main-chain.neofs.devenv:30333 [ true ffffffffffffffffffffffffffffffffffffffff [ 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 ] [ InnerRingCandidateFee 10000000000 WithdrawFee 100000000 ] ]
@echo "Waiting for deployment to happen" && sleep 2
@NEOGO=vendor/neo-go WALLET=wallets/wallet.json CONFIG=wallets/config.yml ./bin/deposit.sh
@./vendor/neofs-adm --config neofs-adm.yml morph init --alphabet-wallets ./services/ir --contracts vendor/contracts || die "Failed to initialize Alphabet wallets"
@for f in ./services/storage/wallet*.json; do echo "Transfer GAS to wallet $${f}" && ./vendor/neofs-adm -c neofs-adm.yml morph refill-gas --storage-wallet $${f} --gas 10.0 --alphabet-wallets services/ir || die "Failed to transfer GAS to alphabet wallets"; done
$(call error_handler,$@);
@echo "NeoFS sidechain environment is deployed"
@echo "NeoFS chain environment is deployed"

.PHONY: up/testing
up/testing:
Expand Down Expand Up @@ -232,9 +231,9 @@ clean:
.PHONY: env
env:
@$(foreach envvar,$(GREP_DOTENV),echo $(envvar);)
@echo MORPH_BLOCK_TIME=$(shell grep 'TimePerBlock' $(MORPH_CHAIN_PROTOCOL) | awk '{print $$2}')
@echo NEOFS_CHAIN_BLOCK_TIME=$(shell grep 'time_per_block' $(NEOFS_CHAIN_PROTOCOL) | awk '{print $$2}')
@echo MAINNET_BLOCK_TIME=$(shell grep 'TimePerBlock' $(CHAIN_PROTOCOL) | awk '{print $$2}')
@echo MORPH_MAGIC=$(shell grep 'Magic' $(MORPH_CHAIN_PROTOCOL) | awk '{print $$2}')
@echo NEOFS_CHAIN_MAGIC=$(shell grep 'magic' $(NEOFS_CHAIN_PROTOCOL) | awk '{print $$2}')

# Restart storage nodes with clean volumes
.PHONY: restart.storage-clean
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ password of inner ring wallet is `one`. See examples in `make help`.

```
$ make update.epoch_duration val=30
Changing EpochDuration configration value to 30
Changing EpochDuration configuration value to 30
Enter account NNudMSGzEoktFzdYGYoNb3bzHzbmM1genF password >
Sent invocation transaction dbb8c1145b6d10f150135630e13bb0dc282023163f5956c6945a60db0cb45cb0
Updating NeoFS epoch to 2
Expand All @@ -102,7 +102,6 @@ guide](docs/macOS.md) in `docs` directory.
│   ├── basenet
│   ├── chain
│   ├── ir
│   ├── morph_chain
│   └── storage
├── vendor # Temporary files and artifacts
└── wallets # Wallet files to manage GAS assets
Expand Down Expand Up @@ -150,7 +149,9 @@ Display addresses and host names for each running service, if available.

### clean

Clean up `vendor` directory.
Clean up `vendor` directory. Remove services' Docker volumes incl:
- stored NeoFS objects
- NeoFS chain state

## How to prepare environment to run neofs-testcases

Expand All @@ -167,7 +168,7 @@ From the root of the project, run:
sudo ./bin/update_hosts.sh
```
This script will change the subnet address in the services/coredns/Corefile and
in the services/morph_chain/protocol.privnet.yml configuration files.
in the services/ir/cfg/config.yml configuration files.
And it will add or change ip addresses in the /etc/hosts file.
After running the script, make sure that the contents of these files
are correct.
Expand Down
4 changes: 2 additions & 2 deletions bin/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ else
fi

# Change config value in side chain
echo "Changing ${KEY} configration value to ${VALUE}"
echo "Changing ${KEY} configuration value to ${VALUE}"

# shellcheck disable=SC2086
${NEOGO} contract invokefunction \
--wallet-config ${CONFIG_IMG} \
-a ${ADDR} --force \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
-r http://ir01.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
setConfig bytes:beefcafe \
string:${KEY} \
Expand Down
6 changes: 3 additions & 3 deletions bin/resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
source bin/helper.sh

# NeoGo binary path.
NEOGO="${NEOGO:-docker exec morph_chain neo-go}"
NEOGO="${NEOGO:-docker exec main_chain neo-go}"
# NNS contract script hash
output=$(curl -s --data '{ "id": 1, "jsonrpc": "2.0", "method": "getcontractstate", "params": [1] }' \
"http://morph-chain.${LOCAL_DOMAIN}:30333/") \
"http://ir01.${LOCAL_DOMAIN}:30333/") \
|| die "Cannot fetch NNS contract state"

NNS_ADDR=$(jq -r '.result.hash' <<< "$output") \
|| die "Cannot parse NNS contract hash: $NNS_ADDR"

${NEOGO} contract testinvokefunction \
-r "http://morph-chain.${LOCAL_DOMAIN}:30333" \
-r "http://ir01.${LOCAL_DOMAIN}:30333" \
"${NNS_ADDR}" resolve string:"${1}" int:16 \
| jq -r '.stack[0].value | if type=="array" then .[0].value else . end' \
| base64 -d \
Expand Down
39 changes: 19 additions & 20 deletions bin/tests/update_hosts_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ set -e

: "${TEST_HOSTS_FILE:=$(mktemp)}"
: "${TEST_COREFILE:=$(mktemp)}"
: "${TEST_MORPH_CHAIN_CONFIG:=$(mktemp)}"
: "${TEST_NEOFS_CHAIN_CONFIG:=$(mktemp)}"

: "${TEMP_ENV_FILE:=$(mktemp)}"

: "${BASE_HOSTS_FILE:=/etc/hosts}"
: "${BASE_COREFILE:=services/coredns/Corefile}"
: "${BASE_MORPH_CHAIN_CONFIG:=services/morph_chain/protocol.privnet.yml}"
: "${BASE_NEOFS_CHAIN_CONFIG:=services/ir/cfg/config.yml}"
: "${BASE_ENV_FILE:=.env}"

cleanup() {
rm -f "$TEST_HOSTS_FILE" "$TEST_COREFILE" "$TEST_MORPH_CHAIN_CONFIG"
rm -f "$TEST_HOSTS_FILE" "$TEST_COREFILE" "$TEST_NEOFS_CHAIN_CONFIG"
cp "$TEMP_ENV_FILE" "$BASE_ENV_FILE"
}

run_update_hosts() {
HOSTS_FILE="$TEST_HOSTS_FILE" COREFILE="$TEST_COREFILE" MORPH_CHAIN_CONFIG="$TEST_MORPH_CHAIN_CONFIG" ./bin/update_hosts.sh > /dev/null
HOSTS_FILE="$TEST_HOSTS_FILE" COREFILE="$TEST_COREFILE" NEOFS_CHAIN_CONFIG="$TEST_NEOFS_CHAIN_CONFIG" ./bin/update_hosts.sh > /dev/null
}

check_test() {
Expand All @@ -44,7 +44,7 @@ prepare_environment() {
cleanup
:>"$TEST_HOSTS_FILE"
:>"$TEST_COREFILE"
:>"$TEST_MORPH_CHAIN_CONFIG"
:>"$TEST_NEOFS_CHAIN_CONFIG"
sed -i 's/^IPV4_PREFIX=192\.168\.130/IPV4_PREFIX=192\.168\.100/' "$BASE_ENV_FILE"
}

Expand All @@ -65,7 +65,7 @@ empty_file_test() {
out=""
check_test "$out" "$empty_output" "$test_name corefile"

empty_output=$(cat "$TEST_MORPH_CHAIN_CONFIG")
empty_output=$(cat "$TEST_NEOFS_CHAIN_CONFIG")
out=""
check_test "$out" "$empty_output" "$test_name config"
}
Expand All @@ -91,16 +91,16 @@ update_entries_in_hosts_test() {
echo "Running update entries in $BASE_HOSTS_FILE tests..."
prepare_environment

echo "192.168.130.90 morph-chain.neofs.devenv
echo "192.168.100.61 ir01.neofs.devenv
127.0.0.1 localhost" > "$TEST_HOSTS_FILE"
run_update_hosts
expected_output="192.168.100.90 morph-chain.neofs.devenv
expected_output="192.168.100.61 ir01.neofs.devenv
127.0.0.1 localhost
192.168.100.10 bastion.neofs.devenv
192.168.100.50 main-chain.neofs.devenv
192.168.100.53 coredns.neofs.devenv
192.168.100.81 http.neofs.devenv
192.168.100.61 ir01.neofs.devenv
192.168.100.102 k6_node.neofs.devenv
192.168.100.101 nats.neofs.devenv
192.168.100.83 rest.neofs.devenv
192.168.100.82 s3.neofs.devenv
Expand All @@ -119,7 +119,6 @@ echo "127.0.0.1 localhost
192.168.130.53 coredns.neofs.devenv
192.168.130.81 http.neofs.devenv
192.168.130.61 ir01.neofs.devenv
192.168.130.90 morph-chain.neofs.devenv
192.168.130.101 nats.neofs.devenv
192.168.130.83 rest.neofs.devenv
192.168.130.82 s3.neofs.devenv
Expand All @@ -135,15 +134,15 @@ echo "127.0.0.1 localhost
192.168.100.53 coredns.neofs.devenv
192.168.100.81 http.neofs.devenv
192.168.100.61 ir01.neofs.devenv
192.168.100.90 morph-chain.neofs.devenv
192.168.100.101 nats.neofs.devenv
192.168.100.83 rest.neofs.devenv
192.168.100.82 s3.neofs.devenv
192.168.100.82 *.s3.neofs.devenv
192.168.100.71 s01.neofs.devenv
192.168.100.72 s02.neofs.devenv
192.168.100.73 s03.neofs.devenv
192.168.100.74 s04.neofs.devenv"
192.168.100.74 s04.neofs.devenv
192.168.100.102 k6_node.neofs.devenv"

update_hosts_output=$(cat "$TEST_HOSTS_FILE")
check_test "$expected_output" "$update_hosts_output" "update all entries in $BASE_HOSTS_FILE"
Expand All @@ -155,7 +154,7 @@ update_corefile_test() {
echo "Running update $BASE_COREFILE file test..."
prepare_environment
echo ". {
nns http://192.168.130.90:30333
nns http://192.168.130.61:30333
transfer {
to *
}
Expand All @@ -164,7 +163,7 @@ update_corefile_test() {
}" > "$TEST_COREFILE"
run_update_hosts
expected_output=". {
nns http://192.168.100.90:30333
nns http://192.168.100.61:30333
transfer {
to *
}
Expand All @@ -178,31 +177,31 @@ update_corefile_test() {
update_configfile_test() {
local expected_output
local update_output
echo "Running update $BASE_MORPH_CHAIN_CONFIG file test..."
echo "Running update $BASE_NEOFS_CHAIN_CONFIG file test..."
prepare_environment
echo "P2P:
Addresses:
- \":20333\"
RPC:
Addresses:
- \"192.168.130.90:30333\"
- \"192.168.130.61:30333\"
Prometheus:
Addresses:
- \":20001\"
Pprof:
Addresses:
- \":20011\"" > "$TEST_MORPH_CHAIN_CONFIG"
- \":20011\"" > "$TEST_NEOFS_CHAIN_CONFIG"
run_update_hosts
expected_output="P2P:
Addresses:
- \":20333\"
RPC:
Addresses:
- \"192.168.100.90:30333\"
- \"192.168.130.61:30333\"
Prometheus:
Addresses:
Expand All @@ -211,8 +210,8 @@ update_configfile_test() {
Pprof:
Addresses:
- \":20011\""
update_output=$(cat "$TEST_MORPH_CHAIN_CONFIG")
check_test "$expected_output" "$update_output" "update $BASE_MORPH_CHAIN_CONFIG file"
update_output=$(cat "$TEST_NEOFS_CHAIN_CONFIG")
check_test "$expected_output" "$update_output" "update $BASE_NEOFS_CHAIN_CONFIG file"
}

cp "$BASE_ENV_FILE" "$TEMP_ENV_FILE"
Expand Down
12 changes: 6 additions & 6 deletions bin/tick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ else
ADDR=$(jq -r .accounts[0].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
fi

# Grep Morph block time
SIDECHAIN_PROTO="${SIDECHAIN_PROTO:-services/morph_chain/protocol.privnet.yml}"
BLOCK_DURATION=$(grep TimePerBlock < "$SIDECHAIN_PROTO" | awk '{print $2}') \
# Grep NeoFS chain block time
NEOFS_CHAIN_PROTO="${NEOFS_CHAIN_PROTO:-services/ir/cfg/config.yml}"
BLOCK_DURATION=$(grep time_per_block < "$NEOFS_CHAIN_PROTO" | awk '{print $2}') \
|| die "Cannot fetch block duration"
NETMAP_ADDR=$(bin/resolve.sh netmap.neofs) || die "Cannot resolve netmap.neofs"

# Fetch current epoch value
EPOCH=$(${NEOGO} contract testinvokefunction \
-r "http://morph-chain.${LOCAL_DOMAIN}:30333" "${NETMAP_ADDR}" epoch \
-r "http://ir01.${LOCAL_DOMAIN}:30333" "${NETMAP_ADDR}" epoch \
| grep 'value' | awk -F'"' '{ print $4 }') \
|| die "Cannot fetch epoch from netmap contract"

Expand All @@ -39,11 +39,11 @@ echo "Updating NeoFS epoch to $((EPOCH+1))"
${NEOGO} contract invokefunction \
--wallet-config ${CONFIG_IMG} \
-a ${ADDR} --force \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
-r http://ir01.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
newEpoch int:$((EPOCH+1)) -- ${ADDR}:Global \
|| die "Cannot increment an epoch"

# Wait one Morph block to ensure the transaction broadcasted
# Wait one NeoFS chain block to ensure the transaction broadcasted
# shellcheck disable=SC2086
sleep $BLOCK_DURATION
15 changes: 8 additions & 7 deletions bin/update_hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ set -e

: "${HOSTS_FILE:=/etc/hosts}"
: "${COREFILE:=services/coredns/Corefile}"
: "${MORPH_CHAIN_CONFIG:=services/morph_chain/protocol.privnet.yml}"
: "${NEOFS_CHAIN_CONFIG:=services/ir/cfg/config.yml}"
temp_file=$(mktemp)

# Get default hosts
make hosts > "$temp_file"

# Get the morph-chain IP address from the $COREFILE file
morph_chain_ip=$(grep "morph-chain.neofs.devenv" "$temp_file" | awk '{print $1}')
# Get the NeoFS chain IP address from the $COREFILE file
neofs_chain_ip=$(grep "ir01.neofs.devenv" "$temp_file" | awk '{print $1}')

# Replace the IP address in the $COREFILE file
sed -i -E "s/(nns[[:space:]]*http\:\/\/)([0-9]{1,3}[.]){3}[0-9]{1,3}(:30333)/\1$morph_chain_ip\3/" "$COREFILE"
sed -i -E "s/(nns[[:space:]]*http\:\/\/)([0-9]{1,3}[.]){3}[0-9]{1,3}(:30333)/\1$neofs_chain_ip\3/" "$COREFILE"

# Get the line numbers of "Addresses:"
addresses_lines=$(grep -n "Addresses:" "$MORPH_CHAIN_CONFIG" | cut -d ':' -f 1)
# FIXME(#302): grep by 'listen:' is unstable, jump to exact YAML fields
addresses_lines=$(grep -n "listen:" "$NEOFS_CHAIN_CONFIG" | cut -d ':' -f 1)

# Loop through each line number with "Addresses:"
for addresses_line in $addresses_lines; do
# Increment the line number to find the line with the IP and port
target_line=$((addresses_line + 1))

# Replace the IP address in the target line in the MORPH_CHAIN_CONFIG file
sed -i "${target_line}s/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/$morph_chain_ip/" "$MORPH_CHAIN_CONFIG"
# Replace the IP address in the target line in the NEOFS_CHAIN_CONFIG file
sed -i "${target_line}s/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/$neofs_chain_ip/" "$NEOFS_CHAIN_CONFIG"
done

while IFS=" " read -r ip domain; do
Expand Down
Loading

0 comments on commit 95acc4b

Please sign in to comment.