Skip to content

Commit

Permalink
fix: send evidences with non-empty infraction block header (#3578)
Browse files Browse the repository at this point in the history
* try to fill infraction header in double voting msg

* reformat

* fix nit

* fmt

* Formatting

* Make infraction block header required

* Stop after submitting double voting evidence to the provider

* Force refresh of account before sending a tx

* Revert refresh on every call

* Remove hermes binary at root

* Send ICS misbehaviour for CCV consumer chain in misbehaviour worker

* Make the evidence command resilient to error, eg. because a client was already frozen

* Improve logging

* Go back to refreshing the account everytime

* Improve CI test script

* Improve logs

* Add `key-name` and `check-past-blocks` arguments to `evidence` command (#3603)

* Add `key-name` and `check-past-blocks` arguments to `evidence` command

* Update templates

* Better logs

* Update nix flake

* Patch check-guide tool with CCV protos

* Do not refresh account everytime

* Fix for zero height

* Update ICS misbehaviour test to use a different wallet for the `evidence` command

* Remove double sign script

---------

Co-authored-by: Romain Ruetschi <106849+romac@users.noreply.github.com>
  • Loading branch information
sainoe and romac authored Sep 13, 2023
1 parent be8940b commit b6d03a1
Show file tree
Hide file tree
Showing 11 changed files with 849 additions and 576 deletions.
122 changes: 73 additions & 49 deletions ci/misbehaviour-ics/misbehaviour_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eu
set -eux

diag() {
echo ">>
Expand Down Expand Up @@ -28,14 +28,20 @@ PROV_NODE_DIR=${HOME_DIR}/provider-${MONIKER}
CONS_NODE_DIR=${HOME_DIR}/consumer-${MONIKER}
CONS_FORK_NODE_DIR=${HOME_DIR}/consumer-fork-${MONIKER}

# Coordinator key
PROV_KEY=${MONIKER}-key

# Coordinator keys
PROV_KEY1=${MONIKER}-key1
PROV_KEY2=${MONIKER}-key2

# Clean start
pkill -f interchain-security-pd &> /dev/null || true
rm -rf ${PROV_NODE_DIR}

pkill -f interchain-security-cd &> /dev/null || true
rm -rf ${CONS_NODE_DIR}
rm -rf ${CONS_FORK_NODE_DIR}

pkill -f hermes 2> /dev/null || true

# Build genesis file and node directory structure
interchain-security-pd init $MONIKER --chain-id provider --home ${PROV_NODE_DIR}
jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"86400s\"" \
Expand All @@ -44,18 +50,22 @@ jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.par

sleep 1

# Create account keypair
interchain-security-pd keys add $PROV_KEY --home ${PROV_NODE_DIR} --keyring-backend test --output json > ${PROV_NODE_DIR}/${PROV_KEY}.json 2>&1
# Create account keypairs
interchain-security-pd keys add $PROV_KEY1 --home ${PROV_NODE_DIR} --keyring-backend test --output json > ${PROV_NODE_DIR}/${PROV_KEY1}.json 2>&1
interchain-security-pd keys add $PROV_KEY2 --home ${PROV_NODE_DIR} --keyring-backend test --output json > ${PROV_NODE_DIR}/${PROV_KEY2}.json 2>&1
sleep 1

# Add stake to user
PROV_ACCOUNT_ADDR=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY}.json)
interchain-security-pd add-genesis-account $PROV_ACCOUNT_ADDR $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
# Add stake to users
PROV_ACCOUNT_ADDR1=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY1}.json)
interchain-security-pd add-genesis-account $PROV_ACCOUNT_ADDR1 $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
PROV_ACCOUNT_ADDR2=$(jq -r '.address' ${PROV_NODE_DIR}/${PROV_KEY2}.json)
interchain-security-pd add-genesis-account $PROV_ACCOUNT_ADDR2 $USER_COINS --home ${PROV_NODE_DIR} --keyring-backend test
sleep 1


# Stake 1/1000 user's coins
interchain-security-pd gentx $PROV_KEY $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER
interchain-security-pd gentx $PROV_KEY1 $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER
# interchain-security-pd gentx $PROV_KEY2 $STAKE --chain-id provider --home ${PROV_NODE_DIR} --keyring-backend test --moniker $MONIKER
sleep 1

interchain-security-pd collect-gentxs --home ${PROV_NODE_DIR} --gentx-dir ${PROV_NODE_DIR}/config/gentx/
Expand Down Expand Up @@ -99,35 +109,35 @@ tee ${PROV_NODE_DIR}/consumer-proposal.json<<EOF
}
EOF

interchain-security-pd keys show $PROV_KEY --keyring-backend test --home ${PROV_NODE_DIR}
interchain-security-pd keys show $PROV_KEY1 --keyring-backend test --home ${PROV_NODE_DIR}
interchain-security-pd keys show $PROV_KEY2 --keyring-backend test --home ${PROV_NODE_DIR}

# Submit consumer chain proposal
interchain-security-pd tx gov submit-proposal consumer-addition ${PROV_NODE_DIR}/consumer-proposal.json --chain-id provider --from $PROV_KEY --home ${PROV_NODE_DIR} --node tcp://${NODE_IP}:26658 --keyring-backend test -b block -y
interchain-security-pd tx gov submit-proposal consumer-addition ${PROV_NODE_DIR}/consumer-proposal.json --chain-id provider --from $PROV_KEY1 --home ${PROV_NODE_DIR} --node tcp://${NODE_IP}:26658 --keyring-backend test -b block -y

sleep 1

# Vote yes to proposal
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY --chain-id provider --home ${PROV_NODE_DIR} -b block -y --keyring-backend test
interchain-security-pd tx gov vote 1 yes --from $PROV_KEY1 --chain-id provider --home ${PROV_NODE_DIR} -b block -y --keyring-backend test
# interchain-security-pd tx gov vote 1 yes --from $PROV_KEY2 --chain-id provider --home ${PROV_NODE_DIR} -b block -y --keyring-backend test

sleep 3

## CONSUMER CHAIN ##

# Clean start
pkill -f interchain-security-cd &> /dev/null || true
rm -rf ${CONS_NODE_DIR}
rm -rf ${CONS_FORK_NODE_DIR}

# Build genesis file and node directory structure
interchain-security-cd init $MONIKER --chain-id consumer --home ${CONS_NODE_DIR}
interchain-security-cd init $MONIKER --chain-id consumer --home ${CONS_NODE_DIR}
sleep 1

# Create user account keypair
interchain-security-cd keys add $PROV_KEY --home ${CONS_NODE_DIR} --keyring-backend test --output json > ${CONS_NODE_DIR}/${PROV_KEY}.json 2>&1
# Create user account keypairs
interchain-security-cd keys add $PROV_KEY1 --home ${CONS_NODE_DIR} --keyring-backend test --output json > ${CONS_NODE_DIR}/${PROV_KEY1}.json 2>&1
interchain-security-cd keys add $PROV_KEY2 --home ${CONS_NODE_DIR} --keyring-backend test --output json > ${CONS_NODE_DIR}/${PROV_KEY2}.json 2>&1

# Add stake to user account
CONS_ACCOUNT_ADDR=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY}.json)
interchain-security-cd add-genesis-account $CONS_ACCOUNT_ADDR 1000000000stake --home ${CONS_NODE_DIR}
# Add stake to user accounts
CONS_ACCOUNT_ADDR1=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY1}.json)
interchain-security-cd add-genesis-account $CONS_ACCOUNT_ADDR1 1000000000stake --home ${CONS_NODE_DIR}
CONS_ACCOUNT_ADDR2=$(jq -r '.address' ${CONS_NODE_DIR}/${PROV_KEY2}.json)
interchain-security-cd add-genesis-account $CONS_ACCOUNT_ADDR2 1000000000stake --home ${CONS_NODE_DIR}

# Add consumer genesis states to genesis file
interchain-security-pd query provider consumer-genesis consumer --home ${PROV_NODE_DIR} -o json > consumer_gen.json
Expand All @@ -146,7 +156,7 @@ cp ${PROV_NODE_DIR}/config/node_key.json ${CONS_NODE_DIR}/config/node_key.json
sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${NODE_IP}:26648\"/" ${CONS_NODE_DIR}/config/client.toml

# Start gaia
interchain-security-cd start --home ${CONS_NODE_DIR} \
interchain-security-cd start --home ${CONS_NODE_DIR} \
--rpc.laddr tcp://${NODE_IP}:26648 \
--grpc.address ${NODE_IP}:9081 \
--address tcp://${NODE_IP}:26645 \
Expand All @@ -156,9 +166,6 @@ interchain-security-cd start --home ${CONS_NODE_DIR} \

sleep 3

# Setup Hermes in packet relayer mode
pkill -f hermes 2> /dev/null || true

tee $HOME_DIR/config.toml <<EOF
[global]
log_level = "debug"
Expand Down Expand Up @@ -189,7 +196,7 @@ grpc_addr = "tcp://${NODE_IP}:9081"
key_name = "relayer"
max_gas = 2000000
rpc_addr = "http://${NODE_IP}:26648"
rpc_timeout = "10s"
rpc_timeout = "30s"
store_prefix = "ibc"
trusting_period = "2days"
event_source = { mode = "push", url = "ws://${NODE_IP}:26648/websocket" }
Expand All @@ -211,7 +218,7 @@ grpc_addr = "tcp://${NODE_IP}:9091"
key_name = "relayer"
max_gas = 2000000
rpc_addr = "http://${NODE_IP}:26658"
rpc_timeout = "10s"
rpc_timeout = "30s"
store_prefix = "ibc"
trusting_period = "2days"
event_source = { mode = "push", url = "ws://${NODE_IP}:26658/websocket" }
Expand All @@ -230,9 +237,10 @@ $HERMES --config $HOME_DIR/config.toml keys delete --chain consumer --all
$HERMES --config $HOME_DIR/config.toml keys delete --chain provider --all

# Restore keys to hermes relayer
$HERMES --config $HOME_DIR/config.toml keys add --key-file ${CONS_NODE_DIR}/${PROV_KEY}.json --chain consumer
$HERMES --config $HOME_DIR/config.toml keys add --key-file ${PROV_NODE_DIR}/${PROV_KEY}.json --chain provider

$HERMES --config $HOME_DIR/config.toml keys add --key-name relayer --key-file ${CONS_NODE_DIR}/${PROV_KEY1}.json --chain consumer
$HERMES --config $HOME_DIR/config.toml keys add --key-name evidence --key-file ${CONS_NODE_DIR}/${PROV_KEY2}.json --chain consumer
$HERMES --config $HOME_DIR/config.toml keys add --key-name relayer --key-file ${PROV_NODE_DIR}/${PROV_KEY1}.json --chain provider
$HERMES --config $HOME_DIR/config.toml keys add --key-name evidence --key-file ${PROV_NODE_DIR}/${PROV_KEY2}.json --chain provider

sleep 5

Expand All @@ -253,22 +261,31 @@ $HERMES --config $HOME_DIR/config.toml \

sleep 5

$HERMES --config $HOME_DIR/config.toml --json start &> $HOME_DIR/hermes-logs &
$HERMES --config $HOME_DIR/config.toml start &> $HOME_DIR/hermes-logs &

interchain-security-pd q tendermint-validator-set --home ${PROV_NODE_DIR}
interchain-security-cd q tendermint-validator-set --home ${CONS_NODE_DIR}

DELEGATIONS=$(interchain-security-pd q staking delegations $PROV_ACCOUNT_ADDR --home ${PROV_NODE_DIR} -o json)
DELEGATIONS1=$(interchain-security-pd q staking delegations $PROV_ACCOUNT_ADDR1 --home ${PROV_NODE_DIR} -o json)
OPERATOR_ADDR1=$(echo $DELEGATIONS1 | jq -r '.delegation_responses[0].delegation.validator_address')

OPERATOR_ADDR=$(echo $DELEGATIONS | jq -r '.delegation_responses[0].delegation.validator_address')
# DELEGATIONS2=$(interchain-security-pd q staking delegations $PROV_ACCOUNT_ADDR2 --home ${PROV_NODE_DIR} -o json)
# OPERATOR_ADDR2=$(echo $DELEGATIONS2 | jq -r '.delegation_responses[0].delegation.validator_address')

interchain-security-pd tx staking delegate $OPERATOR_ADDR 1000000stake \
--from $PROV_KEY \
interchain-security-pd tx staking delegate $OPERATOR_ADDR1 1000000stake \
--from $PROV_KEY1 \
--keyring-backend test \
--home ${PROV_NODE_DIR} \
--chain-id provider \
-y -b block

# interchain-security-pd tx staking delegate $OPERATOR_ADDR2 1000000stake \
# --from $PROV_KEY2 \
# --keyring-backend test \
# --home ${PROV_NODE_DIR} \
# --chain-id provider \
# -y -b block

sleep 13

interchain-security-pd q tendermint-validator-set --home ${PROV_NODE_DIR}
Expand Down Expand Up @@ -354,7 +371,7 @@ cp -r ${CONS_NODE_DIR} ${CONS_FORK_NODE_DIR}
sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${NODE_IP}:26638\"/" ${CONS_FORK_NODE_DIR}/config/client.toml

# Start gaia
interchain-security-cd start --home ${CONS_FORK_NODE_DIR} \
interchain-security-cd start --home ${CONS_FORK_NODE_DIR} \
--rpc.laddr tcp://${NODE_IP}:26638 \
--grpc.address ${NODE_IP}:9071 \
--address tcp://${NODE_IP}:26635 \
Expand All @@ -376,16 +393,23 @@ sleep 10
diag "Updating client on forked chain using trusted height $TRUSTED_HEIGHT"
$HERMES --config $HOME_DIR/config_fork.toml update client --client 07-tendermint-0 --host-chain provider --trusted-height $TRUSTED_HEIGHT

sleep 10

# Check the client state on provider and verify it is frozen
FROZEN_HEIGHT=$($HERMES --config $HOME_DIR/config.toml --json query client state --chain provider --client 07-tendermint-0 | tail -n 1 | jq '.result.frozen_height.revision_height')
for ((i = 0; i < 10; i++)); do
# Check the client state on provider and verify it is frozen
FROZEN_HEIGHT=$($HERMES --config $HOME_DIR/config.toml --json query client state --chain provider --client 07-tendermint-0 | tail -n 1 | jq '.result.frozen_height.revision_height')

diag "Frozen height: $FROZEN_HEIGHT"

diag "Frozen height: $FROZEN_HEIGHT"
if [ "$FROZEN_HEIGHT" != "null" ]; then
diag "Client is frozen, success!"
exit 0
else
diag "Client is not frozen, waiting 5 seconds..."
sleep 5
fi
done

if [ "$FROZEN_HEIGHT" != "null" ]; then
diag "Client is frozen, success!"
else
diag "Client is not frozen, aborting."
exit 1
fi
diag "Client is not frozen, aborting."
diag "Hermes logs:"
cat $HOME_DIR/hermes-logs
exit 1
Loading

0 comments on commit b6d03a1

Please sign in to comment.