Skip to content

Commit e0f8796

Browse files
authored
add flag to reject transactions below default config (#1602) (#1604)
1 parent 775a02e commit e0f8796

File tree

6 files changed

+59
-45
lines changed

6 files changed

+59
-45
lines changed

cmd/utils/flags.go

+5
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ var (
667667
Usage: "Allow the sequencer to proceed transactions with 0 gas price",
668668
Value: false,
669669
}
670+
RejectLowGasPriceTransactions = cli.BoolFlag{
671+
Name: "zkevm.reject-low-gas-price-transactions",
672+
Usage: "Reject the sequencer to proceed transactions with low gas price",
673+
Value: false,
674+
}
670675
AllowPreEIP155Transactions = cli.BoolFlag{
671676
Name: "zkevm.allow-pre-eip155-transactions",
672677
Usage: "Allow the sequencer to proceed pre-EIP155 transactions",

eth/ethconfig/config_zkevm.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Zk struct {
5353
ExecutorMaxConcurrentRequests int
5454
Limbo bool
5555
AllowFreeTransactions bool
56+
RejectLowGasPriceTransactions bool
5657
AllowPreEIP155Transactions bool
5758
EffectiveGasPriceForEthTransfer uint8
5859
EffectiveGasPriceForErc20Transfer uint8

turbo/cli/default_flags.go

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ var DefaultFlags = []cli.Flag{
221221
&utils.ExecutorMaxConcurrentRequests,
222222
&utils.Limbo,
223223
&utils.AllowFreeTransactions,
224+
&utils.RejectLowGasPriceTransactions,
224225
&utils.AllowPreEIP155Transactions,
225226
&utils.EffectiveGasPriceForEthTransfer,
226227
&utils.EffectiveGasPriceForErc20Transfer,

turbo/cli/flags_zkevm.go

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
195195
ExecutorMaxConcurrentRequests: ctx.Int(utils.ExecutorMaxConcurrentRequests.Name),
196196
Limbo: ctx.Bool(utils.Limbo.Name),
197197
AllowFreeTransactions: ctx.Bool(utils.AllowFreeTransactions.Name),
198+
RejectLowGasPriceTransactions: ctx.Bool(utils.RejectLowGasPriceTransactions.Name),
198199
AllowPreEIP155Transactions: ctx.Bool(utils.AllowPreEIP155Transactions.Name),
199200
EffectiveGasPriceForEthTransfer: uint8(math.Round(effectiveGasPriceForEthTransferVal * 255.0)),
200201
EffectiveGasPriceForErc20Transfer: uint8(math.Round(effectiveGasPriceForErc20TransferVal * 255.0)),

turbo/jsonrpc/eth_api.go

+47-45
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,29 @@ func (api *BaseAPI) pruneMode(tx kv.Tx) (*prune.Mode, error) {
353353
// APIImpl is implementation of the EthAPI interface based on remote Db access
354354
type APIImpl struct {
355355
*BaseAPI
356-
ethBackend rpchelper.ApiBackend
357-
txPool txpool.TxpoolClient
358-
mining txpool.MiningClient
359-
gasCache *GasPriceCache
360-
db kv.RoDB
361-
GasCap uint64
362-
FeeCap float64
363-
ReturnDataLimit int
364-
ZkRpcUrl string
365-
PoolManagerUrl string
366-
AllowFreeTransactions bool
367-
AllowPreEIP155Transactions bool
368-
AllowUnprotectedTxs bool
369-
MaxGetProofRewindBlockCount int
370-
L1RpcUrl string
371-
DefaultGasPrice uint64
372-
MaxGasPrice uint64
373-
GasPriceFactor float64
374-
L1GasPrice L1GasPrice
375-
SubscribeLogsChannelSize int
376-
logger log.Logger
377-
VirtualCountersSmtReduction float64
356+
ethBackend rpchelper.ApiBackend
357+
txPool txpool.TxpoolClient
358+
mining txpool.MiningClient
359+
gasCache *GasPriceCache
360+
db kv.RoDB
361+
GasCap uint64
362+
FeeCap float64
363+
ReturnDataLimit int
364+
ZkRpcUrl string
365+
PoolManagerUrl string
366+
AllowFreeTransactions bool
367+
AllowPreEIP155Transactions bool
368+
AllowUnprotectedTxs bool
369+
MaxGetProofRewindBlockCount int
370+
L1RpcUrl string
371+
DefaultGasPrice uint64
372+
MaxGasPrice uint64
373+
GasPriceFactor float64
374+
L1GasPrice L1GasPrice
375+
SubscribeLogsChannelSize int
376+
logger log.Logger
377+
VirtualCountersSmtReduction float64
378+
RejectLowGasPriceTransactions bool
378379
}
379380

380381
// NewEthAPI returns APIImpl instance
@@ -384,29 +385,30 @@ func NewEthAPI(base *BaseAPI, db kv.RoDB, eth rpchelper.ApiBackend, txPool txpoo
384385
}
385386

386387
return &APIImpl{
387-
BaseAPI: base,
388-
db: db,
389-
ethBackend: eth,
390-
txPool: txPool,
391-
mining: mining,
392-
gasCache: NewGasPriceCache(),
393-
GasCap: gascap,
394-
FeeCap: feecap,
395-
AllowUnprotectedTxs: allowUnprotectedTxs,
396-
ReturnDataLimit: returnDataLimit,
397-
ZkRpcUrl: ethCfg.L2RpcUrl,
398-
PoolManagerUrl: ethCfg.PoolManagerUrl,
399-
AllowFreeTransactions: ethCfg.AllowFreeTransactions,
400-
AllowPreEIP155Transactions: ethCfg.AllowPreEIP155Transactions,
401-
MaxGetProofRewindBlockCount: maxGetProofRewindBlockCount,
402-
L1RpcUrl: ethCfg.L1RpcUrl,
403-
DefaultGasPrice: ethCfg.DefaultGasPrice,
404-
MaxGasPrice: ethCfg.MaxGasPrice,
405-
GasPriceFactor: ethCfg.GasPriceFactor,
406-
L1GasPrice: L1GasPrice{},
407-
SubscribeLogsChannelSize: subscribeLogsChannelSize,
408-
logger: logger,
409-
VirtualCountersSmtReduction: ethCfg.VirtualCountersSmtReduction,
388+
BaseAPI: base,
389+
db: db,
390+
ethBackend: eth,
391+
txPool: txPool,
392+
mining: mining,
393+
gasCache: NewGasPriceCache(),
394+
GasCap: gascap,
395+
FeeCap: feecap,
396+
AllowUnprotectedTxs: allowUnprotectedTxs,
397+
ReturnDataLimit: returnDataLimit,
398+
ZkRpcUrl: ethCfg.L2RpcUrl,
399+
PoolManagerUrl: ethCfg.PoolManagerUrl,
400+
AllowFreeTransactions: ethCfg.AllowFreeTransactions,
401+
AllowPreEIP155Transactions: ethCfg.AllowPreEIP155Transactions,
402+
MaxGetProofRewindBlockCount: maxGetProofRewindBlockCount,
403+
L1RpcUrl: ethCfg.L1RpcUrl,
404+
DefaultGasPrice: ethCfg.DefaultGasPrice,
405+
MaxGasPrice: ethCfg.MaxGasPrice,
406+
GasPriceFactor: ethCfg.GasPriceFactor,
407+
L1GasPrice: L1GasPrice{},
408+
SubscribeLogsChannelSize: subscribeLogsChannelSize,
409+
logger: logger,
410+
VirtualCountersSmtReduction: ethCfg.VirtualCountersSmtReduction,
411+
RejectLowGasPriceTransactions: ethCfg.RejectLowGasPriceTransactions,
410412
}
411413
}
412414

turbo/jsonrpc/send_transaction.go

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutility
6363
}
6464
}
6565

66+
if api.RejectLowGasPriceTransactions && txn.GetPrice().Uint64() < api.DefaultGasPrice {
67+
return common.Hash{}, errors.New("transaction price is too low")
68+
}
69+
6670
// If the transaction fee cap is already specified, ensure the
6771
// fee of the given transaction is _reasonable_.
6872
if err := checkTxFee(txn.GetPrice().ToBig(), txn.GetGas(), api.FeeCap); err != nil {

0 commit comments

Comments
 (0)