Skip to content

Commit

Permalink
upgraded to ics v3.2.0 (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Jan 10, 2024
1 parent 349fce3 commit 2113b4f
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 147 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ import (
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibchost "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
ccvstaking "github.com/cosmos/interchain-security/v3/x/ccv/democracy/staking"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types"
"github.com/spf13/cast"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
Expand Down Expand Up @@ -154,9 +154,9 @@ import (
ccvconsumer "github.com/cosmos/interchain-security/v3/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvstaking "github.com/cosmos/interchain-security/v3/x/ccv/democracy/staking"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/core"
)

const (
Expand Down Expand Up @@ -970,7 +970,7 @@ func (app *StrideApp) Name() string { return app.BaseApp.Name() }
func (app *StrideApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }

// GetStakingKeeper implements the TestingApp interface.
func (app *StrideApp) GetStakingKeeper() core.StakingKeeper {
func (app *StrideApp) GetStakingKeeper() ibctestingtypes.StakingKeeper {
return app.StakingKeeper
}

Expand Down
104 changes: 56 additions & 48 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/ed25519"
tmencoding "github.com/cometbft/cometbft/crypto/encoding"
tmtypesproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -24,12 +25,12 @@ import (
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/cosmos/ibc-go/v7/testing/simapp"
appProvider "github.com/cosmos/interchain-security/v3/app/provider"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
icstestingutils "github.com/cosmos/interchain-security/v3/testutil/ibc_testing"
e2e "github.com/cosmos/interchain-security/v3/testutil/integration"
ccvprovidertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -139,67 +140,74 @@ func (s *AppTestHelper) SetupIBCChains(hostChainID string) {
s.Coordinator = ibctesting.NewCoordinator(s.T(), 0)

// Initialize a provider testing app
s.ProviderChain = ibctesting.NewTestChain(s.T(), s.Coordinator, icstestingutils.ProviderAppIniter, ProviderChainID)
ibctesting.DefaultTestingAppInit = icstestingutils.ProviderAppIniter
s.ProviderChain = ibctesting.NewTestChain(s.T(), s.Coordinator, ProviderChainID)
s.ProviderApp = s.ProviderChain.App.(*appProvider.App)

// Initialize a stride testing app by casting a StrideApp -> TestingApp
s.StrideChain = ibctesting.NewTestChainWithValSet(s.T(), s.Coordinator, app.InitStrideIBCTestingApp, StrideChainID,
s.ProviderChain.Vals, s.ProviderChain.Signers)

// Initialize a host testing app using SimApp -> TestingApp
s.HostChain = ibctesting.NewTestChain(s.T(), s.Coordinator, ibctesting.SetupTestingApp, hostChainID)

// Update coordinator
s.Coordinator.Chains = map[string]*ibctesting.TestChain{
StrideChainID: s.StrideChain,
hostChainID: s.HostChain,
ProviderChainID: s.ProviderChain,
}
s.IbcEnabled = true

// valsets must match
providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.ProviderChain.Vals)
strideValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.StrideChain.Vals)
s.Require().True(len(providerValUpdates) == len(strideValUpdates), "initial valset not matching")

// for i := 0; i < len(providerValUpdates); i++ {
// addr1 := ccvutils.GetChangePubKeyAddress(providerValUpdates[i])
// addr2 := ccvutils.GetChangePubKeyAddress(strideValUpdates[i])
// s.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
// }

// move chains to the next block
s.ProviderChain.NextBlock()
s.StrideChain.NextBlock()
s.HostChain.NextBlock()

ibctesting.DefaultTestingAppInit = ibctesting.SetupTestingApp
s.HostChain = ibctesting.NewTestChain(s.T(), s.Coordinator, hostChainID)

// create a consumer addition prop
// NOTE: the initial height passed to CreateConsumerClient
// must be the height on the consumer when InitGenesis is called
prop := testkeeper.GetTestConsumerAdditionProp()
prop.ChainId = StrideChainID
prop.UnbondingPeriod = s.ProviderApp.GetTestStakingKeeper().UnbondingTime(s.ProviderChain.GetContext())
prop.InitialHeight = clienttypes.Height{RevisionNumber: 0, RevisionHeight: 3}

// create a consumer client on the provider chain
providerKeeper := s.ProviderApp.GetProviderKeeper()
// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
err := providerKeeper.CreateConsumerClient(
s.ProviderChain.GetContext(),
&ccvprovidertypes.ConsumerAdditionProposal{
ChainId: s.StrideChain.ChainID,
InitialHeight: s.StrideChain.LastHeader.GetHeight().(clienttypes.Height),
BlocksPerDistributionTransmission: 50,
CcvTimeoutPeriod: time.Hour,
TransferTimeoutPeriod: time.Hour,
UnbondingPeriod: time.Hour * 504,
ConsumerRedistributionFraction: "0.75",
HistoricalEntries: 10000,
},
prop,
)
s.Require().NoError(err)

// move provider to next block to commit the state
s.ProviderChain.NextBlock()
// move provider and host chain to next block
s.Coordinator.CommitBlock(s.ProviderChain)
s.Coordinator.CommitBlock(s.HostChain)

// initialize the consumer chain with the genesis state stored on the provider
strideConsumerGenesis, found := providerKeeper.GetConsumerGenesis(
s.ProviderChain.GetContext(),
s.StrideChain.ChainID,
StrideChainID,
)
s.Require().True(found, "consumer genesis not found")

// use the initial validator set from the consumer genesis as the stride chain's initial set
var strideValSet []*tmtypes.Validator
for _, update := range strideConsumerGenesis.InitialValSet {
tmPubKey, err := tmencoding.PubKeyFromProto(update.PubKey)
s.Require().NoError(err)
strideValSet = append(strideValSet, &tmtypes.Validator{
PubKey: tmPubKey,
VotingPower: update.Power,
Address: tmPubKey.Address(),
ProposerPriority: 0,
})
}

// Initialize the stride consumer chain, casted as a TestingApp
ibctesting.DefaultTestingAppInit = app.InitStrideIBCTestingApp(strideConsumerGenesis.InitialValSet)
s.StrideChain = ibctesting.NewTestChainWithValSet(
s.T(),
s.Coordinator,
StrideChainID,
tmtypes.NewValidatorSet(strideValSet),
s.ProviderChain.Signers,
)

// Call InitGenesis on the consumer
s.StrideChain.App.(*app.StrideApp).GetConsumerKeeper().InitGenesis(s.StrideChain.GetContext(), &strideConsumerGenesis)

// Update coordinator
s.Coordinator.Chains = map[string]*ibctesting.TestChain{
StrideChainID: s.StrideChain,
hostChainID: s.HostChain,
ProviderChainID: s.ProviderChain,
}
s.IbcEnabled = true
}

// Creates clients, connections, and a transfer channel between stride and a host chain
Expand All @@ -217,7 +225,7 @@ func (s *AppTestHelper) CreateTransferChannel(hostChainID string) {

// Replace stride and host apps with those from TestingApp
s.App = s.StrideChain.App.(*app.StrideApp)
// s.HostApp = s.HostChain.GetSimApp()
s.HostApp = s.HostChain.GetSimApp()
s.Ctx = s.StrideChain.GetContext()

// Finally confirm the channel was setup properly
Expand Down
26 changes: 20 additions & 6 deletions app/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

sdkmath "cosmossdk.io/math"
cometbftdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/abci/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/secp256k1"
"github.com/cometbft/cometbft/libs/log"
Expand All @@ -18,12 +19,13 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
appconsumer "github.com/cosmos/interchain-security/v3/app/consumer"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"

testutil "github.com/Stride-Labs/stride/v16/testutil"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"

cmdcfg "github.com/Stride-Labs/stride/v16/cmd/strided/config"
testutil "github.com/Stride-Labs/stride/v16/testutil"
)

const Bech32Prefix = "stride"
Expand Down Expand Up @@ -174,7 +176,19 @@ func GenesisStateWithValSet(app *StrideApp) GenesisState {
}

// Initializes a new Stride App casted as a TestingApp for IBC support
func InitStrideIBCTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) {
app := InitStrideTestApp(false)
return app, NewDefaultGenesisState()
func InitStrideIBCTestingApp(initValPowers []types.ValidatorUpdate) func() (ibctesting.TestingApp, map[string]json.RawMessage) {
return func() (ibctesting.TestingApp, map[string]json.RawMessage) {
encoding := appconsumer.MakeTestEncodingConfig()
app := InitStrideTestApp(false)
genesisState := NewDefaultGenesisState()

// Feed consumer genesis with provider validators
var consumerGenesis ccvtypes.ConsumerGenesisState
encoding.Codec.MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
consumerGenesis.Params.Enabled = true
genesisState[consumertypes.ModuleName] = encoding.Codec.MustMarshalJSON(&consumerGenesis)

return app, genesisState
}
}
3 changes: 2 additions & 1 deletion app/upgrades/v12/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
"github.com/spf13/cast"
)

Expand Down Expand Up @@ -49,7 +50,7 @@ func CreateUpgradeHandler(
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

var consumerGenesis = consumertypes.GenesisState{}
var consumerGenesis = ccvtypes.ConsumerGenesisState{}
cdc.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis)

consumerGenesis.PreCCV = true
Expand Down
5 changes: 3 additions & 2 deletions cmd/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
"github.com/spf13/cobra"

"github.com/Stride-Labs/stride/v16/testutil"
Expand Down Expand Up @@ -150,9 +151,9 @@ type GenesisData struct {
GenesisFile string
GenDoc *tmtypes.GenesisDoc
AppState map[string]json.RawMessage
ConsumerModuleState *ccvconsumertypes.GenesisState
ConsumerModuleState *ccvtypes.ConsumerGenesisState
}

func NewGenesisData(genesisFile string, genDoc *tmtypes.GenesisDoc, appState map[string]json.RawMessage, consumerModuleState *ccvconsumertypes.GenesisState) *GenesisData {
func NewGenesisData(genesisFile string, genDoc *tmtypes.GenesisDoc, appState map[string]json.RawMessage, consumerModuleState *ccvtypes.ConsumerGenesisState) *GenesisData {
return &GenesisData{GenesisFile: genesisFile, GenDoc: genDoc, AppState: appState, ConsumerModuleState: consumerModuleState}
}
54 changes: 28 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/Stride-Labs/stride/v16
go 1.19

require (
cosmossdk.io/math v1.0.1
cosmossdk.io/math v1.1.2
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.4
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/cosmos/ics23/go v0.10.0
github.com/cosmos/interchain-security/v3 v3.1.0
github.com/cosmos/interchain-security/v3 v3.2.0
github.com/evmos/vesting v0.0.0-20230818101748-9ea561e4529c
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
Expand All @@ -21,37 +21,44 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529
google.golang.org/grpc v1.57.0
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98
google.golang.org/grpc v1.58.2
gopkg.in/yaml.v2 v2.4.0

)

require github.com/linxGnu/grocksdb v1.7.16 // indirect

require github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect

require (
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect
cosmossdk.io/log v1.2.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/oxyno-zeta/gomock-extra-matcher v1.1.0 // indirect
github.com/rs/zerolog v1.29.1 // indirect
golang.org/x/sync v0.2.0 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
github.com/oxyno-zeta/gomock-extra-matcher v1.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/zerolog v1.30.0 // indirect
go.uber.org/mock v0.2.0 // indirect
golang.org/x/sync v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
)

require (
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.0
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
Expand Down Expand Up @@ -159,20 +166,20 @@ require (
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect; indirect ustrd
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect

)
Expand All @@ -183,12 +190,7 @@ replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 //indirect
// fork SDK to fix SDKv0.47 Distribution Bug
// TODO - Remove this patch and update Tokens in a subsequent upgrade handler
github.com/cosmos/cosmos-sdk => github.com/Stride-Labs/cosmos-sdk v0.47.4-stride-distribution-fix-1

// Two changes
// (1) Testing infra
// (2) Fix bech32 bug
github.com/cosmos/interchain-security/v3 => github.com/Stride-Labs/interchain-security/v3 v3.1.0-remove-validation-bug-7d3d9d
github.com/cosmos/cosmos-sdk => github.com/Stride-Labs/cosmos-sdk v0.47.5-stride-distribution-fix-0

// Add additional verification check to ensure an account is a BaseAccount type before converting
// it to a vesting account: https://github.com/Stride-Labs/vesting/pull/1
Expand Down
Loading

0 comments on commit 2113b4f

Please sign in to comment.