Skip to content

Commit

Permalink
chore: slightly refactor app.go and ante.go
Browse files Browse the repository at this point in the history
  • Loading branch information
yoosah committed Mar 22, 2024
1 parent e4ab96a commit 069b9e6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
31 changes: 14 additions & 17 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ import (
// HandlerOptions extend the SDK's AnteHandler opts by requiring the IBC
// channel keeper.
type HandlerOptions struct {
Cdc codec.BinaryCodec
AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
EvmKeeper evmante.EVMKeeper
FeegrantKeeper authante.FeegrantKeeper
VolunteerKeeper volunteerante.VolunteerKeeper
SignModeHandler authsigning.SignModeHandler
SigGasConsumer authante.SignatureVerificationGasConsumer
FeeMarketKeeper evmante.FeeMarketKeeper
MaxTxGasWanted uint64
TxFeeChecker authante.TxFeeChecker
Cdc codec.BinaryCodec
AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
EvmKeeper evmante.EVMKeeper
FeegrantKeeper authante.FeegrantKeeper
VolunteerKeeper volunteerante.VolunteerKeeper
ExtensionOptionChecker authante.ExtensionOptionChecker
SignModeHandler authsigning.SignModeHandler
SigGasConsumer authante.SignatureVerificationGasConsumer
FeeMarketKeeper evmante.FeeMarketKeeper
MaxTxGasWanted uint64
TxFeeChecker authante.TxFeeChecker

BypassMinFeeMsgTypes []string
TxCounterStoreKey storetypes.StoreKey
Expand Down Expand Up @@ -79,11 +80,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler")
}

sigGasConsumer := opts.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = authante.DefaultSigVerificationGasConsumer
}

return func(
ctx sdk.Context, tx sdk.Tx, sim bool,
) (newCtx sdk.Context, err error) {
Expand Down Expand Up @@ -140,6 +136,7 @@ func newCosmosAnteHandler(opts HandlerOptions) sdk.AnteHandler {
evmante.NewAuthzLimiterDecorator(disabledAuthzMsgs),
volunteerante.NewRejectDelegateVolunteerValidatorDecorator(opts.VolunteerKeeper),
authante.NewSetUpContextDecorator(), // second decorator. SetUpContext must be called before other decorators
authante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(opts.TxCounterStoreKey),
wasmkeeper.NewGasRegisterDecorator(opts.WasmKeeper.GetGasRegister()),
Expand Down
10 changes: 7 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -78,6 +79,7 @@ type XplaApp struct { // nolint: golint

legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint
Expand Down Expand Up @@ -107,7 +109,6 @@ func NewXplaApp(
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig xplaappparams.EncodingConfig,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
Expand All @@ -118,6 +119,10 @@ func NewXplaApp(
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig

// App Opts
skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))
invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))

bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
Expand All @@ -127,6 +132,7 @@ func NewXplaApp(
app := &XplaApp{
BaseApp: bApp,
legacyAmino: legacyAmino,
txConfig: txConfig,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
Expand All @@ -149,8 +155,6 @@ func NewXplaApp(
wasmOpts,
)

skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

// 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)...)
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/server"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -116,6 +118,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

func setup(chainId string) (*xplaapp.XplaApp, xplaapp.GenesisState) {
db := dbm.NewMemDB()
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[server.FlagInvCheckPeriod] = 5

encCdc := xplaapp.MakeTestEncodingConfig()
app := xplaapp.NewXplaApp(
log.NewNopLogger(),
Expand All @@ -124,7 +129,6 @@ func setup(chainId string) (*xplaapp.XplaApp, xplaapp.GenesisState) {
true,
map[int64]bool{},
xplaapp.DefaultNodeHome,
5,
encCdc,
EmptyAppOptions{},
[]wasmkeeper.Option{},
Expand Down
11 changes: 9 additions & 2 deletions cmd/xplad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ func (ac appCreator) newApp(
return xpla.NewXplaApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
ac.encCfg,
appOpts,
wasmOpts,
Expand Down Expand Up @@ -334,6 +333,15 @@ func (ac appCreator) appExport(
return servertypes.ExportedApp{}, errors.New("application home is not set")
}

// InvCheckPeriod
viperAppOpts, ok := appOpts.(*viper.Viper)
if !ok {
return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
}
// overwrite the FlagInvCheckPeriod
viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
appOpts = viperAppOpts

var loadLatest bool
if height == -1 {
loadLatest = true
Expand All @@ -347,7 +355,6 @@ func (ac appCreator) appExport(
loadLatest,
map[int64]bool{},
homePath,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
ac.encCfg,
appOpts,
emptyWasmOpts,
Expand Down

0 comments on commit 069b9e6

Please sign in to comment.