Skip to content

Commit

Permalink
Merge branch 'main' into sam/add-sttia-rate-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Mar 6, 2024
2 parents 73c33df + 48239b6 commit 6b1f14e
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 174 deletions.
4 changes: 2 additions & 2 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
consumerante "github.com/cosmos/interchain-security/v3/app/consumer/ante"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
consumerante "github.com/cosmos/interchain-security/v4/app/consumer/ante"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand Down
12 changes: 6 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ import (
tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types"
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"
ccvdistr "github.com/cosmos/interchain-security/v3/x/ccv/democracy/distribution"
ccvgov "github.com/cosmos/interchain-security/v3/x/ccv/democracy/governance"
ccvstaking "github.com/cosmos/interchain-security/v3/x/ccv/democracy/staking"
ccvconsumer "github.com/cosmos/interchain-security/v4/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
ccvdistr "github.com/cosmos/interchain-security/v4/x/ccv/democracy/distribution"
ccvgov "github.com/cosmos/interchain-security/v4/x/ccv/democracy/governance"
ccvstaking "github.com/cosmos/interchain-security/v4/x/ccv/democracy/staking"
evmosvesting "github.com/evmos/vesting/x/vesting"
evmosvestingclient "github.com/evmos/vesting/x/vesting/client"
evmosvestingkeeper "github.com/evmos/vesting/x/vesting/keeper"
Expand Down
22 changes: 13 additions & 9 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
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"
icstestingutils "github.com/cosmos/interchain-security/v3/testutil/ibc_testing"
e2e "github.com/cosmos/interchain-security/v3/testutil/integration"
testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
appProvider "github.com/cosmos/interchain-security/v4/app/provider"
icstestingutils "github.com/cosmos/interchain-security/v4/testutil/ibc_testing"
e2e "github.com/cosmos/interchain-security/v4/testutil/integration"
testkeeper "github.com/cosmos/interchain-security/v4/testutil/keeper"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -183,7 +184,7 @@ func (s *AppTestHelper) SetupIBCChains(hostChainID string) {

// 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 {
for _, update := range strideConsumerGenesis.Provider.InitialValSet {
tmPubKey, err := tmencoding.PubKeyFromProto(update.PubKey)
s.Require().NoError(err)
strideValSet = append(strideValSet, &tmtypes.Validator{
Expand All @@ -195,7 +196,7 @@ func (s *AppTestHelper) SetupIBCChains(hostChainID string) {
}

// Initialize the stride consumer chain, casted as a TestingApp
ibctesting.DefaultTestingAppInit = app.InitStrideIBCTestingApp(strideConsumerGenesis.InitialValSet)
ibctesting.DefaultTestingAppInit = app.InitStrideIBCTestingApp(strideConsumerGenesis.Provider.InitialValSet)
s.StrideChain = ibctesting.NewTestChainWithValSet(
s.T(),
s.Coordinator,
Expand All @@ -205,7 +206,10 @@ func (s *AppTestHelper) SetupIBCChains(hostChainID string) {
)

// Call InitGenesis on the consumer
s.StrideChain.App.(*app.StrideApp).GetConsumerKeeper().InitGenesis(s.StrideChain.GetContext(), &strideConsumerGenesis)
genesisState := consumertypes.DefaultGenesisState()
genesisState.Params = strideConsumerGenesis.Params
genesisState.Provider = strideConsumerGenesis.Provider
s.StrideChain.App.(*app.StrideApp).GetConsumerKeeper().InitGenesis(s.StrideChain.GetContext(), genesisState)
s.StrideChain.NextBlock()

// Update coordinator
Expand Down Expand Up @@ -236,7 +240,7 @@ func (s *AppTestHelper) CreateTransferChannel(hostChainID string) {
s.Ctx = s.StrideChain.GetContext()

// Finally confirm the channel was setup properly
s.Require().Equal("07-tendermint-1", s.TransferPath.EndpointA.ClientID, "stride clientID")
s.Require().Equal("07-tendermint-0", s.TransferPath.EndpointA.ClientID, "stride clientID")
s.Require().Equal(ibctesting.FirstConnectionID, s.TransferPath.EndpointA.ConnectionID, "stride connectionID")
s.Require().Equal(ibctesting.FirstChannelID, s.TransferPath.EndpointA.ChannelID, "stride transfer channelID")
}
Expand Down
12 changes: 6 additions & 6 deletions app/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
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"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
appconsumer "github.com/cosmos/interchain-security/v4/app/consumer"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types"

cmdcfg "github.com/Stride-Labs/stride/v18/cmd/strided/config"
testutil "github.com/Stride-Labs/stride/v18/testutil"
Expand Down Expand Up @@ -169,8 +169,8 @@ func GenesisStateWithValSet(app *StrideApp) GenesisState {
}

consumerGenesisState := testutil.CreateMinimalConsumerTestGenesis()
consumerGenesisState.InitialValSet = initValPowers
consumerGenesisState.ProviderConsensusState.NextValidatorsHash = tmtypes.NewValidatorSet(vals).Hash()
consumerGenesisState.Provider.InitialValSet = initValPowers
consumerGenesisState.Provider.ConsensusState.NextValidatorsHash = tmtypes.NewValidatorSet(vals).Hash()
consumerGenesisState.Params.Enabled = true
genesisState[consumertypes.ModuleName] = app.AppCodec().MustMarshalJSON(consumerGenesisState)

Expand All @@ -187,7 +187,7 @@ func InitStrideIBCTestingApp(initValPowers []types.ValidatorUpdate) func() (ibct
// Feed consumer genesis with provider validators
var consumerGenesis ccvtypes.ConsumerGenesisState
encoding.Codec.MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
consumerGenesis.Provider.InitialValSet = initValPowers
consumerGenesis.Params.Enabled = true
genesisState[consumertypes.ModuleName] = encoding.Codec.MustMarshalJSON(&consumerGenesis)

Expand Down
3 changes: 2 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
evmosvestingtypes "github.com/evmos/vesting/x/vesting/types"

ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
Expand Down Expand Up @@ -257,6 +257,7 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) {
app.mm,
app.configurator,
app.appCodec,
app.ConsumerKeeper,
app.RatelimitKeeper,
app.WasmKeeper,
),
Expand Down
7 changes: 3 additions & 4 deletions app/upgrades/v12/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
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"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
"github.com/spf13/cast"
)

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

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

consumerGenesis.PreCCV = true
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v14/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
evmosvestingkeeper "github.com/evmos/vesting/x/vesting/keeper"
"github.com/evmos/vesting/x/vesting/types"
evmosvestingtypes "github.com/evmos/vesting/x/vesting/types"
Expand Down
56 changes: 47 additions & 9 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper"
)

const (
Expand All @@ -21,13 +22,16 @@ const (
CelestiaTransferChannelId = "channel-162"
OsmosisTransferChannelId = "channel-5"
RateLimitDurationHours = 24

WasmAdmin = "stride159smvptpq6evq0x6jmca6t8y7j8xmwj6kxapyh"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v19
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
cdc codec.Codec,
consumerKeeper ccvconsumerkeeper.Keeper,
ratelimitKeeper ratelimitkeeper.Keeper,
wasmKeeper wasmkeeper.Keeper,
) upgradetypes.UpgradeHandler {
Expand All @@ -38,20 +42,22 @@ func CreateUpgradeHandler(
ctx.Logger().Info("Running module migrations...")
newVm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return newVm, err
return newVm, errorsmod.Wrapf(err, "unable to run module migrations")
}

// Update wasm params so that contracts can only be uploaded through governance
wasmParams := wasmKeeper.GetParams(ctx)
wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{
Permission: wasmtypes.AccessTypeNobody,
Addresses: []string{},
// Migrate ICS to v4
if err := MigrateICSOutstandingDowntime(ctx, consumerKeeper); err != nil {
return newVm, errorsmod.Wrapf(err, "unable to migrate ICS to v14")
}
wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody
if err := wasmKeeper.SetParams(ctx, wasmParams); err != nil {
return newVm, err

// Update wasm upload permissions
if err := SetWasmPermissions(ctx, wasmKeeper); err != nil {
return newVm, errorsmod.Wrapf(err, "unable to set wasm permissions")
}

// Migrate to open sourced rate limiter
MigrateRateLimitModule(ctx, ratelimitKeeper)

// Add stTIA rate limits to Celestia and Osmosis
if err := AddStTiaRateLimit(ctx, ratelimitKeeper); err != nil {
return newVm, err
Expand All @@ -61,6 +67,24 @@ func CreateUpgradeHandler(
}
}

// Migrates Outstanding Downtime for upgrade to ICS v4
// https://github.com/cosmos/interchain-security/blob/release/v4.0.x/UPGRADING.md#v40x
func MigrateICSOutstandingDowntime(ctx sdk.Context, ck ccvconsumerkeeper.Keeper) error {
ctx.Logger().Info("Migrating ICS outstanding downtime...")

downtimes := ck.GetAllOutstandingDowntimes(ctx)
for _, od := range downtimes {
consAddr, err := sdk.ConsAddressFromBech32(od.ValidatorConsensusAddress)
if err != nil {
return err
}
ck.DeleteOutstandingDowntime(ctx, consAddr)
}

ctx.Logger().Info("Finished ICS outstanding downtime")
return nil
}

// Migrate the rate limit module to the open sourced version
// The module has the same store key so all the rate limit types
// can remain unchanged
Expand Down Expand Up @@ -101,3 +125,17 @@ func AddStTiaRateLimit(ctx sdk.Context, k ratelimitkeeper.Keeper) error {

return nil
}

// Update wasm params so that contracts can only be uploaded through governance
func SetWasmPermissions(ctx sdk.Context, wk wasmkeeper.Keeper) error {
wasmParams := wk.GetParams(ctx)
wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{
Permission: wasmtypes.AccessTypeAnyOfAddresses,
Addresses: []string{WasmAdmin},
}
wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody
if err := wk.SetParams(ctx, wasmParams); err != nil {
return err
}
return nil
}
9 changes: 9 additions & 0 deletions app/upgrades/v19/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -47,6 +48,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
// Check state after upgrade
checkMigratedRateLimits()
checkStTiaRateLimits()
s.CheckWasmPerms()
}

func (s *UpgradeTestSuite) SetupRateLimitMigration() func() {
Expand Down Expand Up @@ -159,3 +161,10 @@ func (s *UpgradeTestSuite) SetupStTiaRateLimits() func() {
s.Require().Equal(expectedRateLimitToOsmosis, actualOsmosisRateLimit)
}
}

func (s *UpgradeTestSuite) CheckWasmPerms() {
wasmParams := s.App.WasmKeeper.GetParams(s.Ctx)
s.Require().Equal(wasmtypes.AccessTypeAnyOfAddresses, wasmParams.CodeUploadAccess.Permission, "upload permission")
s.Require().Equal(v19.WasmAdmin, wasmParams.CodeUploadAccess.Addresses[0], "upload address")
s.Require().Equal(wasmtypes.AccessTypeNobody, wasmParams.InstantiateDefaultPermission, "instantiate permission")
}
8 changes: 4 additions & 4 deletions cmd/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"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"
ccvconsumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types"
"github.com/spf13/cobra"

"github.com/Stride-Labs/stride/v18/testutil"
Expand Down Expand Up @@ -71,8 +71,8 @@ func AddConsumerSectionCmd(defaultNodeHome string) *cobra.Command {
return errorsmod.Wrap(err, "could not convert val updates to validator set")
}

genesisState.InitialValSet = initialValset
genesisState.ProviderConsensusState.NextValidatorsHash = tmtypes.NewValidatorSet(vals).Hash()
genesisState.Provider.InitialValSet = initialValset
genesisState.Provider.ConsensusState.NextValidatorsHash = tmtypes.NewValidatorSet(vals).Hash()

state.ConsumerModuleState = genesisState
return nil
Expand Down
Loading

0 comments on commit 6b1f14e

Please sign in to comment.