diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 43ffb00d0c..654b548eaf 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -233,6 +233,14 @@ func (app *BaseApp) MountKVStores(keys map[string]*sdk.KVStoreKey) { } } +// MountTransientStores mounts all transient stores to the provided keys in +// the BaseApp multistore. +func (app *BaseApp) MountTransientStores(keys map[string]*sdk.TransientStoreKey) { + for _, key := range keys { + app.MountStore(key, sdk.StoreTypeTransient) + } +} + // MountMemoryStores mounts all in-memory KVStores with the BaseApp's internal // commit multi-store. func (app *BaseApp) MountMemoryStores(keys map[string]*sdk.MemoryStoreKey) { diff --git a/x/ibc/core/02-client/client/utils/utils.go b/x/ibc/core/02-client/client/utils/utils.go index 60381b7cca..5e36b82c62 100644 --- a/x/ibc/core/02-client/client/utils/utils.go +++ b/x/ibc/core/02-client/client/utils/utils.go @@ -150,15 +150,28 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64, return ibctmtypes.Header{}, 0, err } + page = 0 + count = 10_000 + voters, err := node.Voters(context.Background(), &height, &page, &count) + if err != nil { + return ibctmtypes.Header{}, 0, err + } + protoCommit := commit.SignedHeader.ToProto() protoValset, err := tmtypes.NewValidatorSet(validators.Validators).ToProto() if err != nil { return ibctmtypes.Header{}, 0, err } + protoVoterSet, err := tmtypes.WrapValidatorsToVoterSet(voters.Voters).ToProto() + if err != nil { + return ibctmtypes.Header{}, 0, err + } + header := ibctmtypes.Header{ SignedHeader: protoCommit, ValidatorSet: protoValset, + VoterSet: protoVoterSet, } return header, height, nil diff --git a/x/ibc/core/02-client/keeper/client_test.go b/x/ibc/core/02-client/keeper/client_test.go index 5dd5dc7172..85683fd33a 100644 --- a/x/ibc/core/02-client/keeper/client_test.go +++ b/x/ibc/core/02-client/keeper/client_test.go @@ -54,11 +54,12 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() { return header } createPastUpdateFn := func(fillHeight, trustedHeight clienttypes.Height) *ibctmtypes.Header { + voterSet := tmtypes.WrapValidatorsToVoterSet(suite.chainB.Vals.Validators) consState, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(suite.chainA.GetContext(), path.EndpointA.ClientID, trustedHeight) suite.Require().True(found) return suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(fillHeight.RevisionHeight), trustedHeight, consState.(*ibctmtypes.ConsensusState).Timestamp.Add(time.Second*5), - suite.chainB.Vals, suite.chainB.Vals, suite.chainB.Signers) + suite.chainB.Vals, suite.chainB.Vals, voterSet, voterSet, suite.chainB.Signers) } cases := []struct { @@ -430,7 +431,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { altPrivVal := ibctestingmock.NewPV() altPubKey, err := altPrivVal.GetPubKey() suite.Require().NoError(err) - altVal := tmtypes.NewValidator(altPubKey, 4) + altVal := ibctesting.NewTestValidator(altPubKey, 4) // Set valSet here with suite.valSet so it doesn't get reset on each testcase valSet := suite.valSet @@ -442,6 +443,9 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { // Create alternative validator set with only altVal altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) + bothVoterSet := tmtypes.WrapValidatorsToVoterSet(bothValSet.Validators) + voterSet := tmtypes.WrapValidatorsToVoterSet(valSet.Validators) + // Create signer array and ensure it is in same order as bothValSet _, suiteVal := suite.valSet.GetByIndex(0) bothSigners := ibctesting.CreateSortedSignerArray(altPrivVal, suite.privVal, altVal, suiteVal) @@ -463,8 +467,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "trusting period misbehavior should pass", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: clientID, }, func() error { @@ -479,8 +483,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "time misbehavior should pass", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+5), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+5), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: clientID, }, func() error { @@ -495,8 +499,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "misbehavior at later height should pass", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, altTime, bothValSet, valSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, altTime, bothValSet, valSet, bothVoterSet, voterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, valSet, bothVoterSet, voterSet, bothSigners), ClientId: clientID, }, func() error { @@ -521,8 +525,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "misbehavior at later height with different trusted heights should pass", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, altTime, bothValSet, valSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), heightPlus3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, altTime, bothValSet, valSet, bothVoterSet, voterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), heightPlus3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: clientID, }, func() error { @@ -547,8 +551,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "misbehavior ValidateBasic fails: misbehaviour height is at same height as trusted height", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight), testClientHeight, altTime, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight), testClientHeight, altTime, bothValSet, valSet, bothVoterSet, voterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: clientID, }, func() error { @@ -563,8 +567,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "trusted ConsensusState1 not found", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), heightPlus3, altTime, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), heightPlus3, altTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, valSet, bothVoterSet, voterSet, bothSigners), ClientId: clientID, }, func() error { @@ -579,8 +583,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "trusted ConsensusState2 not found", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, altTime, bothValSet, valSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), heightPlus3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), testClientHeight, altTime, bothValSet, valSet, bothVoterSet, voterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(heightPlus5.RevisionHeight+1), heightPlus3, suite.ctx.BlockTime(), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: clientID, }, func() error { @@ -601,8 +605,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "client already is not active - client is frozen", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: clientID, }, func() error { @@ -620,8 +624,8 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { { "misbehaviour check failed", &ibctmtypes.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), altValSet, bothValSet, altSigners), + Header1: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, altTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight+1), testClientHeight, suite.ctx.BlockTime(), altValSet, bothValSet, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators), bothVoterSet, altSigners), ClientId: clientID, }, func() error { diff --git a/x/ibc/core/02-client/keeper/keeper_test.go b/x/ibc/core/02-client/keeper/keeper_test.go index 30abb35d15..3c12cf232c 100644 --- a/x/ibc/core/02-client/keeper/keeper_test.go +++ b/x/ibc/core/02-client/keeper/keeper_test.go @@ -92,10 +92,11 @@ func (suite *KeeperTestSuite) SetupTest() { testClientHeightMinus1 := types.NewHeight(0, height-1) - validator := tmtypes.NewValidator(pubKey, 1) + validator := ibctesting.NewTestValidator(pubKey, 1) suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) suite.valSetHash = suite.valSet.Hash() - suite.header = suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight), testClientHeightMinus1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal}) + voterSet := tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators) + suite.header = suite.chainA.CreateTMClientHeader(testChainID, int64(testClientHeight.RevisionHeight), testClientHeightMinus1, now2, suite.valSet, suite.valSet, voterSet, voterSet, []tmtypes.PrivValidator{suite.privVal}) suite.consensusState = ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("hash")), suite.valSetHash) var validators stakingtypes.Validators @@ -103,7 +104,7 @@ func (suite *KeeperTestSuite) SetupTest() { privVal := ibctestingmock.NewPV() tmPk, err := privVal.GetPubKey() suite.Require().NoError(err) - pk, err := cryptocodec.FromTmPubKeyInterface(tmPk) + pk, err := cryptocodec.FromOcPubKeyInterface(tmPk) suite.Require().NoError(err) val, err := stakingtypes.NewValidator(sdk.ValAddress(pk.Address()), pk, stakingtypes.Description{}) suite.Require().NoError(err) @@ -327,9 +328,10 @@ func (suite KeeperTestSuite) TestConsensusStateHelpers() { nextState := ibctmtypes.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot([]byte("next")), suite.valSetHash) testClientHeightPlus5 := types.NewHeight(0, height+5) + voterSet := tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators) header := suite.chainA.CreateTMClientHeader(testClientID, int64(testClientHeightPlus5.RevisionHeight), testClientHeight, suite.header.Header.Time.Add(time.Minute), - suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal}) + suite.valSet, suite.valSet, voterSet, voterSet, []tmtypes.PrivValidator{suite.privVal}) // mock update functionality clientState.LatestHeight = header.GetHeight().(types.Height) diff --git a/x/ibc/core/02-client/types/genesis_test.go b/x/ibc/core/02-client/types/genesis_test.go index 21ad996f22..012433fccd 100644 --- a/x/ibc/core/02-client/types/genesis_test.go +++ b/x/ibc/core/02-client/types/genesis_test.go @@ -52,11 +52,12 @@ func (suite *TypesTestSuite) TestValidateGenesis() { now := time.Now().UTC() - val := tmtypes.NewValidator(pubKey, 10) + val := ibctesting.NewTestValidator(pubKey, 10) valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val}) + voterSet := tmtypes.WrapValidatorsToVoterSet(valSet.Validators) heightMinus1 := types.NewHeight(0, height-1) - header := suite.chainA.CreateTMClientHeader(chainID, int64(clientHeight.RevisionHeight), heightMinus1, now, valSet, valSet, []tmtypes.PrivValidator{privVal}) + header := suite.chainA.CreateTMClientHeader(chainID, int64(clientHeight.RevisionHeight), heightMinus1, now, valSet, valSet, voterSet, voterSet, []tmtypes.PrivValidator{privVal}) testCases := []struct { name string diff --git a/x/ibc/core/02-client/types/msgs_test.go b/x/ibc/core/02-client/types/msgs_test.go index 12b79a8f29..c517d4398e 100644 --- a/x/ibc/core/02-client/types/msgs_test.go +++ b/x/ibc/core/02-client/types/msgs_test.go @@ -490,8 +490,8 @@ func (suite *TypesTestSuite) TestMarshalMsgSubmitMisbehaviour() { "tendermint client", func() { height := types.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height)) heightMinus1 := types.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height)-1) - header1 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Signers) - header2 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time.Add(time.Minute), suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Signers) + header1 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Voters, suite.chainA.Voters, suite.chainA.Signers) + header2 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time.Add(time.Minute), suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Voters, suite.chainA.Voters, suite.chainA.Signers) misbehaviour := ibctmtypes.NewMisbehaviour("tendermint", header1, header2) msg, err = types.NewMsgSubmitMisbehaviour("tendermint", misbehaviour, suite.chainA.SenderAccount.GetAddress().String()) @@ -548,8 +548,8 @@ func (suite *TypesTestSuite) TestMsgSubmitMisbehaviour_ValidateBasic() { func() { height := types.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height)) heightMinus1 := types.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height)-1) - header1 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Signers) - header2 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time.Add(time.Minute), suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Signers) + header1 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Voters, suite.chainA.Voters, suite.chainA.Signers) + header2 := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, int64(height.RevisionHeight), heightMinus1, suite.chainA.CurrentHeader.Time.Add(time.Minute), suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Voters, suite.chainA.Voters, suite.chainA.Signers) misbehaviour := ibctmtypes.NewMisbehaviour("tendermint", header1, header2) msg, err = types.NewMsgSubmitMisbehaviour("tendermint", misbehaviour, suite.chainA.SenderAccount.GetAddress().String()) diff --git a/x/ibc/core/03-connection/types/msgs_test.go b/x/ibc/core/03-connection/types/msgs_test.go index 48968efc24..4a90db0ecb 100644 --- a/x/ibc/core/03-connection/types/msgs_test.go +++ b/x/ibc/core/03-connection/types/msgs_test.go @@ -21,7 +21,7 @@ import ( ) var ( - signer = "cosmos1ckgw5d7jfj7wwxjzs9fdrdev9vc8dzcw3n2lht" + signer = "link1kerpa33qxdwvrgms5qr7xegfxnewzm6s46ce7t" emptyPrefix = commitmenttypes.MerklePrefix{} emptyProof = []byte{} diff --git a/x/ibc/core/genesis_test.go b/x/ibc/core/genesis_test.go index ff3371afb0..7e88de9785 100644 --- a/x/ibc/core/genesis_test.go +++ b/x/ibc/core/genesis_test.go @@ -59,7 +59,7 @@ func TestIBCTestSuite(t *testing.T) { } func (suite *IBCTestSuite) TestValidateGenesis() { - header := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, suite.chainA.CurrentHeader.Height, clienttypes.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height-1)), suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Signers) + header := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, suite.chainA.CurrentHeader.Height, clienttypes.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height-1)), suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Voters, suite.chainA.Voters, suite.chainA.Signers) testCases := []struct { name string @@ -225,7 +225,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { } func (suite *IBCTestSuite) TestInitGenesis() { - header := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, suite.chainA.CurrentHeader.Height, clienttypes.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height-1)), suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Signers) + header := suite.chainA.CreateTMClientHeader(suite.chainA.ChainID, suite.chainA.CurrentHeader.Height, clienttypes.NewHeight(0, uint64(suite.chainA.CurrentHeader.Height-1)), suite.chainA.CurrentHeader.Time, suite.chainA.Vals, suite.chainA.Vals, suite.chainA.Voters, suite.chainA.Voters, suite.chainA.Signers) testCases := []struct { name string diff --git a/x/ibc/light-clients/99-ostracon/types/errors.go b/x/ibc/light-clients/99-ostracon/types/errors.go index 0aa631daad..26bc58c90c 100644 --- a/x/ibc/light-clients/99-ostracon/types/errors.go +++ b/x/ibc/light-clients/99-ostracon/types/errors.go @@ -23,4 +23,5 @@ var ( ErrUnbondingPeriodExpired = sdkerrors.Register(SubModuleName, 12, "time since latest trusted state has passed the unbonding period") ErrInvalidProofSpecs = sdkerrors.Register(SubModuleName, 13, "invalid proof specs") ErrInvalidValidatorSet = sdkerrors.Register(SubModuleName, 14, "invalid validator set") + ErrInvalidVoterSet = sdkerrors.Register(SubModuleName, 99, "invalid voter set") ) diff --git a/x/ibc/light-clients/99-ostracon/types/misbehaviour.go b/x/ibc/light-clients/99-ostracon/types/misbehaviour.go index 3d71470d9e..01c944e39f 100644 --- a/x/ibc/light-clients/99-ostracon/types/misbehaviour.go +++ b/x/ibc/light-clients/99-ostracon/types/misbehaviour.go @@ -64,9 +64,15 @@ func (misbehaviour Misbehaviour) ValidateBasic() error { if misbehaviour.Header1.TrustedValidators == nil { return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header1 cannot be empty") } + if misbehaviour.Header1.TrustedVoters == nil { + return sdkerrors.Wrap(ErrInvalidVoterSet, "trusted voter set in Header1 cannot be empty") + } if misbehaviour.Header2.TrustedValidators == nil { return sdkerrors.Wrap(ErrInvalidValidatorSet, "trusted validator set in Header2 cannot be empty") } + if misbehaviour.Header2.TrustedVoters == nil { + return sdkerrors.Wrap(ErrInvalidVoterSet, "trusted voter set in Header2 cannot be empty") + } if misbehaviour.Header1.Header.ChainID != misbehaviour.Header2.Header.ChainID { return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers must have identical chainIDs") } @@ -103,29 +109,29 @@ func (misbehaviour Misbehaviour) ValidateBasic() error { } if err := validCommit(misbehaviour.Header1.Header.ChainID, *blockID1, - misbehaviour.Header1.Commit, misbehaviour.Header1.ValidatorSet); err != nil { + misbehaviour.Header1.Commit, misbehaviour.Header1.VoterSet); err != nil { return err } if err := validCommit(misbehaviour.Header2.Header.ChainID, *blockID2, - misbehaviour.Header2.Commit, misbehaviour.Header2.ValidatorSet); err != nil { + misbehaviour.Header2.Commit, misbehaviour.Header2.VoterSet); err != nil { return err } return nil } // validCommit checks if the given commit is a valid commit from the passed-in validatorset -func validCommit(chainID string, blockID tmtypes.BlockID, commit *tmproto.Commit, valSet *tmproto.ValidatorSet) (err error) { +func validCommit(chainID string, blockID tmtypes.BlockID, commit *tmproto.Commit, voterSet *tmproto.VoterSet) (err error) { tmCommit, err := tmtypes.CommitFromProto(commit) if err != nil { return sdkerrors.Wrap(err, "commit is not tendermint commit type") } - tmValset, err := tmtypes.ValidatorSetFromProto(valSet) + tmVoterSet, err := tmtypes.VoterSetFromProto(voterSet) if err != nil { return sdkerrors.Wrap(err, "validator set is not tendermint validator set type") } - if err := tmValset.VerifyCommitLight(chainID, blockID, tmCommit.Height, tmCommit); err != nil { - return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "validator set did not commit to header") + if err := tmVoterSet.VerifyCommitLight(chainID, blockID, tmCommit.Height, tmCommit); err != nil { + return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "voter set did not commit to header") } return nil diff --git a/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle.go b/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle.go index f6a71f34fa..00707e4b07 100644 --- a/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle.go +++ b/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle.go @@ -102,7 +102,7 @@ func checkMisbehaviourHeader( clientState *ClientState, consState *ConsensusState, header *Header, currentTimestamp time.Time, ) error { - tmTrustedValset, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) + tmTrustedVoterSet, err := tmtypes.VoterSetFromProto(header.TrustedVoters) if err != nil { return sdkerrors.Wrap(err, "trusted validator set is not tendermint validator set type") } @@ -135,7 +135,7 @@ func checkMisbehaviourHeader( // - ValidatorSet must have TrustLevel similarity with trusted FromValidatorSet // - ValidatorSets on both headers are valid given the last trusted ValidatorSet - if err := tmTrustedValset.VerifyCommitLightTrusting( + if err := tmTrustedVoterSet.VerifyCommitLightTrusting( chainID, tmCommit, clientState.TrustLevel.ToTendermint(), ); err != nil { return sdkerrors.Wrapf(clienttypes.ErrInvalidMisbehaviour, "validator set in header has too much change from trusted validator set: %v", err) diff --git a/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle_test.go b/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle_test.go index bef84a5c80..08e2383fa7 100644 --- a/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle_test.go +++ b/x/ibc/light-clients/99-ostracon/types/misbehaviour_handle_test.go @@ -20,10 +20,11 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { altPubKey, err := altPrivVal.GetPubKey() suite.Require().NoError(err) - altVal := tmtypes.NewValidator(altPubKey, 4) + altVal := ibctesting.NewTestValidator(altPubKey, 4) // Create bothValSet with both suite validator and altVal bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal)) + bothVoterSet := tmtypes.WrapValidatorsToVoterSet(bothValSet.Validators) // OSTRACON_CODE bothValsHash := bothValSet.Hash() // Create alternative validator set with only altVal altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) @@ -57,8 +58,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -72,8 +73,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+3), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+3), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -87,8 +88,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+3), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Hour), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+3), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Hour), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -102,8 +103,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), heightMinus1, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -117,8 +118,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), heightMinus3, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -132,8 +133,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), heightMinus3, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainIDRevision0, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainIDRevision0, int64(height.RevisionHeight+1), heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainIDRevision0, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainIDRevision0, int64(height.RevisionHeight+1), heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -147,8 +148,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), heightMinus3, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainIDRevision0, 3, heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainIDRevision0, 3, heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainIDRevision0, 3, heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainIDRevision0, 3, heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -162,8 +163,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), heightMinus3, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainIDRevision1, 1, heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainIDRevision1, 1, heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainIDRevision1, 1, heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainIDRevision1, 1, heightMinus3, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -177,8 +178,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, suite.valSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -192,8 +193,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -207,8 +208,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+3), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+3), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -222,8 +223,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader("ethermint", int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader("ethermint", int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader("ethermint", int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader("ethermint", int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -237,8 +238,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), heightMinus3, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -252,8 +253,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), suite.valsHash), heightMinus3, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus3, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus3, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -267,8 +268,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -282,8 +283,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -308,8 +309,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -323,8 +324,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), heightMinus1, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now.Add(trustingPeriod), @@ -338,8 +339,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, suite.valSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, suite.valSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, suite.valSet, bothVoterSet, tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators), bothSigners), ClientId: chainID, }, suite.now, @@ -353,8 +354,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, altValSet, bothValSet, altSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, altValSet, bothValSet, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators), bothVoterSet, altSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), ClientId: chainID, }, suite.now, @@ -368,8 +369,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), altValSet, bothValSet, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators), bothVoterSet, altSigners), ClientId: chainID, }, suite.now, @@ -383,8 +384,8 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() { types.NewConsensusState(suite.now, commitmenttypes.NewMerkleRoot(tmhash.Sum([]byte("app_hash"))), bothValsHash), height, &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, altValSet, bothValSet, altSigners), - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), altValSet, bothValSet, altSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now, altValSet, bothValSet, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators), bothVoterSet, altSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+1), height, suite.now.Add(time.Minute), altValSet, bothValSet, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators), bothVoterSet, altSigners), ClientId: chainID, }, suite.now, diff --git a/x/ibc/light-clients/99-ostracon/types/misbehaviour_test.go b/x/ibc/light-clients/99-ostracon/types/misbehaviour_test.go index 30892b0d07..2cba5c3061 100644 --- a/x/ibc/light-clients/99-ostracon/types/misbehaviour_test.go +++ b/x/ibc/light-clients/99-ostracon/types/misbehaviour_test.go @@ -18,9 +18,10 @@ func (suite *TendermintTestSuite) TestMisbehaviour() { signers := []tmtypes.PrivValidator{suite.privVal} heightMinus1 := clienttypes.NewHeight(0, height.RevisionHeight-1) + voterSet := tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators) misbehaviour := &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, voterSet, voterSet, signers), ClientId: clientID, } @@ -35,7 +36,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { revisionHeight := int64(height.RevisionHeight) - altVal := tmtypes.NewValidator(altPubKey, revisionHeight) + altVal := ibctesting.NewTestValidator(altPubKey, revisionHeight) // Create bothValSet with both suite validator and altVal bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal)) @@ -52,6 +53,9 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { heightMinus1 := clienttypes.NewHeight(0, height.RevisionHeight-1) + voterSet := tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators) + bothVoterSet := tmtypes.WrapValidatorsToVoterSet(bothValSet.Validators) + testCases := []struct { name string misbehaviour *types.Misbehaviour @@ -62,7 +66,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "valid fork misbehaviour, two headers at same height have different time", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, voterSet, voterSet, signers), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -71,7 +75,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { { "valid time misbehaviour, both headers at different heights are at same time", &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight+5), heightMinus1, suite.now, suite.valSet, suite.valSet, signers), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, voterSet, voterSet, signers), Header2: suite.header, ClientId: clientID, }, @@ -94,7 +98,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "valid misbehaviour with different trusted headers", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), clienttypes.NewHeight(0, height.RevisionHeight-3), suite.now.Add(time.Minute), suite.valSet, bothValSet, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), clienttypes.NewHeight(0, height.RevisionHeight-3), suite.now.Add(time.Minute), suite.valSet, bothValSet, voterSet, bothVoterSet, signers), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -103,7 +107,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { { "trusted height is 0 in Header1", &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), clienttypes.ZeroHeight(), suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), clienttypes.ZeroHeight(), suite.now.Add(time.Minute), suite.valSet, suite.valSet, voterSet, voterSet, signers), Header2: suite.header, ClientId: clientID, }, @@ -114,7 +118,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "trusted height is 0 in Header2", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), clienttypes.ZeroHeight(), suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), clienttypes.ZeroHeight(), suite.now.Add(time.Minute), suite.valSet, suite.valSet, voterSet, voterSet, signers), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -123,7 +127,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { { "trusted valset is nil in Header1", &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, nil, signers), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, nil, voterSet, nil, signers), Header2: suite.header, ClientId: clientID, }, @@ -134,7 +138,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "trusted valset is nil in Header2", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, nil, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now.Add(time.Minute), suite.valSet, nil, voterSet, nil, signers), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -144,7 +148,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "invalid client ID ", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, voterSet, voterSet, signers), ClientId: "GAIA", }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -154,7 +158,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "chainIDs do not match", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader("ethermint", int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, signers), + Header2: suite.chainA.CreateTMClientHeader("ethermint", int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, voterSet, voterSet, signers), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -164,7 +168,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "header2 height is greater", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, 6, clienttypes.NewHeight(0, height.RevisionHeight+1), suite.now, suite.valSet, suite.valSet, signers), + Header2: suite.chainA.CreateTMClientHeader(chainID, 6, clienttypes.NewHeight(0, height.RevisionHeight+1), suite.now, suite.valSet, suite.valSet, voterSet, voterSet, signers), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { return nil }, @@ -173,13 +177,13 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { { "header 1 doesn't have 2/3 majority", &types.Misbehaviour{ - Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, bothValSet, suite.valSet, bothSigners), + Header1: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners), Header2: suite.header, ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { // voteSet contains only altVal which is less than 2/3 of total power (height/1height) - wrongVoteSet := tmtypes.NewVoteSet(chainID, int64(misbehaviour.Header1.GetHeight().GetRevisionHeight()), 1, tmproto.PrecommitType, altValSet) + wrongVoteSet := tmtypes.NewVoteSet(chainID, int64(misbehaviour.Header1.GetHeight().GetRevisionHeight()), 1, tmproto.PrecommitType, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators)) blockID, err := tmtypes.BlockIDFromProto(&misbehaviour.Header1.Commit.BlockID) if err != nil { return err @@ -195,12 +199,12 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "header 2 doesn't have 2/3 majority", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, bothValSet, suite.valSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { // voteSet contains only altVal which is less than 2/3 of total power (height/1height) - wrongVoteSet := tmtypes.NewVoteSet(chainID, int64(misbehaviour.Header2.GetHeight().GetRevisionHeight()), 1, tmproto.PrecommitType, altValSet) + wrongVoteSet := tmtypes.NewVoteSet(chainID, int64(misbehaviour.Header2.GetHeight().GetRevisionHeight()), 1, tmproto.PrecommitType, tmtypes.WrapValidatorsToVoterSet(altValSet.Validators)) blockID, err := tmtypes.BlockIDFromProto(&misbehaviour.Header2.Commit.BlockID) if err != nil { return err @@ -216,7 +220,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() { "validators sign off on wrong commit", &types.Misbehaviour{ Header1: suite.header, - Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, bothValSet, suite.valSet, bothSigners), + Header2: suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners), ClientId: clientID, }, func(misbehaviour *types.Misbehaviour) error { diff --git a/x/ibc/light-clients/99-ostracon/types/ostracon_test.go b/x/ibc/light-clients/99-ostracon/types/ostracon_test.go index 82b287b4ca..8cd00463c9 100644 --- a/x/ibc/light-clients/99-ostracon/types/ostracon_test.go +++ b/x/ibc/light-clients/99-ostracon/types/ostracon_test.go @@ -19,10 +19,10 @@ import ( ) const ( - chainID = "gaia" - chainIDRevision0 = "gaia-revision-0" - chainIDRevision1 = "gaia-revision-1" - clientID = "gaiamainnet" + chainID = "lbm" + chainIDRevision0 = "lbm-revision-0" + chainIDRevision1 = "lbm-revision-1" + clientID = "lbmmainnet" trustingPeriod time.Duration = time.Hour * 24 * 7 * 2 ubdPeriod time.Duration = time.Hour * 24 * 7 * 3 maxClockDrift time.Duration = time.Second * 10 @@ -83,10 +83,11 @@ func (suite *TendermintTestSuite) SetupTest() { heightMinus1 := clienttypes.NewHeight(0, height.RevisionHeight-1) - val := tmtypes.NewValidator(pubKey, 10) + val := ibctesting.NewTestValidator(pubKey, 10) suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{val}) suite.valsHash = suite.valSet.Hash() - suite.header = suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal}) + voterSet := tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators) + suite.header = suite.chainA.CreateTMClientHeader(chainID, int64(height.RevisionHeight), heightMinus1, suite.now, suite.valSet, suite.valSet, voterSet, voterSet, []tmtypes.PrivValidator{suite.privVal}) suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1, Time: suite.now}) } diff --git a/x/ibc/light-clients/99-ostracon/types/update.go b/x/ibc/light-clients/99-ostracon/types/update.go index 6901f2075a..184834b2f7 100644 --- a/x/ibc/light-clients/99-ostracon/types/update.go +++ b/x/ibc/light-clients/99-ostracon/types/update.go @@ -182,7 +182,7 @@ func checkValidity( ) } - tmTrustedValidators, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators) + tmTrustedVoters, err := tmtypes.VoterSetFromProto(header.TrustedVoters) if err != nil { return sdkerrors.Wrap(err, "trusted validator set in not tendermint validator set type") } @@ -192,7 +192,7 @@ func checkValidity( return sdkerrors.Wrap(err, "signed header in not tendermint signed header type") } - tmValidatorSet, err := tmtypes.ValidatorSetFromProto(header.ValidatorSet) + tmVoterSet, err := tmtypes.VoterSetFromProto(header.VoterSet) if err != nil { return sdkerrors.Wrap(err, "validator set in not tendermint validator set type") } @@ -233,9 +233,9 @@ func checkValidity( // - assert header timestamp is not past the trusting period // - assert header timestamp is past latest stored consensus state timestamp // - assert that a TrustLevel proportion of TrustedValidators signed new Commit - err = light.Verify( + err = light.VerifyWithVoterSet( &signedHeader, - tmTrustedValidators, tmSignedHeader, tmValidatorSet, + tmTrustedVoters, tmSignedHeader, tmVoterSet, clientState.TrustingPeriod, currentTimestamp, clientState.MaxClockDrift, clientState.TrustLevel.ToTendermint(), ) if err != nil { diff --git a/x/ibc/light-clients/99-ostracon/types/update_test.go b/x/ibc/light-clients/99-ostracon/types/update_test.go index d147b97499..63099118ef 100644 --- a/x/ibc/light-clients/99-ostracon/types/update_test.go +++ b/x/ibc/light-clients/99-ostracon/types/update_test.go @@ -22,6 +22,8 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { newHeader *types.Header currentTime time.Time bothValSet *tmtypes.ValidatorSet + voterSet *tmtypes.VoterSet + bothVoterSet *tmtypes.VoterSet signers []tmtypes.PrivValidator bothSigners []tmtypes.PrivValidator ) @@ -39,9 +41,10 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { heightMinus3 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight-3) heightPlus5 := clienttypes.NewHeight(height.RevisionNumber, height.RevisionHeight+5) - altVal := tmtypes.NewValidator(altPubKey, revisionHeight) + altVal := ibctesting.NewTestValidator(altPubKey, revisionHeight) // Create alternative validator set with only altVal, invalid update (too much change in valSet) altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) + altVoterSet := tmtypes.WrapValidatorsToVoterSet(altValSet.Validators) altSigners := []tmtypes.PrivValidator{altPrivVal} testCases := []struct { @@ -55,7 +58,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -66,7 +69,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, bothValSet, suite.valSet, bothSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners) currentTime = suite.now }, expFrozen: false, @@ -77,7 +80,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), bothValSet.Hash()) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, bothValSet, bothValSet, bothSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners) currentTime = suite.now }, expFrozen: false, @@ -89,7 +92,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) consStateHeight = heightMinus3 - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightMinus1.RevisionHeight), heightMinus3, suite.headerTime, bothValSet, suite.valSet, bothSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightMinus1.RevisionHeight), heightMinus3, suite.headerTime, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners) currentTime = suite.now }, expFrozen: false, @@ -101,7 +104,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { clientState = types.NewClientState(chainIDRevision1, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) consStateHeight = heightMinus3 - newHeader = suite.chainA.CreateTMClientHeader(chainIDRevision0, int64(height.RevisionHeight), heightMinus3, suite.headerTime, bothValSet, suite.valSet, bothSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainIDRevision0, int64(height.RevisionHeight), heightMinus3, suite.headerTime, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners) currentTime = suite.now }, expPass: true, @@ -111,7 +114,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, heightPlus1, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now ctx := suite.chainA.GetContext().WithBlockTime(currentTime) // Store the header's consensus state in client store before UpdateClient call @@ -125,7 +128,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, heightPlus1, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now ctx := suite.chainA.GetContext().WithBlockTime(currentTime) // Change the consensus state of header and store in client store to create a conflict @@ -143,7 +146,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { // create an intermediate consensus state with the same time as the newHeader to create a time violation. // header time is after client time consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now prevConsensusState := types.NewConsensusState(suite.headerTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) ctx := suite.chainA.GetContext().WithBlockTime(currentTime) @@ -161,7 +164,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { // create the next consensus state with the same time as the intermediate newHeader to create a time violation. // header time is after clientTime consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now nextConsensusState := types.NewConsensusState(suite.headerTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) ctx := suite.chainA.GetContext().WithBlockTime(currentTime) @@ -177,7 +180,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader("ethermint", int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader("ethermint", int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -188,7 +191,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainIDRevision0, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainIDRevision1, 1, height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainIDRevision1, 1, height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expPass: false, @@ -198,7 +201,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainIDRevision1, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clienttypes.NewHeight(1, 1), commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainIDRevision1, 3, height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainIDRevision1, 3, height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -209,7 +212,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, bothValSet, suite.valSet, bothSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, bothValSet, suite.valSet, bothVoterSet, voterSet, bothSigners) currentTime = suite.now }, expFrozen: false, @@ -220,7 +223,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), bothValSet.Hash()) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, bothValSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, bothValSet, voterSet, bothVoterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -231,7 +234,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, altValSet, suite.valSet, altSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, altValSet, suite.valSet, altVoterSet, voterSet, altSigners) currentTime = suite.now }, expFrozen: false, @@ -242,7 +245,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, bothValSet, bothValSet, bothSigners) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus5.RevisionHeight), height, suite.headerTime, bothValSet, bothValSet, bothVoterSet, bothVoterSet, bothSigners) currentTime = suite.now }, expFrozen: false, @@ -253,7 +256,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) // make current time pass trusting period from last timestamp on clientstate currentTime = suite.now.Add(trustingPeriod) }, @@ -265,7 +268,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.now.Add(time.Minute), suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -276,7 +279,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.clientTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.clientTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -287,7 +290,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { setup: func(suite *TendermintTestSuite) { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightPlus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) // cause new header to fail validatebasic by changing commit height to mismatch header height newHeader.SignedHeader.Commit.Height = revisionHeight - 1 currentTime = suite.now @@ -301,7 +304,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { clientState = types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, clienttypes.NewHeight(height.RevisionNumber, heightPlus5.RevisionHeight), commitmenttypes.GetSDKSpecs(), upgradePath, false, false) consensusState = types.NewConsensusState(suite.clientTime, commitmenttypes.NewMerkleRoot(suite.header.Header.GetAppHash()), suite.valsHash) // Make new header at height less than latest client state - newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightMinus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, signers) + newHeader = suite.chainA.CreateTMClientHeader(chainID, int64(heightMinus1.RevisionHeight), height, suite.headerTime, suite.valSet, suite.valSet, voterSet, voterSet, signers) currentTime = suite.now }, expFrozen: false, @@ -321,6 +324,9 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { _, suiteVal := suite.valSet.GetByIndex(0) bothSigners = ibctesting.CreateSortedSignerArray(altPrivVal, suite.privVal, altVal, suiteVal) + voterSet = tmtypes.WrapValidatorsToVoterSet(suite.valSet.Validators) + bothVoterSet = tmtypes.WrapValidatorsToVoterSet(bothValSet.Validators) + consStateHeight = height // must be explicitly changed // setup test tc.setup(suite) diff --git a/x/ibc/testing/app.go b/x/ibc/testing/app.go index 6cf9d618d1..a41318069c 100644 --- a/x/ibc/testing/app.go +++ b/x/ibc/testing/app.go @@ -71,7 +71,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs bondAmt := sdk.TokensFromConsensusPower(1, powerReduction) for _, val := range valSet.Validators { - pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) + pk, err := cryptocodec.FromOcPubKeyInterface(val.PubKey) require.NoError(t, err) pkAny, err := codectypes.NewAnyWithValue(pk) require.NoError(t, err) diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 04ac254ba0..7987f7cf04 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -19,6 +19,7 @@ import ( "github.com/line/lbm-sdk/x/staking/teststaking" stakingtypes "github.com/line/lbm-sdk/x/staking/types" abci "github.com/line/ostracon/abci/types" + "github.com/line/ostracon/crypto" "github.com/line/ostracon/crypto/tmhash" tmproto "github.com/line/ostracon/proto/ostracon/types" tmprotoversion "github.com/line/ostracon/proto/ostracon/version" @@ -61,6 +62,7 @@ type TestChain struct { Codec codec.BinaryCodec Vals *tmtypes.ValidatorSet + Voters *tmtypes.VoterSet Signers []tmtypes.PrivValidator // autogenerated sender private key @@ -70,6 +72,12 @@ type TestChain struct { SenderAccounts []SenderAccount } +func NewTestValidator(pubkey crypto.PubKey, votingPower int64) *tmtypes.Validator { + val := tmtypes.NewValidator(pubkey, votingPower) + val.VotingWeight = val.VotingPower + return val +} + // NewTestChainWithValSet initializes a new TestChain instance with the given validator set // and signer array. It also initializes 10 Sender accounts with a balance of 10000000000000000000 coins of // bond denom to use for tests. @@ -135,6 +143,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va TxConfig: txConfig, Codec: app.AppCodec(), Vals: valSet, + Voters: tmtypes.WrapValidatorsToVoterSet(valSet.Validators), Signers: signers, SenderPrivKey: senderAccs[0].SenderPrivKey, SenderAccount: senderAccs[0].SenderAccount, @@ -160,7 +169,7 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain { privVal := mock.NewPV() pubKey, err := privVal.GetPubKey() require.NoError(t, err) - validators = append(validators, tmtypes.NewValidator(pubKey, 1)) + validators = append(validators, NewTestValidator(pubKey, 1)) signersByAddress[pubKey.Address().String()] = privVal } @@ -289,6 +298,14 @@ func (chain *TestChain) sendMsgs(msgs ...sdk.Msg) error { return err } +func (chain *TestChain) CommitBlock() { + chain.App.EndBlock(abci.RequestEndBlock{Height: chain.CurrentHeader.Height}) + chain.App.Commit() + + chain.App.BeginRecheckTx(abci.RequestBeginRecheckTx{Header: chain.CurrentHeader}) + chain.App.EndRecheckTx(abci.RequestEndRecheckTx{Height: chain.CurrentHeader.Height}) +} + // SendMsgs delivers a transaction through the application. It updates the senders sequence // number and updates the TestChain's headers. It returns the result and error if one // occurred. @@ -347,13 +364,33 @@ func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bo valSet := stakingtypes.Validators(histInfo.Valset) - tmValidators, err := teststaking.ToTmValidators(valSet, sdk.DefaultPowerReduction) + tmValidators, err := teststaking.ToOcValidators(valSet, sdk.DefaultPowerReduction) if err != nil { panic(err) } return tmtypes.NewValidatorSet(tmValidators), true } +func (chain *TestChain) GetVotersAtHeight(height int64) (*tmtypes.VoterSet, bool) { + histInfo, ok := chain.App.GetStakingKeeper().GetHistoricalInfo(chain.GetContext(), height) + if !ok { + return nil, false + } + + // Voters of test chain is always same to validator set + voters := stakingtypes.Validators(histInfo.Valset) + ocVoters, err := teststaking.ToOcValidators(voters, sdk.DefaultPowerReduction) + if err != nil { + panic(err) + } + // Validators saved in HistoricalInfo store have no voting power. + // We set voting weight same as voting power for test. + for i := 0; i < len(ocVoters); i++ { + ocVoters[i].VotingWeight = ocVoters[i].VotingPower + } + return tmtypes.WrapValidatorsToVoterSet(ocVoters), true +} + // GetAcknowledgement retrieves an acknowledgement for the provided packet. If the // acknowledgement does not exist then testing will fail. func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte { @@ -383,14 +420,16 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa trustedHeight = chain.GetClientState(clientID).GetLatestHeight().(clienttypes.Height) } var ( - tmTrustedVals *tmtypes.ValidatorSet - ok bool + tmTrustedVals *tmtypes.ValidatorSet + tmTrustedVoters *tmtypes.VoterSet + ok bool ) // Once we get TrustedHeight from client, we must query the validators from the counterparty chain // If the LatestHeight == LastHeader.Height, then TrustedValidators are current validators // If LatestHeight < LastHeader.Height, we can query the historical validator set from HistoricalInfo if trustedHeight == counterparty.LastHeader.GetHeight() { tmTrustedVals = counterparty.Vals + tmTrustedVoters = counterparty.Voters } else { // NOTE: We need to get validators from counterparty at height: trustedHeight+1 // since the last trusted validators for a header at height h @@ -400,6 +439,11 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa if !ok { return nil, sdkerrors.Wrapf(ibctmtypes.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight) } + + tmTrustedVoters, ok = counterparty.GetVotersAtHeight(int64(trustedHeight.RevisionHeight + 1)) + if !ok { + return nil, sdkerrors.Wrapf(ibctmtypes.ErrInvalidHeaderHeight, "could not retrieve trusted voters at trustedHeight: %d", trustedHeight) + } } // inject trusted fields into last header // for now assume revision number is 0 @@ -409,7 +453,12 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa if err != nil { return nil, err } + trustedVoters, err := tmTrustedVoters.ToProto() + if err != nil { + return nil, err + } header.TrustedValidators = trustedVals + header.TrustedVoters = trustedVoters return header, nil } @@ -423,17 +472,20 @@ func (chain *TestChain) ExpireClient(amount time.Duration) { // CurrentTMClientHeader creates a TM header using the current header parameters // on the chain. The trusted fields in the header are set to nil. func (chain *TestChain) CurrentTMClientHeader() *ibctmtypes.Header { - return chain.CreateTMClientHeader(chain.ChainID, chain.CurrentHeader.Height, clienttypes.Height{}, chain.CurrentHeader.Time, chain.Vals, nil, chain.Signers) + return chain.CreateTMClientHeader(chain.ChainID, chain.CurrentHeader.Height, clienttypes.Height{}, chain.CurrentHeader.Time, chain.Vals, nil, chain.Voters, nil, chain.Signers) } // CreateTMClientHeader creates a TM header to update the TM client. Args are passed in to allow // caller flexibility to use params that differ from the chain. -func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *ibctmtypes.Header { +func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, tmVoterSet, tmTrustedVoterSet *tmtypes.VoterSet, signers []tmtypes.PrivValidator) *ibctmtypes.Header { var ( - valSet *tmproto.ValidatorSet - trustedVals *tmproto.ValidatorSet + valSet *tmproto.ValidatorSet + trustedVals *tmproto.ValidatorSet + voterSet *tmproto.VoterSet + trustedVoters *tmproto.VoterSet ) require.NotNil(chain.T, tmValSet) + require.NotNil(chain.T, tmVoterSet) vsetHash := tmValSet.Hash() @@ -446,17 +498,18 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, LastCommitHash: chain.App.LastCommitID().Hash, DataHash: tmhash.Sum([]byte("data_hash")), ValidatorsHash: vsetHash, + VotersHash: tmVoterSet.Hash(), NextValidatorsHash: vsetHash, ConsensusHash: tmhash.Sum([]byte("consensus_hash")), AppHash: chain.CurrentHeader.AppHash, LastResultsHash: tmhash.Sum([]byte("last_results_hash")), EvidenceHash: tmhash.Sum([]byte("evidence_hash")), - ProposerAddress: tmValSet.Proposer.Address, //nolint:staticcheck + ProposerAddress: tmValSet.SelectProposer([]byte{}, blockHeight, 0).Address, //nolint:staticcheck } hhash := tmHeader.Hash() blockID := MakeBlockID(hhash, 3, tmhash.Sum([]byte("part_set"))) - voteSet := tmtypes.NewVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, tmValSet) + voteSet := tmtypes.NewVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, tmVoterSet) commit, err := tmtypes.MakeCommit(blockID, blockHeight, 1, voteSet, signers, timestamp) require.NoError(chain.T, err) @@ -476,13 +529,27 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64, require.NoError(chain.T, err) } + voterSet, err = tmVoterSet.ToProto() + if err != nil { + panic(err) + } + + if tmTrustedVoterSet != nil { + trustedVoters, err = tmTrustedVoterSet.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, + VoterSet: voterSet, TrustedHeight: trustedHeight, TrustedValidators: trustedVals, + TrustedVoters: trustedVoters, } } @@ -534,7 +601,7 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope require.NoError(chain.T, err) } - chain.App.Commit() + chain.CommitBlock() chain.NextBlock() } @@ -562,7 +629,7 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc require.NoError(chain.T, err) } - chain.App.Commit() + chain.CommitBlock() chain.NextBlock() } diff --git a/x/ibc/testing/chain_test.go b/x/ibc/testing/chain_test.go index edd7873a9f..0af13e04c9 100644 --- a/x/ibc/testing/chain_test.go +++ b/x/ibc/testing/chain_test.go @@ -19,8 +19,8 @@ func TestCreateSortedSignerArray(t *testing.T) { pubKey2, err := privVal2.GetPubKey() require.NoError(t, err) - validator1 := tmtypes.NewValidator(pubKey1, 1) - validator2 := tmtypes.NewValidator(pubKey2, 2) + validator1 := ibctesting.NewTestValidator(pubKey1, 1) + validator2 := ibctesting.NewTestValidator(pubKey2, 2) expected := []tmtypes.PrivValidator{privVal2, privVal1} diff --git a/x/ibc/testing/coordinator.go b/x/ibc/testing/coordinator.go index 7a00397458..1c4fdfc0ec 100644 --- a/x/ibc/testing/coordinator.go +++ b/x/ibc/testing/coordinator.go @@ -181,7 +181,7 @@ func GetChainID(index int) string { // CONTRACT: the passed in list of indexes must not contain duplicates func (coord *Coordinator) CommitBlock(chains ...*TestChain) { for _, chain := range chains { - chain.App.Commit() + chain.CommitBlock() chain.NextBlock() } coord.IncrementTime() @@ -191,7 +191,7 @@ func (coord *Coordinator) CommitBlock(chains ...*TestChain) { func (coord *Coordinator) CommitNBlocks(chain *TestChain, n uint64) { for i := uint64(0); i < n; i++ { chain.App.BeginBlock(abci.RequestBeginBlock{Header: chain.CurrentHeader}) - chain.App.Commit() + chain.CommitBlock() chain.NextBlock() coord.IncrementTime() } diff --git a/x/ibc/testing/mock/privval.go b/x/ibc/testing/mock/privval.go index 212d36212d..1caeed4c3e 100644 --- a/x/ibc/testing/mock/privval.go +++ b/x/ibc/testing/mock/privval.go @@ -23,7 +23,7 @@ func NewPV() PV { // GetPubKey implements PrivValidator interface func (pv PV) GetPubKey() (crypto.PubKey, error) { - return cryptocodec.ToTmPubKeyInterface(pv.PrivKey.PubKey()) + return cryptocodec.ToOcPubKeyInterface(pv.PrivKey.PubKey()) } // SignVote implements PrivValidator interface @@ -47,3 +47,7 @@ func (pv PV) SignProposal(chainID string, proposal *tmproto.Proposal) error { proposal.Signature = sig return nil } + +func (pv PV) GenerateVRFProof(message []byte) (crypto.Proof, error) { + return nil, nil +} diff --git a/x/ibc/testing/simapp/sim_test.go b/x/ibc/testing/simapp/sim_test.go index 4c8841fe0e..8ac60eb907 100644 --- a/x/ibc/testing/simapp/sim_test.go +++ b/x/ibc/testing/simapp/sim_test.go @@ -9,6 +9,7 @@ import ( "github.com/line/lbm-sdk/baseapp" "github.com/line/lbm-sdk/store" + "github.com/line/lbm-sdk/store/cache" sdk "github.com/line/lbm-sdk/types" simtypes "github.com/line/lbm-sdk/types/simulation" authtypes "github.com/line/lbm-sdk/x/auth/types" @@ -54,7 +55,8 @@ func fauxMerkleModeOpt(bapp *baseapp.BaseApp) { // interBlockCacheOpt returns a BaseApp option function that sets the persistent // inter-block write-through cache. func interBlockCacheOpt() func(*baseapp.BaseApp) { - return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager()) + return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager( + cache.DefaultCommitKVStoreCacheSize, cache.NopMetricsProvider())) } func TestFullAppSimulation(t *testing.T) { diff --git a/x/ibc/testing/simapp/simd/cmd/root.go b/x/ibc/testing/simapp/simd/cmd/root.go index 8676911c37..71e1dcfe41 100644 --- a/x/ibc/testing/simapp/simd/cmd/root.go +++ b/x/ibc/testing/simapp/simd/cmd/root.go @@ -28,6 +28,7 @@ import ( "github.com/line/ostracon/libs/log" "github.com/spf13/cast" "github.com/spf13/cobra" + "github.com/spf13/viper" dbm "github.com/tendermint/tm-db" "github.com/line/lbm-sdk/x/ibc/testing/simapp" @@ -231,8 +232,10 @@ type appCreator struct { func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application { var cache sdk.MultiStorePersistentCache + ibCacheMetricsProvider := baseapp.MetricsProvider(cast.ToBool(viper.GetBool(server.FlagPrometheus))) if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) { - cache = store.NewCommitKVStoreCacheManager() + cache = store.NewCommitKVStoreCacheManager( + cast.ToInt(appOpts.Get(server.FlagInterBlockCacheSize)), ibCacheMetricsProvider) } skipUpgradeHeights := make(map[int64]bool)