Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix start command #2988

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 74 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package app

import (
"encoding/json"
"fmt"
"io"
"os"

abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand All @@ -29,13 +31,17 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/gogoproto/proto"

srvflags "github.com/evmos/ethermint/server/flags"

Expand All @@ -57,15 +63,17 @@ var (
// capabilities aren't needed for testing.
type IrisApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
configurator module.Configurator

keepers.AppKeepers

configurator module.Configurator
interfaceRegistry types.InterfaceRegistry
codec codec.Codec
txConfig client.TxConfig
legacyAmino *codec.LegacyAmino

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

// simulation manager
sm *module.SimulationManager
Expand All @@ -77,13 +85,15 @@ func NewIrisApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
encodingConfig params.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *IrisApp {
appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
encodingConfig := params.MakeEncodingConfig()

appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.LegacyAmino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

// Setup Mempool
baseAppOptions = append(baseAppOptions, NoOpMempoolOption())
Expand All @@ -92,7 +102,7 @@ func NewIrisApp(
iristypes.AppName,
logger,
db,
encodingConfig.TxConfig.TxDecoder(),
txConfig.TxDecoder(),
baseAppOptions...,
)
bApp.SetCommitMultiStoreTracer(traceStore)
Expand All @@ -101,9 +111,10 @@ func NewIrisApp(

app := &IrisApp{
BaseApp: bApp,
legacyAmino: legacyAmino,
appCodec: appCodec,
codec: appCodec,
interfaceRegistry: interfaceRegistry,
txConfig: txConfig,
legacyAmino: legacyAmino,
}

// get skipUpgradeHeights from the app options
Expand Down Expand Up @@ -137,6 +148,24 @@ func NewIrisApp(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(appModules(app, encodingConfig, skipGenesisInvariants)...)
app.bm = newBasicManagerFromManager(app)

enabledSignModes := append([]sigtypes.SignMode(nil), authtx.DefaultSignModes...)
enabledSignModes = append(enabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)

txConfigOpts := authtx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}

txConfig, err := authtx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
if err != nil {
panic(err)
}
app.txConfig = txConfig

// NOTE: upgrade module is required to be prioritized
app.mm.SetOrderPreBlockers(
Expand Down Expand Up @@ -196,7 +225,7 @@ func NewIrisApp(
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SignModeHandler: txConfig.SignModeHandler(),
},
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
Expand All @@ -220,6 +249,19 @@ func NewIrisApp(
app.SetEndBlocker(app.EndBlocker)
app.RegisterUpgradePlans()

// At startup, after all modules have been registered, check that all prot
// annotations are correct.
protoFiles, err := proto.MergedRegistry()
if err != nil {
panic(err)
}
err = msgservice.ValidateProtoAnnotations(protoFiles)
if err != nil {
// Once we switch to using protoreflect-based antehandlers, we might
// want to panic here instead of logging a warning.
fmt.Fprintln(os.Stderr, err.Error())
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down Expand Up @@ -264,7 +306,7 @@ func (app *IrisApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*a
if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()); err != nil {
return nil, err
}
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
return app.mm.InitGenesis(ctx, app.codec, genesisState)
}

// LoadHeight loads a particular height
Expand Down Expand Up @@ -306,19 +348,34 @@ func (app *IrisApp) LegacyAmino() *codec.LegacyAmino {
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *IrisApp) AppCodec() codec.Codec {
return app.appCodec
return app.codec
}

// InterfaceRegistry returns IrisApp's InterfaceRegistry
func (app *IrisApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// EncodingConfig returns IrisApp's EncodingConfig
func (app *IrisApp) EncodingConfig() params.EncodingConfig {
return params.EncodingConfig{
InterfaceRegistry: app.interfaceRegistry,
LegacyAmino: app.legacyAmino,
Codec: app.codec,
TxConfig: app.txConfig,
}
}

// SimulationManager implements the SimulationApp interface
func (app *IrisApp) SimulationManager() *module.SimulationManager {
return app.sm
}

// BasicManager return the basic manager
func (app *IrisApp) BasicManager() module.BasicManager {
return app.bm
}

// RegisterAPIRoutes registers all application module routes with the provided API server.
func (app *IrisApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
clientCtx := apiSvr.ClientCtx
Expand All @@ -329,7 +386,7 @@ func (app *IrisApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICo
// Register node gRPC service for grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
app.bm.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
Expand All @@ -344,7 +401,7 @@ func (app *IrisApp) RegisterServices() {
if !ok {
panic("unable to cast mod into AppModule")
}
rpc.RegisterService(app.appCodec, m, app.configurator, app.AppKeepers)
rpc.RegisterService(app.codec, m, app.configurator, app.AppKeepers)
}
}

Expand Down Expand Up @@ -377,7 +434,7 @@ func (app *IrisApp) RegisterNodeService(clientCtx client.Context, c config.Confi

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (app *IrisApp) DefaultGenesis() map[string]json.RawMessage {
return ModuleBasics.DefaultGenesis(app.AppCodec())
return app.bm.DefaultGenesis(app.AppCodec())
}

// Init initializes the IrisApp.
Expand Down
20 changes: 6 additions & 14 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package app

import (
enccodec "github.com/evmos/ethermint/encoding/codec"

"github.com/irisnet/irishub/v4/app/params"
)

// RegisterEncodingConfig registers concrete types on codec
func RegisterEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
enccodec.RegisterLegacyAminoCodec(encodingConfig.Amino)
enccodec.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
// func RegisterEncodingConfig() params.EncodingConfig {
// encodingConfig := params.MakeEncodingConfig()
// enccodec.RegisterLegacyAminoCodec(encodingConfig.Amino)
// enccodec.RegisterInterfaces(encodingConfig.InterfaceRegistry)
// return encodingConfig
// }
3 changes: 2 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"encoding/json"
"fmt"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -37,7 +38,7 @@ func (app *IrisApp) ExportAppStateAndValidators(
service.PrepForZeroHeightGenesis(ctx, app.ServiceKeeper)
}

genState, err := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
genState, err := app.mm.ExportGenesisForModules(ctx, app.codec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}
Expand Down
11 changes: 0 additions & 11 deletions app/genesis.go

This file was deleted.

27 changes: 0 additions & 27 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keepers

import (
"github.com/spf13/cast"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/log"
"cosmossdk.io/math"
Expand All @@ -11,16 +10,11 @@ import (
evidencetypes "cosmossdk.io/x/evidence/types"
"cosmossdk.io/x/feegrant"
feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
"cosmossdk.io/x/tx/signing"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
"github.com/cosmos/gogoproto/proto"

upgradekeeper "cosmossdk.io/x/upgrade/keeper"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand Down Expand Up @@ -128,8 +122,6 @@ type AppKeepers struct {
tkeys map[string]*storetypes.TransientStoreKey
memKeys map[string]*storetypes.MemoryStoreKey

interfaceRegistry types.InterfaceRegistry

scopedIBCKeeper capabilitykeeper.ScopedKeeper
scopedTransferKeeper capabilitykeeper.ScopedKeeper
scopedIBCMockKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -198,26 +190,7 @@ func New(
logger log.Logger,
appOpts servertypes.AppOptions,
) AppKeepers {
signingOptions := signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
CustomGetSigners: map[protoreflect.FullName]signing.GetSignersFunc{
evmtypes.MsgEthereumTxCustomGetSigner.MsgType: evmtypes.MsgEthereumTxCustomGetSigner.Fn,
},
}
interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signingOptions,
})

appKeepers := AppKeepers{}

appKeepers.interfaceRegistry = interfaceRegistry

// Set keys KVStoreKey, TransientStoreKey, MemoryStoreKey
appKeepers.genStoreKeys()

Expand Down
Loading
Loading