diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index bd6203f5669..90e0963ae86 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -662,6 +662,11 @@ var ( Usage: "Allow the sequencer to proceed transactions with 0 gas price", Value: false, } + RejectLowGasPriceTransactions = cli.BoolFlag{ + Name: "zkevm.reject-low-gas-price-transactions", + Usage: "Reject the sequencer to proceed transactions with low gas price", + Value: false, + } AllowPreEIP155Transactions = cli.BoolFlag{ Name: "zkevm.allow-pre-eip155-transactions", Usage: "Allow the sequencer to proceed pre-EIP155 transactions", diff --git a/eth/ethconfig/config_zkevm.go b/eth/ethconfig/config_zkevm.go index fd8c3712146..c7173832a5b 100644 --- a/eth/ethconfig/config_zkevm.go +++ b/eth/ethconfig/config_zkevm.go @@ -54,6 +54,7 @@ type Zk struct { ExecutorMaxConcurrentRequests int Limbo bool AllowFreeTransactions bool + RejectLowGasPriceTransactions bool AllowPreEIP155Transactions bool EffectiveGasPriceForEthTransfer uint8 EffectiveGasPriceForErc20Transfer uint8 diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index d4e397af575..4272fb1f300 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -220,6 +220,7 @@ var DefaultFlags = []cli.Flag{ &utils.ExecutorMaxConcurrentRequests, &utils.Limbo, &utils.AllowFreeTransactions, + &utils.RejectLowGasPriceTransactions, &utils.AllowPreEIP155Transactions, &utils.EffectiveGasPriceForEthTransfer, &utils.EffectiveGasPriceForErc20Transfer, diff --git a/turbo/cli/flags_zkevm.go b/turbo/cli/flags_zkevm.go index 1d6f42331a9..ae01417fe3e 100644 --- a/turbo/cli/flags_zkevm.go +++ b/turbo/cli/flags_zkevm.go @@ -189,6 +189,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) { ExecutorMaxConcurrentRequests: ctx.Int(utils.ExecutorMaxConcurrentRequests.Name), Limbo: ctx.Bool(utils.Limbo.Name), AllowFreeTransactions: ctx.Bool(utils.AllowFreeTransactions.Name), + RejectLowGasPriceTransactions: ctx.Bool(utils.RejectLowGasPriceTransactions.Name), AllowPreEIP155Transactions: ctx.Bool(utils.AllowPreEIP155Transactions.Name), EffectiveGasPriceForEthTransfer: uint8(math.Round(effectiveGasPriceForEthTransferVal * 255.0)), EffectiveGasPriceForErc20Transfer: uint8(math.Round(effectiveGasPriceForErc20TransferVal * 255.0)), diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index 54aa076ee0e..3908558027e 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -353,28 +353,29 @@ func (api *BaseAPI) pruneMode(tx kv.Tx) (*prune.Mode, error) { // APIImpl is implementation of the EthAPI interface based on remote Db access type APIImpl struct { *BaseAPI - ethBackend rpchelper.ApiBackend - txPool txpool.TxpoolClient - mining txpool.MiningClient - gasCache *GasPriceCache - db kv.RoDB - GasCap uint64 - FeeCap float64 - ReturnDataLimit int - ZkRpcUrl string - PoolManagerUrl string - AllowFreeTransactions bool - AllowPreEIP155Transactions bool - AllowUnprotectedTxs bool - MaxGetProofRewindBlockCount int - L1RpcUrl string - DefaultGasPrice uint64 - MaxGasPrice uint64 - GasPriceFactor float64 - L1GasPrice L1GasPrice - SubscribeLogsChannelSize int - logger log.Logger - VirtualCountersSmtReduction float64 + ethBackend rpchelper.ApiBackend + txPool txpool.TxpoolClient + mining txpool.MiningClient + gasCache *GasPriceCache + db kv.RoDB + GasCap uint64 + FeeCap float64 + ReturnDataLimit int + ZkRpcUrl string + PoolManagerUrl string + AllowFreeTransactions bool + AllowPreEIP155Transactions bool + AllowUnprotectedTxs bool + MaxGetProofRewindBlockCount int + L1RpcUrl string + DefaultGasPrice uint64 + MaxGasPrice uint64 + GasPriceFactor float64 + L1GasPrice L1GasPrice + SubscribeLogsChannelSize int + logger log.Logger + VirtualCountersSmtReduction float64 + RejectLowGasPriceTransactions bool } // NewEthAPI returns APIImpl instance @@ -384,29 +385,30 @@ func NewEthAPI(base *BaseAPI, db kv.RoDB, eth rpchelper.ApiBackend, txPool txpoo } return &APIImpl{ - BaseAPI: base, - db: db, - ethBackend: eth, - txPool: txPool, - mining: mining, - gasCache: NewGasPriceCache(), - GasCap: gascap, - FeeCap: feecap, - AllowUnprotectedTxs: allowUnprotectedTxs, - ReturnDataLimit: returnDataLimit, - ZkRpcUrl: ethCfg.L2RpcUrl, - PoolManagerUrl: ethCfg.PoolManagerUrl, - AllowFreeTransactions: ethCfg.AllowFreeTransactions, - AllowPreEIP155Transactions: ethCfg.AllowPreEIP155Transactions, - MaxGetProofRewindBlockCount: maxGetProofRewindBlockCount, - L1RpcUrl: ethCfg.L1RpcUrl, - DefaultGasPrice: ethCfg.DefaultGasPrice, - MaxGasPrice: ethCfg.MaxGasPrice, - GasPriceFactor: ethCfg.GasPriceFactor, - L1GasPrice: L1GasPrice{}, - SubscribeLogsChannelSize: subscribeLogsChannelSize, - logger: logger, - VirtualCountersSmtReduction: ethCfg.VirtualCountersSmtReduction, + BaseAPI: base, + db: db, + ethBackend: eth, + txPool: txPool, + mining: mining, + gasCache: NewGasPriceCache(), + GasCap: gascap, + FeeCap: feecap, + AllowUnprotectedTxs: allowUnprotectedTxs, + ReturnDataLimit: returnDataLimit, + ZkRpcUrl: ethCfg.L2RpcUrl, + PoolManagerUrl: ethCfg.PoolManagerUrl, + AllowFreeTransactions: ethCfg.AllowFreeTransactions, + AllowPreEIP155Transactions: ethCfg.AllowPreEIP155Transactions, + MaxGetProofRewindBlockCount: maxGetProofRewindBlockCount, + L1RpcUrl: ethCfg.L1RpcUrl, + DefaultGasPrice: ethCfg.DefaultGasPrice, + MaxGasPrice: ethCfg.MaxGasPrice, + GasPriceFactor: ethCfg.GasPriceFactor, + L1GasPrice: L1GasPrice{}, + SubscribeLogsChannelSize: subscribeLogsChannelSize, + logger: logger, + VirtualCountersSmtReduction: ethCfg.VirtualCountersSmtReduction, + RejectLowGasPriceTransactions: ethCfg.RejectLowGasPriceTransactions, } } diff --git a/turbo/jsonrpc/send_transaction.go b/turbo/jsonrpc/send_transaction.go index db237e9d680..fb9637e0d37 100644 --- a/turbo/jsonrpc/send_transaction.go +++ b/turbo/jsonrpc/send_transaction.go @@ -63,6 +63,10 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutility } } + if api.RejectLowGasPriceTransactions && txn.GetPrice().Uint64() < api.DefaultGasPrice { + return common.Hash{}, errors.New("transaction price is too low") + } + // If the transaction fee cap is already specified, ensure the // fee of the given transaction is _reasonable_. if err := checkTxFee(txn.GetPrice().ToBig(), txn.GetGas(), api.FeeCap); err != nil {