Skip to content

Commit

Permalink
wip: updated the server and cmd to run in kava
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Oct 25, 2024
1 parent 2269119 commit 25d6caa
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 328 deletions.
165 changes: 118 additions & 47 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
package app

import (
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/x/feegrant"
"encoding/json"
"fmt"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/evmos/ethermint/encoding"
"github.com/spf13/cobra"
"io"
"net/http"
Expand Down Expand Up @@ -50,6 +55,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -71,7 +77,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
Expand All @@ -85,11 +90,9 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
Expand All @@ -102,19 +105,16 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
"github.com/evmos/ethermint/simapp"
simappparams "github.com/evmos/ethermint/simapp/params"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/client/cli"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
cmdconfig "github.com/evmos/ethermint/cmd/config"
"github.com/evmos/ethermint/simapp"

consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
Expand Down Expand Up @@ -153,43 +153,44 @@ var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

ac = addresscodec.NewBech32Codec("ethermint")
// authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ac = authcodec.NewBech32Codec(cmdconfig.Bech32PrefixAccAddr)

Check warning

Code scanning / CodeQL

Directly using the bech32 constants Warning

Directly using the bech32 constants instead of the configuration values

LegacyProposalHandler = govclient.NewProposalHandler(func() *cobra.Command { return upgradeclient.NewCmdSubmitUpgradeProposal(ac) })
LegacyCancelProposalHandler = govclient.NewProposalHandler(func() *cobra.Command { return upgradeclient.NewCmdSubmitCancelUpgradeProposal(ac) })

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic([]govclient.ProposalHandler{
paramsclient.ProposalHandler,
LegacyProposalHandler,
LegacyCancelProposalHandler,
govclient.NewProposalHandler(ibcclientclient.NewTxCmd),
//ibcclientclient.UpgradeProposalHandler,
}),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
authzmodule.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
vesting.AppModuleBasic{},
// Ethermint modules
evm.AppModuleBasic{},
feemarket.AppModuleBasic{},
)
//// ModuleBasics defines the module BasicManager is in charge of setting up basic,
//// non-dependant module elements, such as codec registration
//// and genesis verification.
//ModuleBasics = module.NewBasicManager(
// auth.AppModuleBasic{},
// genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
// bank.AppModuleBasic{},
// capability.AppModuleBasic{},
// staking.AppModuleBasic{},
// mint.AppModuleBasic{},
// distr.AppModuleBasic{},
// gov.NewAppModuleBasic([]govclient.ProposalHandler{
// paramsclient.ProposalHandler,
// LegacyProposalHandler,
// LegacyCancelProposalHandler,
// govclient.NewProposalHandler(ibcclientclient.NewTxCmd),
// //ibcclientclient.UpgradeProposalHandler,
// }),
// params.AppModuleBasic{},
// crisis.AppModuleBasic{},
// slashing.AppModuleBasic{},
// ibc.AppModuleBasic{},
// authzmodule.AppModuleBasic{},
// feegrantmodule.AppModuleBasic{},
// upgrade.AppModuleBasic{},
// evidence.AppModuleBasic{},
// ibctransfer.AppModuleBasic{},
// vesting.AppModuleBasic{},
// // Ethermint modules
// evm.AppModuleBasic{},
// feemarket.AppModuleBasic{},
//)

// module account permissions
maccPerms = map[string][]string{
Expand Down Expand Up @@ -257,7 +258,8 @@ type EthermintApp struct {
FeeMarketKeeper feemarketkeeper.Keeper

// the module manager
mm *module.Manager
mm *module.Manager
BasicModuleManager module.BasicManager

// the configurator
configurator module.Configurator
Expand All @@ -272,10 +274,11 @@ func NewEthermintApp(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig simappparams.EncodingConfig,
//encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *EthermintApp {
encodingConfig := encoding.MakeConfig()
appCodec := encodingConfig.Codec
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand Down Expand Up @@ -335,6 +338,7 @@ func NewEthermintApp(

// allow x/gov to modify consensus parameters
authAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
fmt.Println("authAddr: ", authAddr)
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authAddr, runtime.EventService{})

// set the BaseApp's parameter store to the consensus keeper
Expand All @@ -354,9 +358,11 @@ func NewEthermintApp(
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
ethermint.ProtoAccount,
//ethermint.ProtoAccount,
authtypes.ProtoBaseAccount,
maccPerms,
ac,
//authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
sdk.GetConfig().GetBech32AccountAddrPrefix(),
authAddr,
)
Expand All @@ -368,14 +374,32 @@ func NewEthermintApp(
authAddr,
logger,
)
// app.stakingKeeper = stakingkeeper.NewKeeper(
// appCodec,
// runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
// app.accountKeeper,
// app.bankKeeper,
// govAuthAddrStr,
// // TODO(boodyvo): validate which codecs to use. Looks like for validation before it used another codec, using AccAddress
// addresscodec.NewBech32Codec(Bech32PrefixValAddr),
// addresscodec.NewBech32Codec(Bech32PrefixConsAddr),
// )
fmt.Println("prefix val", sdk.GetConfig().GetBech32ValidatorAddrPrefix())
fmt.Println("prefix cons", sdk.GetConfig().GetBech32ConsensusAddrPrefix())
stakingKeeper := stakingkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
app.AccountKeeper,
app.BankKeeper,
authAddr,
authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
//addresscodec.NewBech32Codec(Bech32PrefixValAddr),
//addresscodec.NewBech32Codec(Bech32PrefixConsAddr),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
//authcodec.NewBech32Codec(cmdconfig.Bech32PrefixValAddr),
//authcodec.NewBech32Codec(cmdconfig.Bech32PrefixConsAddr),
//authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
//authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -539,6 +563,27 @@ func NewEthermintApp(
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper),
)

// BasicModuleManager defines the module BasicManager which is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default, it is composed of all the modules from the module manager.
// Additionally, app module basics can be overwritten by passing them as an argument.
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
// TODO(boodyvo): validate if we need this, as it requires custom changes into cosmos-sdk
//stakingtypes.ModuleName: staking.AppModuleBasic{AppModuleBasic: &sdkstaking.AppModuleBasic{}},
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
},
),
//ibctransfertypes.ModuleName: ibctransfer.AppModuleBasic{AppModuleBasic: &ibctransfer.AppModuleBasic{}},
},
)
app.BasicModuleManager.RegisterLegacyAminoCodec(cdc)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
Expand Down Expand Up @@ -782,6 +827,11 @@ func (app *EthermintApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (app *EthermintApp) DefaultGenesis() simapp.GenesisState {
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down Expand Up @@ -823,7 +873,7 @@ func (app *EthermintApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.
node.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
Expand Down Expand Up @@ -852,6 +902,27 @@ func (app *EthermintApp) RegisterNodeService(clientCtx client.Context, cfg confi
node.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
}

// AutoCliOpts returns the autocli options for the app.
func (app *EthermintApp) AutoCliOpts() autocli.AppOptions {
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range app.mm.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
moduleName := moduleWithName.Name()
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
modules[moduleName] = appModule
}
}
}

return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down
28 changes: 18 additions & 10 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/evmos/ethermint/simapp"

"github.com/evmos/ethermint/encoding"
)

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() simapp.GenesisState {
encCfg := encoding.MakeConfig(ModuleBasics)
return ModuleBasics.DefaultGenesis(encCfg.Codec)
}
//func NewDefaultGenesisState() simapp.GenesisState {

//encCfg := encoding.MakeConfig(ModuleBasics)
//return ModuleBasics.DefaultGenesis(encCfg.Codec)
//}

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
Expand Down Expand Up @@ -106,7 +104,12 @@ func (app *EthermintApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAd

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, []byte(val.GetOperator()))
valAddr, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
// should we panic?
panic(err)
}
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valAddr)
return false
})

Expand Down Expand Up @@ -141,7 +144,12 @@ func (app *EthermintApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAd
// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, []byte(val.GetOperator()))
valAddr, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
// TODO(boodyvo): should we panic?
panic(err)
}
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)
if err != nil {
// TODO(boodyvo): should we return stop = true here?
return false
Expand All @@ -160,7 +168,7 @@ func (app *EthermintApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAd
return false
}

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, []byte(val.GetOperator())); err != nil {
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valAddr); err != nil {
return true
}
return false
Expand Down
Loading

0 comments on commit 25d6caa

Please sign in to comment.