Skip to content

Commit 54db35b

Browse files
authoredJan 6, 2025
add flag to reject transactions below default config (#1602)
1 parent 6f83396 commit 54db35b

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
@@ -662,6 +662,11 @@ var (
662662
Usage: "Allow the sequencer to proceed transactions with 0 gas price",
663663
Value: false,
664664
}
665+
RejectLowGasPriceTransactions = cli.BoolFlag{
666+
Name: "zkevm.reject-low-gas-price-transactions",
667+
Usage: "Reject the sequencer to proceed transactions with low gas price",
668+
Value: false,
669+
}
665670
AllowPreEIP155Transactions = cli.BoolFlag{
666671
Name: "zkevm.allow-pre-eip155-transactions",
667672
Usage: "Allow the sequencer to proceed pre-EIP155 transactions",

‎eth/ethconfig/config_zkevm.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type Zk struct {
5454
ExecutorMaxConcurrentRequests int
5555
Limbo bool
5656
AllowFreeTransactions bool
57+
RejectLowGasPriceTransactions bool
5758
AllowPreEIP155Transactions bool
5859
EffectiveGasPriceForEthTransfer uint8
5960
EffectiveGasPriceForErc20Transfer uint8

‎turbo/cli/default_flags.go

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

‎turbo/cli/flags_zkevm.go

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
189189
ExecutorMaxConcurrentRequests: ctx.Int(utils.ExecutorMaxConcurrentRequests.Name),
190190
Limbo: ctx.Bool(utils.Limbo.Name),
191191
AllowFreeTransactions: ctx.Bool(utils.AllowFreeTransactions.Name),
192+
RejectLowGasPriceTransactions: ctx.Bool(utils.RejectLowGasPriceTransactions.Name),
192193
AllowPreEIP155Transactions: ctx.Bool(utils.AllowPreEIP155Transactions.Name),
193194
EffectiveGasPriceForEthTransfer: uint8(math.Round(effectiveGasPriceForEthTransferVal * 255.0)),
194195
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)