From 901403c2652fbe2689e6c0272394aebbc94b1f7a Mon Sep 17 00:00:00 2001 From: Trinity Date: Fri, 6 Sep 2024 16:02:10 +0700 Subject: [PATCH] Add manual scripts for mesh security --- scripts/mesh/multinode.sh | 122 ++++++++++++++++ scripts/mesh/runnode.sh | 45 ++++++ scripts/mesh/test_immediate_unbond.sh | 195 ++++++++++++++++++++++++++ scripts/mesh/test_mvp.sh | 141 +++++++++++++++++++ scripts/mesh/test_zero_max_cap.sh | 166 ++++++++++++++++++++++ scripts/mesh/testibc/chain1.sh | 77 ++++++++++ scripts/mesh/testibc/chain2.sh | 81 +++++++++++ scripts/mesh/testibc/config.yaml | 57 ++++++++ scripts/mesh/testibc/instantiate.sh | 113 +++++++++++++++ scripts/mesh/testibc/rly.sh | 36 +++++ scripts/mesh/update_params.json | 16 +++ 11 files changed, 1049 insertions(+) create mode 100755 scripts/mesh/multinode.sh create mode 100755 scripts/mesh/runnode.sh create mode 100755 scripts/mesh/test_immediate_unbond.sh create mode 100755 scripts/mesh/test_mvp.sh create mode 100755 scripts/mesh/test_zero_max_cap.sh create mode 100755 scripts/mesh/testibc/chain1.sh create mode 100755 scripts/mesh/testibc/chain2.sh create mode 100644 scripts/mesh/testibc/config.yaml create mode 100755 scripts/mesh/testibc/instantiate.sh create mode 100755 scripts/mesh/testibc/rly.sh create mode 100644 scripts/mesh/update_params.json diff --git a/scripts/mesh/multinode.sh b/scripts/mesh/multinode.sh new file mode 100755 index 00000000..700c8a5a --- /dev/null +++ b/scripts/mesh/multinode.sh @@ -0,0 +1,122 @@ +#!/bin/bash +set -xeu + +# always returns true so set -e doesn't exit if it is not running. +killall meshd || true +rm -rf $HOME/.meshd/ + +# make four mesh directories +mkdir $HOME/.meshd +cd $HOME/.meshd/ +mkdir $HOME/.meshd/validator1 +mkdir $HOME/.meshd/validator2 +mkdir $HOME/.meshd/validator3 + +# init all three validators +meshd init --chain-id=testing-1 validator1 --home=$HOME/.meshd/validator1 +meshd init --chain-id=testing-1 validator2 --home=$HOME/.meshd/validator2 +meshd init --chain-id=testing-1 validator3 --home=$HOME/.meshd/validator3 + +# create keys for all three validators +meshd keys add validator1 --keyring-backend=test --home=$HOME/.meshd/validator1 +meshd keys add validator2 --keyring-backend=test --home=$HOME/.meshd/validator2 +meshd keys add validator3 --keyring-backend=test --home=$HOME/.meshd/validator3 + +# create validator node with tokens to transfer to the three other nodes +meshd add-genesis-account $(meshd keys show validator1 -a --keyring-backend=test --home=$HOME/.meshd/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator1 +meshd add-genesis-account $(meshd keys show validator2 -a --keyring-backend=test --home=$HOME/.meshd/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator1 +meshd add-genesis-account $(meshd keys show validator3 -a --keyring-backend=test --home=$HOME/.meshd/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator1 +meshd add-genesis-account $(meshd keys show validator1 -a --keyring-backend=test --home=$HOME/.meshd/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator2 +meshd add-genesis-account $(meshd keys show validator2 -a --keyring-backend=test --home=$HOME/.meshd/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator2 +meshd add-genesis-account $(meshd keys show validator3 -a --keyring-backend=test --home=$HOME/.meshd/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator2 +meshd add-genesis-account $(meshd keys show validator1 -a --keyring-backend=test --home=$HOME/.meshd/validator1) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator3 +meshd add-genesis-account $(meshd keys show validator2 -a --keyring-backend=test --home=$HOME/.meshd/validator2) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator3 +meshd add-genesis-account $(meshd keys show validator3 -a --keyring-backend=test --home=$HOME/.meshd/validator3) 10000000000000000000000000000000stake,10000000000000000000000000000000osmo --home=$HOME/.meshd/validator3 +meshd gentx validator1 1000000000000000000000stake --keyring-backend=test --home=$HOME/.meshd/validator1 --chain-id=testing-1 +meshd gentx validator2 1000000000000000000000stake --keyring-backend=test --home=$HOME/.meshd/validator2 --chain-id=testing-1 +meshd gentx validator3 1000000000000000000000stake --keyring-backend=test --home=$HOME/.meshd/validator3 --chain-id=testing-1 + +cp validator2/config/gentx/*.json $HOME/.meshd/validator1/config/gentx/ +cp validator3/config/gentx/*.json $HOME/.meshd/validator1/config/gentx/ +meshd collect-gentxs --home=$HOME/.meshd/validator1 + +# cp validator1/config/genesis.json $HOME/.meshd/validator2/config/genesis.json +# cp validator1/config/genesis.json $HOME/.meshd/validator3/config/genesis.json + + +# change app.toml values +VALIDATOR1_APP_TOML=$HOME/.meshd/validator1/config/app.toml +VALIDATOR2_APP_TOML=$HOME/.meshd/validator2/config/app.toml +VALIDATOR3_APP_TOML=$HOME/.meshd/validator3/config/app.toml + +# validator1 +sed -i -E 's|localhost:9090|localhost:9050|g' $VALIDATOR1_APP_TOML +sed -i -E 's|127.0.0.1:9090|127.0.0.1:9050|g' $VALIDATOR1_APP_TOML + +# validator2 +sed -i -E 's|tcp://localhost:1317|tcp://localhost:1316|g' $VALIDATOR2_APP_TOML +# sed -i -E 's|127.0.0.1:9090|127.0.0.1:9088|g' $VALIDATOR2_APP_TOML +sed -i -E 's|localhost:9090|localhost:9088|g' $VALIDATOR2_APP_TOML +# sed -i -E 's|0.0.0.0:9091|0.0.0.0:9089|g' $VALIDATOR2_APP_TOML +sed -i -E 's|localhost:9091|localhost:9089|g' $VALIDATOR2_APP_TOML +sed -i -E 's|tcp://0.0.0.0:10337|tcp://0.0.0.0:10347|g' $VALIDATOR2_APP_TOML + +# validator3 +sed -i -E 's|tcp://localhost:1317|tcp://localhost:1315|g' $VALIDATOR3_APP_TOML +# sed -i -E 's|127.0.0.1:9090|127.0.0.1:9086|g' $VALIDATOR3_APP_TOML +sed -i -E 's|localhost:9090|localhost:9086|g' $VALIDATOR3_APP_TOML +# sed -i -E 's|0.0.0.0:9091|0.0.0.0:9087|g' $VALIDATOR3_APP_TOML +sed -i -E 's|localhost:9091|localhost:9087|g' $VALIDATOR3_APP_TOML +sed -i -E 's|tcp://0.0.0.0:10337|tcp://0.0.0.0:10357|g' $VALIDATOR3_APP_TOML + +# change config.toml values +VALIDATOR1_CONFIG=$HOME/.meshd/validator1/config/config.toml +VALIDATOR2_CONFIG=$HOME/.meshd/validator2/config/config.toml +VALIDATOR3_CONFIG=$HOME/.meshd/validator3/config/config.toml + + +# validator1 +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR1_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR1_CONFIG + + +# validator2 +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26655|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26654|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26653|g' $VALIDATOR2_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|prometheus_listen_addr = ":26660"|prometheus_listen_addr = ":26630"|g' $VALIDATOR2_CONFIG + +# validator3 +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26652|g' $VALIDATOR3_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26651|g' $VALIDATOR3_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' $VALIDATOR3_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR3_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR3_CONFIG +sed -i -E 's|prometheus_listen_addr = ":26660"|prometheus_listen_addr = ":26620"|g' $VALIDATOR3_CONFIG + +# copy validator1 genesis file to validator2-3 +cp $HOME/.meshd/validator1/config/genesis.json $HOME/.meshd/validator2/config/genesis.json +cp $HOME/.meshd/validator1/config/genesis.json $HOME/.meshd/validator3/config/genesis.json + +# copy tendermint node id of validator1 to persistent peers of validator2-3 +node1=$(meshd tendermint show-node-id --home=$HOME/.meshd/validator1) +node2=$(meshd tendermint show-node-id --home=$HOME/.meshd/validator2) +node3=$(meshd tendermint show-node-id --home=$HOME/.meshd/validator3) +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656,$node3@localhost:26656\"|g" $HOME/.meshd/validator1/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656,$node3@localhost:26656\"|g" $HOME/.meshd/validator2/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656,$node3@localhost:26656\"|g" $HOME/.meshd/validator3/config/config.toml + + +# # start all three validators/ +# meshd start --home=$HOME/.meshd/validator1 +screen -S mesh1 -t mesh1 -d -m meshd start --home=$HOME/.meshd/validator1 +screen -S mesh2 -t mesh2 -d -m meshd start --home=$HOME/.meshd/validator2 +screen -S mesh3 -t mesh3 -d -m meshd start --home=$HOME/.meshd/validator3 +# meshd start --home=$HOME/.meshd/validator3 + +sleep 7 + +meshd tx bank send $(meshd keys show validator1 -a --keyring-backend=test --home=$HOME/.meshd/validator1) $(meshd keys show validator2 -a --keyring-backend=test --home=$HOME/.meshd/validator2) 100000stake --keyring-backend=test --chain-id=testing-1 -y --home=$HOME/.meshd/validator1 --fees 100000000000000osmo + diff --git a/scripts/mesh/runnode.sh b/scripts/mesh/runnode.sh new file mode 100755 index 00000000..235ce95e --- /dev/null +++ b/scripts/mesh/runnode.sh @@ -0,0 +1,45 @@ +#!/bin/bash +killall meshd || true +rm -rf $HOME/.meshd/ + + +meshd keys add val --keyring-backend test +meshd keys add test1 --keyring-backend test +meshd keys add test2 --keyring-backend test +meshd keys add test3 --keyring-backend test + +# init chain +meshd init test-1 --chain-id testt + +# Change parameter token denominations to stake +cat $HOME/.meshd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="stake"' > $HOME/.meshd/config/tmp_genesis.json && mv $HOME/.meshd/config/tmp_genesis.json $HOME/.meshd/config/genesis.json +cat $HOME/.meshd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="stake"' > $HOME/.meshd/config/tmp_genesis.json && mv $HOME/.meshd/config/tmp_genesis.json $HOME/.meshd/config/genesis.json +cat $HOME/.meshd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="stake"' > $HOME/.meshd/config/tmp_genesis.json && mv $HOME/.meshd/config/tmp_genesis.json $HOME/.meshd/config/genesis.json +cat $HOME/.meshd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="stake"' > $HOME/.meshd/config/tmp_genesis.json && mv $HOME/.meshd/config/tmp_genesis.json $HOME/.meshd/config/genesis.json + +# Allocate genesis accounts (cosmos formatted addresses) +meshd add-genesis-account val 1000000000000stake --keyring-backend test +meshd add-genesis-account test1 1000000000stake --keyring-backend test +meshd add-genesis-account test2 1000000000stake --keyring-backend test +meshd add-genesis-account test3 50000000stake --keyring-backend test + +# Sign genesis transaction +meshd gentx val 1000000stake --keyring-backend test --chain-id testt + +# Collect genesis tx +meshd collect-gentxs + +# Run this to ensure everything worked and that the genesis file is setup correctly +meshd validate-genesis + +# Start the node (remove the --pruning=nothing flag if historical queries are not needed) + + +screen -S meshx -t meshx -d -m meshd start + +sleep 7 + +test2=$(meshd keys show test1 --keyring-backend test -a) +val2=$(meshd keys show val --keyring-backend test -a) + +meshd tx bank send $val2 $test2 100000stake --chain-id testt --keyring-backend test --fees 10stake -y #--node tcp://127.0.0.1:26657 \ No newline at end of file diff --git a/scripts/mesh/test_immediate_unbond.sh b/scripts/mesh/test_immediate_unbond.sh new file mode 100755 index 00000000..28c552b5 --- /dev/null +++ b/scripts/mesh/test_immediate_unbond.sh @@ -0,0 +1,195 @@ +# !/bin/bash +killall meshd || true +killall rly || true +# deploy chain 1 +./scripts/mesh/testibc/chain1.sh +# deploy chain 2 +./scripts/mesh/testibc/chain2.sh +sleep 7 +./scripts/mesh/testibc/instantiate.sh +# run relayer +./scripts/mesh/testibc/rly.sh + +home1node1=$HOME/.meshd/chain1/node1 +home2node1=$HOME/.meshd/chain2/node1 +node2=tcp://127.0.0.1:26667 + +virtual_staking=$(meshd q wasm list-contract-by-code 2 --output json | jq -r '.contracts[0]' ) +converter=$(meshd q wasm list-contract-by-code 3 --output json | jq -r '.contracts[0]' ) +vault=$(meshd q wasm list-contract-by-code 1 --output json --node $node2 | jq -r '.contracts[0]' ) +native_staking=$(meshd q wasm list-contract-by-code 3 --output json --node $node2 | jq -r '.contracts[0]' ) +ext_staking=$(meshd q wasm list-contract-by-code 4 --output json --node $node2 | jq -r '.contracts[0]' ) +test1_provider_addr=$(meshd keys show test1 --keyring-backend test --home=$home2node1 --address) + +# Set virtual staking max cap +meshd tx meshsecurity submit-proposal set-virtual-staking-max-cap $virtual_staking 100000000stake --title "a title" --summary "a summary" --from test1 --keyring-backend test --home=$home1node1 --chain-id chain-1 -y --deposit 10000000stake + +sleep 7 + +meshd tx gov vote 1 yes --from val1 --keyring-backend test --home=$home1node1 --chain-id chain-1 -y + +sleep 5 + +# Update mesh security provider module's params +gov_addr=$(meshd q auth --node $node2 module-account gov -o json | jq ".account.base_account.address") + +echo "gov addr: $gov_addr" +proposal=$(cat < ./scripts/mesh/update_params.json +meshd tx gov submit-proposal ./scripts/mesh/update_params.json --from test1 --keyring-backend test --home=$home2node1 --node $node2 --chain-id chain-2 -y + +sleep 7 + +meshd tx gov vote 1 yes --from val1 --keyring-backend test --home=$home2node1 --chain-id chain-2 --node $node2 -y + +sleep 30 + +# stake from provider(chain2) '{"bond":{}}'=======bond============ +meshd tx wasm execute $vault '{"bond":{"amount":{"amount": "20000000", "denom":"stake"}}}' --from test1 --home=$home2node1 --chain-id chain-2 --keyring-backend test --node $node2 --fees 1stake -y --gas 15406929 + +sleep 7 + +account_query=$(cat < tokens_1 )); then + val2_provider_addr=$(echo "$validators" | jq -r '.validators[0].operator_address') +else + val2_provider_addr=$(echo "$validators" | jq -r '.validators[1].operator_address') +fi + +echo "validator 2: $val2_provider_addr" + +# Stake 10_000_000 stake to val 1 provider chain +stake_msg=$(cat < ./scripts/mesh/update_params.json +meshd tx gov submit-proposal ./scripts/mesh/update_params.json --from test1 --keyring-backend test --home=$home2node1 --node $node2 --chain-id chain-2 -y + +sleep 7 + +meshd tx gov vote 1 yes --from val1 --keyring-backend test --home=$home2node1 --chain-id chain-2 --node $node2 -y + +sleep 30 + +# stake from provider(chain2) '{"bond":{}}'=======bond============ +meshd tx wasm execute $vault '{"bond":{"amount":{"amount": "10000", "denom":"stake"}}}' --from test1 --home=$home2node1 --chain-id chain-2 --keyring-backend test --node $node2 --fees 1stake -y --gas 15406929 + +sleep 7 + +account_query=$(cat < ./scripts/mesh/update_params.json +meshd tx gov submit-proposal ./scripts/mesh/update_params.json --from test1 --keyring-backend test --home=$home2node1 --node $node2 --chain-id chain-2 -y + +sleep 7 + +meshd tx gov vote 1 yes --from val1 --keyring-backend test --home=$home2node1 --chain-id chain-2 --node $node2 -y + +sleep 30 + +# stake from provider(chain2) '{"bond":{}}'=======bond============ +meshd tx wasm execute $vault '{"bond":{"amount":{"amount": "100000000", "denom":"stake"}}}' --from test1 --home=$home2node1 --chain-id chain-2 --keyring-backend test --node $node2 --fees 1stake -y --gas 15406929 + +sleep 7 + +account_query=$(cat < $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="30s"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["slashing"]["params"]["downtime_jail_duration"]="60s"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["slashing"]["params"]["signed_blocks_window"]="10"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["meshsecurity"]["params"]["epoch_length"]=5' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json + +# Allocate genesis accounts (cosmos formatted addresses) +val1=$(meshd keys show val1 --keyring-backend test --home=$home1 -a) +test1=$(meshd keys show test1 --keyring-backend test --home=$home1 -a) +val2=$(meshd keys show val2 --keyring-backend test --home=$home2 -a) +meshd add-genesis-account $val1 1000000000000stake --keyring-backend test --home=$home1 +meshd add-genesis-account $val2 1000000000000stake --keyring-backend test --home=$home1 +meshd add-genesis-account $test1 1000000000stake --keyring-backend test --home=$home1 +cp $home1/config/genesis.json $home2/config/genesis.json + +# Sign genesis transaction +meshd gentx val1 900000000000stake --keyring-backend test --chain-id $chainid --home=$home1 +meshd gentx val2 100000000000stake --keyring-backend test --chain-id $chainid --home=$home2 +cp $home2/config/gentx/*.json $home1/config/gentx/ + +# Collect genesis tx +meshd collect-gentxs --home=$home1 +cp $home1/config/genesis.json $home2/config/genesis.json + +# Run this to ensure everything worked and that the genesis file is setup correctly +meshd validate-genesis --home=$home1 + +# change app.toml values +VALIDATOR1_APP_TOML=$home1/config/app.toml +VALIDATOR2_APP_TOML=$home2/config/app.toml + +sed -i -E 's|tcp://localhost:1317|tcp://localhost:1316|g' $VALIDATOR2_APP_TOML +sed -i -E 's|localhost:9090|localhost:9088|g' $VALIDATOR2_APP_TOML +sed -i -E 's|localhost:9091|localhost:9089|g' $VALIDATOR2_APP_TOML +sed -i -E 's|tcp://0.0.0.0:10337|tcp://0.0.0.0:10347|g' $VALIDATOR2_APP_TOML + +# change config.toml values +VALIDATOR1_CONFIG=$home1/config/config.toml +VALIDATOR2_CONFIG=$home2/config/config.toml +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR1_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR1_CONFIG +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26655|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26654|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26653|g' $VALIDATOR2_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|prometheus_listen_addr = ":26660"|prometheus_listen_addr = ":26630"|g' $VALIDATOR2_CONFIG + +node1=$(meshd tendermint show-node-id --home=$home1) +node2=$(meshd tendermint show-node-id --home=$home2) +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656\"|g" $home1/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656\"|g" $home2/config/config.toml + +# Start the node (remove the --pruning=nothing flag if historical queries are not needed) +screen -S mesh1-node1 -t mesh1-node1 -d -m meshd start --home=$home1 +screen -S mesh1-node2 -t mesh1-node2 -d -m meshd start --home=$home2 \ No newline at end of file diff --git a/scripts/mesh/testibc/chain2.sh b/scripts/mesh/testibc/chain2.sh new file mode 100755 index 00000000..940e9d6b --- /dev/null +++ b/scripts/mesh/testibc/chain2.sh @@ -0,0 +1,81 @@ +#!/bin/bash +set -xeu + +rm -rf $HOME/.meshd/chain2 +home1=$HOME/.meshd/chain2/node1 +home2=$HOME/.meshd/chain2/node2 +chainid=chain-2 + +# init chain +meshd init mesh-2 --chain-id $chainid --home=$home1 +meshd init mesh-2 --chain-id $chainid --home=$home2 + +# keys add +meshd keys add val1 --keyring-backend test --home=$home1 +meshd keys add val2 --keyring-backend test --home=$home2 +meshd keys add test1 --keyring-backend test --home=$home1 + +# Change parameter token denominations to stake +cat $home1/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="30s"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["slashing"]["params"]["downtime_jail_duration"]="60s"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["slashing"]["params"]["signed_blocks_window"]="10"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json +cat $home1/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json + +# Allocate genesis accounts (cosmos formatted addresses) +val1=$(meshd keys show val1 --keyring-backend test --home=$home1 -a) +test1=$(meshd keys show test1 --keyring-backend test --home=$home1 -a) +val2=$(meshd keys show val2 --keyring-backend test --home=$home2 -a) +meshd add-genesis-account $val1 1000000000000stake --keyring-backend test --home=$home1 +meshd add-genesis-account $val2 1000000000000stake --keyring-backend test --home=$home1 +meshd add-genesis-account $test1 1000000000stake --keyring-backend test --home=$home1 +cp $home1/config/genesis.json $home2/config/genesis.json + +# Sign genesis transactions +meshd gentx val1 900000000000stake --keyring-backend test --chain-id $chainid --home $home1 +meshd gentx val2 100000000000stake --keyring-backend test --chain-id $chainid --home $home2 +cp $home2/config/gentx/*.json $home1/config/gentx/ + +# Collect genesis tx +meshd collect-gentxs --home $home1 + +# Run this to ensure everything worked and that the genesis file is setup correctly +meshd validate-genesis --home $home1 +cp $home1/config/genesis.json $home2/config/genesis.json + +# change app.toml values +VALIDATOR1_APP_TOML=$home1/config/app.toml +VALIDATOR2_APP_TOML=$home2/config/app.toml + +sed -i -E 's|tcp://localhost:1317|tcp://localhost:1327|g' $VALIDATOR1_APP_TOML +sed -i -E 's|localhost:9090|localhost:9190|g' $VALIDATOR1_APP_TOML +sed -i -E 's|localhost:9091|localhost:9191|g' $VALIDATOR1_APP_TOML +sed -i -E 's|tcp://0.0.0.0:10337|tcp://0.0.0.0:11337|g' $VALIDATOR1_APP_TOML +sed -i -E 's|tcp://localhost:1317|tcp://localhost:1326|g' $VALIDATOR2_APP_TOML +sed -i -E 's|localhost:9090|localhost:9188|g' $VALIDATOR2_APP_TOML +sed -i -E 's|localhost:9091|localhost:9189|g' $VALIDATOR2_APP_TOML +sed -i -E 's|tcp://0.0.0.0:10337|tcp://0.0.0.0:11347|g' $VALIDATOR2_APP_TOML + +# change config.toml values +VALIDATOR1_CONFIG=$home1/config/config.toml +VALIDATOR2_CONFIG=$home2/config/config.toml +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26668|g' $VALIDATOR1_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26667|g' $VALIDATOR1_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26666|g' $VALIDATOR1_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR1_CONFIG +sed -i -E 's|tcp://127.0.0.1:26658|tcp://127.0.0.1:26665|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://127.0.0.1:26657|tcp://127.0.0.1:26664|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26663|g' $VALIDATOR2_CONFIG +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG + +# peers +NODE1=$(meshd tendermint show-node-id --home=$home1) +NODE2=$(meshd tendermint show-node-id --home=$home2) +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$NODE1@localhost:26666,$NODE2@localhost:26666\"|g" $home1/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$NODE1@localhost:26666,$NODE2@localhost:26666\"|g" $home2/config/config.toml + +# start +screen -S mesh2-node1 -t mesh2-node1 -d -m meshd start --home=$home1 +screen -S mesh2-node2 -t mesh2-node2 -d -m meshd start --home=$home2 \ No newline at end of file diff --git a/scripts/mesh/testibc/config.yaml b/scripts/mesh/testibc/config.yaml new file mode 100644 index 00000000..ab87fa2f --- /dev/null +++ b/scripts/mesh/testibc/config.yaml @@ -0,0 +1,57 @@ +global: + api-listen-addr: :5183 + timeout: 10s + memo: "" + light-cache-size: 20 +chains: + consumer: + type: cosmos + value: + key-directory: /Users/phamminh/.relayer/keys/chain-1/ + key: key1 + chain-id: chain-1 + rpc-addr: http://localhost:26657 + account-prefix: mesh + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 0.01stake + min-gas-amount: 1000000 + max-gas-amount: 0 + debug: false + timeout: 20s + block-timeout: "" + output-format: json + sign-mode: direct + extra-codecs: [] + coin-type: 118 + signing-algorithm: "" + broadcast-mode: batch + min-loop-duration: 0s + extension-options: [] + feegrants: null + provider: + type: cosmos + value: + key-directory: /Users/phamminh/.relayer/keys/chain-2/ + key: key2 + chain-id: chain-2 + rpc-addr: http://localhost:26667 + account-prefix: mesh + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 0.01stake + min-gas-amount: 1000000 + max-gas-amount: 0 + debug: false + timeout: 20s + block-timeout: "" + output-format: json + sign-mode: direct + extra-codecs: [] + coin-type: 118 + signing-algorithm: "" + broadcast-mode: batch + min-loop-duration: 0s + extension-options: [] + feegrants: null +paths: {} diff --git a/scripts/mesh/testibc/instantiate.sh b/scripts/mesh/testibc/instantiate.sh new file mode 100755 index 00000000..599e4756 --- /dev/null +++ b/scripts/mesh/testibc/instantiate.sh @@ -0,0 +1,113 @@ +# !/bin/bash + +home1=$HOME/.meshd/chain1/node1 +chainid1=chain-1 +home2=$HOME/.meshd/chain2/node1 +chainid2=chain-2 + +node1=tcp://127.0.0.1:26657 +node2=tcp://127.0.0.1:26667 +test1=$(meshd keys show test1 --keyring-backend test -a --home=$home1) +val1=$(meshd keys show val1 --keyring-backend test -a --home=$home1) +test2=$(meshd keys show test1 --keyring-backend test -a --home=$home2) +val2=$(meshd keys show val1 --keyring-backend test -a --home=$home2) + +# # #=======bootstrap contract consumer +meshd tx wasm store ./tests/testdata/mesh_simple_price_feed.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 +sleep 7 +meshd tx wasm store ./tests/testdata/mesh_virtual_staking.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 +sleep 7 +meshd tx wasm store ./tests/testdata/mesh_converter.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 +sleep 7 +meshd tx wasm instantiate 1 '{"native_per_foreign": "0.5"}' --node $node1 --label contract-pricefeed --admin $val1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 3059023 +sleep 7 + +price_feed=$(meshd q wasm list-contract-by-code 1 --node $node1 --output json | jq -r '.contracts[0]' ) +echo "price feed contract: $price_feed" + +init_converter=$(cat <