diff --git a/app/ante/ante.go b/app/ante/ante.go index 7b0884f86..e31ee9adb 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -21,6 +21,8 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler { defer ethante.Recover(ctx.Logger(), &err) + sim = options.Simulation + txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx) if ok { opts := txWithExtensions.GetExtensionOptions() diff --git a/app/ante/decorators.go b/app/ante/decorators.go index d288b3dee..688f8a81c 100644 --- a/app/ante/decorators.go +++ b/app/ante/decorators.go @@ -10,6 +10,7 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" coinswaptypes "mods.irisnet.org/modules/coinswap/types" + servicetypes "mods.irisnet.org/modules/service/types" tokenkeeper "mods.irisnet.org/modules/token/keeper" tokentypesv1 "mods.irisnet.org/modules/token/types/v1" tokentypesv1beta1 "mods.irisnet.org/modules/token/types/v1beta1" @@ -76,6 +77,18 @@ func (vsd ValidateServiceDecorator) AnteHandle( simulate bool, next sdk.AnteHandler, ) (sdk.Context, error) { + if simulate { + return next(ctx, tx, simulate) + } + + for _, msg := range tx.GetMsgs() { + switch msg := msg.(type) { + case *servicetypes.MsgCallService: + if msg.Repeated { + return ctx, sdkerrors.Wrap(errortypes.ErrInvalidRequest, "currently does not support to create repeatable service invocation") + } + } + } return next(ctx, tx, simulate) } diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index 38f13e4ae..53461db3e 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -31,6 +31,7 @@ type HandlerOptions struct { FeeMarketKeeper ethante.FeeMarketKeeper BypassMinFeeMsgTypes []string MaxTxGasWanted uint64 + Simulation bool } // newCosmosAnteHandler creates the default ante handler for Ethereum transactions diff --git a/app/app.go b/app/app.go index acdf3686b..54d0e7484 100644 --- a/app/app.go +++ b/app/app.go @@ -177,6 +177,13 @@ func NewIrisApp( app.MountMemoryStores(app.MemoryStoreKeys()) maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)) + + simulation := false + opt = appOpts.Get(params.Simulation) + if opt, ok := opt.(bool); ok { + simulation = opt + } + anteHandler := irishubante.NewAnteHandler( irishubante.HandlerOptions{ HandlerOptions: ante.HandlerOptions{ @@ -195,6 +202,7 @@ func NewIrisApp( FeeMarketKeeper: app.FeeMarketKeeper, BypassMinFeeMsgTypes: []string{}, MaxTxGasWanted: maxGasWanted, + Simulation: simulation, }, ) diff --git a/app/params/params.go b/app/params/params.go index b6aa5fb55..9f73468f5 100644 --- a/app/params/params.go +++ b/app/params/params.go @@ -4,4 +4,5 @@ package params const ( StakePerAccount = "stake_per_account" InitiallyBondedValidators = "initially_bonded_validators" + Simulation = "simulation" ) diff --git a/app/sim_bench_test.go b/app/sim_bench_test.go index 0e3524145..95021f656 100644 --- a/app/sim_bench_test.go +++ b/app/sim_bench_test.go @@ -11,6 +11,8 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" + + "github.com/irisnet/irishub/v4/app/params" ) // Profile with: @@ -51,7 +53,9 @@ func BenchmarkFullAppSimulation(b *testing.B) { nil, true, encfg, - EmptyAppOptions{}, + SimTestAppOptions{ + options: map[string]interface{}{params.Simulation: true}, + }, interBlockCacheOpt(), ) @@ -118,7 +122,9 @@ func BenchmarkInvariants(b *testing.B) { nil, true, encfg, - EmptyAppOptions{}, + SimTestAppOptions{ + options: map[string]interface{}{params.Simulation: true}, + }, interBlockCacheOpt(), ) diff --git a/app/sim_test.go b/app/sim_test.go index 1937770d4..d536673d1 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -478,6 +478,16 @@ func (ao EmptyAppOptions) Get(o string) interface{} { return nil } +// SimTestAppOptions is a stub implementing AppOptions +type SimTestAppOptions struct { + options map[string]interface{} +} + +// Get implements AppOptions +func (o SimTestAppOptions) Get(key string) interface{} { + return o.options[key] +} + func createApp( logger log.Logger, db dbm.DB, @@ -494,7 +504,9 @@ func createApp( nil, true, encodingConfig, - EmptyAppOptions{}, + SimTestAppOptions{ + options: map[string]interface{}{params.Simulation: true}, + }, baseAppOptions..., ) }