From ba45cdac8bde488cc9027a60d43b6109651a831c Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 1 Apr 2021 15:01:16 +0530 Subject: [PATCH 01/22] Refactor tests to use deterministic seed --- .gitignore | 1 + test/relayer_akash_test.go | 4 ++-- test/relayer_gaia_test.go | 7 +++++-- test/setup/Dockerfile.akashtest | 4 +++- test/setup/Dockerfile.gaiatest | 4 +++- test/setup/akash-setup.sh | 15 ++++++++++++++- test/setup/gaia-setup.sh | 15 ++++++++++++++- test/setup/valkeys/.gitkeep | 0 test/test_chains.go | 10 ++++++++++ test/test_setup.go | 21 ++++++++++++++++++++- 10 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 test/setup/valkeys/.gitkeep diff --git a/.gitignore b/.gitignore index 30346ae64..9ecaf916d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ chain-code/ two-chains/ibc-* two-chains/.relayer two-chains/*.log +test/setup/valkeys/*.json diff --git a/test/relayer_akash_test.go b/test/relayer_akash_test.go index 2ddd22359..bef1155b7 100644 --- a/test/relayer_akash_test.go +++ b/test/relayer_akash_test.go @@ -10,8 +10,8 @@ import ( var ( akashChains = []testChain{ - {"ibc-0", gaiaTestConfig}, - {"ibc-1", akashTestConfig}, + {"ibc-0", 0, gaiaTestConfig}, + {"ibc-1", 0, akashTestConfig}, } ) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 10d565ba7..48fc6b362 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -10,8 +10,8 @@ import ( var ( gaiaChains = []testChain{ - {"ibc-0", gaiaTestConfig}, - {"ibc-1", gaiaTestConfig}, + {"ibc-0", 0, gaiaTestConfig}, + {"ibc-1", 0, gaiaTestConfig}, } ) @@ -148,3 +148,6 @@ func TestGaiaReuseIdentifiers(t *testing.T) { require.Equal(t, expectedSrc, src) require.Equal(t, expectedDst, dst) } + +func TestGaiaMisbehaviourMonitoring(t *testing.T) { +} diff --git a/test/setup/Dockerfile.akashtest b/test/setup/Dockerfile.akashtest index 9ee7666fd..f5bed9c23 100644 --- a/test/setup/Dockerfile.akashtest +++ b/test/setup/Dockerfile.akashtest @@ -8,7 +8,9 @@ USER root COPY ./akash-setup.sh . +COPY ./valkeys ./setup/valkeys + EXPOSE 26657 ENTRYPOINT [ "./akash-setup.sh" ] -# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} +# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} {{seeds}} {{priv_validator_key_path}} diff --git a/test/setup/Dockerfile.gaiatest b/test/setup/Dockerfile.gaiatest index 34bef1cb1..7b24204bb 100644 --- a/test/setup/Dockerfile.gaiatest +++ b/test/setup/Dockerfile.gaiatest @@ -14,7 +14,9 @@ WORKDIR /gaia COPY ./gaia-setup.sh . +COPY ./valkeys ./setup/valkeys + EXPOSE 26657 ENTRYPOINT [ "./gaia-setup.sh" ] -# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} +# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} {{seeds}} {{priv_validator_key_path}} diff --git a/test/setup/akash-setup.sh b/test/setup/akash-setup.sh index 741575922..20c1c3296 100755 --- a/test/setup/akash-setup.sh +++ b/test/setup/akash-setup.sh @@ -4,6 +4,8 @@ set -o errexit -o nounset CHAINID=$1 GENACCT=$2 +SEEDS=$3 +PRIVPATH=$4 if [ -z "$1" ]; then echo "Need to input chain id..." @@ -15,12 +17,23 @@ if [ -z "$2" ]; then exit 1 fi +if [ -z "$3" ]; then + echo "Need to input seeds of validator key..." + exit 1 +fi + +if [ -z "$4" ]; then + echo "Need to input path of priv_validator_key json file" + exit 1 +fi + # Build genesis file incl account for passed address coins="10000000000stake,100000000000samoleans" akash init --chain-id $CHAINID $CHAINID -akash keys add validator --keyring-backend="test" +echo $SEEDS | akash keys add validator --keyring-backend="test" --recover akash add-genesis-account $(akash keys show validator -a --keyring-backend="test") $coins akash add-genesis-account $GENACCT $coins +cp $PRIVPATH ~/.akash/config/priv_validator_key.json akash gentx validator 5000000000stake --keyring-backend="test" --chain-id $CHAINID akash collect-gentxs diff --git a/test/setup/gaia-setup.sh b/test/setup/gaia-setup.sh index ea9e4c689..eef6a5d1d 100755 --- a/test/setup/gaia-setup.sh +++ b/test/setup/gaia-setup.sh @@ -4,6 +4,8 @@ set -o errexit -o nounset CHAINID=$1 GENACCT=$2 +SEEDS=$3 +PRIVPATH=$4 if [ -z "$1" ]; then echo "Need to input chain id..." @@ -15,12 +17,23 @@ if [ -z "$2" ]; then exit 1 fi +if [ -z "$3" ]; then + echo "Need to input seeds of validator key..." + exit 1 +fi + +if [ -z "$4" ]; then + echo "Need to input path of priv_validator_key json file" + exit 1 +fi + # Build genesis file incl account for passed address coins="10000000000stake,100000000000samoleans" gaiad init --chain-id $CHAINID $CHAINID -gaiad keys add validator --keyring-backend="test" +echo $SEEDS | gaiad keys add validator --keyring-backend="test" --recover gaiad add-genesis-account $(gaiad keys show validator -a --keyring-backend="test") $coins gaiad add-genesis-account $GENACCT $coins +cp $PRIVPATH ~/.gaia/config/priv_validator_key.json gaiad gentx validator 5000000000stake --keyring-backend="test" --chain-id $CHAINID gaiad collect-gentxs diff --git a/test/setup/valkeys/.gitkeep b/test/setup/valkeys/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_chains.go b/test/test_chains.go index ec12d2609..ef9ef3db7 100644 --- a/test/test_chains.go +++ b/test/test_chains.go @@ -11,6 +11,13 @@ import ( ry "github.com/cosmos/relayer/relayer" ) +const ( + // SEED1 is a mnenomic + SEED1 = "cake blossom buzz suspect image view round utility meat muffin humble club model latin similar glow draw useless kiwi snow laugh gossip roof public" + // SEED2 is a mnemonic + SEED2 = "near little movie lady moon fuel abandon gasp click element muscle elbow taste indoor soft soccer like occur legend coin near random normal adapt" +) + var ( // GAIA BLOCK TIMEOUTS are located in the gaia setup script in the // setup directory. @@ -37,6 +44,8 @@ var ( accountPrefix: "akash", trustingPeriod: "330h", } + + seeds = []string{SEED1, SEED2} ) type ( @@ -44,6 +53,7 @@ type ( // cosmos-sdk based blockchain testChain struct { chainID string + seed int t testChainConfig } diff --git a/test/test_setup.go b/test/test_setup.go index 2ad86f60f..49f4db4cf 100644 --- a/test/test_setup.go +++ b/test/test_setup.go @@ -14,6 +14,9 @@ import ( "github.com/stretchr/testify/require" ry "github.com/cosmos/relayer/relayer" + + tmed25519 "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/privval" ) // spinUpTestChains is to be passed any number of test chains with given configuration options @@ -46,6 +49,7 @@ func spinUpTestChains(t *testing.T, testChains ...testChain) ry.Chains { c := newTestChain(t, tc) chains[i] = c wg.Add(1) + genPrivValKeyJSON(tc.seed) go spinUpTestContainer(t, rchan, pool, c, dir, &wg, tc) } @@ -135,7 +139,12 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, Repository: containerName, // Name must match Repository Tag: "latest", // Must match docker default build tag ExposedPorts: []string{tc.t.rpcPort, c.GetRPCPort()}, - Cmd: []string{c.ChainID, c.MustGetAddress().String()}, + Cmd: []string{ + c.ChainID, + c.MustGetAddress().String(), + fmt.Sprintf("%q", seeds[tc.seed]), + getPrivValFileName(tc.seed), + }, PortBindings: map[dc.Port][]dc.PortBinding{ dc.Port(tc.t.rpcPort): {{HostPort: c.GetRPCPort()}}, }, @@ -207,3 +216,13 @@ func genTestPathAndSet(src, dst *ry.Chain, srcPort, dstPort string) (*ry.Path, e dst.PathEnd = path.Dst return path, nil } + +func genPrivValKeyJSON(seedNumber int) { + privKey := tmed25519.GenPrivKeyFromSecret([]byte(seeds[seedNumber])) + filePV := privval.NewFilePV(privKey, getPrivValFileName(seedNumber), "/") + filePV.Key.Save() +} + +func getPrivValFileName(seedNumber int) string { + return fmt.Sprintf("./setup/valkeys/priv_val%d.json", seedNumber) +} From f57e6c7882964e47477845140922b25210b24702 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 1 Apr 2021 16:02:41 +0530 Subject: [PATCH 02/22] Update docker files --- test/setup/Dockerfile.akashtest | 5 ++++- test/setup/Dockerfile.gaiatest | 6 +----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/setup/Dockerfile.akashtest b/test/setup/Dockerfile.akashtest index f5bed9c23..38f4d2b75 100644 --- a/test/setup/Dockerfile.akashtest +++ b/test/setup/Dockerfile.akashtest @@ -6,6 +6,9 @@ ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 USER root +# Install minimum necessary dependencies, build Cosmos SDK, remove packages +RUN apk add --no-cache $PACKAGES + COPY ./akash-setup.sh . COPY ./valkeys ./setup/valkeys @@ -13,4 +16,4 @@ COPY ./valkeys ./setup/valkeys EXPOSE 26657 ENTRYPOINT [ "./akash-setup.sh" ] -# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} {{seeds}} {{priv_validator_key_path}} +# NOTE: to run this image, docker run -d -p 26657:26657 ./akash-setup.sh {{chain_id}} {{genesis_account}} {{seeds}} {{priv_validator_key_path}} diff --git a/test/setup/Dockerfile.gaiatest b/test/setup/Dockerfile.gaiatest index 7b24204bb..4c5b5c652 100644 --- a/test/setup/Dockerfile.gaiatest +++ b/test/setup/Dockerfile.gaiatest @@ -8,10 +8,6 @@ USER root # Install minimum necessary dependencies, build Cosmos SDK, remove packages RUN apk add --no-cache $PACKAGES -USER gaia - -WORKDIR /gaia - COPY ./gaia-setup.sh . COPY ./valkeys ./setup/valkeys @@ -19,4 +15,4 @@ COPY ./valkeys ./setup/valkeys EXPOSE 26657 ENTRYPOINT [ "./gaia-setup.sh" ] -# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} {{seeds}} {{priv_validator_key_path}} +# NOTE: to run this image, docker run -d -p 26657:26657 ./gaia-setup.sh {{chain_id}} {{genesis_account}} {{seeds}} {{priv_validator_key_path}} From a45f641815c0925921bba7dd2e0bf006377395c1 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 16:43:41 +0530 Subject: [PATCH 03/22] Add misbehaviour monitor tests and address few comments --- test/relayer_akash_test.go | 2 +- test/relayer_gaia_test.go | 148 ++++++++++++++++++++++++++++++++++++- test/setup/akash-setup.sh | 10 +-- test/setup/gaia-setup.sh | 10 +-- test/test_setup.go | 13 +++- 5 files changed, 162 insertions(+), 21 deletions(-) diff --git a/test/relayer_akash_test.go b/test/relayer_akash_test.go index bef1155b7..25eb15f49 100644 --- a/test/relayer_akash_test.go +++ b/test/relayer_akash_test.go @@ -11,7 +11,7 @@ import ( var ( akashChains = []testChain{ {"ibc-0", 0, gaiaTestConfig}, - {"ibc-1", 0, akashTestConfig}, + {"ibc-1", 1, akashTestConfig}, } ) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 48fc6b362..4d8a44bcf 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -2,16 +2,25 @@ package test import ( "testing" + "time" sdk "github.com/cosmos/cosmos-sdk/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" + ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing" "github.com/cosmos/relayer/relayer" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/tmhash" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmprotoversion "github.com/tendermint/tendermint/proto/tendermint/version" + tmtypes "github.com/tendermint/tendermint/types" + tmversion "github.com/tendermint/tendermint/version" ) var ( gaiaChains = []testChain{ {"ibc-0", 0, gaiaTestConfig}, - {"ibc-1", 0, gaiaTestConfig}, + {"ibc-1", 1, gaiaTestConfig}, } ) @@ -150,4 +159,141 @@ func TestGaiaReuseIdentifiers(t *testing.T) { } func TestGaiaMisbehaviourMonitoring(t *testing.T) { + chains := spinUpTestChains(t, gaiaChains...) + + var ( + src = chains.MustGet("ibc-0") + dst = chains.MustGet("ibc-1") + ) + + path, err := genTestPathAndSet(src, dst, "transfer", "transfer") + require.NoError(t, err) + + // create path + _, err = src.CreateClients(dst) + require.NoError(t, err) + testClientPair(t, src, dst) + + _, err = src.CreateOpenConnections(dst, 3, src.GetTimeout()) + require.NoError(t, err) + testConnectionPair(t, src, dst) + + _, err = src.CreateOpenChannels(dst, 3, src.GetTimeout()) + require.NoError(t, err) + testChannelPair(t, src, dst) + + // start the relayer process in it's own goroutine + rlyDone, err := relayer.RunStrategy(src, dst, path.MustGetStrategy()) + require.NoError(t, err) + + // Wait for relay message inclusion in both chains + require.NoError(t, src.WaitForNBlocks(1)) + require.NoError(t, dst.WaitForNBlocks(1)) + + header, err := src.GetLightSignedHeaderAtHeight(0) + require.NoError(t, err) + + height := header.GetHeight().(clienttypes.Height) + heightMinus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight-1) + + privVal := getPrivKey(0) + pubKey := privVal.PubKey() + validator := tmtypes.NewValidator(pubKey, header.ValidatorSet.Proposer.VotingPower) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + signers := []tmtypes.PrivValidator{getFilePV(privVal, 0)} + + // creating duplicate header + newHeader := createTMClientHeader(t, src.ChainID, int64(heightMinus1.RevisionHeight), heightMinus1, + header.GetTime().Add(time.Minute), valSet, valSet, signers, header) + + // update client with duplicate header + updateMsg, err := clienttypes.NewMsgUpdateClient(src.PathEnd.ClientID, newHeader, src.MustGetAddress()) + require.NoError(t, err) + + res, success, err := src.SendMsg(updateMsg) + require.NoError(t, err) + require.True(t, success) + require.Equal(t, 0, res.Code) + + // wait for packet processing + require.NoError(t, dst.WaitForNBlocks(6)) + + // kill relayer routine + rlyDone() + + clientStateRes, err := src.QueryClientState(int64(heightMinus1.RevisionHeight)) + require.NoError(t, err) + + // unpack any into ibc tendermint client state + clientStateExported, err := clienttypes.UnpackClientState(clientStateRes.ClientState) + require.NoError(t, err) + + // cast from interface to concrete type + clientState, ok := clientStateExported.(*ibctmtypes.ClientState) + require.True(t, ok, "error when casting exported clientstate") + + // clientstate should be frozen + require.True(t, clientState.IsFrozen()) +} + +func createTMClientHeader(t *testing.T, chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, + tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator, oldHeader *ibctmtypes.Header) *ibctmtypes.Header { + var ( + valSet *tmproto.ValidatorSet + trustedVals *tmproto.ValidatorSet + ) + require.NotNil(t, tmValSet) + + vsetHash := tmValSet.Hash() + + tmHeader := tmtypes.Header{ + Version: tmprotoversion.Consensus{Block: tmversion.BlockProtocol, App: 2}, + ChainID: chainID, + Height: blockHeight, + Time: timestamp, + LastBlockID: ibctesting.MakeBlockID(make([]byte, tmhash.Size), 10_000, make([]byte, tmhash.Size)), + LastCommitHash: oldHeader.Header.LastCommitHash, + DataHash: tmhash.Sum([]byte("data_hash")), + ValidatorsHash: vsetHash, + NextValidatorsHash: vsetHash, + ConsensusHash: tmhash.Sum([]byte("consensus_hash")), + AppHash: tmhash.Sum([]byte("app_hash")), + LastResultsHash: tmhash.Sum([]byte("last_results_hash")), + EvidenceHash: tmhash.Sum([]byte("evidence_hash")), + ProposerAddress: tmValSet.Proposer.Address, //nolint:staticcheck + } + hhash := tmHeader.Hash() + blockID := ibctesting.MakeBlockID(hhash, 3, tmhash.Sum([]byte("part_set"))) + voteSet := tmtypes.NewVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, tmValSet) + + commit, err := tmtypes.MakeCommit(blockID, blockHeight, 1, voteSet, signers, timestamp) + require.NoError(t, err) + + signedHeader := &tmproto.SignedHeader{ + Header: tmHeader.ToProto(), + Commit: commit.ToProto(), + } + + if tmValSet != nil { + valSet, err = tmValSet.ToProto() + if err != nil { + panic(err) + } + } + + if tmTrustedVals != nil { + trustedVals, err = tmTrustedVals.ToProto() + if err != nil { + panic(err) + } + } + + // The trusted fields may be nil. They may be filled before relaying messages to a client. + // The relayer is responsible for querying client and injecting appropriate trusted fields. + return &ibctmtypes.Header{ + SignedHeader: signedHeader, + ValidatorSet: valSet, + TrustedHeight: trustedHeight, + TrustedValidators: trustedVals, + } } diff --git a/test/setup/akash-setup.sh b/test/setup/akash-setup.sh index 20c1c3296..a7b9001a3 100755 --- a/test/setup/akash-setup.sh +++ b/test/setup/akash-setup.sh @@ -4,8 +4,7 @@ set -o errexit -o nounset CHAINID=$1 GENACCT=$2 -SEEDS=$3 -PRIVPATH=$4 +PRIVPATH=$3 if [ -z "$1" ]; then echo "Need to input chain id..." @@ -18,11 +17,6 @@ if [ -z "$2" ]; then fi if [ -z "$3" ]; then - echo "Need to input seeds of validator key..." - exit 1 -fi - -if [ -z "$4" ]; then echo "Need to input path of priv_validator_key json file" exit 1 fi @@ -30,7 +24,7 @@ fi # Build genesis file incl account for passed address coins="10000000000stake,100000000000samoleans" akash init --chain-id $CHAINID $CHAINID -echo $SEEDS | akash keys add validator --keyring-backend="test" --recover +akash keys add validator --keyring-backend="test" akash add-genesis-account $(akash keys show validator -a --keyring-backend="test") $coins akash add-genesis-account $GENACCT $coins cp $PRIVPATH ~/.akash/config/priv_validator_key.json diff --git a/test/setup/gaia-setup.sh b/test/setup/gaia-setup.sh index eef6a5d1d..76117e815 100755 --- a/test/setup/gaia-setup.sh +++ b/test/setup/gaia-setup.sh @@ -4,8 +4,7 @@ set -o errexit -o nounset CHAINID=$1 GENACCT=$2 -SEEDS=$3 -PRIVPATH=$4 +PRIVPATH=$3 if [ -z "$1" ]; then echo "Need to input chain id..." @@ -18,11 +17,6 @@ if [ -z "$2" ]; then fi if [ -z "$3" ]; then - echo "Need to input seeds of validator key..." - exit 1 -fi - -if [ -z "$4" ]; then echo "Need to input path of priv_validator_key json file" exit 1 fi @@ -30,7 +24,7 @@ fi # Build genesis file incl account for passed address coins="10000000000stake,100000000000samoleans" gaiad init --chain-id $CHAINID $CHAINID -echo $SEEDS | gaiad keys add validator --keyring-backend="test" --recover +gaiad keys add validator --keyring-backend="test" gaiad add-genesis-account $(gaiad keys show validator -a --keyring-backend="test") $coins gaiad add-genesis-account $GENACCT $coins cp $PRIVPATH ~/.gaia/config/priv_validator_key.json diff --git a/test/test_setup.go b/test/test_setup.go index 49f4db4cf..98a5de1e5 100644 --- a/test/test_setup.go +++ b/test/test_setup.go @@ -142,7 +142,6 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, Cmd: []string{ c.ChainID, c.MustGetAddress().String(), - fmt.Sprintf("%q", seeds[tc.seed]), getPrivValFileName(tc.seed), }, PortBindings: map[dc.Port][]dc.PortBinding{ @@ -218,11 +217,19 @@ func genTestPathAndSet(src, dst *ry.Chain, srcPort, dstPort string) (*ry.Path, e } func genPrivValKeyJSON(seedNumber int) { - privKey := tmed25519.GenPrivKeyFromSecret([]byte(seeds[seedNumber])) - filePV := privval.NewFilePV(privKey, getPrivValFileName(seedNumber), "/") + privKey := getPrivKey(seedNumber) + filePV := getFilePV(privKey, seedNumber) filePV.Key.Save() } +func getPrivKey(seedNumber int) tmed25519.PrivKey { + return tmed25519.GenPrivKeyFromSecret([]byte(seeds[seedNumber])) +} + +func getFilePV(privKey tmed25519.PrivKey, seedNumber int) *privval.FilePV { + return privval.NewFilePV(privKey, getPrivValFileName(seedNumber), "/") +} + func getPrivValFileName(seedNumber int) string { return fmt.Sprintf("./setup/valkeys/priv_val%d.json", seedNumber) } From 0d044fdf323c44856fd5454414bcd2c6b89c9e23 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 16:48:23 +0530 Subject: [PATCH 04/22] Fix lint issues --- test/relayer_gaia_test.go | 5 +++-- test/test_chains.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 4d8a44bcf..80ce2ce0c 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -236,8 +236,9 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.True(t, clientState.IsFrozen()) } -func createTMClientHeader(t *testing.T, chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, - tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator, oldHeader *ibctmtypes.Header) *ibctmtypes.Header { +func createTMClientHeader(t *testing.T, chainID string, blockHeight int64, trustedHeight clienttypes.Height, + timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator, + oldHeader *ibctmtypes.Header) *ibctmtypes.Header { var ( valSet *tmproto.ValidatorSet trustedVals *tmproto.ValidatorSet diff --git a/test/test_chains.go b/test/test_chains.go index ef9ef3db7..4b2f29efb 100644 --- a/test/test_chains.go +++ b/test/test_chains.go @@ -13,8 +13,10 @@ import ( const ( // SEED1 is a mnenomic + //nolint:lll SEED1 = "cake blossom buzz suspect image view round utility meat muffin humble club model latin similar glow draw useless kiwi snow laugh gossip roof public" // SEED2 is a mnemonic + //nolint:lll SEED2 = "near little movie lady moon fuel abandon gasp click element muscle elbow taste indoor soft soccer like occur legend coin near random normal adapt" ) From 4c9573d6c3e11243b90c985baed2826b6d48d8ef Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 16:54:44 +0530 Subject: [PATCH 05/22] Modify gaia dockerfile --- test/setup/Dockerfile.gaiatest | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/setup/Dockerfile.gaiatest b/test/setup/Dockerfile.gaiatest index 4c5b5c652..6e0ad0462 100644 --- a/test/setup/Dockerfile.gaiatest +++ b/test/setup/Dockerfile.gaiatest @@ -8,10 +8,20 @@ USER root # Install minimum necessary dependencies, build Cosmos SDK, remove packages RUN apk add --no-cache $PACKAGES +USER gaia + +WORKDIR /gaia + COPY ./gaia-setup.sh . COPY ./valkeys ./setup/valkeys +USER root + +chmod -R 777 ./setup + +USER gaia + EXPOSE 26657 ENTRYPOINT [ "./gaia-setup.sh" ] From 1b027e99fdc6eceeb364530907e3c1b0f4f196be Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 16:59:40 +0530 Subject: [PATCH 06/22] Fix docker run issue --- test/setup/Dockerfile.gaiatest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/setup/Dockerfile.gaiatest b/test/setup/Dockerfile.gaiatest index 6e0ad0462..05df8d437 100644 --- a/test/setup/Dockerfile.gaiatest +++ b/test/setup/Dockerfile.gaiatest @@ -18,7 +18,7 @@ COPY ./valkeys ./setup/valkeys USER root -chmod -R 777 ./setup +RUN chmod -R 777 ./setup USER gaia From 58125d73de4bfbe7144dac8ebb7b7253192cffc3 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 17:09:34 +0530 Subject: [PATCH 07/22] Modify misbehaviour test --- test/relayer_gaia_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 80ce2ce0c..271e48227 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -190,7 +190,10 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.NoError(t, src.WaitForNBlocks(1)) require.NoError(t, dst.WaitForNBlocks(1)) - header, err := src.GetLightSignedHeaderAtHeight(0) + latestHeight, err := src.QueryLatestHeight() + require.NoError(t, err) + + header, err := src.QueryHeaderAtHeight(latestHeight) require.NoError(t, err) height := header.GetHeight().(clienttypes.Height) From 2c7ab07c5fa3c91c466c5294c3b2ffe9957021b3 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 17:18:46 +0530 Subject: [PATCH 08/22] Modify akash tests --- test/setup/Dockerfile.akashtest | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/setup/Dockerfile.akashtest b/test/setup/Dockerfile.akashtest index 38f4d2b75..1ee39cfa3 100644 --- a/test/setup/Dockerfile.akashtest +++ b/test/setup/Dockerfile.akashtest @@ -9,10 +9,20 @@ USER root # Install minimum necessary dependencies, build Cosmos SDK, remove packages RUN apk add --no-cache $PACKAGES +USER akash + +WORKDIR /akash + COPY ./akash-setup.sh . COPY ./valkeys ./setup/valkeys +USER root + +RUN chmod -R 777 ./setup + +USER akash + EXPOSE 26657 ENTRYPOINT [ "./akash-setup.sh" ] From f218c8663c7e5796745d3769c4af665a25757125 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 2 Apr 2021 17:22:48 +0530 Subject: [PATCH 09/22] Revert akash docker file changes --- test/setup/Dockerfile.akashtest | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/setup/Dockerfile.akashtest b/test/setup/Dockerfile.akashtest index 1ee39cfa3..a7de73861 100644 --- a/test/setup/Dockerfile.akashtest +++ b/test/setup/Dockerfile.akashtest @@ -6,23 +6,10 @@ ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 USER root -# Install minimum necessary dependencies, build Cosmos SDK, remove packages -RUN apk add --no-cache $PACKAGES - -USER akash - -WORKDIR /akash - COPY ./akash-setup.sh . COPY ./valkeys ./setup/valkeys -USER root - -RUN chmod -R 777 ./setup - -USER akash - EXPOSE 26657 ENTRYPOINT [ "./akash-setup.sh" ] From befc0e8a8ddf4784021a787ffa4a5037419f44ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 8 Apr 2021 13:23:18 +0200 Subject: [PATCH 10/22] use mock PV --- test/relayer_gaia_test.go | 12 +++++++++--- test/test_setup.go | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 271e48227..fbb603230 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -8,6 +8,7 @@ import ( clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing" + ibctestingmock "github.com/cosmos/cosmos-sdk/x/ibc/testing/mock" "github.com/cosmos/relayer/relayer" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/tmhash" @@ -199,11 +200,16 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { height := header.GetHeight().(clienttypes.Height) heightMinus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight-1) - privVal := getPrivKey(0) - pubKey := privVal.PubKey() + // setup validator for signing duplicate header + privKey := getSDKPrivKey(0) + privVal := ibctestingmock.PV{ + PrivKey: privKey, + } + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) validator := tmtypes.NewValidator(pubKey, header.ValidatorSet.Proposer.VotingPower) valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - signers := []tmtypes.PrivValidator{getFilePV(privVal, 0)} + signers := []tmtypes.PrivValidator{privVal} // creating duplicate header newHeader := createTMClientHeader(t, src.ChainID, int64(heightMinus1.RevisionHeight), heightMinus1, diff --git a/test/test_setup.go b/test/test_setup.go index 98a5de1e5..63362aa3e 100644 --- a/test/test_setup.go +++ b/test/test_setup.go @@ -15,6 +15,8 @@ import ( ry "github.com/cosmos/relayer/relayer" + sdked25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdkcryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" tmed25519 "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/privval" ) @@ -226,6 +228,10 @@ func getPrivKey(seedNumber int) tmed25519.PrivKey { return tmed25519.GenPrivKeyFromSecret([]byte(seeds[seedNumber])) } +func getSDKPrivKey(seedNumber int) sdkcryptotypes.PrivKey { + return sdked25519.GenPrivKeyFromSecret([]byte(seeds[seedNumber])) +} + func getFilePV(privKey tmed25519.PrivKey, seedNumber int) *privval.FilePV { return privval.NewFilePV(privKey, getPrivValFileName(seedNumber), "/") } From 5be9a23af3ca9af03ce58e9f5e1daa97e437f40f Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 18:11:28 +0530 Subject: [PATCH 11/22] Update trusted height in tests --- test/relayer_gaia_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index fbb603230..b6767ab80 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -212,7 +212,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { signers := []tmtypes.PrivValidator{privVal} // creating duplicate header - newHeader := createTMClientHeader(t, src.ChainID, int64(heightMinus1.RevisionHeight), heightMinus1, + newHeader := createTMClientHeader(t, src.ChainID, int64(height.RevisionHeight), heightMinus1, header.GetTime().Add(time.Minute), valSet, valSet, signers, header) // update client with duplicate header From ef8b22d1133dde91d8abd848f1491bc060aa1d47 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 18:55:40 +0530 Subject: [PATCH 12/22] Modify misbehaviour monitoring tests --- test/relayer_gaia_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index b6767ab80..bf1a1f636 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -197,7 +197,18 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { header, err := src.QueryHeaderAtHeight(latestHeight) require.NoError(t, err) - height := header.GetHeight().(clienttypes.Height) + clientStateRes, err := src.QueryClientState(latestHeight) + require.NoError(t, err) + + // unpack any into ibc tendermint client state + clientStateExported, err := clienttypes.UnpackClientState(clientStateRes.ClientState) + require.NoError(t, err) + + // cast from interface to concrete type + clientState, ok := clientStateExported.(*ibctmtypes.ClientState) + require.True(t, ok, "error when casting exported clientstate") + + height := clientState.GetLatestHeight().(clienttypes.Height) heightMinus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight-1) // setup validator for signing duplicate header @@ -230,15 +241,15 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { // kill relayer routine rlyDone() - clientStateRes, err := src.QueryClientState(int64(heightMinus1.RevisionHeight)) + clientStateRes, err = src.QueryClientState(int64(heightMinus1.RevisionHeight)) require.NoError(t, err) // unpack any into ibc tendermint client state - clientStateExported, err := clienttypes.UnpackClientState(clientStateRes.ClientState) + clientStateExported, err = clienttypes.UnpackClientState(clientStateRes.ClientState) require.NoError(t, err) // cast from interface to concrete type - clientState, ok := clientStateExported.(*ibctmtypes.ClientState) + clientState, ok = clientStateExported.(*ibctmtypes.ClientState) require.True(t, ok, "error when casting exported clientstate") // clientstate should be frozen From 31c97b7e125e13b83b1789783c69d42911a34adc Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 19:02:31 +0530 Subject: [PATCH 13/22] Update header height in tests --- test/relayer_gaia_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index bf1a1f636..b894efa94 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -209,7 +209,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.True(t, ok, "error when casting exported clientstate") height := clientState.GetLatestHeight().(clienttypes.Height) - heightMinus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight-1) + heightPlus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight+1) // setup validator for signing duplicate header privKey := getSDKPrivKey(0) @@ -223,7 +223,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { signers := []tmtypes.PrivValidator{privVal} // creating duplicate header - newHeader := createTMClientHeader(t, src.ChainID, int64(height.RevisionHeight), heightMinus1, + newHeader := createTMClientHeader(t, src.ChainID, int64(height.RevisionHeight), heightPlus1, header.GetTime().Add(time.Minute), valSet, valSet, signers, header) // update client with duplicate header @@ -241,7 +241,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { // kill relayer routine rlyDone() - clientStateRes, err = src.QueryClientState(int64(heightMinus1.RevisionHeight)) + clientStateRes, err = src.QueryClientState(int64(heightPlus1.RevisionHeight)) require.NoError(t, err) // unpack any into ibc tendermint client state From b79daf6420d9341acaf3150f8bdba40e10c08889 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 19:09:01 +0530 Subject: [PATCH 14/22] Update params --- test/relayer_gaia_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index b894efa94..220c4ceb5 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -223,7 +223,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { signers := []tmtypes.PrivValidator{privVal} // creating duplicate header - newHeader := createTMClientHeader(t, src.ChainID, int64(height.RevisionHeight), heightPlus1, + newHeader := createTMClientHeader(t, src.ChainID, int64(heightPlus1.RevisionHeight), height, header.GetTime().Add(time.Minute), valSet, valSet, signers, header) // update client with duplicate header From 3703f535f09e6d3a260c5cf32f68db8b4c2ffc3f Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 19:15:58 +0530 Subject: [PATCH 15/22] Add log --- test/relayer_gaia_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 220c4ceb5..ab2a9fe1d 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -230,6 +230,8 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { updateMsg, err := clienttypes.NewMsgUpdateClient(src.PathEnd.ClientID, newHeader, src.MustGetAddress()) require.NoError(t, err) + t.Log("Heights...", newHeader.TrustedHeight.RevisionHeight, newHeader.Header.Height) + res, success, err := src.SendMsg(updateMsg) require.NoError(t, err) require.True(t, success) From 9bba88b1098f66266ac4ed0b4f9bf4296c0bcef7 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 19:22:17 +0530 Subject: [PATCH 16/22] Update revision number --- test/relayer_gaia_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index ab2a9fe1d..2f081e902 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -209,7 +209,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.True(t, ok, "error when casting exported clientstate") height := clientState.GetLatestHeight().(clienttypes.Height) - heightPlus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight+1) + heightPlus1 := clienttypes.NewHeight(height.RevisionNumber+1, height.RevisionHeight+1) // setup validator for signing duplicate header privKey := getSDKPrivKey(0) @@ -230,8 +230,6 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { updateMsg, err := clienttypes.NewMsgUpdateClient(src.PathEnd.ClientID, newHeader, src.MustGetAddress()) require.NoError(t, err) - t.Log("Heights...", newHeader.TrustedHeight.RevisionHeight, newHeader.Header.Height) - res, success, err := src.SendMsg(updateMsg) require.NoError(t, err) require.True(t, success) From cafde281fea0f6f93452a939fac871e21f9d4a3d Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 19:33:51 +0530 Subject: [PATCH 17/22] Modify trusted height --- test/relayer_gaia_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 2f081e902..40ef806c8 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -209,6 +209,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.True(t, ok, "error when casting exported clientstate") height := clientState.GetLatestHeight().(clienttypes.Height) + height.RevisionNumber = 0 heightPlus1 := clienttypes.NewHeight(height.RevisionNumber+1, height.RevisionHeight+1) // setup validator for signing duplicate header From 926f9e17a0df43c0be2f59ad5b80ed5ad8377f62 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 19:40:18 +0530 Subject: [PATCH 18/22] Revert revision number change --- test/relayer_gaia_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 40ef806c8..220c4ceb5 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -209,8 +209,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.True(t, ok, "error when casting exported clientstate") height := clientState.GetLatestHeight().(clienttypes.Height) - height.RevisionNumber = 0 - heightPlus1 := clienttypes.NewHeight(height.RevisionNumber+1, height.RevisionHeight+1) + heightPlus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight+1) // setup validator for signing duplicate header privKey := getSDKPrivKey(0) From ea3ab85e486fa772252733e3aca4983a355828e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 8 Apr 2021 16:29:46 +0200 Subject: [PATCH 19/22] fix chainID and validator set usage --- test/relayer_gaia_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 220c4ceb5..cdc14468b 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -212,7 +212,8 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { heightPlus1 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight+1) // setup validator for signing duplicate header - privKey := getSDKPrivKey(0) + // use key for dst + privKey := getSDKPrivKey(1) privVal := ibctestingmock.PV{ PrivKey: privKey, } @@ -223,7 +224,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { signers := []tmtypes.PrivValidator{privVal} // creating duplicate header - newHeader := createTMClientHeader(t, src.ChainID, int64(heightPlus1.RevisionHeight), height, + newHeader := createTMClientHeader(t, dst.ChainID, int64(heightPlus1.RevisionHeight), height, header.GetTime().Add(time.Minute), valSet, valSet, signers, header) // update client with duplicate header From 77deec9855612187ae55cb5d8ef2728c9437e2a0 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 8 Apr 2021 20:07:17 +0530 Subject: [PATCH 20/22] Update response code check --- test/relayer_gaia_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index cdc14468b..3a1a3d5ef 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -234,7 +234,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { res, success, err := src.SendMsg(updateMsg) require.NoError(t, err) require.True(t, success) - require.Equal(t, 0, res.Code) + require.Equal(t, uint32(0), res.Code) // wait for packet processing require.NoError(t, dst.WaitForNBlocks(6)) From 64a42f3ba5aed5eaae86652405d2da42f5bebfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 8 Apr 2021 17:09:20 +0200 Subject: [PATCH 21/22] misbehaviour tests working :tada: --- relayer/misbehaviour.go | 4 ++-- relayer/naive-strategy.go | 4 +++- test/relayer_gaia_test.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/relayer/misbehaviour.go b/relayer/misbehaviour.go index 2f8cd6a11..db5c47e00 100644 --- a/relayer/misbehaviour.go +++ b/relayer/misbehaviour.go @@ -20,7 +20,7 @@ var ( // against the associated light client. If the headers do not match, the emitted // header and a reconstructed header are used in misbehaviour submission to // the IBC client on the source chain. -func checkAndSubmitMisbehaviour(src *Chain, events map[string][]string) error { +func checkAndSubmitMisbehaviour(src, counterparty *Chain, events map[string][]string) error { hdrs, ok := events[fmt.Sprintf("%s.%s", updateCliTag, headerTag)] if !ok { return nil @@ -52,7 +52,7 @@ func checkAndSubmitMisbehaviour(src *Chain, events map[string][]string) error { return fmt.Errorf("emitted header is not tendermint type") } - trustedHeader, err := src.GetLightSignedHeaderAtHeight(emittedHeader.Header.Height) + trustedHeader, err := counterparty.GetLightSignedHeaderAtHeight(emittedHeader.Header.Height) if err != nil { return err } diff --git a/relayer/naive-strategy.go b/relayer/naive-strategy.go index ddc1ca9dd..696c3e6c9 100644 --- a/relayer/naive-strategy.go +++ b/relayer/naive-strategy.go @@ -232,7 +232,9 @@ func (nrs *NaiveStrategy) UnrelayedAcknowledgements(src, dst *Chain) (*RelaySequ // HandleEvents defines how the relayer will handle block and transaction events as they are emitted func (nrs *NaiveStrategy) HandleEvents(src, dst *Chain, events map[string][]string) { // check for misbehaviour and submit if found - err := checkAndSubmitMisbehaviour(src, events) + // events came from dst chain, use that chain as the source + // the chain messages are submitted to + err := checkAndSubmitMisbehaviour(dst, src, events) if err != nil { src.Error(err) } diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 3a1a3d5ef..13aa1490d 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -242,7 +242,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { // kill relayer routine rlyDone() - clientStateRes, err = src.QueryClientState(int64(heightPlus1.RevisionHeight)) + clientStateRes, err = src.QueryClientState(0) require.NoError(t, err) // unpack any into ibc tendermint client state From 203189a041e6a53297e30dd90e8f4072e827cd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 8 Apr 2021 17:23:38 +0200 Subject: [PATCH 22/22] minor fix in tests --- test/relayer_gaia_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index 13aa1490d..c63eca44b 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -191,10 +191,10 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) { require.NoError(t, src.WaitForNBlocks(1)) require.NoError(t, dst.WaitForNBlocks(1)) - latestHeight, err := src.QueryLatestHeight() + latestHeight, err := dst.QueryLatestHeight() require.NoError(t, err) - header, err := src.QueryHeaderAtHeight(latestHeight) + header, err := dst.QueryHeaderAtHeight(latestHeight) require.NoError(t, err) clientStateRes, err := src.QueryClientState(latestHeight)