From f69a96b2ac242990b959bc7c075a356c1ffb6db5 Mon Sep 17 00:00:00 2001 From: dreamer Date: Thu, 2 Jan 2025 10:52:16 +0800 Subject: [PATCH 1/2] fix: fixed some bugs --- app/app.go | 91 ++++++++++++++++++++----- app/encoding.go | 20 ++---- app/export.go | 3 +- app/genesis.go | 11 --- app/keepers/keepers.go | 27 -------- app/modules.go | 91 ++++++------------------- app/params.go | 23 ------- app/params/config.go | 35 ---------- app/params/doc.go | 19 ------ app/params/encoding.go | 4 +- app/params/params.go | 2 - app/params/proto.go | 14 ++-- app/params/weights.go | 23 ------- app/sim_bench_test.go | 5 -- app/sim_test.go | 18 ++--- cmd/iris/cmd/genesis.go | 2 +- cmd/iris/cmd/root.go | 72 ++++++++++--------- modules/mint/simulation/decoder_test.go | 6 +- testutil/app.go | 18 +---- testutil/test_helpers.go | 23 ++++--- 20 files changed, 177 insertions(+), 330 deletions(-) delete mode 100644 app/genesis.go delete mode 100644 app/params.go delete mode 100644 app/params/config.go delete mode 100644 app/params/doc.go delete mode 100644 app/params/weights.go diff --git a/app/app.go b/app/app.go index 20b7c29c4c..991af735f6 100644 --- a/app/app.go +++ b/app/app.go @@ -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" @@ -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" @@ -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 @@ -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()) @@ -92,7 +102,7 @@ func NewIrisApp( iristypes.AppName, logger, db, - encodingConfig.TxConfig.TxDecoder(), + txConfig.TxDecoder(), baseAppOptions..., ) bApp.SetCommitMultiStoreTracer(traceStore) @@ -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 @@ -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( @@ -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, @@ -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()) @@ -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 @@ -306,7 +348,7 @@ 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 @@ -314,11 +356,26 @@ 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 @@ -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 { @@ -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) } } @@ -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. diff --git a/app/encoding.go b/app/encoding.go index 2cc362065b..3f0255fd74 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -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 +// } diff --git a/app/export.go b/app/export.go index 22e8d74133..9035f06b0e 100644 --- a/app/export.go +++ b/app/export.go @@ -3,6 +3,7 @@ package app import ( "encoding/json" "fmt" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" storetypes "cosmossdk.io/store/types" @@ -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 } diff --git a/app/genesis.go b/app/genesis.go deleted file mode 100644 index 406f132c8d..0000000000 --- a/app/genesis.go +++ /dev/null @@ -1,11 +0,0 @@ -package app - -import ( - "github.com/irisnet/irishub/v4/types" -) - -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState() types.GenesisState { - encCfg := RegisterEncodingConfig() - return ModuleBasics.DefaultGenesis(encCfg.Marshaler) -} diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 68fbb84394..fd4037671c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -2,7 +2,6 @@ package keepers import ( "github.com/spf13/cast" - "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/log" "cosmossdk.io/math" @@ -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" @@ -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 @@ -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() diff --git a/app/modules.go b/app/modules.go index 21fdd83c85..cdff7df404 100644 --- a/app/modules.go +++ b/app/modules.go @@ -43,15 +43,12 @@ import ( iristypes "github.com/irisnet/irishub/v4/types" "github.com/spf13/cobra" - ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - "github.com/cosmos/ibc-go/v8/modules/apps/transfer" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" - //ibcclientclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/client" + // ibcclientclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/client" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" - ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "mods.irisnet.org/modules/coinswap" coinswaptypes "mods.irisnet.org/modules/coinswap/types" @@ -74,20 +71,16 @@ import ( "mods.irisnet.org/modules/token" tokentypes "mods.irisnet.org/modules/token/types" - tibcmttransfer "github.com/bianjieai/tibc-go/modules/tibc/apps/mt_transfer" tibcmttypes "github.com/bianjieai/tibc-go/modules/tibc/apps/mt_transfer/types" - tibcnfttransfer "github.com/bianjieai/tibc-go/modules/tibc/apps/nft_transfer" tibcnfttypes "github.com/bianjieai/tibc-go/modules/tibc/apps/nft_transfer/types" tibc "github.com/bianjieai/tibc-go/modules/tibc/core" tibchost "github.com/bianjieai/tibc-go/modules/tibc/core/24-host" tibccli "github.com/bianjieai/tibc-go/modules/tibc/core/client/cli" - "github.com/evmos/ethermint/x/evm" evmtypes "github.com/evmos/ethermint/x/evm/types" "github.com/evmos/ethermint/x/feemarket" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - nfttransfer "github.com/bianjieai/nft-transfer" ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types" irisappparams "github.com/irisnet/irishub/v4/app/params" @@ -101,71 +94,14 @@ import ( var ( legacyProposalHandlers = []govclient.ProposalHandler{ paramsclient.ProposalHandler, - //distrclient.ProposalHandler, govclient.NewProposalHandler(func() *cobra.Command { return upgradeclient.NewCmdSubmitUpgradeProposal(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())) }), govclient.NewProposalHandler(func() *cobra.Command { return upgradeclient.NewCmdSubmitCancelUpgradeProposal(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())) }), - // todo - //upgradeclient.LegacyProposalHandler, - //upgradeclient.LegacyCancelProposalHandler, - //ibcclientclient.UpdateClientProposalHandler, - //ibcclientclient.UpgradeProposalHandler, } - // 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{}, - authzmodule.AppModuleBasic{}, - genutil.AppModuleBasic{ - GenTxValidator: genutiltypes.DefaultMessageValidator, - }, - bank.AppModuleBasic{}, - capability.AppModuleBasic{}, - staking.AppModuleBasic{}, - mint.AppModuleBasic{}, - distr.AppModuleBasic{}, - gov.NewAppModuleBasic( - append(legacyProposalHandlers, tibccli.GovHandlers...), - ), - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - ibc.AppModuleBasic{}, - ibctm.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - transfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - authzmodule.AppModuleBasic{}, - consensus.AppModuleBasic{}, - ica.AppModuleBasic{}, - - guardian.AppModuleBasic{}, - token.AppModuleBasic{}, - record.AppModuleBasic{}, - nft.AppModuleBasic{}, - htlc.AppModuleBasic{}, - coinswap.AppModuleBasic{}, - service.AppModuleBasic{}, - oracle.AppModuleBasic{}, - random.AppModuleBasic{}, - farm.AppModuleBasic{}, - tibc.AppModuleBasic{}, - tibcnfttransfer.AppModuleBasic{}, - tibcmttransfer.AppModuleBasic{}, - mt.AppModuleBasic{}, - nfttransfer.AppModuleBasic{}, - - evm.AppModuleBasic{}, - feemarket.AppModuleBasic{}, - ) - // module account permissions maccPerms = map[string][]string{ authtypes.FeeCollectorName: {authtypes.Burner}, @@ -195,12 +131,27 @@ var ( } ) +// ModuleBasics defines the module BasicManager that is in charge of setting up basic, +// non-dependant module elements, such as codec registration +// and genesis verification. +func newBasicManagerFromManager(app *IrisApp) module.BasicManager { + basicManager := module.NewBasicManagerFromManager( + app.mm, + map[string]module.AppModuleBasic{ + genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + govtypes.ModuleName: gov.NewAppModuleBasic(append(legacyProposalHandlers, tibccli.GovHandlers...)), + }) + basicManager.RegisterLegacyAminoCodec(app.legacyAmino) + basicManager.RegisterInterfaces(app.interfaceRegistry) + return basicManager +} + func appModules( app *IrisApp, encodingConfig irisappparams.EncodingConfig, skipGenesisInvariants bool, ) []module.AppModule { - appCodec := encodingConfig.Marshaler + appCodec := encodingConfig.Codec return []module.AppModule{ genutil.NewAppModule( @@ -346,7 +297,7 @@ func simulationModules( encodingConfig irisappparams.EncodingConfig, _ bool, ) []module.AppModuleSimulation { - appCodec := encodingConfig.Marshaler + appCodec := encodingConfig.Codec return []module.AppModuleSimulation{ auth.NewAppModule( @@ -501,7 +452,7 @@ func orderBeginBlockers() []string { icatypes.ModuleName, consensustypes.ModuleName, - //self module + // self module tokentypes.ModuleName, tibchost.ModuleName, nfttypes.ModuleName, @@ -554,7 +505,7 @@ func orderEndBlockers() []string { icatypes.ModuleName, consensustypes.ModuleName, - //self module + // self module tokentypes.ModuleName, tibchost.ModuleName, nfttypes.ModuleName, @@ -608,7 +559,7 @@ func orderInitBlockers() []string { icatypes.ModuleName, consensustypes.ModuleName, - //self module + // self module tokentypes.ModuleName, tibchost.ModuleName, nfttypes.ModuleName, diff --git a/app/params.go b/app/params.go deleted file mode 100644 index c1b19b62e7..0000000000 --- a/app/params.go +++ /dev/null @@ -1,23 +0,0 @@ -package app - -// Default simulation operation weights for messages and gov proposals -const ( - DefaultWeightMsgSend int = 100 - DefaultWeightMsgMultiSend int = 10 - DefaultWeightMsgSetWithdrawAddress int = 50 - DefaultWeightMsgWithdrawDelegationReward int = 50 - DefaultWeightMsgWithdrawValidatorCommission int = 50 - DefaultWeightMsgFundCommunityPool int = 50 - DefaultWeightMsgDeposit int = 100 - DefaultWeightMsgVote int = 67 - DefaultWeightMsgUnjail int = 100 - DefaultWeightMsgCreateValidator int = 100 - DefaultWeightMsgEditValidator int = 5 - DefaultWeightMsgDelegate int = 100 - DefaultWeightMsgUndelegate int = 100 - DefaultWeightMsgBeginRedelegate int = 100 - - DefaultWeightCommunitySpendProposal int = 5 - DefaultWeightTextProposal int = 5 - DefaultWeightParamChangeProposal int = 5 -) diff --git a/app/params/config.go b/app/params/config.go deleted file mode 100644 index aead6b5e68..0000000000 --- a/app/params/config.go +++ /dev/null @@ -1,35 +0,0 @@ -package params - -import ( - serverconfig "github.com/cosmos/cosmos-sdk/server/config" -) - -var ( - // BypassMinFeeMsgTypesKey defines the configuration key for the - // BypassMinFeeMsgTypes value. - // nolint: gosec - BypassMinFeeMsgTypesKey = "bypass-min-fee-msg-types" - - // CustomConfigTemplate defines Gaia's custom application configuration TOML - // template. It extends the core SDK template. - CustomConfigTemplate = serverconfig.DefaultConfigTemplate + ` -############################################################################### -### Custom Gaia Configuration ### -############################################################################### -# bypass-min-fee-msg-types defines custom message types the operator may set that -# will bypass minimum fee checks during CheckTx. -# -# Example: -# ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement", ...] -bypass-min-fee-msg-types = [{{ range .BypassMinFeeMsgTypes }}{{ printf "%q, " . }}{{end}}] -` -) - -// CustomAppConfig defines Gaia's custom application configuration. -type CustomAppConfig struct { - serverconfig.Config - - // BypassMinFeeMsgTypes defines custom message types the operator may set that - // will bypass minimum fee checks during CheckTx. - BypassMinFeeMsgTypes []string `mapstructure:"bypass-min-fee-msg-types"` -} diff --git a/app/params/doc.go b/app/params/doc.go deleted file mode 100644 index 7c6035cadc..0000000000 --- a/app/params/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Package params defines the simulation parameters in the gaia. - -It contains the default weights used for each transaction used on the module's -simulation. These weights define the chance for a transaction to be simulated at -any gived operation. - -You can repace the default values for the weights by providing a params.json -file with the weights defined for each of the transaction operations: - - { - "op_weight_msg_send": 60, - "op_weight_msg_delegate": 100, - } - -In the example above, the `MsgSend` has 60% chance to be simulated, while the -`MsgDelegate` will always be simulated. -*/ -package params diff --git a/app/params/encoding.go b/app/params/encoding.go index 3d634abf16..71b58ec7ea 100644 --- a/app/params/encoding.go +++ b/app/params/encoding.go @@ -10,7 +10,7 @@ import ( // This is provided for compatibility between protobuf and amino implementations. type EncodingConfig struct { InterfaceRegistry types.InterfaceRegistry - Marshaler codec.Codec + Codec codec.Codec TxConfig client.TxConfig - Amino *codec.LegacyAmino + LegacyAmino *codec.LegacyAmino } diff --git a/app/params/params.go b/app/params/params.go index 9956444495..741a5d2f39 100644 --- a/app/params/params.go +++ b/app/params/params.go @@ -2,7 +2,5 @@ package params // Simulation parameter constants const ( - StakePerAccount = "stake_per_account" - InitiallyBondedValidators = "initially_bonded_validators" SimulationTest = "simulation_test" ) diff --git a/app/params/proto.go b/app/params/proto.go index 2691bc65ff..f04a04f983 100644 --- a/app/params/proto.go +++ b/app/params/proto.go @@ -8,8 +8,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/cosmos/gogoproto/proto" - evmtypes "github.com/evmos/ethermint/x/evm/types" "google.golang.org/protobuf/reflect/protoreflect" + + enccodec "github.com/evmos/ethermint/encoding/codec" + evmtypes "github.com/evmos/ethermint/x/evm/types" ) // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. @@ -33,10 +35,14 @@ func MakeEncodingConfig() EncodingConfig { marshaler := codec.NewProtoCodec(interfaceRegistry) txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) + // Register the evm types + enccodec.RegisterLegacyAminoCodec(amino) + enccodec.RegisterInterfaces(interfaceRegistry) + return EncodingConfig{ InterfaceRegistry: interfaceRegistry, - Marshaler: marshaler, + Codec: marshaler, TxConfig: txCfg, - Amino: amino, + LegacyAmino: amino, } -} +} \ No newline at end of file diff --git a/app/params/weights.go b/app/params/weights.go deleted file mode 100644 index 0ba377b009..0000000000 --- a/app/params/weights.go +++ /dev/null @@ -1,23 +0,0 @@ -package params - -// Default simulation operation weights for messages and gov proposals -const ( - DefaultWeightMsgSend int = 100 - DefaultWeightMsgMultiSend int = 10 - DefaultWeightMsgSetWithdrawAddress int = 50 - DefaultWeightMsgWithdrawDelegationReward int = 50 - DefaultWeightMsgWithdrawValidatorCommission int = 50 - DefaultWeightMsgFundCommunityPool int = 50 - DefaultWeightMsgDeposit int = 100 - DefaultWeightMsgVote int = 67 - DefaultWeightMsgUnjail int = 100 - DefaultWeightMsgCreateValidator int = 100 - DefaultWeightMsgEditValidator int = 5 - DefaultWeightMsgDelegate int = 100 - DefaultWeightMsgUndelegate int = 100 - DefaultWeightMsgBeginRedelegate int = 100 - - DefaultWeightCommunitySpendProposal int = 5 - DefaultWeightTextProposal int = 5 - DefaultWeightParamChangeProposal int = 5 -) diff --git a/app/sim_bench_test.go b/app/sim_bench_test.go index 884ac78e37..354898be5a 100644 --- a/app/sim_bench_test.go +++ b/app/sim_bench_test.go @@ -45,14 +45,12 @@ func BenchmarkFullAppSimulation(b *testing.B) { } }() - encfg := RegisterEncodingConfig() app := NewIrisApp( logger, db, nil, true, - encfg, SimTestAppOptions{ options: map[string]interface{}{params.SimulationTest: true}, }, @@ -114,14 +112,11 @@ func BenchmarkInvariants(b *testing.B) { } }() - encfg := RegisterEncodingConfig() - app := NewIrisApp( logger, db, nil, true, - encfg, SimTestAppOptions{ options: map[string]interface{}{params.SimulationTest: true}, }, diff --git a/app/sim_test.go b/app/sim_test.go index eb929b9f4e..d2779e7bb8 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -96,9 +96,8 @@ func TestFullAppSimulation(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - encfg := RegisterEncodingConfig() - app := createApp(logger, db, encfg, fauxMerkleModeOpt) + app := createApp(logger, db, fauxMerkleModeOpt) require.Equal(t, "IrisApp", app.Name()) // run randomized simulation @@ -146,8 +145,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - encfg := RegisterEncodingConfig() - app := createApp(logger, db, encfg, fauxMerkleModeOpt) + app := createApp(logger, db, fauxMerkleModeOpt) require.Equal(t, "IrisApp", app.Name()) // Run randomized simulation @@ -193,7 +191,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := createApp(logger, newDB, encfg, fauxMerkleModeOpt) + newApp := createApp(logger, newDB, fauxMerkleModeOpt) require.Equal(t, "IrisApp", newApp.Name()) var genesisState iristypes.GenesisState @@ -296,7 +294,6 @@ func TestAppImportExport(t *testing.T) { func TestAppSimulationAfterImport(t *testing.T) { config := simcli.NewConfigFromFlags() config.ChainID = AppChainID - encfg := RegisterEncodingConfig() db, dir, logger, skip, err := simtestutil.SetupSimulation( config, @@ -316,7 +313,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := createApp(logger, db, encfg, fauxMerkleModeOpt) + app := createApp(logger, db, fauxMerkleModeOpt) require.Equal(t, "IrisApp", app.Name()) // Run randomized simulation @@ -367,7 +364,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := createApp(logger, newDB, encfg, fauxMerkleModeOpt) + newApp := createApp(logger, newDB, fauxMerkleModeOpt) require.Equal(t, "IrisApp", newApp.Name()) _, err = newApp.InitChain(&abci.RequestInitChain{ @@ -408,7 +405,6 @@ func TestAppStateDeterminism(t *testing.T) { numSeeds := 3 numTimesToRunPerSeed := 5 appHashList := make([]json.RawMessage, numTimesToRunPerSeed) - encfg := RegisterEncodingConfig() for i := 0; i < numSeeds; i++ { config.Seed = rand.Int63() @@ -422,7 +418,7 @@ func TestAppStateDeterminism(t *testing.T) { } db := dbm.NewMemDB() - app := createApp(logger, db, encfg, interBlockCacheOpt()) + app := createApp(logger, db, interBlockCacheOpt()) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", @@ -491,7 +487,6 @@ func (o SimTestAppOptions) Get(key string) interface{} { func createApp( logger log.Logger, db dbm.DB, - encodingConfig params.EncodingConfig, baseAppOptions ...func(*baseapp.BaseApp), ) *IrisApp { if baseAppOptions == nil { @@ -503,7 +498,6 @@ func createApp( db, nil, true, - encodingConfig, SimTestAppOptions{ options: map[string]interface{}{params.SimulationTest: true}, }, diff --git a/cmd/iris/cmd/genesis.go b/cmd/iris/cmd/genesis.go index fc697e7f63..7b40108e29 100644 --- a/cmd/iris/cmd/genesis.go +++ b/cmd/iris/cmd/genesis.go @@ -57,7 +57,7 @@ func mergeGenesisCmd(encodingConfig params.EncodingConfig) *cobra.Command { return err } - return merge(encodingConfig.Marshaler, testnetGenesis, mainnetGenesis, outputFile) + return merge(encodingConfig.Codec, testnetGenesis, mainnetGenesis, outputFile) }, } cmd.Flags().String(testnetFile, "", "irishub testnet genesis") diff --git a/cmd/iris/cmd/root.go b/cmd/iris/cmd/root.go index 8677303123..a588ccb7b2 100644 --- a/cmd/iris/cmd/root.go +++ b/cmd/iris/cmd/root.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -31,6 +32,7 @@ import ( ethermintdebug "github.com/evmos/ethermint/client/debug" etherminthd "github.com/evmos/ethermint/crypto/hd" + ethermintserver "github.com/evmos/ethermint/server" servercfg "github.com/evmos/ethermint/server/config" "github.com/irisnet/irishub/v4/app" @@ -42,15 +44,14 @@ import ( // NewRootCmd creates a new root command for simd. It is called once in the // main function. func NewRootCmd() (*cobra.Command, params.EncodingConfig) { + tempApplication := app.NewIrisApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, testutil.EmptyAppOptions{}) + encodingConfig := tempApplication.EncodingConfig() - tempApplication := app.NewIrisApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, app.RegisterEncodingConfig(), testutil.EmptyAppOptions{}) - - encodingConfig := app.RegisterEncodingConfig() initClientCtx := client.Context{}. - WithCodec(encodingConfig.Marshaler). + WithCodec(encodingConfig.Codec). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). WithTxConfig(encodingConfig.TxConfig). - WithLegacyAmino(encodingConfig.Amino). + WithLegacyAmino(encodingConfig.LegacyAmino). WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). WithBroadcastMode(flags.BroadcastSync). @@ -92,7 +93,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { }, } - initRootCmd(rootCmd, encodingConfig) + initRootCmd(rootCmd, encodingConfig, tempApplication.BasicManager()) autoCliOpts := enrichAutoCliOpts(tempApplication.AutoCliOpts(), initClientCtx) if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { @@ -139,51 +140,53 @@ func initAppConfig() (string, interface{}) { return customAppTemplate, srvCfg } -func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { - ac := appCreator{ - encCfg: encodingConfig, - } +func initRootCmd( + rootCmd *cobra.Command, + encodingConfig params.EncodingConfig, + basicManager module.BasicManager, +) { + ac := appCreator{} rootCmd.AddCommand( - genutilcli.InitCmd(app.ModuleBasics, iristypes.DefaultNodeHome), - genutilcli.ValidateGenesisCmd(app.ModuleBasics), + genutilcli.InitCmd(basicManager, iristypes.DefaultNodeHome), + genutilcli.ValidateGenesisCmd(basicManager), AddGenesisAccountCmd(iristypes.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), - testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), + testnetCmd(basicManager, banktypes.GenesisBalancesIterator{}), ethermintdebug.Cmd(), mergeGenesisCmd(encodingConfig), pruning.Cmd(ac.newApp, iristypes.DefaultNodeHome), ) - //ethermintserver.AddCommands( - // rootCmd, - // ethermintserver.NewDefaultStartOptions(ac.newApp, iristypes.DefaultNodeHome), - // ac.appExport, - // addModuleInitFlags, - //) - server.AddCommands( + ethermintserver.AddCommands( rootCmd, - iristypes.DefaultNodeHome, - ac.newApp, + ethermintserver.NewDefaultStartOptions(ac.newApp, iristypes.DefaultNodeHome), ac.appExport, addModuleInitFlags, ) + // server.AddCommands( + // rootCmd, + // iristypes.DefaultNodeHome, + // ac.newApp, + // ac.appExport, + // addModuleInitFlags, + // ) // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( server.StatusCommand(), - genesisCommand(encodingConfig), + genesisCommand(basicManager, encodingConfig), queryCommand(), - txCommand(), + txCommand(basicManager), Commands(iristypes.DefaultNodeHome), ) } // genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter -func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { +func genesisCommand(basicManager module.BasicManager, encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { cmd := genutilcli.GenesisCoreCommand( encodingConfig.TxConfig, - app.ModuleBasics, + basicManager, iristypes.DefaultNodeHome, ) @@ -209,17 +212,19 @@ func queryCommand() *cobra.Command { cmd.AddCommand( rpc.ValidatorCommand(), + server.QueryBlocksCmd(), + server.QueryBlockCmd(), + server.QueryBlockResultsCmd(), authcmd.QueryTxsByEventsCmd(), authcmd.QueryTxCmd(), ) - app.ModuleBasics.AddQueryCommands(cmd) cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd } -func txCommand() *cobra.Command { +func txCommand(basicManager module.BasicManager) *cobra.Command { cmd := &cobra.Command{ Use: "tx", Short: "Transactions subcommands", @@ -239,15 +244,16 @@ func txCommand() *cobra.Command { authcmd.GetDecodeCommand(), ) - //app.ModuleBasics.AddTxCommands(cmd) + // NOTE: this must be registered for now so that submit-legacy-proposal + // message (e.g. consumer-addition proposal) can be routed to the its handler and processed correctly. + basicManager.AddTxCommands(cmd) + // app.ModuleBasics.AddTxCommands(cmd) cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID") return cmd } -type appCreator struct { - encCfg params.EncodingConfig -} +type appCreator struct {} func (ac appCreator) newApp( logger log.Logger, @@ -261,7 +267,6 @@ func (ac appCreator) newApp( db, traceStore, true, - ac.encCfg, appOpts, baseappOptions..., ) @@ -293,7 +298,6 @@ func (ac appCreator) appExport( db, traceStore, loadLatest, - ac.encCfg, appOpts, ) diff --git a/modules/mint/simulation/decoder_test.go b/modules/mint/simulation/decoder_test.go index 100e8f2bf2..c1e4de1829 100644 --- a/modules/mint/simulation/decoder_test.go +++ b/modules/mint/simulation/decoder_test.go @@ -18,12 +18,12 @@ import ( func TestDecodeStore(t *testing.T) { minter := types.NewMinter(time.Now().UTC(), sdkmath.NewIntWithDecimal(2, 9)) - ec := testutil.MakeCodecs() - dec := simulation.NewDecodeStore(ec.Marshaler) + app := testutil.CreateApp(t) + dec := simulation.NewDecodeStore(app.AppCodec()) kvPairs := kv.Pairs{ Pairs: []kv.Pair{ - {Key: types.MinterKey, Value: ec.Marshaler.MustMarshal(&minter)}, + {Key: types.MinterKey, Value: app.AppCodec().MustMarshal(&minter)}, {Key: []byte{0x99}, Value: []byte{0x99}}, }, } diff --git a/testutil/app.go b/testutil/app.go index b392347da8..aa506a98e6 100644 --- a/testutil/app.go +++ b/testutil/app.go @@ -1,17 +1,13 @@ package testutil import ( - "encoding/json" - "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/irisnet/irishub/v4/app" - "github.com/irisnet/irishub/v4/app/params" ) var ( @@ -31,7 +27,6 @@ func setup( baseAppOptions ...func(*baseapp.BaseApp), ) *AppWrapper { db := dbm.NewMemDB() - encCdc := app.RegisterEncodingConfig() if appOpts == nil { appOpts = EmptyAppOptions{} } @@ -40,19 +35,8 @@ func setup( db, nil, true, - encCdc, appOpts, baseAppOptions..., ) return &AppWrapper{app} -} - -// MakeCodecs returns the application codec and tx codec -func MakeCodecs() params.EncodingConfig { - return app.RegisterEncodingConfig() -} - -// DefaultGenesis returns default genesis state as raw bytes -func DefaultGenesis(cdc codec.JSONCodec) map[string]json.RawMessage { - return app.ModuleBasics.DefaultGenesis(cdc) -} +} \ No newline at end of file diff --git a/testutil/test_helpers.go b/testutil/test_helpers.go index af4c83caa2..792d1ea844 100644 --- a/testutil/test_helpers.go +++ b/testutil/test_helpers.go @@ -37,8 +37,6 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/irisnet/irishub/v4/app" ) // CreateApp initializes a new SimApp. A Nop logger is set in SimApp. @@ -71,10 +69,13 @@ func CreateApp(t *testing.T) *AppWrapper { // NewConfig returns a new app config func NewConfig() network.Config { cfg := network.DefaultConfig(NewTestNetworkFixture) - encCfg := app.RegisterEncodingConfig() - cfg.Codec = encCfg.Marshaler + + + tempApp := setup(nil) + encCfg := tempApp.EncodingConfig() + cfg.Codec = encCfg.Codec cfg.TxConfig = encCfg.TxConfig - cfg.LegacyAmino = encCfg.Amino + cfg.LegacyAmino = encCfg.LegacyAmino cfg.InterfaceRegistry = encCfg.InterfaceRegistry cfg.AppConstructor = func(val network.ValidatorI) servertypes.Application { return setup( @@ -83,7 +84,7 @@ func NewConfig() network.Config { bam.SetChainID(cfg.ChainID), ) } - cfg.GenesisState = app.ModuleBasics.DefaultGenesis(cfg.Codec) + cfg.GenesisState = tempApp.DefaultGenesis() return cfg } @@ -247,16 +248,18 @@ func NewTestNetworkFixture() network.TestFixture { bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)), ) } - ec := MakeCodecs() + + tempApp := setup(nil) + ec := tempApp.EncodingConfig() return network.TestFixture{ AppConstructor: appCtr, - GenesisState: DefaultGenesis(ec.Marshaler), + GenesisState: tempApp.DefaultGenesis(), EncodingConfig: testutil.TestEncodingConfig{ InterfaceRegistry: ec.InterfaceRegistry, - Codec: ec.Marshaler, + Codec: ec.Codec, TxConfig: ec.TxConfig, - Amino: ec.Amino, + Amino: ec.LegacyAmino, }, } } From 174e97aa4252fc0378f4a848379e4b1b8771b7dd Mon Sep 17 00:00:00 2001 From: dreamer Date: Thu, 2 Jan 2025 14:38:11 +0800 Subject: [PATCH 2/2] fix start command --- app/modules.go | 15 ++++----------- cmd/iris/cmd/genesis.go | 29 ++++++++--------------------- cmd/iris/cmd/root.go | 38 +++++++++++++++++++++++++++----------- cmd/iris/cmd/util.go | 4 ++-- cmd/iris/main.go | 3 +-- go.mod | 2 +- go.sum | 4 ++-- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/app/modules.go b/app/modules.go index cdff7df404..2b6479f615 100644 --- a/app/modules.go +++ b/app/modules.go @@ -6,10 +6,8 @@ import ( "cosmossdk.io/x/feegrant" feegrantmodule "cosmossdk.io/x/feegrant/module" "cosmossdk.io/x/upgrade" - upgradeclient "cosmossdk.io/x/upgrade/client/cli" upgradetypes "cosmossdk.io/x/upgrade/types" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" @@ -41,14 +39,13 @@ import ( "github.com/cosmos/ibc-go/modules/capability" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" iristypes "github.com/irisnet/irishub/v4/types" - "github.com/spf13/cobra" icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" - // ibcclientclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/client" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "mods.irisnet.org/modules/coinswap" coinswaptypes "mods.irisnet.org/modules/coinswap/types" @@ -94,12 +91,6 @@ import ( var ( legacyProposalHandlers = []govclient.ProposalHandler{ paramsclient.ProposalHandler, - govclient.NewProposalHandler(func() *cobra.Command { - return upgradeclient.NewCmdSubmitUpgradeProposal(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())) - }), - govclient.NewProposalHandler(func() *cobra.Command { - return upgradeclient.NewCmdSubmitCancelUpgradeProposal(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())) - }), } // module account permissions @@ -230,7 +221,9 @@ func appModules( app.interfaceRegistry, ), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), - ibc.NewAppModule(app.IBCKeeper), tibc.NewAppModule(app.TIBCKeeper), + ibc.NewAppModule(app.IBCKeeper), + ibctm.NewAppModule(), + tibc.NewAppModule(app.TIBCKeeper), params.NewAppModule(app.ParamsKeeper), app.TransferModule, app.IBCNftTransferModule, diff --git a/cmd/iris/cmd/genesis.go b/cmd/iris/cmd/genesis.go index 7b40108e29..a0d9846800 100644 --- a/cmd/iris/cmd/genesis.go +++ b/cmd/iris/cmd/genesis.go @@ -2,13 +2,12 @@ package cmd import ( "encoding/json" - "fmt" - "io/ioutil" "github.com/spf13/cobra" - tmjson "github.com/cometbft/cometbft/libs/json" + cometjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/types" + comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -47,12 +46,12 @@ func mergeGenesisCmd(encodingConfig params.EncodingConfig) *cobra.Command { return err } - testnetGenesis, err := genesisDocFromFile(testnetGenesisPath) + testnetGenesis, err := comettypes.GenesisDocFromFile(testnetGenesisPath) if err != nil { return err } - mainnetGenesis, err := genesisDocFromFile(mainnetGenesisPath) + mainnetGenesis, err := comettypes.GenesisDocFromFile(mainnetGenesisPath) if err != nil { return err } @@ -68,11 +67,11 @@ func mergeGenesisCmd(encodingConfig params.EncodingConfig) *cobra.Command { func merge(cdc codec.Codec, testnet, mainnet *types.GenesisDoc, output string) (err error) { var mainnetAppState, testnetAppState map[string]json.RawMessage - if err = tmjson.Unmarshal(mainnet.AppState, &mainnetAppState); err != nil { + if err = cometjson.Unmarshal(mainnet.AppState, &mainnetAppState); err != nil { return err } - if err = tmjson.Unmarshal(testnet.AppState, &testnetAppState); err != nil { + if err = cometjson.Unmarshal(testnet.AppState, &testnetAppState); err != nil { panic(err) } mainnet.Validators = nil @@ -89,7 +88,7 @@ func merge(cdc codec.Codec, testnet, mainnet *types.GenesisDoc, output string) ( mainnet.InitialHeight = 0 mainnet.ChainID = testnet.ChainID - mainnet.AppState, err = tmjson.Marshal(mainnetAppState) + mainnet.AppState, err = cometjson.Marshal(mainnetAppState) if err != nil { return err } @@ -147,16 +146,4 @@ func mergeGov(cdc codec.Codec, testnet, mainnet map[string]json.RawMessage) { govState.VotingParams = testnetgovState.VotingParams govState.TallyParams = testnetgovState.TallyParams mainnet["gov"] = cdc.MustMarshalJSON(&govState) -} - -func genesisDocFromFile(genDocFile string) (*types.GenesisDoc, error) { - jsonBlob, err := ioutil.ReadFile(genDocFile) - if err != nil { - return nil, fmt.Errorf("couldn't read GenesisDoc file: %w", err) - } - genDoc, err := types.GenesisDocFromJSON(jsonBlob) - if err != nil { - return nil, fmt.Errorf("error reading GenesisDoc at %s: %w", genDocFile, err) - } - return genDoc, nil -} +} \ No newline at end of file diff --git a/cmd/iris/cmd/root.go b/cmd/iris/cmd/root.go index a588ccb7b2..93508d2014 100644 --- a/cmd/iris/cmd/root.go +++ b/cmd/iris/cmd/root.go @@ -7,6 +7,7 @@ import ( "os" "github.com/spf13/cobra" + "github.com/spf13/viper" tmcfg "github.com/cometbft/cometbft/config" tmcli "github.com/cometbft/cometbft/libs/cli" @@ -37,16 +38,28 @@ import ( "github.com/irisnet/irishub/v4/app" "github.com/irisnet/irishub/v4/app/params" - "github.com/irisnet/irishub/v4/testutil" iristypes "github.com/irisnet/irishub/v4/types" ) // NewRootCmd creates a new root command for simd. It is called once in the // main function. -func NewRootCmd() (*cobra.Command, params.EncodingConfig) { - tempApplication := app.NewIrisApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, testutil.EmptyAppOptions{}) +func NewRootCmd() *cobra.Command { + // we "pre"-instantiate the application for getting the injected/configured encoding configuration + initAppOptions := viper.New() + tempDir := tempDir() + initAppOptions.Set(flags.FlagHome, tempDir) + tempApplication := app.NewIrisApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, initAppOptions) encodingConfig := tempApplication.EncodingConfig() + defer func() { + if err := tempApplication.Close(); err != nil { + panic(err) + } + if tempDir != iristypes.DefaultNodeHome { + os.RemoveAll(tempDir) + } + }() + initClientCtx := client.Context{}. WithCodec(encodingConfig.Codec). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). @@ -100,7 +113,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { panic(err) } - return rootCmd, encodingConfig + return rootCmd } func enrichAutoCliOpts(autoCliOpts autocli.AppOptions, clientCtx client.Context) autocli.AppOptions { @@ -164,13 +177,6 @@ func initRootCmd( ac.appExport, addModuleInitFlags, ) - // server.AddCommands( - // rootCmd, - // iristypes.DefaultNodeHome, - // ac.newApp, - // ac.appExport, - // addModuleInitFlags, - // ) // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( @@ -309,3 +315,13 @@ func (ac appCreator) appExport( return irisApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) } + +var tempDir = func() string { + dir, err := os.MkdirTemp("", ".iris") + if err != nil { + panic(fmt.Sprintf("failed creating temp directory: %s", err.Error())) + } + defer os.RemoveAll(dir) + + return dir +} diff --git a/cmd/iris/cmd/util.go b/cmd/iris/cmd/util.go index adf364bb9f..83dee43694 100644 --- a/cmd/iris/cmd/util.go +++ b/cmd/iris/cmd/util.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "os" "strings" @@ -233,7 +233,7 @@ func (it *coinConverter) handlePostRun(cmd *cobra.Command) { if it.w != nil { _ = it.w.Close() } - out, _ := ioutil.ReadAll(it.r) + out, _ := io.ReadAll(it.r) os.Stdout = rescueStdout fmt.Println(it.parseYAML(cmd, out)) } diff --git a/cmd/iris/main.go b/cmd/iris/main.go index 00f973de70..99788873bd 100644 --- a/cmd/iris/main.go +++ b/cmd/iris/main.go @@ -11,8 +11,7 @@ import ( ) func main() { - rootCmd, _ := cmd.NewRootCmd() - + rootCmd := cmd.NewRootCmd() if err := svrcmd.Execute(rootCmd, "", types.DefaultNodeHome); err != nil { os.Exit(1) } diff --git a/go.mod b/go.mod index b5eb080832..e7bdc9fca6 100644 --- a/go.mod +++ b/go.mod @@ -268,7 +268,7 @@ require ( replace ( cosmossdk.io/api => github.com/informalsystems/cosmos-sdk/api v0.7.5-lsm // use bianjieai fork of ethermint - github.com/evmos/ethermint => github.com/bianjieai/ethermint v0.22.0-irishub-20240512.0.20241209074239-dfcd609c9182 + github.com/evmos/ethermint => github.com/bianjieai/ethermint v0.22.0-irishub-20240512.0.20250102063401-4dfa00763ed4 // following versions might cause unexpected behavior github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 diff --git a/go.sum b/go.sum index 65f3918ebc..53c343892b 100644 --- a/go.sum +++ b/go.sum @@ -306,8 +306,8 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bianjieai/ethermint v0.22.0-irishub-20240512.0.20241209074239-dfcd609c9182 h1:lNpJUFZO8s0govTACS17XO1v1vV8nrl29P+0me1obNE= -github.com/bianjieai/ethermint v0.22.0-irishub-20240512.0.20241209074239-dfcd609c9182/go.mod h1:0PTcYr7hTvVBjcyR7weKrclYL9tmnL/eTttLiQmqM5o= +github.com/bianjieai/ethermint v0.22.0-irishub-20240512.0.20250102063401-4dfa00763ed4 h1:e/Gtx3jCJAKMl128XqD3wmdrTCwN4Ik99gE+uKtCE1I= +github.com/bianjieai/ethermint v0.22.0-irishub-20240512.0.20250102063401-4dfa00763ed4/go.mod h1:0PTcYr7hTvVBjcyR7weKrclYL9tmnL/eTttLiQmqM5o= github.com/bianjieai/nft-transfer v1.1.3-ibc-v7.3.0.0.20241107152113-c88a3ab19870 h1:gQBLPGM92CGDIhzYEjOjpNVCBa0e8Pse5MtFzGk10x0= github.com/bianjieai/nft-transfer v1.1.3-ibc-v7.3.0.0.20241107152113-c88a3ab19870/go.mod h1:be4fUJhhDupCZJCqwznXgyjfCu8quaabYxfbyT/PxHE= github.com/bianjieai/tibc-go v0.5.1-0.20241202081401-7f861f1a49ef h1:DqCuGxjPQdhmjKRKlQIXeJ+ceYTkCfG1lJBvIifMjV0=