Skip to content

Commit

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

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

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

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

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

initTimeout := providerKeeper.GetParams(suite.providerCtx()).InitTimeoutPeriod
chainID := suite.consumerChain.ChainID

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

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

Expand All @@ -50,7 +49,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 @@ -140,9 +139,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() {
s.providerChain.NextBlock()

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

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

Expand All @@ -158,7 +155,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 @@ -271,8 +268,7 @@ func (s *CCVTestSuite) TestEndBlockRD() {
s.providerChain.NextBlock()

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

// register a consumer reward denom
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params := keeper.GetConsumerParams(ctx)
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 @@ -380,8 +375,7 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() {
s.SetupTransferChannel()

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

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

// register a consumer reward denom
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params := keeper.GetConsumerParams(ctx)
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 @@ -421,14 +414,13 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() {
s.SetupTransferChannel()

// register a consumer reward denom
params, err := keeper.GetConsumerParams(ctx)
s.Require().NoError(err)
params := keeper.GetConsumerParams(ctx)
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: 7 additions & 15 deletions tests/integration/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ func (s *CCVTestSuite) TestPacketSpam() {

// Explicitly set params, initialize slash meter
providerKeeper := s.providerApp.GetProviderKeeper()
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params := providerKeeper.GetParams(s.providerCtx())
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 @@ -377,8 +376,7 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() {

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

// Explicitly set params, initialize slash meter
providerKeeper := s.providerApp.GetProviderKeeper()
params, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params := providerKeeper.GetParams(s.providerCtx())
params.SlashMeterReplenishFraction = "0.05" // 5% total power can be jailed
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -709,8 +706,7 @@ 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, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params := providerKeeper.GetParams(s.providerCtx())
params.SlashMeterReplenishFraction = "0.3"
providerKeeper.SetParams(s.providerCtx(), params)
s.Require().Equal(int64(1200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64())
Expand All @@ -729,8 +725,7 @@ 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, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params := providerKeeper.GetParams(s.providerCtx())
params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -790,8 +785,7 @@ 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, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)
params := providerKeeper.GetParams(s.providerCtx())
params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down Expand Up @@ -945,9 +939,7 @@ 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, err := providerKeeper.GetParams(s.providerCtx())
s.Require().NoError(err)

params := providerKeeper.GetParams(s.providerCtx())
params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())
Expand Down
7 changes: 4 additions & 3 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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 @@ -117,7 +116,8 @@ func NewMockedKeepers(ctrl *gomock.Controller) MockedKeepers {
func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) providerkeeper.Keeper {
return providerkeeper.NewKeeper(
params.Cdc,
runtime.NewKVStoreService(params.StoreKey),
params.StoreKey,
*params.ParamsSubspace,
mocks.MockScopedKeeper,
mocks.MockChannelKeeper,
mocks.MockPortKeeper,
Expand All @@ -139,7 +139,8 @@ func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) provi
func NewInMemConsumerKeeper(params InMemKeeperParams, mocks MockedKeepers) consumerkeeper.Keeper {
return consumerkeeper.NewKeeper(
params.Cdc,
runtime.NewKVStoreService(params.StoreKey),
params.StoreKey,
*params.ParamsSubspace,
mocks.MockScopedKeeper,
mocks.MockChannelKeeper,
mocks.MockPortKeeper,
Expand Down
6 changes: 1 addition & 5 deletions x/ccv/consumer/ibc_module_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer_test

import (
"fmt"
"testing"

transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand Down Expand Up @@ -227,10 +226,7 @@ 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 := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.LastDistributionTransmissionKey())
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.LastDistributionTransmissionKey())
ltbh := ccv.LastTransmissionBlockHeight{}
if err == nil && bz != nil {
if 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 := k.storeService.OpenKVStore(ctx)
store := ctx.KVStore(k.storeKey)
bz, err := ltbh.Marshal()
if err != nil {
panic(fmt.Errorf("failed to marshal LastTransmissionBlockHeight: %w", err))
Expand Down
6 changes: 1 addition & 5 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ 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, err := k.GetConsumerParams(ctx)
if err != nil {
panic(fmt.Sprintf("failed getting consumer parameters: %v", err))
}

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

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

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

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

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

0 comments on commit ad40546

Please sign in to comment.