From 830bc4fbcdabbd4bd0d1ab21f2d8937c756368ed Mon Sep 17 00:00:00 2001 From: MSalopek Date: Mon, 18 Sep 2023 10:54:44 +0200 Subject: [PATCH] partial: migrate ccv/keeper.go to new store interface --- x/ccv/consumer/keeper/keeper.go | 22 +- x/ccv/provider/keeper/distribution.go | 4 +- x/ccv/provider/keeper/hooks.go | 24 +- x/ccv/provider/keeper/keeper.go | 284 ++++++++++++++---------- x/ccv/provider/keeper/key_assignment.go | 9 +- x/ccv/provider/keeper/proposal.go | 9 +- 6 files changed, 202 insertions(+), 150 deletions(-) diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index ed5fee1b4a..8e5cd64fcc 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -11,6 +11,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" + "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" @@ -29,7 +30,8 @@ import ( // Keeper defines the Cross-Chain Validation Consumer Keeper type Keeper struct { - storeKey storetypes.StoreKey + storeKey storetypes.StoreKey // TODO: maybe needs to be removed? + storeService store.KVStoreService cdc codec.BinaryCodec paramStore paramtypes.Subspace scopedKeeper ccv.ScopedKeeper @@ -338,7 +340,7 @@ func (k Keeper) GetLastStandaloneValidators(ctx sdk.Context) []stakingtypes.Vali // i.e., the slice contains the IDs of the matured VSCPackets. func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []ccv.MaturingVSCPacket) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) defer iterator.Close() @@ -370,7 +372,7 @@ func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPacke // If two entries have the same maturityTime, then they are ordered by vscID. func (k Keeper) GetAllPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []ccv.MaturingVSCPacket) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -471,7 +473,7 @@ func (k Keeper) DeleteHeightValsetUpdateID(ctx sdk.Context, height uint64) { // Thus, the returned array is in ascending order of heights. func (k Keeper) GetAllHeightToValsetUpdateIDs(ctx sdk.Context) (heightToValsetUpdateIDs []ccv.HeightToValsetUpdateID) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.HeightValsetUpdateIDBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.HeightValsetUpdateIDBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -517,7 +519,7 @@ func (k Keeper) DeleteOutstandingDowntime(ctx sdk.Context, consAddress string) { // Thus, the returned array is in ascending order of consAddresses. func (k Keeper) GetAllOutstandingDowntimes(ctx sdk.Context) (downtimes []ccv.OutstandingDowntime) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.OutstandingDowntimeBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.OutstandingDowntimeBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -566,7 +568,7 @@ func (k Keeper) DeleteCCValidator(ctx sdk.Context, addr []byte) { // Thus, the returned array is in ascending order of addresses. func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChainValidator) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.CrossChainValidatorBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.CrossChainValidatorBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -582,7 +584,7 @@ func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChai func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Validator) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, stakingtypes.ValidatorsKey) + iterator := storetypes.KVStorePrefixIterator(store, stakingtypes.ValidatorsKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -609,7 +611,7 @@ func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint // DeleteHeadOfPendingPackets deletes the head of the pending packets queue. func (k Keeper) DeleteHeadOfPendingPackets(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) defer iterator.Close() if !iterator.Valid() { return @@ -643,7 +645,7 @@ func (k Keeper) GetAllPendingPacketsWithIdx(ctx sdk.Context) []ConsumerPacketDat store := ctx.KVStore(k.storeKey) // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var packet ccv.ConsumerPacketData @@ -675,7 +677,7 @@ func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) keysToDel := [][]byte{} defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ccv/provider/keeper/distribution.go b/x/ccv/provider/keeper/distribution.go index 1b3336aefa..2cf6ef08f6 100644 --- a/x/ccv/provider/keeper/distribution.go +++ b/x/ccv/provider/keeper/distribution.go @@ -3,6 +3,8 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ) @@ -46,7 +48,7 @@ func (k Keeper) DeleteConsumerRewardDenom( func (k Keeper) GetAllConsumerRewardDenoms(ctx sdk.Context) (consumerRewardDenoms []string) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.ConsumerRewardDenomsBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ConsumerRewardDenomsBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ccv/provider/keeper/hooks.go b/x/ccv/provider/keeper/hooks.go index bdd9d08758..3a467d4c2d 100644 --- a/x/ccv/provider/keeper/hooks.go +++ b/x/ccv/provider/keeper/hooks.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -22,7 +24,7 @@ func (k *Keeper) Hooks() Hooks { } // This stores a record of each unbonding op from staking, allowing us to track which consumer chains have unbonded -func (h Hooks) AfterUnbondingInitiated(ctx sdk.Context, id uint64) error { +func (h Hooks) AfterUnbondingInitiated(ctx context.Context, id uint64) error { var consumerChainIDS []string for _, chain := range h.k.GetAllConsumerChains(ctx) { @@ -111,7 +113,7 @@ func ValidatorConsensusKeyInUse(k *Keeper, ctx sdk.Context, valAddr sdk.ValAddre return inUse } -func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error { +func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress) error { if ValidatorConsensusKeyInUse(h.k, ctx, valAddr) { // Abort TX, do NOT allow validator to be created panic("cannot create a validator with a consensus key that is already in use or was recently in use as an assigned consumer chain key") @@ -119,7 +121,7 @@ func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) er return nil } -func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, valConsAddr sdk.ConsAddress, valAddr sdk.ValAddress) error { +func (h Hooks) AfterValidatorRemoved(ctx context.Context, valConsAddr sdk.ConsAddress, valAddr sdk.ValAddress) error { for _, validatorConsumerPubKey := range h.k.GetAllValidatorConsumerPubKeys(ctx, nil) { if sdk.ConsAddress(validatorConsumerPubKey.ProviderAddr).Equals(valConsAddr) { consumerAddrTmp, err := ccvtypes.TMCryptoPublicKeyToConsAddr(*validatorConsumerPubKey.ConsumerKey) @@ -137,34 +139,34 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, valConsAddr sdk.ConsAddres return nil } -func (h Hooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { +func (h Hooks) BeforeDelegationCreated(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { return nil } -func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { +func (h Hooks) BeforeDelegationSharesModified(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { return nil } -func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { +func (h Hooks) AfterDelegationModified(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { return nil } -func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ math.LegacyDec) error { +func (h Hooks) BeforeValidatorSlashed(_ context.Context, _ sdk.ValAddress, _ math.LegacyDec) error { return nil } -func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) error { +func (h Hooks) BeforeValidatorModified(_ context.Context, _ sdk.ValAddress) error { return nil } -func (h Hooks) AfterValidatorBonded(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { +func (h Hooks) AfterValidatorBonded(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { return nil } -func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { +func (h Hooks) AfterValidatorBeginUnbonding(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { return nil } -func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { +func (h Hooks) BeforeDelegationRemoved(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error { return nil } diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 5481391a36..21cb5bdbd7 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "encoding/binary" "fmt" "reflect" @@ -13,10 +14,12 @@ import ( ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -30,7 +33,13 @@ import ( // Keeper defines the Cross-Chain Validation Provider Keeper type Keeper struct { - storeKey storetypes.StoreKey + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string + + storeKey storetypes.StoreKey // TODO: remove + storeService store.KVStoreService + cdc codec.BinaryCodec paramSpace paramtypes.Subspace scopedKeeper ccv.ScopedKeeper @@ -55,7 +64,7 @@ func NewKeeper( stakingKeeper ccv.StakingKeeper, slashingKeeper ccv.SlashingKeeper, accountKeeper ccv.AccountKeeper, evidenceKeeper ccv.EvidenceKeeper, distributionKeeper ccv.DistributionKeeper, bankKeeper ccv.BankKeeper, - feeCollectorName string, + feeCollectorName, authority string, ) Keeper { // set KeyTable if it has not already been set if !paramSpace.HasKeyTable() { @@ -65,6 +74,7 @@ func NewKeeper( k := Keeper{ cdc: cdc, storeKey: key, + authority: authority, paramSpace: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, @@ -84,9 +94,14 @@ func NewKeeper( return k } +// GetAuthority returns the x/ccv/provider module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} + // SetParamSpace sets the param space for the provider keeper. // Note: this is only used for testing! -func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { +func (k *Keeper) SetParamSpace(ctx context.Context, ps paramtypes.Subspace) { k.paramSpace = ps } @@ -116,56 +131,69 @@ func (k Keeper) mustValidateFields() { } // Logger returns a module-specific logger. -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", "x/"+ibchost.ModuleName+"-"+types.ModuleName) +func (k Keeper) Logger(ctx context.Context) log.Logger { + sdkCtx := sdk.UnwrapSDKContext(ctx) + return sdkCtx.Logger().With("module", "x/"+ibchost.ModuleName+"-"+types.ModuleName) } +// TODO: port v50 // IsBound checks if the CCV module is already bound to the desired port -func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { +func (k Keeper) IsBound(ctx context.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } +// TODO: port v50 // BindPort defines a wrapper function for the port Keeper's function in // order to expose it to module's InitGenesis function -func (k Keeper) BindPort(ctx sdk.Context, portID string) error { +func (k Keeper) BindPort(ctx context.Context, portID string) error { cap := k.portKeeper.BindPort(ctx, portID) return k.ClaimCapability(ctx, cap, host.PortPath(portID)) } // GetPort returns the portID for the CCV module. Used in ExportGenesis -func (k Keeper) GetPort(ctx sdk.Context) string { - store := ctx.KVStore(k.storeKey) - return string(store.Get(types.PortKey())) +func (k Keeper) GetPort(ctx context.Context) (string, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PortKey()) + if err != nil { + return "", err + } + return string(bz), nil } // SetPort sets the portID for the CCV module. Used in InitGenesis -func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetPort(ctx context.Context, portID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(types.PortKey(), []byte(portID)) } +// TODO: port v50 // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function -func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool { +func (k Keeper) AuthenticateCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) bool { return k.scopedKeeper.AuthenticateCapability(ctx, cap, name) } +// TODO: port v50 // ClaimCapability allows the transfer module that can claim a capability that IBC module // passes to it -func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error { +func (k Keeper) ClaimCapability(ctx context.Context, cap *capabilitytypes.Capability, name string) error { return k.scopedKeeper.ClaimCapability(ctx, cap, name) } // SetChainToChannel sets the mapping from a consumer chainID to the CCV channel ID for that consumer chain. -func (k Keeper) SetChainToChannel(ctx sdk.Context, chainID, channelID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetChainToChannel(ctx context.Context, chainID, channelID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(types.ChainToChannelKey(chainID), []byte(channelID)) } // GetChainToChannel gets the CCV channelID for the given consumer chainID -func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ChainToChannelKey(chainID)) +func (k Keeper) GetChainToChannel(ctx context.Context, chainID string) (string, bool) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ChainToChannelKey(chainID)) + if err != nil { + // TODO: port v50 + panic("store errored") + } if bz == nil { return "", false } @@ -173,8 +201,8 @@ func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool } // DeleteChainToChannel deletes the CCV channel ID for the given consumer chain ID -func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) DeleteChainToChannel(ctx context.Context, chainID string) { + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ChainToChannelKey(chainID)) } @@ -184,9 +212,9 @@ func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { // Note that the registered consumer chains are stored under keys with the following format: // ChainToClientBytePrefix | chainID // Thus, the returned array is in ascending order of chainIDs. -func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.ChainToClientBytePrefix}) +func (k Keeper) GetAllConsumerChains(ctx context.Context) (chains []types.Chain) { + store := k.storeService.OpenKVStore(ctx) + iterator := storetypes.KVStorePrefixIterator(runtime.KVStoreAdapter(store), []byte{types.ChainToClientBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -204,24 +232,27 @@ func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { } // SetChannelToChain sets the mapping from the CCV channel ID to the consumer chainID. -func (k Keeper) SetChannelToChain(ctx sdk.Context, channelID, chainID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetChannelToChain(ctx context.Context, channelID, chainID string) { + store := k.storeService.OpenKVStore(ctx) store.Set(types.ChannelToChainKey(channelID), []byte(chainID)) } // GetChannelToChain gets the consumer chainID for a given CCV channelID -func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ChannelToChainKey(channelID)) +func (k Keeper) GetChannelToChain(ctx context.Context, channelID string) (string, bool, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ChannelToChainKey(channelID)) + if err != nil { + return "", false, err + } if bz == nil { - return "", false + return "", false, nil } - return string(bz), true + return string(bz), true, nil } // DeleteChannelToChain deletes the consumer chain ID for a given CCV channelID -func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) DeleteChannelToChain(ctx context.Context, channelID string) { + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ChannelToChainKey(channelID)) } @@ -232,9 +263,9 @@ func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { // is stored under keys with the following format: // ChannelToChainBytePrefix | channelID // Thus, the returned array is in ascending order of channelIDs. -func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.ChannelToChain) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.ChannelToChainBytePrefix}) +func (k Keeper) GetAllChannelToChains(ctx context.Context) (channels []types.ChannelToChain) { + store := k.storeService.OpenKVStore(ctx) + iterator := storetypes.KVStorePrefixIterator(runtime.KVStoreAdapter(store), []byte{types.ChannelToChainBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -251,8 +282,8 @@ func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.Channel return channels } -func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen ccv.GenesisState) error { - store := ctx.KVStore(k.storeKey) +func (k Keeper) SetConsumerGenesis(ctx context.Context, chainID string, gen ccv.GenesisState) error { + store := k.storeService.OpenKVStore(ctx) bz, err := gen.Marshal() if err != nil { return err @@ -262,11 +293,14 @@ func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen ccv.Gene return nil } -func (k Keeper) GetConsumerGenesis(ctx sdk.Context, chainID string) (ccv.GenesisState, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConsumerGenesisKey(chainID)) +func (k Keeper) GetConsumerGenesis(ctx context.Context, chainID string) (ccv.GenesisState, bool, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ConsumerGenesisKey(chainID)) + if err != nil { + return ccv.GenesisState{}, false, err + } if bz == nil { - return ccv.GenesisState{}, false + return ccv.GenesisState{}, false, nil } var data ccv.GenesisState @@ -275,17 +309,17 @@ func (k Keeper) GetConsumerGenesis(ctx sdk.Context, chainID string) (ccv.Genesis // the ConsumerGenesis is assumed to be correctly serialized in SetConsumerGenesis. panic(fmt.Errorf("consumer genesis could not be unmarshaled: %w", err)) } - return data, true + return data, true, nil } -func (k Keeper) DeleteConsumerGenesis(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) DeleteConsumerGenesis(ctx context.Context, chainID string) { + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ConsumerGenesisKey(chainID)) } // VerifyConsumerChain verifies that the chain trying to connect on the channel handshake // is the expected consumer chain. -func (k Keeper) VerifyConsumerChain(ctx sdk.Context, channelID string, connectionHops []string) error { +func (k Keeper) VerifyConsumerChain(ctx context.Context, channelID string, connectionHops []string) error { if len(connectionHops) != 1 { return errorsmod.Wrap(channeltypes.ErrTooManyConnectionHops, "must have direct connection to provider chain") } @@ -316,7 +350,7 @@ func (k Keeper) VerifyConsumerChain(ctx sdk.Context, channelID string, connectio // chain then close the channel, so that another channel can be made. // // SetConsumerChain is called by OnChanOpenConfirm. -func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { +func (k Keeper) SetConsumerChain(ctx context.Context, channelID string) error { channel, ok := k.channelKeeper.GetChannel(ctx, ccv.ProviderPortID, channelID) if !ok { return errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "channel not found for channel ID: %s", channelID) @@ -359,7 +393,7 @@ func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { } // SetUnbondingOp sets the UnbondingOp by its unique ID -func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { +func (k Keeper) SetUnbondingOp(ctx context.Context, unbondingOp types.UnbondingOp) { store := ctx.KVStore(k.storeKey) bz, err := unbondingOp.Marshal() if err != nil { @@ -373,11 +407,14 @@ func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { } // GetUnbondingOp gets a UnbondingOp by its unique ID -func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UnbondingOpKey(id)) +func (k Keeper) GetUnbondingOp(ctx context.Context, id uint64) (types.UnbondingOp, bool, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.UnbondingOpKey(id)) + if err != nil { + return types.UnbondingOp{}, false, err + } if bz == nil { - return types.UnbondingOp{}, false + return types.UnbondingOp{}, false, err } var unbondingOp types.UnbondingOp @@ -387,12 +424,12 @@ func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, b panic(fmt.Errorf("failed to unmarshal UnbondingOp: %w", err)) } - return unbondingOp, true + return unbondingOp, true, nil } // DeleteUnbondingOp deletes a UnbondingOp given its ID -func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) DeleteUnbondingOp(ctx context.Context, id uint64) { + store := k.storeService.OpenKVStore(ctx) store.Delete(types.UnbondingOpKey(id)) } @@ -403,9 +440,9 @@ func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { // Note that UnbondingOps are stored under keys with the following format: // UnbondingOpBytePrefix | ID // Thus, the iteration is in ascending order of IDs. -func (k Keeper) GetAllUnbondingOps(ctx sdk.Context) (ops []types.UnbondingOp) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.UnbondingOpBytePrefix}) +func (k Keeper) GetAllUnbondingOps(ctx context.Context) (ops []types.UnbondingOp) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.UnbondingOpBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -432,7 +469,7 @@ func (k Keeper) GetAllUnbondingOps(ctx sdk.Context) (ops []types.UnbondingOp) { // RemoveConsumerFromUnbondingOp removes a consumer chain ID that the unbonding op with 'id' is waiting on. // The method returns true if the unbonding op can complete. In this case the record is removed from store. // The method panics if the unbonding op with 'id' is not found. -func (k Keeper) RemoveConsumerFromUnbondingOp(ctx sdk.Context, id uint64, chainID string) (canComplete bool) { +func (k Keeper) RemoveConsumerFromUnbondingOp(ctx context.Context, id uint64, chainID string) (canComplete bool) { // Get the unbonding op from store unbondingOp, found := k.GetUnbondingOp(ctx, id) if !found { @@ -470,7 +507,7 @@ func removeStringFromSlice(slice []string, x string) (newSlice []string, numRemo // SetUnbondingOpIndex sets the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID -func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64, ids []uint64) { +func (k Keeper) SetUnbondingOpIndex(ctx context.Context, chainID string, vscID uint64, ids []uint64) { store := ctx.KVStore(k.storeKey) vscUnbondingOps := types.VscUnbondingOps{ @@ -494,9 +531,9 @@ func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint6 // Note that the unbonding indexes for a given chainID are stored under keys with the following format: // UnbondingOpIndexBytePrefix | len(chainID) | chainID | vscID // Thus, the returned array is in ascending order of vscIDs. -func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (indexes []types.VscUnbondingOps) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID)) +func (k Keeper) GetAllUnbondingOpIndexes(ctx context.Context, chainID string) (indexes []types.VscUnbondingOps) { + store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -518,12 +555,16 @@ func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (index // GetUnbondingOpIndex gets the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID -func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) ([]uint64, bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetUnbondingOpIndex(ctx context.Context, chainID string, vscID uint64) ([]uint64, bool, error) { + store := k.storeService.OpenKVStore(ctx) + + bz, err := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) + if err != nil { + return []uint64{}, false, err + } - bz := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) if bz == nil { - return []uint64{}, false + return []uint64{}, false, nil } var vscUnbondingOps types.VscUnbondingOps @@ -533,18 +574,18 @@ func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint6 panic(fmt.Errorf("failed to unmarshal VscUnbondingOps: %w", err)) } - return vscUnbondingOps.GetUnbondingOpIds(), true + return vscUnbondingOps.GetUnbondingOpIds(), true, nil } // DeleteUnbondingOpIndex deletes the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID -func (k Keeper) DeleteUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) DeleteUnbondingOpIndex(ctx context.Context, chainID string, vscID uint64) { + store := k.storeService.OpenKVStore(ctx) store.Delete(types.UnbondingOpIndexKey(chainID, vscID)) } // GetUnbondingOpsFromIndex gets the unbonding ops waiting for a given chainID and vscID -func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valsetUpdateID uint64) (entries []types.UnbondingOp) { +func (k Keeper) GetUnbondingOpsFromIndex(ctx context.Context, chainID string, valsetUpdateID uint64) (entries []types.UnbondingOp) { ids, found := k.GetUnbondingOpIndex(ctx, chainID, valsetUpdateID) if !found { return entries @@ -564,15 +605,18 @@ func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valset } // GetMaturedUnbondingOps returns the list of matured unbonding operation ids -func (k Keeper) GetMaturedUnbondingOps(ctx sdk.Context) (ids []uint64) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.MaturedUnbondingOpsKey()) +func (k Keeper) GetMaturedUnbondingOps(ctx context.Context) ([]uint64, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.MaturedUnbondingOpsKey()) + if err != nil { + return nil, err + } if bz == nil { // Note that every call to ConsumeMaturedUnbondingOps // deletes the MaturedUnbondingOpsKey, which means that // the first call to GetMaturedUnbondingOps after that // will enter this branch. - return nil + return nil, nil } var ops types.MaturedUnbondingOps @@ -581,11 +625,11 @@ func (k Keeper) GetMaturedUnbondingOps(ctx sdk.Context) (ids []uint64) { // the MaturedUnbondingOps are assumed to be correctly serialized in AppendMaturedUnbondingOps. panic(fmt.Errorf("failed to unmarshal MaturedUnbondingOps: %w", err)) } - return ops.GetIds() + return ops.GetIds(), nil } // AppendMaturedUnbondingOps adds a list of ids to the list of matured unbonding operation ids -func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { +func (k Keeper) AppendMaturedUnbondingOps(ctx context.Context, ids []uint64) { if len(ids) == 0 { return } @@ -594,7 +638,7 @@ func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { Ids: append(existingIds, ids...), } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := maturedOps.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -605,7 +649,7 @@ func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { } // ConsumeMaturedUnbondingOps empties and returns list of matured unbonding operation ids (if it exists) -func (k Keeper) ConsumeMaturedUnbondingOps(ctx sdk.Context) []uint64 { +func (k Keeper) ConsumeMaturedUnbondingOps(ctx context.Context) []uint64 { ids := k.GetMaturedUnbondingOps(ctx) store := ctx.KVStore(k.storeKey) store.Delete(types.MaturedUnbondingOpsKey()) @@ -613,7 +657,7 @@ func (k Keeper) ConsumeMaturedUnbondingOps(ctx sdk.Context) []uint64 { } // Retrieves the underlying client state corresponding to a connection ID. -func (k Keeper) getUnderlyingClient(ctx sdk.Context, connectionID string) ( +func (k Keeper) getUnderlyingClient(ctx context.Context, connectionID string) ( clientID string, tmClient *ibctmtypes.ClientState, err error, ) { conn, ok := k.connectionKeeper.GetConnection(ctx, connectionID) @@ -636,7 +680,7 @@ func (k Keeper) getUnderlyingClient(ctx sdk.Context, connectionID string) ( } // chanCloseInit defines a wrapper function for the channel Keeper's function -func (k Keeper) chanCloseInit(ctx sdk.Context, channelID string) error { +func (k Keeper) chanCloseInit(ctx context.Context, channelID string) error { capName := host.ChannelCapabilityPath(ccv.ProviderPortID, channelID) chanCap, ok := k.scopedKeeper.GetCapability(ctx, capName) if !ok { @@ -645,12 +689,12 @@ func (k Keeper) chanCloseInit(ctx sdk.Context, channelID string) error { return k.channelKeeper.ChanCloseInit(ctx, ccv.ProviderPortID, channelID, chanCap) } -func (k Keeper) IncrementValidatorSetUpdateId(ctx sdk.Context) { +func (k Keeper) IncrementValidatorSetUpdateId(ctx context.Context) { validatorSetUpdateId := k.GetValidatorSetUpdateId(ctx) k.SetValidatorSetUpdateId(ctx, validatorSetUpdateId+1) } -func (k Keeper) SetValidatorSetUpdateId(ctx sdk.Context, valUpdateID uint64) { +func (k Keeper) SetValidatorSetUpdateId(ctx context.Context, valUpdateID uint64) { store := ctx.KVStore(k.storeKey) // Convert back into bytes for storage @@ -660,7 +704,7 @@ func (k Keeper) SetValidatorSetUpdateId(ctx sdk.Context, valUpdateID uint64) { store.Set(types.ValidatorSetUpdateIdKey(), bz) } -func (k Keeper) GetValidatorSetUpdateId(ctx sdk.Context) (validatorSetUpdateId uint64) { +func (k Keeper) GetValidatorSetUpdateId(ctx context.Context) (validatorSetUpdateId uint64) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.ValidatorSetUpdateIdKey()) @@ -675,7 +719,7 @@ func (k Keeper) GetValidatorSetUpdateId(ctx sdk.Context) (validatorSetUpdateId u } // SetValsetUpdateBlockHeight sets the block height for a given valset update id -func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, blockHeight uint64) { +func (k Keeper) SetValsetUpdateBlockHeight(ctx context.Context, valsetUpdateId, blockHeight uint64) { store := ctx.KVStore(k.storeKey) heightBytes := make([]byte, 8) binary.BigEndian.PutUint64(heightBytes, blockHeight) @@ -683,7 +727,7 @@ func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, bloc } // GetValsetUpdateBlockHeight gets the block height for a given valset update id -func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) (uint64, bool) { +func (k Keeper) GetValsetUpdateBlockHeight(ctx context.Context, valsetUpdateId uint64) (uint64, bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) if bz == nil { @@ -697,9 +741,9 @@ func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint6 // Note that the mapping from vscIDs to block heights is stored under keys with the following format: // ValsetUpdateBlockHeightBytePrefix | vscID // Thus, the returned array is in ascending order of vscIDs. -func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlockHeights []types.ValsetUpdateIdToHeight) { +func (k Keeper) GetAllValsetUpdateBlockHeights(ctx context.Context) (valsetUpdateBlockHeights []types.ValsetUpdateIdToHeight) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.ValsetUpdateBlockHeightBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ValsetUpdateBlockHeightBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -716,7 +760,7 @@ func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlo } // DeleteValsetUpdateBlockHeight deletes the block height value for a given vaset update id -func (k Keeper) DeleteValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) { +func (k Keeper) DeleteValsetUpdateBlockHeight(ctx context.Context, valsetUpdateId uint64) { store := ctx.KVStore(k.storeKey) store.Delete(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) } @@ -725,7 +769,7 @@ func (k Keeper) DeleteValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId ui // // TODO: SlashAcks should be persisted as a list of ConsumerConsAddr types, not strings. // See https://github.com/cosmos/interchain-security/issues/728 -func (k Keeper) SetSlashAcks(ctx sdk.Context, chainID string, acks []string) { +func (k Keeper) SetSlashAcks(ctx context.Context, chainID string, acks []string) { store := ctx.KVStore(k.storeKey) sa := types.SlashAcks{ @@ -744,7 +788,7 @@ func (k Keeper) SetSlashAcks(ctx sdk.Context, chainID string, acks []string) { // // TODO: SlashAcks should be persisted as a list of ConsumerConsAddr types, not strings. // See https://github.com/cosmos/interchain-security/issues/728 -func (k Keeper) GetSlashAcks(ctx sdk.Context, chainID string) []string { +func (k Keeper) GetSlashAcks(ctx context.Context, chainID string) []string { store := ctx.KVStore(k.storeKey) bz := store.Get(types.SlashAcksKey(chainID)) if bz == nil { @@ -761,7 +805,7 @@ func (k Keeper) GetSlashAcks(ctx sdk.Context, chainID string) []string { } // ConsumeSlashAcks empties and returns the slash acks for a given chain ID -func (k Keeper) ConsumeSlashAcks(ctx sdk.Context, chainID string) (acks []string) { +func (k Keeper) ConsumeSlashAcks(ctx context.Context, chainID string) (acks []string) { acks = k.GetSlashAcks(ctx, chainID) if len(acks) < 1 { return @@ -772,13 +816,13 @@ func (k Keeper) ConsumeSlashAcks(ctx sdk.Context, chainID string) (acks []string } // DeleteSlashAcks deletes the slash acks for a given chain ID -func (k Keeper) DeleteSlashAcks(ctx sdk.Context, chainID string) { +func (k Keeper) DeleteSlashAcks(ctx context.Context, chainID string) { store := ctx.KVStore(k.storeKey) store.Delete(types.SlashAcksKey(chainID)) } // AppendSlashAck appends the given slash ack to the given chain ID slash acks in store -func (k Keeper) AppendSlashAck(ctx sdk.Context, chainID, +func (k Keeper) AppendSlashAck(ctx context.Context, chainID, ack string, // TODO: consumer cons addr should be accepted here, see https://github.com/cosmos/interchain-security/issues/728 ) { acks := k.GetSlashAcks(ctx, chainID) @@ -787,7 +831,7 @@ func (k Keeper) AppendSlashAck(ctx sdk.Context, chainID, } // SetInitChainHeight sets the provider block height when the given consumer chain was initiated -func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint64) { +func (k Keeper) SetInitChainHeight(ctx context.Context, chainID string, height uint64) { store := ctx.KVStore(k.storeKey) heightBytes := make([]byte, 8) binary.BigEndian.PutUint64(heightBytes, height) @@ -796,7 +840,7 @@ func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint6 } // GetInitChainHeight returns the provider block height when the given consumer chain was initiated -func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, bool) { +func (k Keeper) GetInitChainHeight(ctx context.Context, chainID string) (uint64, bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.InitChainHeightKey(chainID)) if bz == nil { @@ -807,13 +851,13 @@ func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, boo } // DeleteInitChainHeight deletes the block height value for which the given consumer chain's channel was established -func (k Keeper) DeleteInitChainHeight(ctx sdk.Context, chainID string) { +func (k Keeper) DeleteInitChainHeight(ctx context.Context, chainID string) { store := ctx.KVStore(k.storeKey) store.Delete(types.InitChainHeightKey(chainID)) } // GetPendingVSCPackets returns the list of pending ValidatorSetChange packets stored under chain ID -func (k Keeper) GetPendingVSCPackets(ctx sdk.Context, chainID string) []ccv.ValidatorSetChangePacketData { +func (k Keeper) GetPendingVSCPackets(ctx context.Context, chainID string) []ccv.ValidatorSetChangePacketData { var packets types.ValidatorSetChangePackets store := ctx.KVStore(k.storeKey) @@ -831,7 +875,7 @@ func (k Keeper) GetPendingVSCPackets(ctx sdk.Context, chainID string) []ccv.Vali // AppendPendingVSCPackets adds the given ValidatorSetChange packet to the list // of pending ValidatorSetChange packets stored under chain ID -func (k Keeper) AppendPendingVSCPackets(ctx sdk.Context, chainID string, newPackets ...ccv.ValidatorSetChangePacketData) { +func (k Keeper) AppendPendingVSCPackets(ctx context.Context, chainID string, newPackets ...ccv.ValidatorSetChangePacketData) { pds := append(k.GetPendingVSCPackets(ctx, chainID), newPackets...) store := ctx.KVStore(k.storeKey) @@ -846,19 +890,19 @@ func (k Keeper) AppendPendingVSCPackets(ctx sdk.Context, chainID string, newPack } // DeletePendingVSCPackets deletes the list of pending ValidatorSetChange packets for chain ID -func (k Keeper) DeletePendingVSCPackets(ctx sdk.Context, chainID string) { +func (k Keeper) DeletePendingVSCPackets(ctx context.Context, chainID string) { store := ctx.KVStore(k.storeKey) store.Delete(types.PendingVSCsKey(chainID)) } // SetConsumerClientId sets the client ID for the given chain ID -func (k Keeper) SetConsumerClientId(ctx sdk.Context, chainID, clientID string) { +func (k Keeper) SetConsumerClientId(ctx context.Context, chainID, clientID string) { store := ctx.KVStore(k.storeKey) store.Set(types.ChainToClientKey(chainID), []byte(clientID)) } // GetConsumerClientId returns the client ID for the given chain ID. -func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bool) { +func (k Keeper) GetConsumerClientId(ctx context.Context, chainID string) (string, bool) { store := ctx.KVStore(k.storeKey) clientIdBytes := store.Get(types.ChainToClientKey(chainID)) if clientIdBytes == nil { @@ -868,13 +912,13 @@ func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bo } // DeleteConsumerClientId removes from the store the clientID for the given chainID. -func (k Keeper) DeleteConsumerClientId(ctx sdk.Context, chainID string) { +func (k Keeper) DeleteConsumerClientId(ctx context.Context, chainID string) { store := ctx.KVStore(k.storeKey) store.Delete(types.ChainToClientKey(chainID)) } // SetInitTimeoutTimestamp sets the init timeout timestamp for the given chain ID -func (k Keeper) SetInitTimeoutTimestamp(ctx sdk.Context, chainID string, ts uint64) { +func (k Keeper) SetInitTimeoutTimestamp(ctx context.Context, chainID string, ts uint64) { store := ctx.KVStore(k.storeKey) tsBytes := make([]byte, 8) binary.BigEndian.PutUint64(tsBytes, ts) @@ -883,7 +927,7 @@ func (k Keeper) SetInitTimeoutTimestamp(ctx sdk.Context, chainID string, ts uint // GetInitTimeoutTimestamp returns the init timeout timestamp for the given chain ID. // This method is used only in testing. -func (k Keeper) GetInitTimeoutTimestamp(ctx sdk.Context, chainID string) (uint64, bool) { +func (k Keeper) GetInitTimeoutTimestamp(ctx context.Context, chainID string) (uint64, bool) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.InitTimeoutTimestampKey(chainID)) if bz == nil { @@ -893,7 +937,7 @@ func (k Keeper) GetInitTimeoutTimestamp(ctx sdk.Context, chainID string) (uint64 } // DeleteInitTimeoutTimestamp removes from the store the init timeout timestamp for the given chainID. -func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { +func (k Keeper) DeleteInitTimeoutTimestamp(ctx context.Context, chainID string) { store := ctx.KVStore(k.storeKey) store.Delete(types.InitTimeoutTimestampKey(chainID)) } @@ -903,9 +947,9 @@ func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { // Note that the init timeout timestamps are stored under keys with the following format: // InitTimeoutTimestampBytePrefix | chainID // Thus, the returned array is in ascending order of chainIDs (NOT in timestamp order). -func (k Keeper) GetAllInitTimeoutTimestamps(ctx sdk.Context) (initTimeoutTimestamps []types.InitTimeoutTimestamp) { +func (k Keeper) GetAllInitTimeoutTimestamps(ctx context.Context) (initTimeoutTimestamps []types.InitTimeoutTimestamp) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.InitTimeoutTimestampBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.InitTimeoutTimestampBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -924,7 +968,7 @@ func (k Keeper) GetAllInitTimeoutTimestamps(ctx sdk.Context) (initTimeoutTimesta // SetVscSendTimestamp sets the VSC send timestamp // for a VSCPacket with ID vscID sent to a chain with ID chainID func (k Keeper) SetVscSendTimestamp( - ctx sdk.Context, + ctx context.Context, chainID string, vscID uint64, timestamp time.Time, @@ -940,7 +984,7 @@ func (k Keeper) SetVscSendTimestamp( // GetVscSendTimestamp returns a VSC send timestamp by chainID and vscID // // Note: This method is used only for testing. -func (k Keeper) GetVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint64) (time.Time, bool) { +func (k Keeper) GetVscSendTimestamp(ctx context.Context, chainID string, vscID uint64) (time.Time, bool) { store := ctx.KVStore(k.storeKey) timeBz := store.Get(types.VscSendingTimestampKey(chainID, vscID)) @@ -957,7 +1001,7 @@ func (k Keeper) GetVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint6 // DeleteVscSendTimestamp removes from the store a specific VSC send timestamp // for the given chainID and vscID. -func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint64) { +func (k Keeper) DeleteVscSendTimestamp(ctx context.Context, chainID string, vscID uint64) { store := ctx.KVStore(k.storeKey) store.Delete(types.VscSendingTimestampKey(chainID, vscID)) } @@ -967,9 +1011,9 @@ func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID ui // Note that the vsc send timestamps of a given chainID are stored under keys with the following format: // VscSendTimestampBytePrefix | len(chainID) | chainID | vscID // Thus, the iteration is in ascending order of vscIDs, and as a result in send timestamp order. -func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSendTimestamps []types.VscSendTimestamp) { +func (k Keeper) GetAllVscSendTimestamps(ctx context.Context, chainID string) (vscSendTimestamps []types.VscSendTimestamp) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -996,9 +1040,9 @@ func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSen } // DeleteVscSendTimestampsForConsumer deletes all VSC send timestamps for a given consumer chain -func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx sdk.Context, consumerChainID string) { +func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx context.Context, consumerChainID string) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, consumerChainID)) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, consumerChainID)) defer iterator.Close() keysToDel := [][]byte{} @@ -1013,9 +1057,9 @@ func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx sdk.Context, consumerChai } // GetFirstVscSendTimestamp gets the vsc send timestamp with the lowest vscID for the given chainID. -func (k Keeper) GetFirstVscSendTimestamp(ctx sdk.Context, chainID string) (vscSendTimestamp types.VscSendTimestamp, found bool) { +func (k Keeper) GetFirstVscSendTimestamp(ctx context.Context, chainID string) (vscSendTimestamp types.VscSendTimestamp, found bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) defer iterator.Close() if iterator.Valid() { @@ -1045,7 +1089,7 @@ func (k Keeper) GetFirstVscSendTimestamp(ctx sdk.Context, chainID string) (vscSe // If an entry exists for a given validator address, at least one // double signing slash packet was received by the provider from at least one consumer chain func (k Keeper) SetSlashLog( - ctx sdk.Context, + ctx context.Context, providerAddr types.ProviderConsAddress, ) { store := ctx.KVStore(k.storeKey) @@ -1055,7 +1099,7 @@ func (k Keeper) SetSlashLog( // GetSlashLog returns a validator's slash log status // True will be returned if an entry exists for a given validator address func (k Keeper) GetSlashLog( - ctx sdk.Context, + ctx context.Context, providerAddr types.ProviderConsAddress, ) (found bool) { store := ctx.KVStore(k.storeKey) @@ -1063,6 +1107,6 @@ func (k Keeper) GetSlashLog( return bz != nil } -func (k Keeper) BondDenom(ctx sdk.Context) string { +func (k Keeper) BondDenom(ctx context.Context) string { return k.stakingKeeper.BondDenom(ctx) } diff --git a/x/ccv/provider/keeper/key_assignment.go b/x/ccv/provider/keeper/key_assignment.go index d440848bbf..19289c35c2 100644 --- a/x/ccv/provider/keeper/key_assignment.go +++ b/x/ccv/provider/keeper/key_assignment.go @@ -4,6 +4,7 @@ import ( "fmt" errorsmod "cosmossdk.io/errors" + storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -70,7 +71,7 @@ func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) // iterate over the validators public keys assigned for chainID prefix = types.ChainIdWithLenKey(types.ConsumerValidatorsBytePrefix, *chainID) } - iterator := sdk.KVStorePrefixIterator(store, prefix) + iterator := storetypes.KVStorePrefixIterator(store, prefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and provider cons address in value bytes, marshaled as protobuf type @@ -154,7 +155,7 @@ func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) // iterate over the mappings from consensus addresses on chainID prefix = types.ChainIdWithLenKey(types.ValidatorsByConsumerAddrBytePrefix, *chainID) } - iterator := sdk.KVStorePrefixIterator(store, prefix) + iterator := storetypes.KVStorePrefixIterator(store, prefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and consumer cons address in value bytes, marshaled as protobuf type @@ -240,7 +241,7 @@ func (k Keeper) SetKeyAssignmentReplacement( func (k Keeper) GetAllKeyAssignmentReplacements(ctx sdk.Context, chainID string) (replacements []types.KeyAssignmentReplacement) { store := ctx.KVStore(k.storeKey) iteratorPrefix := types.ChainIdWithLenKey(types.KeyAssignmentReplacementsBytePrefix, chainID) - iterator := sdk.KVStorePrefixIterator(store, iteratorPrefix) + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and provider cons address in value bytes, marshaled as protobuf type @@ -336,7 +337,7 @@ func (k Keeper) GetConsumerAddrsToPrune( func (k Keeper) GetAllConsumerAddrsToPrune(ctx sdk.Context, chainID string) (consumerAddrsToPrune []types.ConsumerAddrsToPrune) { store := ctx.KVStore(k.storeKey) iteratorPrefix := types.ChainIdWithLenKey(types.ConsumerAddrsToPruneBytePrefix, chainID) - iterator := sdk.KVStorePrefixIterator(store, iteratorPrefix) + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { _, vscID, err := types.ParseChainIdAndUintIdKey(types.ConsumerAddrsToPruneBytePrefix, iterator.Key()) diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index c0e470aaee..b23eb8c2ec 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -11,6 +11,7 @@ import ( ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" errorsmod "cosmossdk.io/errors" + storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -402,7 +403,7 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) { // Note: this method is split out from BeginBlockInit to be easily unit tested. func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecute []types.ConsumerAdditionProposal) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -432,7 +433,7 @@ func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecu // then they are ordered by chainID. func (k Keeper) GetAllPendingConsumerAdditionProps(ctx sdk.Context) (props []types.ConsumerAdditionProposal) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -540,7 +541,7 @@ func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.Consum propsToExecute := []types.ConsumerRemovalProposal{} store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -571,7 +572,7 @@ func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.Consum // Thus, the returned array is in stopTime order. func (k Keeper) GetAllPendingConsumerRemovalProps(ctx sdk.Context) (props []types.ConsumerRemovalProposal) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() {