From 06ea1f7d4a68cd5358349ffe1b91555f69d735c3 Mon Sep 17 00:00:00 2001 From: insumity Date: Fri, 27 Sep 2024 16:01:42 +0200 Subject: [PATCH] remove unused state --- x/ccv/provider/keeper/consumer_lifecycle.go | 1 - x/ccv/provider/keeper/distribution.go | 21 ----------- x/ccv/provider/keeper/distribution_test.go | 36 ------------------- .../provider/migrations/v8/migrations_test.go | 33 ++++++++--------- x/ccv/provider/types/keys.go | 10 ++---- x/ccv/provider/types/keys_test.go | 4 +-- 6 files changed, 19 insertions(+), 86 deletions(-) diff --git a/x/ccv/provider/keeper/consumer_lifecycle.go b/x/ccv/provider/keeper/consumer_lifecycle.go index c51db4392a..af8eef74a6 100644 --- a/x/ccv/provider/keeper/consumer_lifecycle.go +++ b/x/ccv/provider/keeper/consumer_lifecycle.go @@ -486,7 +486,6 @@ func (k Keeper) DeleteConsumerChain(ctx sdk.Context, consumerId string) (err err k.DeleteAllOptedIn(ctx, consumerId) k.DeleteConsumerValSet(ctx, consumerId) - k.DeleteConsumerRewardsAllocation(ctx, consumerId) k.DeleteConsumerRemovalTime(ctx, consumerId) // TODO (PERMISSIONLESS) add newly-added state to be deleted diff --git a/x/ccv/provider/keeper/distribution.go b/x/ccv/provider/keeper/distribution.go index b20c07c15e..7bfc1e8c83 100644 --- a/x/ccv/provider/keeper/distribution.go +++ b/x/ccv/provider/keeper/distribution.go @@ -411,27 +411,6 @@ func (k Keeper) AllocateTokensToConsumerValidators( // consumer reward pools getter and setter -// GetConsumerRewardsAllocation returns the consumer rewards allocation for the given consumer id -func (k Keeper) GetConsumerRewardsAllocation(ctx sdk.Context, consumerId string) (pool types.ConsumerRewardsAllocation) { - store := ctx.KVStore(k.storeKey) - b := store.Get(types.ConsumerRewardsAllocationKey(consumerId)) - k.cdc.MustUnmarshal(b, &pool) - return -} - -// SetConsumerRewardsAllocation sets the consumer rewards allocation for the given consumer id -func (k Keeper) SetConsumerRewardsAllocation(ctx sdk.Context, consumerId string, pool types.ConsumerRewardsAllocation) { - store := ctx.KVStore(k.storeKey) - b := k.cdc.MustMarshal(&pool) - store.Set(types.ConsumerRewardsAllocationKey(consumerId), b) -} - -// DeleteConsumerRewardsAllocation deletes the consumer rewards allocation for the given consumer id -func (k Keeper) DeleteConsumerRewardsAllocation(ctx sdk.Context, consumerId string) { - store := ctx.KVStore(k.storeKey) - store.Delete(types.ConsumerRewardsAllocationKey(consumerId)) -} - // GetConsumerRewardsPool returns the balance // of the consumer rewards pool module account func (k Keeper) GetConsumerRewardsPool(ctx sdk.Context) sdk.Coins { diff --git a/x/ccv/provider/keeper/distribution_test.go b/x/ccv/provider/keeper/distribution_test.go index ee5afd8a2b..6c926aa6b5 100644 --- a/x/ccv/provider/keeper/distribution_test.go +++ b/x/ccv/provider/keeper/distribution_test.go @@ -245,42 +245,6 @@ func TestIdentifyConsumerChainIDFromIBCPacket(t *testing.T) { } } -func TestSetConsumerRewardsAllocation(t *testing.T) { - keeperParams := testkeeper.NewInMemKeeperParams(t) - ctx := keeperParams.Ctx - - ctrl := gomock.NewController(t) - defer ctrl.Finish() - mocks := testkeeper.NewMockedKeepers(ctrl) - providerKeeper := testkeeper.NewInMemProviderKeeper(keeperParams, mocks) - - rewardAllocation := providertypes.ConsumerRewardsAllocation{ - Rewards: sdk.NewDecCoins(sdk.NewDecCoin("uatom", math.NewInt(1000))), - } - - providerKeeper.SetConsumerRewardsAllocation(ctx, "consumer-1", rewardAllocation) - - alloc := providerKeeper.GetConsumerRewardsAllocation(ctx, "consumer-1") - require.Equal(t, rewardAllocation, alloc) -} - -func TestGetConsumerRewardsAllocationNil(t *testing.T) { - keeperParams := testkeeper.NewInMemKeeperParams(t) - ctx := keeperParams.Ctx - - ctrl := gomock.NewController(t) - defer ctrl.Finish() - mocks := testkeeper.NewMockedKeepers(ctrl) - providerKeeper := testkeeper.NewInMemProviderKeeper(keeperParams, mocks) - - alloc := providerKeeper.GetConsumerRewardsAllocation(ctx, "consumer-1") - - expectedRewardAllocation := providertypes.ConsumerRewardsAllocation{ - Rewards: nil, - } - require.Equal(t, expectedRewardAllocation, alloc) -} - func TestIsEligibleForConsumerRewards(t *testing.T) { keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() diff --git a/x/ccv/provider/migrations/v8/migrations_test.go b/x/ccv/provider/migrations/v8/migrations_test.go index c8d98115dc..01dc0f0a2e 100644 --- a/x/ccv/provider/migrations/v8/migrations_test.go +++ b/x/ccv/provider/migrations/v8/migrations_test.go @@ -203,8 +203,6 @@ func StoreChainDataUsingChainIdAsKey(ctx sdk.Context, store storetypes.KVStore, providerKeeper.SetDenylist(ctx, data.ChainId, data.ProviderAddr) - providerKeeper.SetConsumerRewardsAllocation(ctx, data.ChainId, data.ConsumerRewardsAllocation) - providerKeeper.SetConsumerCommissionRate(ctx, data.ChainId, data.ProviderAddr, data.ConsumerCommissionRate) providerKeeper.SetMinimumPowerInTopN(ctx, data.ChainId, data.MinimumPowerInTopN) @@ -291,8 +289,6 @@ func GetChainDataUsingStringId(ctx sdk.Context, providerKeeper providerkeeper.Ke } } - data.ConsumerRewardsAllocation = providerKeeper.GetConsumerRewardsAllocation(ctx, id) - consumerCommissionRate, found := providerKeeper.GetConsumerCommissionRate(ctx, id, providerAddr) if found { data.ConsumerCommissionRate = consumerCommissionRate @@ -328,21 +324,20 @@ func CreateTestChainData(chainId string, clientId string, channelId string) Chai Params: types.ConsumerParams{ConsumerRedistributionFraction: "redistribution fraction"}, NewChain: true, }, - SlashAcks: []string{"slashAck1", "slashAck2"}, - InitChainHeight: uint64(123), - PendingVSCPackets: []types.ValidatorSetChangePacketData{{ValsetUpdateId: uint64(456)}}, - ProviderAddr: providertypes.NewProviderConsAddress([]byte("provider cons address")), - ConsumerKey: crypto.PublicKey{Sum: &crypto.PublicKey_Ed25519{Ed25519: []byte{4}}}, - ConsumerAddr: providertypes.NewConsumerConsAddress([]byte("consumer cons address")), - EquivocationMinHeight: uint64(789), - ConsensusValidator: providertypes.ConsensusValidator{}, - ConsumerRewardsAllocation: providertypes.ConsumerRewardsAllocation{Rewards: sdk.NewDecCoins(sdk.NewDecCoin("uatom", math.NewInt(1000)))}, - ConsumerCommissionRate: math.LegacyNewDec(1), - MinimumPowerInTopN: int64(123456789), - PruneTs: time.Now().UTC(), - TopN: uint32(67), - ValidatorsPowerCap: uint32(30), - ValidatorSetCap: uint32(100), + SlashAcks: []string{"slashAck1", "slashAck2"}, + InitChainHeight: uint64(123), + PendingVSCPackets: []types.ValidatorSetChangePacketData{{ValsetUpdateId: uint64(456)}}, + ProviderAddr: providertypes.NewProviderConsAddress([]byte("provider cons address")), + ConsumerKey: crypto.PublicKey{Sum: &crypto.PublicKey_Ed25519{Ed25519: []byte{4}}}, + ConsumerAddr: providertypes.NewConsumerConsAddress([]byte("consumer cons address")), + EquivocationMinHeight: uint64(789), + ConsensusValidator: providertypes.ConsensusValidator{}, + ConsumerCommissionRate: math.LegacyNewDec(1), + MinimumPowerInTopN: int64(123456789), + PruneTs: time.Now().UTC(), + TopN: uint32(67), + ValidatorsPowerCap: uint32(30), + ValidatorSetCap: uint32(100), } } diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index 345a26e252..ca78611fd8 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -119,7 +119,7 @@ const ( DenylistKeyName = "DenylistKey" - ConsumerRewardsAllocationKeyName = "ConsumerRewardsAllocationKey" + DeprecatedConsumerRewardsAllocationKeyName = "DeprecatedConsumerRewardsAllocationKey" ConsumerCommissionRateKeyName = "ConsumerCommissionRateKey" @@ -331,7 +331,8 @@ func getKeyPrefixes() map[string]byte { // ConsumerRewardsAllocationKey is the key for storing for each consumer the ICS rewards // allocated to the consumer rewards pool - ConsumerRewardsAllocationKeyName: 38, + // [DEPRECATED] + DeprecatedConsumerRewardsAllocationKeyName: 38, // ConsumerCommissionRateKey is the key for storing the commission rate // per validator per consumer chain @@ -606,11 +607,6 @@ func OptedInKey(consumerId string, providerAddr ProviderConsAddress) []byte { return StringIdAndConsAddrKey(OptedInKeyPrefix(), consumerId, providerAddr.ToSdkConsAddr()) } -// ConsumerRewardsAllocationKey returns the key used to store the ICS rewards per consumer chain -func ConsumerRewardsAllocationKey(consumerId string) []byte { - return append([]byte{mustGetKeyPrefix(ConsumerRewardsAllocationKeyName)}, []byte(consumerId)...) -} - // ConsumerCommissionRateKeyPrefix returns the key prefix for storing the commission rate per validator per consumer chain. func ConsumerCommissionRateKeyPrefix() byte { return mustGetKeyPrefix(ConsumerCommissionRateKeyName) diff --git a/x/ccv/provider/types/keys_test.go b/x/ccv/provider/types/keys_test.go index f97f6d2115..814ece665a 100644 --- a/x/ccv/provider/types/keys_test.go +++ b/x/ccv/provider/types/keys_test.go @@ -110,7 +110,8 @@ func TestPreserveBytePrefix(t *testing.T) { i++ require.Equal(t, byte(37), providertypes.DenylistKeyPrefix()) i++ - require.Equal(t, byte(38), providertypes.ConsumerRewardsAllocationKey("13")[0]) + // DEPRECATED + //require.Equal(t, byte(38), providertypes.ConsumerRewardsAllocationKey("13")[0]) i++ require.Equal(t, byte(39), providertypes.ConsumerCommissionRateKeyPrefix()) i++ @@ -198,7 +199,6 @@ func getAllFullyDefinedKeys() [][]byte { providertypes.AllowlistKey("13", providertypes.NewProviderConsAddress([]byte{0x05})), providertypes.DenylistKey("13", providertypes.NewProviderConsAddress([]byte{0x05})), providertypes.OptedInKey("13", providertypes.NewProviderConsAddress([]byte{0x05})), - providertypes.ConsumerRewardsAllocationKey("13"), providertypes.ConsumerCommissionRateKey("13", providertypes.NewProviderConsAddress([]byte{0x05})), providertypes.MinimumPowerInTopNKey("13"), providertypes.ConsumerAddrsToPruneV2Key("13", time.Time{}),