diff --git a/changelog.md b/changelog.md index a05ef80dee..6892399f13 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- [#3835](https://github.com/ignite/cli/pull/3835) Add `--minimal` flag to `scaffold chain` to scaffold a chain with the least amount of sdk modules + ## [`v28.1.1`](https://github.com/ignite/cli/releases/tag/v28.1.1) ### Fixes diff --git a/ignite/cmd/scaffold_chain.go b/ignite/cmd/scaffold_chain.go index 464f611852..e6e5cc37bf 100644 --- a/ignite/cmd/scaffold_chain.go +++ b/ignite/cmd/scaffold_chain.go @@ -10,6 +10,7 @@ import ( ) const ( + flagMinimal = "minimal" flagNoDefaultModule = "no-module" flagSkipGit = "skip-git" @@ -80,6 +81,7 @@ about Cosmos SDK on https://docs.cosmos.network c.Flags().Bool(flagNoDefaultModule, false, "create a project without a default module") c.Flags().StringSlice(flagParams, []string{}, "add default module parameters") c.Flags().Bool(flagSkipGit, false, "skip Git repository initialization") + c.Flags().Bool(flagMinimal, false, "create a minimal blockchain (with the minimum required Cosmos SDK modules)") return c } @@ -94,6 +96,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { appPath = flagGetPath(cmd) noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule) skipGit, _ = cmd.Flags().GetBool(flagSkipGit) + minimal, _ = cmd.Flags().GetBool(flagMinimal) ) params, err := cmd.Flags().GetStringSlice(flagParams) @@ -118,6 +121,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { addressPrefix, noDefaultModule, skipGit, + minimal, params, ) if err != nil { diff --git a/ignite/cmd/scaffold_module.go b/ignite/cmd/scaffold_module.go index c40591f671..12afe992b7 100644 --- a/ignite/cmd/scaffold_module.go +++ b/ignite/cmd/scaffold_module.go @@ -18,7 +18,7 @@ import ( // moduleNameKeeperAlias is a map of well known module names that have a different keeper name than the usual Keeper. var moduleNameKeeperAlias = map[string]string{ - "auth": "account", + "auth": "account", // TODO(@julienrbrt) remove this when x/accounts is released } const ( diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index 98149679fa..c199e13c44 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -159,6 +159,7 @@ type Config struct { Faucet Faucet `yaml:"faucet,omitempty"` Client Client `yaml:"client,omitempty"` Genesis xyaml.Map `yaml:"genesis,omitempty"` + Minimal bool `yaml:"minimal,omitempty"` } // GetVersion returns the config version. @@ -166,6 +167,11 @@ func (c Config) GetVersion() version.Version { return c.Version } +// IsChainMinimal returns true if the chain is minimally scaffolded. +func (c Config) IsChainMinimal() bool { + return c.Minimal +} + // SetDefaults assigns default values to empty config fields. func (c *Config) SetDefaults() error { return mergo.Merge(c, DefaultConfig()) diff --git a/ignite/pkg/cosmosgen/install.go b/ignite/pkg/cosmosgen/install.go index 5ef17e74de..1863b85d31 100644 --- a/ignite/pkg/cosmosgen/install.go +++ b/ignite/pkg/cosmosgen/install.go @@ -24,6 +24,9 @@ func DepTools() []string { // grpc-gateway plugins. "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway", "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2", + + // goimports + "golang.org/x/tools/cmd/goimports", } } @@ -32,10 +35,12 @@ func InstallDepTools(ctx context.Context, appPath string) error { if err := gocmd.ModTidy(ctx, appPath); err != nil { return err } + err := gocmd.Install(ctx, appPath, DepTools()) if gocmd.IsInstallError(err) { return errors.New("unable to install dependency tools, run `ignite doctor` and try again") } + return err } diff --git a/ignite/pkg/gocmd/gocmd.go b/ignite/pkg/gocmd/gocmd.go index af9287ba2e..13d9560803 100644 --- a/ignite/pkg/gocmd/gocmd.go +++ b/ignite/pkg/gocmd/gocmd.go @@ -229,6 +229,11 @@ func PackageLiteral(path, version string) string { return fmt.Sprintf("%s@%s", path, version) } +// Imports runs goimports on path with options. +func GoImports(ctx context.Context, path string) error { + return exec.Exec(ctx, []string{"goimports", "-w", path}) +} + // binaryPath determines the path where binary will be located at. func binaryPath(output, binary string) (string, error) { if output != "" { diff --git a/ignite/services/scaffolder/init.go b/ignite/services/scaffolder/init.go index f861ebf31f..1e018bcf35 100644 --- a/ignite/services/scaffolder/init.go +++ b/ignite/services/scaffolder/init.go @@ -25,7 +25,7 @@ func Init( cacheStorage cache.Storage, tracer *placeholder.Tracer, root, name, addressPrefix string, - noDefaultModule, skipGit bool, + noDefaultModule, skipGit, minimal bool, params []string, ) (path string, err error) { pathInfo, err := gomodulepath.Parse(name) @@ -46,7 +46,7 @@ func Init( path = filepath.Join(root, appFolder) // create the project - err = generate(ctx, tracer, pathInfo, addressPrefix, path, noDefaultModule, params) + err = generate(ctx, tracer, pathInfo, addressPrefix, path, noDefaultModule, minimal, params) if err != nil { return "", err } @@ -73,7 +73,7 @@ func generate( pathInfo gomodulepath.Path, addressPrefix, absRoot string, - noDefaultModule bool, + noDefaultModule, minimal bool, params []string, ) error { // Parse params with the associated type @@ -96,6 +96,7 @@ func generate( GitHubPath: githubPath, BinaryNamePrefix: pathInfo.Root, AddressPrefix: addressPrefix, + IsChainMinimal: minimal, }) if err != nil { return err diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index c5fc8ae5bb..4b2c5a9e54 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -69,10 +69,13 @@ func finish(ctx context.Context, cacheStorage cache.Storage, path, gomodPath str return err } - if err := gocmd.ModTidy(ctx, path); err != nil { + if err := gocmd.Fmt(ctx, path); err != nil { return err } - return gocmd.Fmt(ctx, path) + + _ = gocmd.GoImports(ctx, path) // goimports installation could fail, so ignore the error + + return gocmd.ModTidy(ctx, path) } func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodPath string) error { diff --git a/ignite/templates/app/app.go b/ignite/templates/app/app.go index be1955dd46..fb89241163 100644 --- a/ignite/templates/app/app.go +++ b/ignite/templates/app/app.go @@ -2,6 +2,7 @@ package app import ( "embed" + "fmt" "io/fs" "github.com/gobuffalo/genny/v2" @@ -16,6 +17,12 @@ import ( //go:embed files/* files/**/* var files embed.FS +var ( + ibcConfig = "app/ibc.go" + minimalAppConfig = "app/app_config_minimal.go" + appConfig = "app/app_config.go" +) + // NewGenerator returns the generator to scaffold a new Cosmos SDK app. func NewGenerator(opts *Options) (*genny.Generator, error) { // Remove "files/" prefix @@ -24,9 +31,28 @@ func NewGenerator(opts *Options) (*genny.Generator, error) { return nil, errors.Errorf("generator sub: %w", err) } g := genny.New() - if err := g.OnlyFS(subfs, opts.IncludePrefixes, nil); err != nil { + + // always exclude minimal app config it will be created later + // app_config_minimal is only used for the minimal app template + excludePrefix := []string{minimalAppConfig} + if opts.IsChainMinimal { + // minimal chain does not have ibc or classic app config + excludePrefix = append(excludePrefix, ibcConfig, appConfig) + } + + if err := g.SelectiveFS(subfs, opts.IncludePrefixes, nil, excludePrefix, nil); err != nil { return g, errors.Errorf("generator fs: %w", err) } + + if opts.IsChainMinimal { + file, err := subfs.Open(fmt.Sprintf("%s.plush", minimalAppConfig)) + if err != nil { + return g, errors.Errorf("open minimal app config: %w", err) + } + + g.File(genny.NewFile(appConfig, file)) + } + ctx := plush.NewContext() ctx.Set("ModulePath", opts.ModulePath) ctx.Set("AppName", opts.AppName) @@ -34,6 +60,7 @@ func NewGenerator(opts *Options) (*genny.Generator, error) { ctx.Set("BinaryNamePrefix", opts.BinaryNamePrefix) ctx.Set("AddressPrefix", opts.AddressPrefix) ctx.Set("DepTools", cosmosgen.DepTools()) + ctx.Set("IsChainMinimal", opts.IsChainMinimal) plushhelpers.ExtendPlushContext(ctx) g.Transformer(xgenny.Transformer(ctx)) diff --git a/ignite/templates/app/files/app/app.go.plush b/ignite/templates/app/files/app/app.go.plush index cbcb43e814..6516f5e5c9 100644 --- a/ignite/templates/app/files/app/app.go.plush +++ b/ignite/templates/app/files/app/app.go.plush @@ -12,6 +12,29 @@ import ( evidencekeeper "cosmossdk.io/x/evidence/keeper" feegrantkeeper "cosmossdk.io/x/feegrant/keeper" upgradekeeper "cosmossdk.io/x/upgrade/keeper" + _ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/auth" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects +<%= if (!IsChainMinimal) { %> + _ "cosmossdk.io/x/circuit" // import for side-effects + _ "cosmossdk.io/x/evidence" // import for side-effects + _ "cosmossdk.io/x/feegrant/module" // import for side-effects + _ "cosmossdk.io/x/upgrade" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects + _ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects + _ "github.com/cosmos/ibc-go/modules/capability" // import for side-effects + _ "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" // import for side-effects + _ "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" // import for side-effects +<% } %> dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" @@ -87,9 +110,12 @@ type App struct { AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper StakingKeeper *stakingkeeper.Keeper + DistrKeeper distrkeeper.Keeper + ConsensusParamsKeeper consensuskeeper.Keeper + +<%= if (!IsChainMinimal) { %> SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper GovKeeper *govkeeper.Keeper CrisisKeeper *crisiskeeper.Keeper UpgradeKeeper *upgradekeeper.Keeper @@ -98,7 +124,6 @@ type App struct { EvidenceKeeper evidencekeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper GroupKeeper groupkeeper.Keeper - ConsensusParamsKeeper consensuskeeper.Keeper CircuitBreakerKeeper circuitkeeper.Keeper // IBC @@ -114,6 +139,7 @@ type App struct { ScopedIBCTransferKeeper capabilitykeeper.ScopedKeeper ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper ScopedICAHostKeeper capabilitykeeper.ScopedKeeper +<% } %> // this line is used by starport scaffolding # stargate/app/keeperDeclaration @@ -130,6 +156,7 @@ func init() { DefaultNodeHome = filepath.Join(userHomeDir, "."+Name) } +<%= if (!IsChainMinimal) { %> // getGovProposalHandlers return the chain proposal handlers. func getGovProposalHandlers() []govclient.ProposalHandler { var govProposalHandlers []govclient.ProposalHandler @@ -142,18 +169,21 @@ func getGovProposalHandlers() []govclient.ProposalHandler { return govProposalHandlers } +<% } %> // AppConfig returns the default app config. func AppConfig() depinject.Config { return depinject.Configs( appConfig, - // Loads the ao config from a YAML file. + // Loads the app config from a YAML file. // appconfig.LoadYAML(AppConfigYAML), depinject.Supply( // supply custom module basics map[string]module.AppModuleBasic{ genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + <%= if (!IsChainMinimal) { %> govtypes.ModuleName: gov.NewAppModuleBasic(getGovProposalHandlers()), + <% } %> // this line is used by starport scaffolding # stargate/appConfig/moduleBasic }, ), @@ -179,12 +209,14 @@ func New( depinject.Supply( // Supply the application options appOpts, + <%= if (!IsChainMinimal) { %> // Supply with IBC keeper getter for the IBC modules with App Wiring. // The IBC Keeper cannot be passed because it has not been initiated yet. // Passing the getter, the app IBC Keeper will always be accessible. // This needs to be removed after IBC supports App Wiring. app.GetIBCKeeper, app.GetCapabilityScopedKeeper, + <% } %> // Supply the logger logger, @@ -239,9 +271,11 @@ func New( &app.AccountKeeper, &app.BankKeeper, &app.StakingKeeper, + &app.DistrKeeper, + &app.ConsensusParamsKeeper, +<%= if (!IsChainMinimal) { %> &app.SlashingKeeper, &app.MintKeeper, - &app.DistrKeeper, &app.GovKeeper, &app.CrisisKeeper, &app.UpgradeKeeper, @@ -250,8 +284,8 @@ func New( &app.EvidenceKeeper, &app.FeeGrantKeeper, &app.GroupKeeper, - &app.ConsensusParamsKeeper, &app.CircuitBreakerKeeper, +<% } %> // this line is used by starport scaffolding # stargate/app/keeperDefinition ); err != nil { panic(err) @@ -291,8 +325,10 @@ func New( app.App = appBuilder.Build(db, traceStore, baseAppOptions...) +<%= if (!IsChainMinimal) { %> // Register legacy modules app.registerIBCModules() +<% } %> // register streaming services if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil { @@ -301,20 +337,21 @@ func New( /**** Module Options ****/ +<%= if (!IsChainMinimal) { %> app.ModuleManager.RegisterInvariants(app.CrisisKeeper) +<% } %> - // add test gRPC service for testing gRPC queries in isolation - testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{}) - +<%= if (!IsChainMinimal) { %> // create the simulation manager and define the order of the modules for deterministic simulations // - // NOTE: this is not required apps that don't use the simulator for fuzz testing - // transactions + // NOTE: this is not required apps that don't use the simulator for fuzz testing transactions overrideModules := map[string]module.AppModuleSimulation{ authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), } +<% } else { %> + overrideModules := make(map[string]module.AppModuleSimulation) +<% } %> app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules) - app.sm.RegisterStoreDecoders() // A custom InitChainer can be set if extra pre-init-genesis logic is required. @@ -382,12 +419,24 @@ func (app *App) kvStoreKeys() map[string]*storetypes.KVStoreKey { return keys } +<%= if (!IsChainMinimal) { %> // GetSubspace returns a param subspace for a given module name. func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) return subspace } +// GetIBCKeeper returns the IBC keeper. +func (app *App) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetCapabilityScopedKeeper returns the capability scoped keeper. +func (app *App) GetCapabilityScopedKeeper(moduleName string) capabilitykeeper.ScopedKeeper { + return app.CapabilityKeeper.ScopeToModule(moduleName) +} +<% } %> + // SimulationManager implements the SimulationApp interface. func (app *App) SimulationManager() *module.SimulationManager { return app.sm @@ -406,16 +455,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig docs.RegisterOpenAPIService(Name, apiSvr.Router) } -// GetIBCKeeper returns the IBC keeper. -func (app *App) GetIBCKeeper() *ibckeeper.Keeper { - return app.IBCKeeper -} - -// GetCapabilityScopedKeeper returns the capability scoped keeper. -func (app *App) GetCapabilityScopedKeeper(moduleName string) capabilitykeeper.ScopedKeeper { - return app.CapabilityKeeper.ScopeToModule(moduleName) -} - // GetMaccPerms returns a copy of the module account permissions // // NOTE: This is solely to be used for testing purposes. diff --git a/ignite/templates/app/files/app/app_config.go.plush b/ignite/templates/app/files/app/app_config.go.plush index 8c0d34a74a..1fe60a6353 100644 --- a/ignite/templates/app/files/app/app_config.go.plush +++ b/ignite/templates/app/files/app/app_config.go.plush @@ -25,47 +25,27 @@ import ( upgrademodulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/core/appconfig" - _ "cosmossdk.io/x/circuit" // import for side-effects circuittypes "cosmossdk.io/x/circuit/types" - _ "cosmossdk.io/x/evidence" // import for side-effects evidencetypes "cosmossdk.io/x/evidence/types" "cosmossdk.io/x/feegrant" - _ "cosmossdk.io/x/feegrant/module" // import for side-effects - _ "cosmossdk.io/x/upgrade" // import for side-effects upgradetypes "cosmossdk.io/x/upgrade/types" "github.com/cosmos/cosmos-sdk/runtime" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" "github.com/cosmos/cosmos-sdk/x/authz" - _ "github.com/cosmos/cosmos-sdk/x/authz/module" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - _ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects - consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - _ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - _ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/group" - _ "github.com/cosmos/cosmos-sdk/x/group/module" // import for side-effects - _ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - _ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - _ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - _ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - _ "github.com/cosmos/ibc-go/modules/capability" // import for side-effects capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" - _ "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" // import for side-effects icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" - _ "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" // import for side-effects ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -105,7 +85,7 @@ var ( vestingtypes.ModuleName, circuittypes.ModuleName, group.ModuleName, - consensusparamtypes.ModuleName, + consensustypes.ModuleName, circuittypes.ModuleName, // chain modules // this line is used by starport scaffolding # stargate/app/initGenesis diff --git a/ignite/templates/app/files/app/app_config_minimal.go.plush b/ignite/templates/app/files/app/app_config_minimal.go.plush new file mode 100644 index 0000000000..e133dd41a7 --- /dev/null +++ b/ignite/templates/app/files/app/app_config_minimal.go.plush @@ -0,0 +1,156 @@ +package app + +import ( + runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" + appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" + authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1" + consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" + distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" + genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" + stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" + txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" + "cosmossdk.io/core/appconfig" + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/runtime" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + // this line is used by starport scaffolding # stargate/app/moduleImport +) + +var ( + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // NOTE: The genutils module must also occur after auth so that it can access the params from auth. + // NOTE: Capability module must occur first so that it can initialize any capabilities + // so that other modules that want to create or claim capabilities afterwards in InitChain + // can do so safely. + + genesisModuleOrder = []string{ + // cosmos-sdk modules + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + genutiltypes.ModuleName, + // chain modules + // this line is used by starport scaffolding # stargate/app/initGenesis + } + + // 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. + // NOTE: staking module is required if HistoricalEntries param > 0 + beginBlockers = []string{ + // cosmos sdk modules + distrtypes.ModuleName, + stakingtypes.ModuleName, + // chain modules + // this line is used by starport scaffolding # stargate/app/beginBlockers + } + + endBlockers = []string{ + // cosmos sdk modules + stakingtypes.ModuleName, + // chain modules + // this line is used by starport scaffolding # stargate/app/endBlockers + } + + preBlockers = []string{ + upgradetypes.ModuleName, + // this line is used by starport scaffolding # stargate/app/preBlockers + } + + // module account permissions + moduleAccPerms = []*authmodulev1.ModuleAccountPermission{ + {Account: authtypes.FeeCollectorName}, + {Account: distrtypes.ModuleName}, + {Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}}, + {Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + {Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}}, + // this line is used by starport scaffolding # stargate/app/maccPerms + } + + // blocked account addresses + blockAccAddrs = []string{ + authtypes.FeeCollectorName, + distrtypes.ModuleName, + stakingtypes.BondedPoolName, + stakingtypes.NotBondedPoolName, + } + + // appConfig application configuration (used by depinject) + appConfig = appconfig.Compose(&appv1alpha1.Config{ + Modules: []*appv1alpha1.ModuleConfig{ + { + Name: runtime.ModuleName, + Config: appconfig.WrapAny(&runtimev1alpha1.Module{ + AppName: Name, + PreBlockers: preBlockers, + BeginBlockers: beginBlockers, + EndBlockers: endBlockers, + InitGenesis: genesisModuleOrder, + OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{ + { + ModuleName: authtypes.ModuleName, + KvStoreKey: "acc", + }, + }, + // When ExportGenesis is not specified, the export genesis module order + // is equal to the init genesis order + // ExportGenesis: genesisModuleOrder, + // Uncomment if you want to set a custom migration order here. + // OrderMigrations: nil, + }), + }, + { + Name: authtypes.ModuleName, + Config: appconfig.WrapAny(&authmodulev1.Module{ + Bech32Prefix: AccountAddressPrefix, + ModuleAccountPermissions: moduleAccPerms, + // By default modules authority is the governance module. This is configurable with the following: + // Authority: "group", // A custom module authority can be set using a module name + // Authority: "cosmos1cwwv22j5ca08ggdv9c2uky355k908694z577tv", // or a specific address + }), + }, + { + Name: "tx", + Config: appconfig.WrapAny(&txconfigv1.Config{}), + }, + { + Name: banktypes.ModuleName, + Config: appconfig.WrapAny(&bankmodulev1.Module{ + BlockedModuleAccountsOverride: blockAccAddrs, + }), + }, + { + Name: consensustypes.ModuleName, + Config: appconfig.WrapAny(&consensusmodulev1.Module{}), + }, + { + Name: distrtypes.ModuleName, + Config: appconfig.WrapAny(&distrmodulev1.Module{}), + }, + { + Name: stakingtypes.ModuleName, + Config: appconfig.WrapAny(&stakingmodulev1.Module{ + // NOTE: specifying a prefix is only necessary when using bech32 addresses + // If not specfied, the auth Bech32Prefix appended with "valoper" and "valcons" is used by default + Bech32PrefixValidator: AccountAddressPrefix + "valoper", + Bech32PrefixConsensus: AccountAddressPrefix + "valcons", + }), + }, + { + Name: genutiltypes.ModuleName, + Config: appconfig.WrapAny(&genutilmodulev1.Module{}), + }, + // this line is used by starport scaffolding # stargate/app/moduleConfig + }, + }) +) diff --git a/ignite/templates/app/files/app/export.go.plush b/ignite/templates/app/files/app/export.go.plush index 21203b274e..94d498b703 100644 --- a/ignite/templates/app/files/app/export.go.plush +++ b/ignite/templates/app/files/app/export.go.plush @@ -69,8 +69,10 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str allowedAddrsMap[addr] = true } +<%= if (!IsChainMinimal) { %> /* Just to be safe, assert the invariants on current state. */ app.CrisisKeeper.AssertInvariants(ctx) +<% } %> /* Handle fee distribution state. */ @@ -220,6 +222,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str log.Fatal(err) } +<%= if (!IsChainMinimal) { %> /* Handle slashing state. */ // reset start height on signing infos @@ -231,4 +234,5 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str return false }, ) +<% } %> } diff --git a/ignite/templates/app/files/app/sim_bench_test.go.plush b/ignite/templates/app/files/app/sim_bench_test.go.plush index 4609b99d76..72c361845b 100644 --- a/ignite/templates/app/files/app/sim_bench_test.go.plush +++ b/ignite/templates/app/files/app/sim_bench_test.go.plush @@ -74,6 +74,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { } } +<%= if (!IsChainMinimal) { %> func BenchmarkInvariants(b *testing.B) { b.ReportAllocs() @@ -148,3 +149,4 @@ func BenchmarkInvariants(b *testing.B) { }) } } +<% } %> \ No newline at end of file diff --git a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush index a6aebddd02..42e4490bb9 100644 --- a/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush +++ b/ignite/templates/app/files/cmd/{{binaryNamePrefix}}d/cmd/root.go.plush @@ -104,6 +104,7 @@ func NewRootCmd() *cobra.Command { }, } +<%= if (!IsChainMinimal) { %> // Since the IBC modules don't support dependency injection, we need to // manually register the modules on the client side. // This needs to be removed after IBC supports App Wiring. @@ -112,6 +113,7 @@ func NewRootCmd() *cobra.Command { moduleBasicManager[name] = module.CoreAppModuleBasicAdaptor(name, mod) autoCliOpts.Modules[name] = mod } +<% } %> initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleBasicManager) overwriteFlagDefaults(rootCmd, map[string]string{ diff --git a/ignite/templates/app/options.go b/ignite/templates/app/options.go index 7e8a5e4bd0..0176c02db1 100644 --- a/ignite/templates/app/options.go +++ b/ignite/templates/app/options.go @@ -10,6 +10,7 @@ type Options struct { AddressPrefix string // IncludePrefixes is used to filter the files to include from the generator IncludePrefixes []string + IsChainMinimal bool } // Validate that options are usable. diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/genesis_test.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/genesis_test.go.plush index 2d472574c2..dd61abf11d 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/genesis_test.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/genesis_test.go.plush @@ -5,7 +5,7 @@ import ( keepertest "<%= modulePath %>/testutil/keeper" "<%= modulePath %>/testutil/nullify" - "<%= modulePath %>/x/<%= moduleName %>/module" + <%= moduleName %> "<%= modulePath %>/x/<%= moduleName %>/module" "<%= modulePath %>/x/<%= moduleName %>/types" "github.com/stretchr/testify/require" ) diff --git a/integration/app/cmd_app_test.go b/integration/app/cmd_app_test.go index f6d8b5079a..58abdabd2a 100644 --- a/integration/app/cmd_app_test.go +++ b/integration/app/cmd_app_test.go @@ -13,6 +13,7 @@ import ( envtest "github.com/ignite/cli/v28/integration" ) +// TestGenerateAnApp tests scaffolding a new chain. func TestGenerateAnApp(t *testing.T) { var ( env = envtest.New(t) @@ -25,6 +26,19 @@ func TestGenerateAnApp(t *testing.T) { app.EnsureSteady() } +// TestGenerateAnAppMinimal tests scaffolding a new minimal chain. +func TestGenerateAnAppMinimal(t *testing.T) { + var ( + env = envtest.New(t) + app = env.Scaffold("blog", "--minimal") + ) + + _, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog")) + require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded") + + app.EnsureSteady() +} + // TestGenerateAnAppWithName tests scaffolding a new chain using a local name instead of a GitHub URI. func TestGenerateAnAppWithName(t *testing.T) { var ( diff --git a/integration/doctor/testdata/existing-tools.go.txt b/integration/doctor/testdata/existing-tools.go.txt index 8ba1acd5b8..c4c9dd3cff 100644 --- a/integration/doctor/testdata/existing-tools.go.txt +++ b/integration/doctor/testdata/existing-tools.go.txt @@ -38,6 +38,7 @@ import ( _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway" _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger" _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2" + _ "golang.org/x/tools/cmd/goimports" _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" _ "google.golang.org/protobuf/cmd/protoc-gen-go" ) diff --git a/integration/doctor/testdata/missing-tools.go.txt b/integration/doctor/testdata/missing-tools.go.txt index fe63f572f8..be6e75296b 100644 --- a/integration/doctor/testdata/missing-tools.go.txt +++ b/integration/doctor/testdata/missing-tools.go.txt @@ -30,4 +30,5 @@ import ( _ "github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar" _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway" _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2" + _ "golang.org/x/tools/cmd/goimports" )