Skip to content

Commit

Permalink
refactor: demonstrate app.yaml instead of app_config.go
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Aug 17, 2023
1 parent e1c37c1 commit ca8a997
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 133 deletions.
37 changes: 36 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package app

import (
_ "embed"
"io"
"os"
"path/filepath"

dbm "github.com/cosmos/cosmos-db"

"cosmossdk.io/core/appconfig"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
Expand All @@ -25,12 +27,26 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/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
)

// DefaultNodeHome default home directories for the application daemon
var DefaultNodeHome string

//go:embed app.yaml
var AppConfigYAML []byte

var (
_ runtime.AppI = (*MiniApp)(nil)
_ servertypes.Application = (*MiniApp)(nil)
Expand Down Expand Up @@ -66,6 +82,19 @@ func init() {
DefaultNodeHome = filepath.Join(userHomeDir, ".minid")
}

// AppConfig returns the default app config.
func AppConfig() depinject.Config {
return depinject.Configs(
appconfig.LoadYAML(AppConfigYAML),
depinject.Supply(
// supply custom module basics
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
},
),
)
}

// NewMiniApp returns a reference to an initialized MiniApp.
func NewMiniApp(
logger log.Logger,
Expand All @@ -81,7 +110,13 @@ func NewMiniApp(
)

if err := depinject.Inject(
depinject.Configs(AppConfig, depinject.Supply(logger, appOpts)),
depinject.Configs(
AppConfig(),
depinject.Supply(
logger,
appOpts,
),
),
&appBuilder,
&app.appCodec,
&app.legacyAmino,
Expand Down
54 changes: 54 additions & 0 deletions app/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
modules:
- name: runtime
config:
"@type": cosmos.app.runtime.v1alpha1.Module
app_name: MiniApp
# 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
begin_blockers: [distribution, staking]
end_blockers: [staking]
# 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.
init_genesis: [auth, bank, distribution, staking, genutil]
override_store_keys:
- module_name: auth
kv_store_key: acc

- name: auth
config:
"@type": cosmos.auth.module.v1.Module
bech32_prefix: mini
module_account_permissions:
- account: fee_collector
- account: distribution
- account: bonded_tokens_pool
permissions: [burner, staking]
- account: not_bonded_tokens_pool
permissions: [burner, staking]

- name: bank
config:
"@type": cosmos.bank.module.v1.Module
blocked_module_accounts_override:
[auth, distribution, bonded_tokens_pool, not_bonded_tokens_pool]

- name: staking
config:
"@type": cosmos.staking.module.v1.Module

- name: distribution
config:
"@type": cosmos.distribution.module.v1.Module

- name: consensus
config:
"@type": cosmos.consensus.module.v1.Module

- name: genutil
config:
"@type": cosmos.genutil.module.v1.Module

- name: tx
config:
"@type": cosmos.tx.config.v1.Config
130 changes: 0 additions & 130 deletions app/app_config.go

This file was deleted.

9 changes: 7 additions & 2 deletions cmd/minid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"io"
"os"
"time"

cmtcfg "github.com/cometbft/cometbft/config"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -53,7 +54,7 @@ func NewRootCmd() *cobra.Command {
moduleBasicManager module.BasicManager
)

if err := depinject.Inject(depinject.Configs(app.AppConfig, depinject.Supply(log.NewNopLogger())),
if err := depinject.Inject(depinject.Configs(app.AppConfig(), depinject.Supply(log.NewNopLogger())),
&interfaceRegistry,
&appCodec,
&txConfig,
Expand Down Expand Up @@ -119,7 +120,11 @@ func NewRootCmd() *cobra.Command {
srvCfg := serverconfig.DefaultConfig()
srvCfg.MinGasPrices = "0mini"

return server.InterceptConfigsPreRunHandler(cmd, serverconfig.DefaultConfigTemplate, srvCfg, cmtcfg.DefaultConfig())
// overwrite the block timeout
cmtCfg := cmtcfg.DefaultConfig()
cmtCfg.Consensus.TimeoutCommit = 3 * time.Second

return server.InterceptConfigsPreRunHandler(cmd, serverconfig.DefaultConfigTemplate, srvCfg, cmtCfg)
},
}

Expand Down

0 comments on commit ca8a997

Please sign in to comment.