Skip to content

Commit

Permalink
add further changes to fix build errors on sovereign, consumer, and c…
Browse files Browse the repository at this point in the history
…onsumer democracy
  • Loading branch information
jstr1121 committed Apr 4, 2023
1 parent bdb0b37 commit cb6550a
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 2,225 deletions.
3 changes: 1 addition & 2 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"github.com/tendermint/spm/cosmoscmd"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"

Expand Down Expand Up @@ -871,7 +870,7 @@ func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {

// GetTxConfig implements the TestingApp interface.
func (app *App) GetTxConfig() client.TxConfig {
return cosmoscmd.MakeEncodingConfig(ModuleBasics).TxConfig
return appparams.MakeEncodingConfig().TxConfig
}

// RegisterAPIRoutes registers all application module routes with the provided
Expand Down
2 changes: 1 addition & 1 deletion app/consumer-democracy/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/interchain-security/app/consumer/params"
"github.com/cosmos/interchain-security/app/consumer-democracy/params"
)

// MakeEncodingConfig creates an EncodingConfig for testing
Expand Down
3 changes: 1 addition & 2 deletions app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"github.com/tendermint/spm/cosmoscmd"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"

Expand Down Expand Up @@ -703,7 +702,7 @@ func (app *App) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {

// GetTxConfig implements the TestingApp interface.
func (app *App) GetTxConfig() client.TxConfig {
return cosmoscmd.MakeEncodingConfig(ModuleBasics).TxConfig
return appparams.MakeEncodingConfig().TxConfig
}

// RegisterAPIRoutes registers all application module routes with the provided
Expand Down
30 changes: 14 additions & 16 deletions app/sovereign/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -82,7 +84,6 @@ import (
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
"github.com/spf13/cast"
"github.com/tendermint/spm/cosmoscmd"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"

Expand All @@ -102,6 +103,7 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
appparams "github.com/cosmos/interchain-security/app/sovereign/params"
)

const (
Expand Down Expand Up @@ -195,8 +197,6 @@ type SovereignApp struct {
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
Expand Down Expand Up @@ -249,13 +249,10 @@ func New(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *SovereignApp {
encodingConfig := appparams.MakeEncodingConfig()
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -282,7 +279,6 @@ func New(
cdc: cdc,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
Expand Down Expand Up @@ -358,6 +354,7 @@ func New(
app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
app.CrisisKeeper = crisiskeeper.NewKeeper(
appCodec,
keys[crisistypes.StoreKey],
Expand All @@ -368,14 +365,15 @@ func New(
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights,
keys[upgradetypes.StoreKey],
appCodec,
homePath,
app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// get skipUpgradeHeights from the app options
skipUpgradeHeights := map[int64]bool{}
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
homePath := cast.ToString(appOpts.Get(flags.FlagHome))
// set the governance module account as the authority for conducting upgrades
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper.SetHooks(
Expand Down
30 changes: 4 additions & 26 deletions app/sovereign/encoding.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
package app

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/interchain-security/app/sovereign/params"
)

// This data structure (EncodingConfig) is heavily inspired by Quicksilver. https://github.com/ingenuity-build/quicksilver/blob/main/app/encoding.go
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

encodingConfig := EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
Expand Down
32 changes: 32 additions & 0 deletions app/sovereign/params/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package params

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}
6 changes: 3 additions & 3 deletions cmd/interchain-security-cdd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

app "github.com/cosmos/interchain-security/app/consumer"
"github.com/cosmos/interchain-security/app/consumer-demoracy/params"
app "github.com/cosmos/interchain-security/app/consumer-democracy"
"github.com/cosmos/interchain-security/app/consumer-democracy/params"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down Expand Up @@ -175,7 +175,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
)

// add rosetta
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
}

func addModuleInitFlags(startCmd *cobra.Command) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/interchain-security-sd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

app "github.com/cosmos/interchain-security/app/consumer"
app "github.com/cosmos/interchain-security/app/sovereign"
"github.com/cosmos/interchain-security/app/sovereign/params"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -174,7 +174,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
)

// add rosetta
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Marshaler))
}

func addModuleInitFlags(startCmd *cobra.Command) {
Expand Down Expand Up @@ -268,7 +268,7 @@ func appExport(
appOpts servertypes.AppOptions,
modulesToExport []string,
) (servertypes.ExportedApp, error) {
var cApp *app.App
var cApp *app.SovereignApp

// this check is necessary as we use the flag in x/upgrade.
// we can exit more gracefully by checking the flag here.
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func (k Keeper) QueueVSCMaturedPackets(ctx sdk.Context) {
}

// QueueSlashPacket appends a slash packet containing the given validator data and slashing info to queue.
func (k Keeper) QueueSlashPacket(ctx sdk.Context, validator abci.Validator, valsetUpdateID uint64, infraction stakingtypes.InfractionType) {
func (k Keeper) QueueSlashPacket(ctx sdk.Context, validator abci.Validator, valsetUpdateID uint64, infraction stakingtypes.Infraction) {
consAddr := sdk.ConsAddress(validator.Address)
downtime := infraction == stakingtypes.Downtime
downtime := infraction == stakingtypes.Infraction_INFRACTION_DOWNTIME

// return if an outstanding downtime request is set for the validator
if downtime && k.OutstandingDowntime(ctx, consAddr) {
Expand Down
20 changes: 13 additions & 7 deletions x/ccv/consumer/keeper/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"time"

"cosmossdk.io/math"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"

abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -123,18 +124,22 @@ func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) s

// Slash queues a slashing request for the the provider chain
// All queued slashing requests will be cleared in EndBlock
func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec, infraction stakingtypes.InfractionType) {
if infraction == stakingtypes.InfractionEmpty {
return
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec) math.Int {
// Do nothing when no reason provided for slash
return math.ZeroInt()
}

func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, infraction stakingtypes.Infraction) math.Int {
if infraction == stakingtypes.Infraction_INFRACTION_UNSPECIFIED {
return math.ZeroInt()
}

if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) {
if k.stakingKeeper == nil {
return
return math.ZeroInt()
}

k.stakingKeeper.Slash(ctx, addr, infractionHeight, power, slashFactor, infraction)
return
return k.stakingKeeper.SlashWithInfractionReason(ctx, consAddr, infractionHeight, power, slashFactor, infraction)
}

// get VSC ID for infraction height
Expand All @@ -148,11 +153,12 @@ func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, p
k.QueueSlashPacket(
ctx,
abci.Validator{
Address: addr.Bytes(),
Address: consAddr.Bytes(),
Power: power},
vscID,
infraction,
)
return math.ZeroInt()
}

// Jail performs jail operation on democracy staking validator if block height after last sovereign height
Expand Down
17 changes: 0 additions & 17 deletions x/ccv/consumer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -109,21 +108,11 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
// TODO
}

// Route implements the AppModule interface
func (am AppModule) Route() sdk.Route {
return sdk.Route{}
}

// QuerierRoute implements the AppModule interface
func (AppModule) QuerierRoute() string {
return consumertypes.QuerierRoute
}

// LegacyQuerierHandler implements the AppModule interface
func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {
return nil
}

// RegisterServices registers module services.
// TODO
func (am AppModule) RegisterServices(cfg module.Configurator) {
Expand Down Expand Up @@ -235,12 +224,6 @@ func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedP
return nil
}

// RandomizedParams creates randomized consumer param changes for the simulator.
// TODO
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}

// RegisterStoreDecoder registers a decoder for consumer module's types
// TODO
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
Expand Down
Loading

0 comments on commit cb6550a

Please sign in to comment.