Skip to content

Commit

Permalink
Minor cleanups and comments (#1712)
Browse files Browse the repository at this point in the history
* Minor cleanups and comments

* Lint
  • Loading branch information
alpe authored Nov 13, 2023
1 parent 4313d7f commit 6f8c0a9
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 66 deletions.
1 change: 1 addition & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type HandlerOptions struct {
CircuitKeeper *circuitkeeper.Keeper
}

// NewAnteHandler constructor
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, errors.New("account keeper is required for ante builder")
Expand Down
33 changes: 21 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,21 @@ func NewWasmApp(
logger,
)

// optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
// enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
// txConfigOpts := tx.ConfigOptions{
// EnabledSignModes: enabledSignModes,
// TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
// }
// txConfig, err := tx.NewTxConfigWithOptions(
// appCodec,
// txConfigOpts,
// )
// if err != nil {
// panic(err)
// }
// app.txConfig = txConfig

app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
Expand Down Expand Up @@ -510,9 +525,7 @@ func NewWasmApp(
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
// This should be removed. It is still in place to avoid failures of modules that have not yet been upgraded.
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))

govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:
Expand All @@ -530,6 +543,9 @@ func NewWasmApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
Expand Down Expand Up @@ -631,9 +647,6 @@ func NewWasmApp(
wasmOpts...,
)

// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

// Create Transfer Stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
Expand Down Expand Up @@ -725,7 +738,6 @@ func NewWasmApp(
paramsclient.ProposalHandler,
},
),
ibctm.ModuleName: ibctm.AppModuleBasic{},
})
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
Expand Down Expand Up @@ -873,12 +885,7 @@ func NewWasmApp(
// meaning that both `runMsgs` and `postHandler` state will be committed if
// both are successful, and both will be reverted if any of the two fails.
//
// The SDK exposes a default postHandlers chain, which comprises of only
// one decorator: the Transaction Tips decorator. However, some chains do
// not need it by default, so feel free to comment the next line if you do
// not need tips.
// To read more about tips:
// https://docs.cosmos.network/main/core/tips.html
// The SDK exposes a default postHandlers chain
//
// Please note that changing any of the anteHandler or postHandler chain is
// likely to be a state-machine breaking change, which needs a coordinated
Expand Down Expand Up @@ -933,6 +940,8 @@ func (app *WasmApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtype
if err != nil {
panic(fmt.Errorf("failed to create AnteHandler: %s", err))
}

// Set the AnteHandler for the app
app.SetAnteHandler(anteHandler)
}

Expand Down
19 changes: 0 additions & 19 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ package app

import (
"encoding/json"
"testing"

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

"cosmossdk.io/log"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
)

// GenesisState of the blockchain is represented here as a map of raw json
Expand All @@ -21,13 +12,3 @@ import (
// the ModuleBasicManager which populates json from each BasicModule
// object provided to it during init.
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
// Deprecated: use wasmApp.DefaultGenesis() instead
func NewDefaultGenesisState(t *testing.T) GenesisState {
t.Helper()
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
// note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go)
tempApp := NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), []wasmkeeper.Option{})
return tempApp.DefaultGenesis()
}
20 changes: 3 additions & 17 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,6 @@ func SetupWithGenesisValSet(
})
require.NoError(t, err)

votes := make([]abci.VoteInfo, len(valSet.Validators))
for i, v := range valSet.Validators {
votes[i] = abci.VoteInfo{
Validator: abci.Validator{Address: v.Address, Power: v.VotingPower},
}
}

_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
Hash: app.LastCommitID().Hash,
Expand Down Expand Up @@ -236,12 +229,12 @@ func AddTestAddrsIncremental(app *WasmApp, ctx sdk.Context, accNum int, accAmt s

func addTestAddrs(app *WasmApp, ctx sdk.Context, accNum int, accAmt sdkmath.Int, strategy simtestutil.GenerateAccountStrategy) []sdk.AccAddress {
testAddrs := strategy(accNum)

denom, err := app.StakingKeeper.BondDenom(ctx)
bondDenom, err := app.StakingKeeper.BondDenom(ctx)
if err != nil {
panic(err)
}
initCoins := sdk.NewCoins(sdk.NewCoin(denom, accAmt))

initCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, accAmt))

for _, addr := range testAddrs {
initAccountWithCoins(app, ctx, addr, initCoins)
Expand All @@ -262,13 +255,6 @@ func initAccountWithCoins(app *WasmApp, ctx sdk.Context, addr sdk.AccAddress, co
}
}

// ModuleAccountAddrs provides a list of blocked module accounts from configuration in AppConfig
//
// Ported from WasmApp
func ModuleAccountAddrs() map[string]bool {
return BlockedAddresses()
}

var emptyWasmOptions []wasmkeeper.Option

// NewTestNetworkFixture returns a new WasmApp AppConstructor for network simulation tests
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/noop/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewUpgrade(semver string) upgrades.Upgrade {
}

func CreateUpgradeHandler(
mm *module.Manager,
mm upgrades.ModuleManager,
configurator module.Configurator,
ak *upgrades.AppKeepers,
) upgradetypes.UpgradeHandler {
Expand Down
8 changes: 7 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package upgrades

import (
"context"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

Expand All @@ -11,6 +13,10 @@ import (
type AppKeepers struct {
authkeeper.AccountKeeper
}
type ModuleManager interface {
RunMigrations(ctx context.Context, cfg module.Configurator, fromVM module.VersionMap) (module.VersionMap, error)
GetVersionMap() module.VersionMap
}

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
// must have written, in order for the state migration to go smoothly.
Expand All @@ -21,6 +27,6 @@ type Upgrade struct {
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator, *AppKeepers) upgradetypes.UpgradeHandler
CreateUpgradeHandler func(ModuleManager, module.Configurator, *AppKeepers) upgradetypes.UpgradeHandler
StoreUpgrades storetypes.StoreUpgrades
}
2 changes: 1 addition & 1 deletion app/upgrades/v050/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var Upgrade = upgrades.Upgrade{
}

func CreateUpgradeHandler(
mm *module.Manager,
mm upgrades.ModuleManager,
configurator module.Configurator,
ak *upgrades.AppKeepers,
) upgradetypes.UpgradeHandler {
Expand Down
36 changes: 21 additions & 15 deletions cmd/wasmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
Expand Down Expand Up @@ -49,15 +48,17 @@ func NewRootCmd() *cobra.Command {
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithHomeDir(app.DefaultNodeHome).
WithViper("") // In wasmd, we don't use any prefix for env variables.

rootCmd := &cobra.Command{
Use: version.AppName,
Short: "Wasm Daemon (server)",
Use: version.AppName,
Short: "Wasm Daemon (server)",
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
Expand All @@ -75,19 +76,24 @@ func NewRootCmd() *cobra.Command {
}

// This needs to go after ReadFromClientConfig, as that function
// sets the RPC client needed for SIGN_MODE_TEXTUAL.
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL),
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
// sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode
// is only available if the client is online.
if !initClientCtx.Offline {
enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
}
txConfig, err := tx.NewTxConfigWithOptions(
initClientCtx.Codec,
txConfigOpts,
)
if err != nil {
return err
}

initClientCtx = initClientCtx.WithTxConfig(txConfig)
}
txConfigWithTextual, err := tx.NewTxConfigWithOptions(
codec.NewProtoCodec(encodingConfig.InterfaceRegistry),
txConfigOpts,
)
if err != nil {
return err
}
initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual)

if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
Expand Down

0 comments on commit 6f8c0a9

Please sign in to comment.