Skip to content

Commit

Permalink
remove unused state
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Sep 27, 2024
1 parent 85dc280 commit 06ea1f7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 86 deletions.
1 change: 0 additions & 1 deletion x/ccv/provider/keeper/consumer_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 0 additions & 36 deletions x/ccv/provider/keeper/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 14 additions & 19 deletions x/ccv/provider/migrations/v8/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
}

Expand Down
10 changes: 3 additions & 7 deletions x/ccv/provider/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const (

DenylistKeyName = "DenylistKey"

ConsumerRewardsAllocationKeyName = "ConsumerRewardsAllocationKey"
DeprecatedConsumerRewardsAllocationKeyName = "DeprecatedConsumerRewardsAllocationKey"

ConsumerCommissionRateKeyName = "ConsumerCommissionRateKey"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -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{}),
Expand Down

0 comments on commit 06ea1f7

Please sign in to comment.