From 53c7a1af8dfc53f4f891d4c6488b0c09985e6c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:27:54 +0100 Subject: [PATCH] refactor: rename GetValsAtHeight to GetTrustedValidators (#5831) * refactor: rename GetValsAtHeight to GetTrustedValidators * add migration doc entry * Update testing/chain.go * lint: make lint-fix to the rescue. --------- Co-authored-by: DimitrisJim --- docs/docs/05-migrations/13-v8-to-v9.md | 1 + .../07-tendermint/misbehaviour_handle_test.go | 152 +++++++++--------- .../07-tendermint/update_test.go | 70 ++++---- testing/chain.go | 18 +-- 4 files changed, 121 insertions(+), 120 deletions(-) diff --git a/docs/docs/05-migrations/13-v8-to-v9.md b/docs/docs/05-migrations/13-v8-to-v9.md index ee4657da395..00f6a0bde63 100644 --- a/docs/docs/05-migrations/13-v8-to-v9.md +++ b/docs/docs/05-migrations/13-v8-to-v9.md @@ -43,6 +43,7 @@ Please use the new functions `path.Setup`, `path.SetupClients`, `path.SetupConne - The `mock.PV` type has been removed in favour of [`cmttypes.MockPV`](https://github.com/cometbft/cometbft/blob/v0.38.5/types/priv_validator.go#L50) ([#5709](https://github.com/cosmos/ibc-go/pull/5709)). - Functions `ConstructUpdateTMClientHeader` and `ConstructUpdateTMClientHeaderWithTrustedHeight` of `TestChain` type have been replaced with `IBCClientHeader`. This function will construct a `07-tendermint` header to update the light client on the counterparty chain. The trusted height must be passed in as a non-zero height. +- `GetValsAtHeight` has been renamed to `GetTrustedValidators` ## Relayers diff --git a/modules/light-clients/07-tendermint/misbehaviour_handle_test.go b/modules/light-clients/07-tendermint/misbehaviour_handle_test.go index 60363558811..97c00b993ff 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_handle_test.go +++ b/modules/light-clients/07-tendermint/misbehaviour_handle_test.go @@ -41,10 +41,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid fork misbehaviour", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -60,8 +60,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid time misbehaviour", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+3, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -74,8 +74,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid time misbehaviour, header 1 time strictly less than header 2 time", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+3, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -88,8 +88,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid misbehavior at height greater than last consensusState", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -101,16 +101,16 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid misbehaviour with different trusted heights", func() { trustedHeight1 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals1, found := suite.chainB.GetValsAtHeight(int64(trustedHeight1.RevisionHeight)) - suite.Require().True(found) + trustedVals1, err := suite.chainB.GetTrustedValidators(int64(trustedHeight1.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) trustedHeight2 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals2, found := suite.chainB.GetValsAtHeight(int64(trustedHeight2.RevisionHeight)) - suite.Require().True(found) + trustedVals2, err := suite.chainB.GetTrustedValidators(int64(trustedHeight2.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight1, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals1, suite.chainB.Signers), @@ -123,10 +123,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid misbehaviour at a previous revision", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -146,8 +146,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid misbehaviour at a future revision", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -164,8 +164,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "valid misbehaviour with trusted heights at a previous revision", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) // increment revision of chainID err = path.EndpointB.UpgradeChain() @@ -184,10 +184,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "consensus state's valset hash different from misbehaviour should still pass", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -207,10 +207,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "invalid misbehaviour: misbehaviour from different chain", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -240,8 +240,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "trusted consensus state does not exist", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight.Increment().(clienttypes.Height), suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -258,10 +258,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "trusting period expired", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -278,10 +278,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "header 1 valset has too much change", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -296,10 +296,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "header 2 valset has too much change", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -314,10 +314,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { "both header 1 and header 2 valsets have too much change", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -389,10 +389,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "valid fork misbehaviour", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -408,8 +408,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "valid time misbehaviour", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+3, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -422,8 +422,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "valid time misbehaviour, header 1 time strictly less than header 2 time", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+3, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -436,8 +436,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "valid misbehavior at height greater than last consensusState", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -449,16 +449,16 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "valid misbehaviour with different trusted heights", func() { trustedHeight1 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals1, found := suite.chainB.GetValsAtHeight(int64(trustedHeight1.RevisionHeight)) - suite.Require().True(found) + trustedVals1, err := suite.chainB.GetTrustedValidators(int64(trustedHeight1.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) trustedHeight2 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals2, found := suite.chainB.GetValsAtHeight(int64(trustedHeight2.RevisionHeight)) - suite.Require().True(found) + trustedVals2, err := suite.chainB.GetTrustedValidators(int64(trustedHeight2.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight1, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals1, suite.chainB.Signers), @@ -471,10 +471,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "consensus state's valset hash different from misbehaviour should still pass", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -494,10 +494,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "invalid misbehaviour: misbehaviour from different chain", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -512,7 +512,7 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "misbehaviour trusted validators does not match validator hash in trusted consensus state", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -527,8 +527,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "trusted consensus state does not exist", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight.Increment().(clienttypes.Height), suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -545,10 +545,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "trusting period expired", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -565,10 +565,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "header 1 valset has too much change", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -583,10 +583,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "header 2 valset has too much change", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -601,10 +601,10 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { "both header 1 and header 2 valsets have too much change", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) diff --git a/modules/light-clients/07-tendermint/update_test.go b/modules/light-clients/07-tendermint/update_test.go index 6e16581630e..b321fa24112 100644 --- a/modules/light-clients/07-tendermint/update_test.go +++ b/modules/light-clients/07-tendermint/update_test.go @@ -49,8 +49,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // passing the ProposedHeader.Height as the block height as it will become a previous height once we commit N blocks header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) @@ -68,8 +68,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // Create bothValSet with both suite validator and altVal bothValSet := cmttypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) @@ -85,8 +85,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // Create bothValSet with both suite validator and altVal bothValSet := cmttypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) @@ -116,8 +116,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // this will err as altValSet.Hash() != consState.NextValidatorsHash header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time, altValSet, altValSet, trustedVals, altSigners) @@ -129,8 +129,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time, altValSet, altValSet, trustedVals, altSigners) }, @@ -140,8 +140,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { name: "unsuccessful verify header: header height revision and trusted height revision mismatch", malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) header = suite.chainB.CreateTMClientHeader(chainIDRevision1, 3, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) }, @@ -152,8 +152,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) heightMinus1 := clienttypes.NewHeight(trustedHeight.RevisionNumber, trustedHeight.RevisionHeight-1) @@ -175,8 +175,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time.Add(-time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) }, @@ -187,8 +187,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) header = suite.chainB.CreateTMClientHeader(chainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) }, @@ -199,8 +199,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + suite.Require().NoError(err) header = suite.chainA.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+1, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) @@ -213,8 +213,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // passing the ProposedHeader.Height as the block height as it will become an update to previous revision once we upgrade the client header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) @@ -230,8 +230,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // passing the ProposedHeader.Height as the block height as it will become a previous height once we commit N blocks header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) @@ -248,8 +248,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) header = suite.chainB.CreateTMClientHeader(suite.chainB.ChainID+"-1", suite.chainB.ProposedHeader.Height+5, trustedHeight, suite.chainB.ProposedHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) }, @@ -261,8 +261,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { malleate: func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) // increment the revision of the chain err = path.EndpointB.UpgradeChain() @@ -646,10 +646,10 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { "invalid fork misbehaviour: identical headers", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) - err := path.EndpointA.UpdateClient() + err = path.EndpointA.UpdateClient() suite.Require().NoError(err) height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) @@ -665,8 +665,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { "invalid time misbehaviour: monotonically increasing time", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) clientMessage = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+3, trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -750,8 +750,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { "valid time misbehaviour: not monotonically increasing time", func() { trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) + trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) + suite.Require().NoError(err) clientMessage = &ibctm.Misbehaviour{ Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.ProposedHeader.Height+3, trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), diff --git a/testing/chain.go b/testing/chain.go index b713bac2950..fff0a937302 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -399,9 +399,9 @@ func (chain *TestChain) GetConsensusState(clientID string, height exported.Heigh return chain.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(chain.GetContext(), clientID, height) } -// GetValsAtHeight will return the trusted validator set of the chain for the given trusted height. It will return -// a success boolean depending on if the validator set exists or not at that height. -func (chain *TestChain) GetValsAtHeight(trustedHeight int64) (*cmttypes.ValidatorSet, bool) { +// GetTrustedValidators will return the trusted validator set of the chain for the given trusted height. Otherwise +// it will return an error. +func (chain *TestChain) GetTrustedValidators(trustedHeight int64) (*cmttypes.ValidatorSet, error) { // historical information does not store the validator set which committed the header at // height h. During BeginBlock, it stores the last updated validator set. This is equivalent to // the next validator set at height h. This is because cometbft processes the validator set @@ -418,7 +418,7 @@ func (chain *TestChain) GetValsAtHeight(trustedHeight int64) (*cmttypes.Validato // for height h, we can simply query using the trusted height. histInfo, err := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), trustedHeight) if err != nil { - return nil, false + return nil, err } valSet := stakingtypes.Validators{ @@ -427,9 +427,9 @@ func (chain *TestChain) GetValsAtHeight(trustedHeight int64) (*cmttypes.Validato tmValidators, err := testutil.ToCmtValidators(valSet, sdk.DefaultPowerReduction) if err != nil { - panic(err) + return nil, err } - return cmttypes.NewValidatorSet(tmValidators), true + return cmttypes.NewValidatorSet(tmValidators), nil } // GetAcknowledgement retrieves an acknowledgement for the provided packet. If the @@ -633,9 +633,9 @@ func (chain *TestChain) IBCClientHeader(header *ibctm.Header, trustedHeight clie return nil, errorsmod.Wrap(ibctm.ErrInvalidHeaderHeight, "trustedHeight must be a non-zero height") } - cmtTrustedVals, ok := chain.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - if !ok { - return nil, errorsmod.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) + cmtTrustedVals, err := chain.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) + if err != nil { + return nil, err } trustedVals, err := cmtTrustedVals.ToProto()