From 67aa39b7fa795abb1519a5afb9731fdfa34d0c71 Mon Sep 17 00:00:00 2001 From: jstr1121 Date: Thu, 19 Jan 2023 23:27:13 +0800 Subject: [PATCH] update for slashing sovereign validators for the fault made before consumer chain upgrade height --- app/consumer-democracy/app.go | 1 + app/consumer/app.go | 1 + consumer/start_consumer2.sh | 313 ++++++++++++++++++++++++++++ consumer/start_provider2.sh | 133 ++++++++++++ x/ccv/consumer/keeper/keeper.go | 19 ++ x/ccv/consumer/keeper/validators.go | 92 +++++++- x/ccv/consumer/module.go | 2 + x/ccv/consumer/types/keys.go | 15 +- x/ccv/types/expected_keepers.go | 7 + 9 files changed, 572 insertions(+), 11 deletions(-) create mode 100644 consumer/start_consumer2.sh create mode 100644 consumer/start_provider2.sh diff --git a/app/consumer-democracy/app.go b/app/consumer-democracy/app.go index e2a436db72..860be9ef07 100644 --- a/app/consumer-democracy/app.go +++ b/app/consumer-democracy/app.go @@ -419,6 +419,7 @@ func New( &app.IBCKeeper.PortKeeper, app.IBCKeeper.ConnectionKeeper, app.IBCKeeper.ClientKeeper, + app.StakingKeeper, app.SlashingKeeper, app.BankKeeper, app.AccountKeeper, diff --git a/app/consumer/app.go b/app/consumer/app.go index ce343a9f52..c44f266d9b 100644 --- a/app/consumer/app.go +++ b/app/consumer/app.go @@ -334,6 +334,7 @@ func New( &app.IBCKeeper.PortKeeper, app.IBCKeeper.ConnectionKeeper, app.IBCKeeper.ClientKeeper, + nil, app.SlashingKeeper, app.BankKeeper, app.AccountKeeper, diff --git a/consumer/start_consumer2.sh b/consumer/start_consumer2.sh new file mode 100644 index 0000000000..38238c569c --- /dev/null +++ b/consumer/start_consumer2.sh @@ -0,0 +1,313 @@ +#!/bin/bash +set -eux + +SOVEREIGN_HOME="$HOME/.sovereign" +CONSUMER_HOME="$HOME/.consumer" +CONSUMER_HOME1="$HOME/.consumer1" +PROVIDER_CHAIN_ID="provider" +CONSUMER_CHAIN_ID="consumer" +MONIKER="consumer" +VALIDATOR="validator" +VALIDATOR1="validator1" +KEYRING="--keyring-backend test" +TX_FLAGS="--gas-adjustment 100 --gas auto" +PROVIDER_BINARY="interchain-security-pd" +SOVEREIGN_BINARY="interchain-security-sd" +CONSUMER_BINARY="interchain-security-cdd" +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +SOVEREIGN_RPC_LADDR="$NODE_IP:26648" +SOVEREIGN_GRPC_ADDR="$NODE_IP:9081" +CONSUMER_RPC_LADDR="$NODE_IP:26638" +CONSUMER_GRPC_ADDR="$NODE_IP:9071" +CONSUMER_RPC_LADDR1="$NODE_IP:26628" +CONSUMER_GRPC_ADDR1="$NODE_IP:9061" +CONSUMER_USER="consumer" +SOVEREIGN_VALIDATOR="sovereign_validator" +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_NODE_ADDRESS="tcp://localhost:26658" + +# Clean start +killall $SOVEREIGN_BINARY &> /dev/null || true +killall $CONSUMER_BINARY &> /dev/null || true +rm -rf $CONSUMER_HOME +rm -rf $CONSUMER_HOME1 +rm -rf $SOVEREIGN_HOME + +################SOVEREIGN############################ +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $SOVEREIGN_HOME +sleep 1 + +# Create user account keypair +$SOVEREIGN_BINARY keys add $CONSUMER_USER $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/consumer_keypair.json 2>&1 +$SOVEREIGN_BINARY keys add $SOVEREIGN_VALIDATOR $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/sovereign_validator_keypair.json 2>&1 + +# Add account in genesis (required by Hermes) +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/consumer_keypair.json) 1000000000stake --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/sovereign_validator_keypair.json) 1000000000000stake --home $SOVEREIGN_HOME + +# generate genesis for sovereign chain +$SOVEREIGN_BINARY gentx $SOVEREIGN_VALIDATOR 10000000000stake $KEYRING --chain-id=$CONSUMER_CHAIN_ID --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY collect-gentxs --home $SOVEREIGN_HOME +sed -i '' 's/"voting_period": "172800s"/"voting_period": "20s"/g' $SOVEREIGN_HOME/config/genesis.json + +################CONSUMER############################ + +# Build genesis file and node directory structure +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME +sleep 1 + +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME/config/priv_validator_key.json $CONSUMER_HOME/config/priv_validator_key.json +cp $PROVIDER_HOME/config/node_key.json $CONSUMER_HOME/config/node_key.json + +#######CHAIN2####### +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME1 +sleep 1 +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME1/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME1/config/priv_validator_key.json $CONSUMER_HOME1/config/priv_validator_key.json +cp $PROVIDER_HOME1/config/node_key.json $CONSUMER_HOME1/config/node_key.json + +##########SET CONFIG.TOML##################### +# Set default client port +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${SOVEREIGN_RPC_LADDR}\"/" $SOVEREIGN_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR}\"/" $CONSUMER_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR1}\"/" $CONSUMER_HOME1/config/client.toml +sovereign=$($SOVEREIGN_BINARY tendermint show-node-id --home $SOVEREIGN_HOME) +node=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME) +node1=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME1) + +# sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636,$node1@localhost:26626\"/" "$SOVEREIGN_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node1@localhost:26626\"/" "$CONSUMER_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node@localhost:26636\"/" "$CONSUMER_HOME1"/config/config.toml + +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636\"/" "$SOVEREIGN_HOME"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646\"/" "$CONSUMER_HOME"/config/config.toml + +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1318\"/" "$CONSUMER_HOME"/config/app.toml +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1319\"/" "$CONSUMER_HOME1"/config/app.toml + +# Start the chain +$SOVEREIGN_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$SOVEREIGN_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $SOVEREIGN_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 10 + +###########################UPGRADE TO SOVEREIGN CHAIN########################## + +$SOVEREIGN_BINARY tx gov submit-proposal software-upgrade "v07-Theta" --upgrade-height=7 \ +--title="upgrade to consumer chain" --description="upgrade to consumer chain description" \ +--from=$SOVEREIGN_VALIDATOR $KEYRING --chain-id=$CONSUMER_CHAIN_ID \ +--home=$SOVEREIGN_HOME --yes -b block --deposit="100000000stake" + +# Vote yes to proposal +$SOVEREIGN_BINARY tx gov vote 1 yes --from $SOVEREIGN_VALIDATOR --chain-id $CONSUMER_CHAIN_ID --node tcp://$SOVEREIGN_RPC_LADDR \ +--home $SOVEREIGN_HOME -b block -y $KEYRING +sleep 30 + +###########################START BINARIES AGAIN AFTER UPGRADE########################## +$SOVEREIGN_BINARY query gov proposals --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR +# $SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR1 + +killall $SOVEREIGN_BINARY &> /dev/null || true + +# Add ccv section to SOVEREIGN_HOME genesis to be used on upgrade handler +if ! $PROVIDER_BINARY q provider consumer-genesis "$CONSUMER_CHAIN_ID" --node "$PROVIDER_NODE_ADDRESS" --output json > "$SOVEREIGN_HOME"/consumer_section.json; +then + echo "Failed to get consumer genesis for the chain-id '$CONSUMER_CHAIN_ID'! Finalize genesis failed. For more details please check the log file in output directory." + exit 1 +fi + +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' "$SOVEREIGN_HOME"/config/genesis.json "$SOVEREIGN_HOME"/consumer_section.json > "$SOVEREIGN_HOME"/genesis_consumer.json && \ + mv "$SOVEREIGN_HOME"/genesis_consumer.json "$SOVEREIGN_HOME"/config/genesis.json + +# Modify genesis params +jq ".app_state.ccvconsumer.params.blocks_per_distribution_transmission = \"70\" | .app_state.tokenfactory.paused = { \"paused\": false }" \ + $SOVEREIGN_HOME/config/genesis.json > \ + $SOVEREIGN_HOME/edited_genesis.json && mv $SOVEREIGN_HOME/edited_genesis.json $SOVEREIGN_HOME/config/genesis.json +sleep 1 + + +$CONSUMER_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$CONSUMER_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $CONSUMER_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 30 + +######################################HERMES################################### + +# Setup Hermes in packet relayer mode +killall hermes 2> /dev/null || true + +tee ~/.hermes/config.toml< ~/.hermes/logs & + +############################################################ + +PROVIDER_VALIDATOR_ADDRESS=$(jq -r .address $PROVIDER_HOME/keypair.json) +DELEGATIONS=$($PROVIDER_BINARY q staking delegations $PROVIDER_VALIDATOR_ADDRESS --home $PROVIDER_HOME --node tcp://${PROVIDER_RPC_LADDR} -o json) +OPERATOR_ADDR=$(echo $DELEGATIONS | jq -r .delegation_responses[0].delegation.validator_address) + +$PROVIDER_BINARY tx staking delegate $OPERATOR_ADDR 50000000stake \ + --from $VALIDATOR \ + $KEYRING \ + --home $PROVIDER_HOME \ + --node tcp://${PROVIDER_RPC_LADDR} \ + --chain-id $PROVIDER_CHAIN_ID -y -b block +sleep 1 + +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR} +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR1} + +$CONSUMER_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$CONSUMER_BINARY status --node tcp://$CONSUMER_RPC_LADDR + +$CONSUMER_BINARY query staking params --node=tcp://$CONSUMER_RPC_LADDR +$PROVIDER_BINARY query staking params --node=tcp://${PROVIDER_RPC_LADDR} diff --git a/consumer/start_provider2.sh b/consumer/start_provider2.sh new file mode 100644 index 0000000000..613f7ae597 --- /dev/null +++ b/consumer/start_provider2.sh @@ -0,0 +1,133 @@ +#!/bin/bash +set -eux + +TOTAL_COINS=100000000000stake +STAKE_COINS=100000000stake +TOTAL_COINS1=120000000000stake +STAKE_COINS1=1000000stake +PROVIDER_BINARY=interchain-security-pd +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_CHAIN_ID=provider +PROVIDER_MONIKER=provider +VALIDATOR=validator +VALIDATOR1=validator1 +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +PROVIDER_DELEGATOR=delegator + +# Clean start +killall $PROVIDER_BINARY &> /dev/null || true + +#######VALIDATOR1####################### +rm -rf $PROVIDER_HOME + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME --chain-id $PROVIDER_CHAIN_ID +jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"11600s\" | .app_state.provider.params.template_client.trusting_period = \"11300s\"" \ $PROVIDER_HOME/config/genesis.json > \ + $PROVIDER_HOME/edited_genesis.json && mv $PROVIDER_HOME/edited_genesis.json $PROVIDER_HOME/config/genesis.json +sleep 1 + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair.json 2>&1 +sleep 1 +$PROVIDER_BINARY keys add $PROVIDER_DELEGATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair_delegator.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair_delegator.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 + +# Stake 1/1000 user's coins +$PROVIDER_BINARY gentx $VALIDATOR $STAKE_COINS --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME --keyring-backend test --moniker $VALIDATOR +sleep 1 + +###########VALIDATOR 2############################ +rm -rf $PROVIDER_HOME1 + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME1 --chain-id $PROVIDER_CHAIN_ID +cp $PROVIDER_HOME/config/genesis.json $PROVIDER_HOME1/config/genesis.json + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR1 --home $PROVIDER_HOME1 --keyring-backend test --output json > $PROVIDER_HOME1/keypair.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME1/keypair.json) $TOTAL_COINS1 --home $PROVIDER_HOME1 --keyring-backend test +sleep 1 + +####################GENTX AND DISTRIBUTE GENESIS############################## +cp -r $PROVIDER_HOME/config/gentx $PROVIDER_HOME1/config/ + +# Stake 1/1000 user's coins +# $PROVIDER_BINARY gentx $VALIDATOR1 $STAKE_COINS1 --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME1 --keyring-backend test --moniker $VALIDATOR1 +# sleep 1 + +$PROVIDER_BINARY collect-gentxs --home $PROVIDER_HOME1 --gentx-dir $PROVIDER_HOME1/config/gentx/ +sleep 1 + +cp $PROVIDER_HOME1/config/genesis.json $PROVIDER_HOME/config/genesis.json + +####################ADDING PEERS#################### +node=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME) +node1=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME1) +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26656\"/" "$PROVIDER_HOME1"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$node1@localhost:26666\"/" "$PROVIDER_HOME"/config/config.toml + +#################### Start the chain node1 ################### +$PROVIDER_BINARY start \ + --home $PROVIDER_HOME \ + --rpc.laddr tcp://$PROVIDER_RPC_LADDR \ + --grpc.address $PROVIDER_GRPC_ADDR \ + --address tcp://${NODE_IP}:26655 \ + --p2p.laddr tcp://${NODE_IP}:26656 \ + --grpc-web.enable=false \ + --trace \ + &> $PROVIDER_HOME/logs & + +#################### Start the chain node2 ################### +# $PROVIDER_BINARY start \ +# --home $PROVIDER_HOME1 \ +# --rpc.laddr tcp://$PROVIDER_RPC_LADDR1 \ +# --grpc.address $PROVIDER_GRPC_ADDR1 \ +# --address tcp://${NODE_IP}:26665 \ +# --p2p.laddr tcp://${NODE_IP}:26666 \ +# --grpc-web.enable=false \ +# --trace \ +# &> $PROVIDER_HOME1/logs & +sleep 10 + +# Build consumer chain proposal file +tee $PROVIDER_HOME/consumer-proposal.json<