Skip to content

Commit

Permalink
Changed to store service
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Nov 13, 2023
1 parent e96a3f1 commit a958853
Show file tree
Hide file tree
Showing 32 changed files with 814 additions and 559 deletions.
6 changes: 2 additions & 4 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ func New(
// communication over IBC is not affected by these changes
app.ConsumerKeeper = consumerkeeper.NewNonZeroKeeper(
appCodec,
keys[consumertypes.StoreKey],
app.GetSubspace(consumertypes.ModuleName),
runtime.NewKVStoreService(keys[consumertypes.StoreKey]),
)

app.IBCKeeper = ibckeeper.NewKeeper(
Expand All @@ -448,8 +447,7 @@ func New(
// Create CCV consumer and modules
app.ConsumerKeeper = consumerkeeper.NewKeeper(
appCodec,
keys[consumertypes.StoreKey],
app.GetSubspace(consumertypes.ModuleName),
runtime.NewKVStoreService(keys[consumertypes.StoreKey]),
scopedIBCConsumerKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
Expand Down
6 changes: 2 additions & 4 deletions app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ func New(
// communication over IBC is not affected by these changes
app.ConsumerKeeper = ibcconsumerkeeper.NewNonZeroKeeper(
appCodec,
keys[ibcconsumertypes.StoreKey],
app.GetSubspace(ibcconsumertypes.ModuleName),
runtime.NewKVStoreService(keys[ibcconsumertypes.StoreKey]),
)

app.IBCKeeper = ibckeeper.NewKeeper(
Expand All @@ -374,8 +373,7 @@ func New(
// initialize the actual consumer keeper
app.ConsumerKeeper = ibcconsumerkeeper.NewKeeper(
appCodec,
keys[ibcconsumertypes.StoreKey],
app.GetSubspace(ibcconsumertypes.ModuleName),
runtime.NewKVStoreService(keys[ibcconsumertypes.StoreKey]),
scopedIBCConsumerKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
Expand Down
3 changes: 1 addition & 2 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ func New(

app.ProviderKeeper = icsproviderkeeper.NewKeeper(
appCodec,
keys[providertypes.StoreKey],
app.GetSubspace(providertypes.ModuleName),
runtime.NewKVStoreService(keys[providertypes.StoreKey]),
scopedIBCProviderKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/channel_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func (suite *CCVTestSuite) TestInitTimeout() {

for i, tc := range testCases {
providerKeeper := suite.providerApp.GetProviderKeeper()
initTimeout := providerKeeper.GetParams(suite.providerCtx()).InitTimeoutPeriod
params, err := providerKeeper.GetParams(suite.providerCtx())
suite.Require().NoError(err)
initTimeout := params.InitTimeoutPeriod

chainID := suite.consumerChain.ChainID

// check that the init timeout timestamp is set
Expand Down
32 changes: 20 additions & 12 deletions tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (s *CCVTestSuite) TestRewardsDistribution() {
s.providerChain.NextBlock()

// register a consumer reward denom
params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
s.Require().NoError(err)
params.RewardDenoms = []string{sdk.DefaultBondDenom}
s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params)

Expand All @@ -49,7 +50,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() {
consumerFeePoolAddr := consumerAccountKeeper.GetModuleAccount(s.consumerCtx(), authtypes.FeeCollectorName).GetAddress()
feePoolTokensOld := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr)
fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100)))
err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees)
err = consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees)
s.Require().NoError(err)
feePoolTokens := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr)
s.Require().Equal(math.NewInt(100).Add(feePoolTokensOld.AmountOf(sdk.DefaultBondDenom)), feePoolTokens.AmountOf(sdk.DefaultBondDenom))
Expand Down Expand Up @@ -139,7 +140,9 @@ func (s *CCVTestSuite) TestSendRewardsRetries() {
s.providerChain.NextBlock()

// Register denom on consumer chain
params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
s.Require().NoError(err)

params.RewardDenoms = []string{sdk.DefaultBondDenom}
s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params)

Expand All @@ -155,7 +158,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() {

// fill fee pool
fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100)))
err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(),
err = consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(),
s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees)
s.Require().NoError(err)

Expand Down Expand Up @@ -268,7 +271,8 @@ func (s *CCVTestSuite) TestEndBlockRD() {
s.providerChain.NextBlock()

if tc.denomRegistered {
params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
s.Require().NoError(err)
params.RewardDenoms = []string{sdk.DefaultBondDenom}
s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params)
}
Expand Down Expand Up @@ -338,12 +342,13 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() {
s.SetupTransferChannel()

// register a consumer reward denom
params := keeper.GetConsumerParams(ctx)
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params.RewardDenoms = []string{sdk.DefaultBondDenom}
keeper.SetParams(ctx, params)

// send coins to the pool which is used for collect reward distributions to be sent to the provider
err := bankKeeper.SendCoinsFromAccountToModule(
err = bankKeeper.SendCoinsFromAccountToModule(
ctx,
s.consumerChain.SenderAccount.GetAddress(),
consumertypes.ConsumerToSendToProviderName,
Expand Down Expand Up @@ -375,7 +380,8 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() {
s.SetupTransferChannel()

// register a consumer reward denom
params := keeper.GetConsumerParams(ctx)
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params.RewardDenoms = []string{"uatom"}
keeper.SetParams(ctx, params)

Expand All @@ -391,13 +397,14 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() {
s.SetupTransferChannel()

// register a consumer reward denom
params := keeper.GetConsumerParams(ctx)
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params.RewardDenoms = []string{sdk.DefaultBondDenom}
params.DistributionTransmissionChannel = ""
keeper.SetParams(ctx, params)

// send coins to the pool which is used for collect reward distributions to be sent to the provider
err := bankKeeper.SendCoinsFromAccountToModule(
err = bankKeeper.SendCoinsFromAccountToModule(
ctx,
s.consumerChain.SenderAccount.GetAddress(),
consumertypes.ConsumerToSendToProviderName,
Expand All @@ -414,13 +421,14 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() {
s.SetupTransferChannel()

// register a consumer reward denom
params := keeper.GetConsumerParams(ctx)
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params.RewardDenoms = []string{sdk.DefaultBondDenom}
params.ProviderFeePoolAddrStr = ""
keeper.SetParams(ctx, params)

// send coins to the pool which is used for collect reward distributions to be sent to the provider
err := bankKeeper.SendCoinsFromAccountToModule(
err = bankKeeper.SendCoinsFromAccountToModule(
ctx,
s.consumerChain.SenderAccount.GetAddress(),
consumertypes.ConsumerToSendToProviderName,
Expand Down
22 changes: 15 additions & 7 deletions tests/integration/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ func (s *CCVTestSuite) TestPacketSpam() {

// Explicitly set params, initialize slash meter
providerKeeper := s.providerApp.GetProviderKeeper()
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params.SlashMeterReplenishFraction = "0.75" // Allow 3/4 of validators to be jailed
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -376,7 +377,8 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() {

// Explicitly set params, initialize slash meter
providerKeeper := s.providerApp.GetProviderKeeper()
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params.SlashMeterReplenishFraction = "0.1"
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -469,7 +471,8 @@ func (s *CCVTestSuite) TestQueueOrdering() {

// Explicitly set params, initialize slash meter
providerKeeper := s.providerApp.GetProviderKeeper()
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params.SlashMeterReplenishFraction = "0.05" // 5% total power can be jailed
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -706,7 +709,8 @@ func (s *CCVTestSuite) TestSlashMeterAllowanceChanges() {
s.Require().Equal(int64(200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64())

// Now we change replenish fraction and assert new expected allowance.
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params.SlashMeterReplenishFraction = "0.3"
providerKeeper.SetParams(s.providerCtx(), params)
s.Require().Equal(int64(1200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64())
Expand All @@ -725,7 +729,8 @@ func (s *CCVTestSuite) TestSlashSameValidator() {
providerKeeper := s.providerApp.GetProviderKeeper()

// Set replenish fraction to 1.0 so that all sent packets should handled immediately (no throttling)
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -785,7 +790,8 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes
providerKeeper := s.providerApp.GetProviderKeeper()

// Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no throttling)
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -939,7 +945,9 @@ func (s *CCVTestSuite) TestVscMaturedHandledPerBlockLimit() {
providerKeeper := s.providerApp.GetProviderKeeper()

// Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no jail throttling)
params := providerKeeper.GetParams(s.providerCtx())
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)

params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down
7 changes: 3 additions & 4 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -116,8 +117,7 @@ func NewMockedKeepers(ctrl *gomock.Controller) MockedKeepers {
func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) providerkeeper.Keeper {
return providerkeeper.NewKeeper(
params.Cdc,
params.StoreKey,
*params.ParamsSubspace,
runtime.NewKVStoreService(params.StoreKey),
mocks.MockScopedKeeper,
mocks.MockChannelKeeper,
mocks.MockPortKeeper,
Expand All @@ -139,8 +139,7 @@ func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) provi
func NewInMemConsumerKeeper(params InMemKeeperParams, mocks MockedKeepers) consumerkeeper.Keeper {
return consumerkeeper.NewKeeper(
params.Cdc,
params.StoreKey,
*params.ParamsSubspace,
runtime.NewKVStoreService(params.StoreKey),
mocks.MockScopedKeeper,
mocks.MockChannelKeeper,
mocks.MockPortKeeper,
Expand Down
6 changes: 5 additions & 1 deletion x/ccv/consumer/ibc_module_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package consumer_test

import (
"fmt"
"testing"

transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand Down Expand Up @@ -226,7 +227,10 @@ func TestOnChanOpenAck(t *testing.T) {
transfertypes.PortID,
"", // signer unused
)

err := keeper.SetParams(params.ctx, ccv.DefaultParams())
if err != nil {
panic(fmt.Sprintf("Setting params failed %v", err))
}
transferChannelID := ""
keeper.SetDistributionTransmissionChannel(params.ctx, transferChannelID)

Expand Down
8 changes: 4 additions & 4 deletions x/ccv/consumer/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ func (k Keeper) AllowedRewardDenoms(ctx sdk.Context) []string {
}

func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmissionBlockHeight {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.LastDistributionTransmissionKey())
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.LastDistributionTransmissionKey())
ltbh := ccv.LastTransmissionBlockHeight{}
if bz != nil {
if err == nil && bz != nil {
if err := ltbh.Unmarshal(bz); err != nil {
panic(fmt.Errorf("failed to unmarshal LastTransmissionBlockHeight: %w", err))
}
Expand All @@ -216,7 +216,7 @@ func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmis
}

func (k Keeper) SetLastTransmissionBlockHeight(ctx sdk.Context, ltbh ccv.LastTransmissionBlockHeight) {
store := ctx.KVStore(k.storeKey)
store := k.storeService.OpenKVStore(ctx)
bz, err := ltbh.Marshal()
if err != nil {
panic(fmt.Errorf("failed to marshal LastTransmissionBlockHeight: %w", err))
Expand Down
6 changes: 5 additions & 1 deletion x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.GenesisState) []abci.Val

// ExportGenesis returns the CCV consumer module's exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) {
params := k.GetConsumerParams(ctx)
params, err := k.GetConsumerParams(ctx)
if err != nil {
panic(fmt.Sprintf("failed getting consumer parameters: %v", err))
}

if !params.Enabled {
return ccv.DefaultGenesisState()
}
Expand Down
12 changes: 9 additions & 3 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func TestInitGenesis(t *testing.T) {
assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs)

require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address)
require.Equal(t, gs.Params, ck.GetConsumerParams(ctx))
params, err := ck.GetConsumerParams(ctx)
require.NoError(t, err)
require.Equal(t, gs.Params, params)
},
}, {
"restart a chain without an established CCV channel",
Expand Down Expand Up @@ -157,7 +159,9 @@ func TestInitGenesis(t *testing.T) {
assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs)
assertProviderClientID(t, ctx, &ck, provClientID)
require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address)
require.Equal(t, gs.Params, ck.GetConsumerParams(ctx))
params, err := ck.GetConsumerParams(ctx)
require.NoError(t, err)
require.Equal(t, gs.Params, params)
},
}, {
"restart a chain with an established CCV channel",
Expand Down Expand Up @@ -206,7 +210,9 @@ func TestInitGenesis(t *testing.T) {
assertHeightValsetUpdateIDs(t, ctx, &ck, updatedHeightValsetUpdateIDs)
assertProviderClientID(t, ctx, &ck, provClientID)

require.Equal(t, gs.Params, ck.GetConsumerParams(ctx))
params, err := ck.GetConsumerParams(ctx)
require.NoError(t, err)
require.Equal(t, gs.Params, params)
},
},
}
Expand Down
5 changes: 4 additions & 1 deletion x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func (k Keeper) QueryParams(c context.Context, //nolint:golint
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

p := k.GetConsumerParams(ctx)
p, err := k.GetConsumerParams(ctx)
if err != nil {
return nil, status.Errorf(codes.NotFound, "no consumer parameters found")
}

return &types.QueryParamsResponse{Params: p}, nil
}
Expand Down
Loading

0 comments on commit a958853

Please sign in to comment.