Skip to content

Commit

Permalink
run new line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed May 19, 2024
1 parent d72fdad commit 747fdfc
Show file tree
Hide file tree
Showing 309 changed files with 6,280 additions and 1,728 deletions.
7 changes: 6 additions & 1 deletion app/ante/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func NewAuthzLimiterDecorator(disabledMsgTypes ...string) AuthzLimiterDecorator
}
}

func (ald AuthzLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
func (ald AuthzLimiterDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 1); err != nil {
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error())
}
Expand Down
31 changes: 26 additions & 5 deletions app/ante/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ func NewEthMempoolFeeDecorator(ek EVMKeeper) EthMempoolFeeDecorator {
}
}

func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
func (mpd MinGasPriceDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType, "invalid transaction type %T, expected sdk.FeeTx", tx)
Expand Down Expand Up @@ -143,7 +148,12 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

// AnteHandle ensures that the that the effective fee from the transaction is greater than the
// minimum global fee, which is defined by the MinGasPrice (parameter) * GasLimit (tx argument).
func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
func (empd EthMinGasPriceDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
minGasPrice := empd.feesKeeper.GetParams(ctx).MinGasPrice

// short-circuit if min gas price is 0
Expand Down Expand Up @@ -195,7 +205,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
return ctx, errorsmod.Wrapf(
errortypes.ErrInsufficientFee,
"provided fee < minimum global fee (%d < %d). Please increase the priority tip (for EIP-1559 txs) or the gas prices (for access list or legacy txs)", //nolint:lll
fee.TruncateInt().Int64(), requiredFee.TruncateInt().Int64(),
fee.TruncateInt().Int64(),
requiredFee.TruncateInt().Int64(),
)
}
}
Expand All @@ -206,7 +217,12 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
// AnteHandle ensures that the provided fees meet a minimum threshold for the validator.
// This check only for local mempool purposes, and thus it is only run on (Re)CheckTx.
// The logic is also skipped if the London hard fork and EIP-1559 are enabled.
func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
func (mfd EthMempoolFeeDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
if !ctx.IsCheckTx() || simulate {
return next(ctx, tx, simulate)
}
Expand All @@ -226,7 +242,12 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
for _, msg := range tx.GetMsgs() {
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownRequest,
"invalid message type %T, expected %T",
msg,
(*evmtypes.MsgEthereumTx)(nil),
)
}

fee := sdk.NewDecFromBigInt(ethMsg.GetFee())
Expand Down
45 changes: 37 additions & 8 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
ethante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
options.FeegrantKeeper,
options.TxFeeChecker,
),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand All @@ -78,17 +83,26 @@ func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {

func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first
ethante.NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against minimal-gas-prices
ethante.NewEthMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), // Check eth effective gas price against the global MinGasPrice
ethante.NewEthSetUpContextDecorator(
options.EvmKeeper,
), // outermost AnteDecorator. SetUpContext must be called first
ethante.NewEthMempoolFeeDecorator(
options.EvmKeeper,
), // Check eth effective gas price against minimal-gas-prices
ethante.NewEthMinGasPriceDecorator(
options.FeeMarketKeeper,
options.EvmKeeper,
), // Check eth effective gas price against the global MinGasPrice
ethante.NewEthValidateBasicDecorator(options.EvmKeeper),
ethante.NewEthSigVerificationDecorator(options.EvmKeeper),
ethante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
ethante.NewCanTransferDecorator(options.EvmKeeper),
ethante.NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted),
ethante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator.
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
ethante.NewEthEmitEventDecorator(options.EvmKeeper), // emit eth tx hash and index at the very last ante handler.
ethante.NewEthEmitEventDecorator(
options.EvmKeeper,
), // emit eth tx hash and index at the very last ante handler.
)
}

Expand All @@ -104,7 +118,12 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
ethante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
options.FeegrantKeeper,
options.TxFeeChecker,
),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand All @@ -129,7 +148,12 @@ func newCosmosAnteHandlerForSystemTx(options HandlerOptions) sdk.AnteHandler {
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
options.FeegrantKeeper,
options.TxFeeChecker,
),
NewSystemPriorityDecorator(),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
Expand Down Expand Up @@ -160,7 +184,12 @@ func NewSetUpContextDecorator() SetUpContextDecorator {
return SetUpContextDecorator{}
}

func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
func (sud SetUpContextDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
// all transactions must implement GasTx
gasTx, ok := tx.(GasTx)
if !ok {
Expand Down
50 changes: 43 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,11 @@ func New(
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), app.ObserverKeeper.Hooks()),
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.ObserverKeeper.Hooks(),
),
)

app.AuthzKeeper = authzkeeper.NewKeeper(
Expand Down Expand Up @@ -685,10 +689,36 @@ func New(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
gov.NewAppModule(
appCodec,
&app.GovKeeper,
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(govtypes.ModuleName),
),
slashing.NewAppModule(
appCodec,
app.SlashingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(slashingtypes.ModuleName),
),
distr.NewAppModule(
appCodec,
app.DistrKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(distrtypes.ModuleName),
),
staking.NewAppModule(
appCodec,
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
params.NewAppModule(app.ParamsKeeper),
Expand Down Expand Up @@ -803,7 +833,9 @@ func New(
SigGasConsumer: evmante.DefaultSigVerificationGasConsumer,
MaxTxGasWanted: maxGasWanted,
DisabledAuthzMsgs: []string{
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}), // disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(
&evmtypes.MsgEthereumTx{},
), // disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
Expand Down Expand Up @@ -980,7 +1012,11 @@ func GetMaccPerms() map[string][]string {
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
func initParamsKeeper(
appCodec codec.BinaryCodec,
legacyAmino *codec.LegacyAmino,
key, tkey storetypes.StoreKey,
) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
Expand Down
56 changes: 48 additions & 8 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,66 @@ var (
// GetSimulatorFlags gets the values of all the available simulation flags
func GetSimulatorFlags() {
// config fields
flag.StringVar(&FlagGenesisFileValue, "Genesis", "", "custom simulation genesis file; cannot be used with params file")
flag.StringVar(&FlagParamsFileValue, "Params", "", "custom simulation params file which overrides any random params; cannot be used with genesis")
flag.StringVar(&FlagExportParamsPathValue, "ExportParamsPath", "", "custom file path to save the exported params JSON")
flag.IntVar(&FlagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params")
flag.StringVar(&FlagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON")
flag.StringVar(&FlagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
flag.StringVar(
&FlagGenesisFileValue,
"Genesis",
"",
"custom simulation genesis file; cannot be used with params file",
)
flag.StringVar(
&FlagParamsFileValue,
"Params",
"",
"custom simulation params file which overrides any random params; cannot be used with genesis",
)
flag.StringVar(
&FlagExportParamsPathValue,
"ExportParamsPath",
"",
"custom file path to save the exported params JSON",
)
flag.IntVar(
&FlagExportParamsHeightValue,
"ExportParamsHeight",
0,
"height to which export the randomly generated params",
)
flag.StringVar(
&FlagExportStatePathValue,
"ExportStatePath",
"",
"custom file path to save the exported app state JSON",
)
flag.StringVar(
&FlagExportStatsPathValue,
"ExportStatsPath",
"",
"custom file path to save the exported simulation statistics JSON",
)
flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed")
flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation")
flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output")
flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit")
flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation")
flag.BoolVar(&FlagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
flag.BoolVar(
&FlagAllInvariantsValue,
"PrintAllInvariants",
false,
"print all invariants if a broken invariant is found",
)

// simulation flags
flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")
flag.BoolVar(&FlagVerboseValue, "Verbose", false, "verbose log output")
flag.UintVar(&FlagPeriodValue, "Period", 0, "run slow invariants only once every period assertions")
flag.Int64Var(&FlagGenesisTimeValue, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time")
flag.Int64Var(
&FlagGenesisTimeValue,
"GenesisTime",
0,
"override genesis UNIX time instead of using a random UNIX time",
)
}

// NewConfigFromFlags creates a simulation from the retrieved values of the flags.
Expand Down
6 changes: 5 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
_, err := app.DistrKeeper.WithdrawDelegationRewards(
ctx,
delegation.GetDelegatorAddr(),
delegation.GetValidatorAddr(),
)
if err != nil {
panic(err)
}
Expand Down
7 changes: 5 additions & 2 deletions app/mempool/priority_nonce_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func PriorityNonceWithOnRead(onRead func(tx sdk.Tx)) PriorityNonceMempoolOption
// PriorityNonceWithTxReplacement sets a callback to be called when duplicated
// transaction nonce detected during mempool insert. An application can define a
// transaction replacement rule based on tx priority or certain transaction fields.
func PriorityNonceWithTxReplacement(txReplacementRule func(op, np int64, oTx, nTx sdk.Tx) bool) PriorityNonceMempoolOption {
func PriorityNonceWithTxReplacement(
txReplacementRule func(op, np int64, oTx, nTx sdk.Tx) bool,
) PriorityNonceMempoolOption {
return func(mp *PriorityNonceMempool) {
mp.txReplacement = txReplacementRule
}
Expand Down Expand Up @@ -203,7 +205,8 @@ func (mp *PriorityNonceMempool) Insert(ctx context.Context, tx sdk.Tx) error {
// changes.
sk := txMeta{nonce: nonce, sender: sender}
if oldScore, txExists := mp.scores[sk]; txExists {
if mp.txReplacement != nil && !mp.txReplacement(oldScore.priority, priority, senderIndex.Get(key).Value.(sdk.Tx), tx) {
if mp.txReplacement != nil &&
!mp.txReplacement(oldScore.priority, priority, senderIndex.Get(key).Value.(sdk.Tx), tx) {
return fmt.Errorf(
"tx doesn't fit the replacement rule, oldPriority: %v, newPriority: %v, oldTx: %v, newTx: %v",
oldScore.priority,
Expand Down
23 changes: 13 additions & 10 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,22 @@ func SetupHandlers(app *App) {
upgradeHandlerFns, storeUpgrades = allUpgrades.mergeAllUpgrades()
}

app.UpgradeKeeper.SetUpgradeHandler(constant.Version, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + constant.Version)
app.UpgradeKeeper.SetUpgradeHandler(
constant.Version,
func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + constant.Version)

var err error
for _, upgradeHandler := range upgradeHandlerFns {
vm, err = upgradeHandler(ctx, vm)
if err != nil {
return vm, err
var err error
for _, upgradeHandler := range upgradeHandlerFns {
vm, err = upgradeHandler(ctx, vm)
if err != nil {
return vm, err
}
}
}

return app.mm.RunMigrations(ctx, app.configurator, vm)
})
return app.mm.RunMigrations(ctx, app.configurator, vm)
},
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
Expand Down
Loading

0 comments on commit 747fdfc

Please sign in to comment.