Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove consumer genesis migration on provider #997

Merged
merged 9 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions x/ccv/consumer/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ const (
// received over CCV channel but not yet flushed over ABCI
PendingChangesByteKey

// PendingDataPacketsByteKey is the byte key for storing
// a list of data packets that cannot be sent yet to the provider
// chain either because the CCV channel is not established or
// because the client is expired
PendingDataPacketsByteKey

// PreCCVByteKey is the byte to store the consumer is running on democracy staking module without consumer
PreCCVByteKey

// InitialValSetByteKey is the byte to store the initial validator set for a consumer
InitialValSetByteKey

// NOTE: This prefix is depreciated, but left in place to avoid consumer state migrations
LastStandaloneHeightByteKey

// SmallestNonOptOutPowerByteKey is the byte that will store the smallest val power that cannot opt out
SmallestNonOptOutPowerByteKey

// HistoricalInfoKey is the byte prefix that will store the historical info for a given height
HistoricalInfoBytePrefix

Expand All @@ -67,24 +85,9 @@ const (
// CrossChainValidatorPrefix is the byte prefix that will store cross-chain validators by consensus address
CrossChainValidatorBytePrefix

// PendingDataPacketsByteKey is the byte key for storing
// a list of data packets that cannot be sent yet to the provider
// chain either because the CCV channel is not established or
// because the client is expired
PendingDataPacketsByteKey

// PreCCVByteKey is the byte to store the consumer is running on democracy staking module without consumer
PreCCVByteKey

// InitialValSetByteKey is the byte to store the initial validator set for a consumer
InitialValSetByteKey

// InitGenesisHeightByteKey is the byte that will store the init genesis height
InitGenesisHeightByteKey

// SmallestNonOptOutPowerByteKey is the byte that will store the smallest val power that cannot opt out
SmallestNonOptOutPowerByteKey

// StandaloneTransferChannelIDByteKey is the byte storing the channelID of transfer channel
// that existed from a standalone chain changing over to a consumer
StandaloneTransferChannelIDByteKey
Expand Down Expand Up @@ -170,7 +173,7 @@ func CrossChainValidatorKey(addr []byte) []byte {
// that cannot be sent yet to the provider chain either because the CCV channel
// is not established or because the client is expired.
func PendingDataPacketsKey() []byte {
return []byte{PendingDataPacketsByteKey}
return []byte{PendingDataPacketsBytePrefix}
}

func PreCCVKey() []byte {
Expand Down
20 changes: 12 additions & 8 deletions x/ccv/consumer/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ func getAllKeyPrefixes() []byte {
ProviderClientByteKey,
ProviderChannelByteKey,
PendingChangesByteKey,
PendingDataPacketsByteKey,
PreCCVByteKey,
InitialValSetByteKey,
LastStandaloneHeightByteKey,
SmallestNonOptOutPowerByteKey,
HistoricalInfoBytePrefix,
PacketMaturityTimeBytePrefix,
HeightValsetUpdateIDBytePrefix,
OutstandingDowntimeBytePrefix,
PendingDataPacketsBytePrefix,
CrossChainValidatorBytePrefix,
PendingDataPacketsByteKey,
PreCCVByteKey,
InitialValSetByteKey,
InitGenesisHeightByteKey,
SmallestNonOptOutPowerByteKey,
StandaloneTransferChannelIDByteKey,
PrevStandaloneChainByteKey,
}
Expand All @@ -61,16 +63,18 @@ func getAllFullyDefinedKeys() [][]byte {
ProviderClientIDKey(),
ProviderChannelKey(),
PendingChangesKey(),
// PendingDataPacketsKey() does not use duplicated prefix with value of 0x06
PreCCVKey(),
InitialValSetKey(),
// LastStandaloneHeightKey() is depreciated
SmallestNonOptOutPowerKey(),
HistoricalInfoKey(0),
PacketMaturityTimeKey(0, time.Time{}),
HeightValsetUpdateIDKey(0),
OutstandingDowntimeKey([]byte{}),
CrossChainValidatorKey([]byte{}),
PendingDataPacketsKey(),
PreCCVKey(),
InitialValSetKey(),
CrossChainValidatorKey([]byte{}),
InitGenesisHeightKey(),
SmallestNonOptOutPowerKey(),
StandaloneTransferChannelIDKey(),
PrevStandaloneChainKey(),
}
Expand Down
14 changes: 4 additions & 10 deletions x/ccv/provider/keeper/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func (m Migrator) Migratev1Tov2(ctx sdk.Context) error {
sdk.NewCoin(m.ccvProviderKeeper.BondDenom(ctx), sdk.NewInt(10000000)),
)

// Delete select consumer genesis states for consumers that're launched
MigrateConsumerGenesisStatesv1Tov2(ctx, m.ccvProviderKeeper)
// Consumer genesis states persisted on the provider do not need to be migrated,
// as protobuf serialization is able to gracefully handle unpopulated fields when deserializing.
// See https://github.com/smarshall-spitzbart/ics-migration-tests/commit/b589e3982c26783ed66e954051f7da1ead16de68
// which passes, proving the addition of preCCV will not break things.

// Migrate keys to accommodate fix from https://github.com/cosmos/interchain-security/pull/786
MigrateKeysv1Tov2(ctx, m.ccvProviderKeeper)
Expand Down Expand Up @@ -80,14 +82,6 @@ func MigrateParamsv1Tov2(ctx sdk.Context, paramsSubspace paramtypes.Subspace, co
paramsSubspace.SetParamSet(ctx, &newParams)
}

func MigrateConsumerGenesisStatesv1Tov2(ctx sdk.Context, providerKeeper Keeper) {
// We could try to migrate existing ConsumerGenesisStates, but they're not needed after consumer launch.
// Hence we delete them strategically.
providerKeeper.DeleteConsumerGenesis(ctx, "neutron-1") // See https://github.com/neutron-org/mainnet-assets#parameters

// TODO: determine if any other ConsumerGenesisStates need to be deleted, or actually migrated!
}

// Due to https://github.com/cosmos/interchain-security/pull/786,
// validators' slash logs are stored under the key prefix for slash acks.
// This method will extract "slash logs" from the slash acks part of the store, and put the slash logs
Expand Down
19 changes: 0 additions & 19 deletions x/ccv/provider/keeper/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
types2 "github.com/cosmos/ibc-go/v4/modules/light-clients/07-tendermint/types"
"github.com/cosmos/interchain-security/v2/testutil/crypto"
testutil "github.com/cosmos/interchain-security/v2/testutil/keeper"
consumertypes "github.com/cosmos/interchain-security/v2/x/ccv/consumer/types"
providerkeeper "github.com/cosmos/interchain-security/v2/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/v2/x/ccv/provider/types"
ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types"
Expand Down Expand Up @@ -124,24 +123,6 @@ type v1Params struct {
MaxThrottledPackets int64 `protobuf:"varint,8,opt,name=max_throttled_packets,json=maxThrottledPackets,proto3" json:"max_throttled_packets,omitempty"`
}

func TestMigrateConsumerGenesisv1Tov2(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t))
defer ctrl.Finish()

_, found := providerKeeper.GetConsumerGenesis(ctx, "neutron-1")
require.False(t, found)

providerKeeper.SetConsumerGenesis(ctx, "neutron-1", consumertypes.GenesisState{})

_, found = providerKeeper.GetConsumerGenesis(ctx, "neutron-1")
require.True(t, found)

providerkeeper.MigrateConsumerGenesisStatesv1Tov2(ctx, providerKeeper)

_, found = providerKeeper.GetConsumerGenesis(ctx, "neutron-1")
require.False(t, found)
}

func TestMigrateKeysv1Tov2(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t))
defer ctrl.Finish()
Expand Down