Skip to content

Commit

Permalink
add flag to reject transactions below default config (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Jan 6, 2025
1 parent 6f83396 commit 54db35b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Zk struct {
ExecutorMaxConcurrentRequests int
Limbo bool
AllowFreeTransactions bool
RejectLowGasPriceTransactions bool
AllowPreEIP155Transactions bool
EffectiveGasPriceForEthTransfer uint8
EffectiveGasPriceForErc20Transfer uint8
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ var DefaultFlags = []cli.Flag{
&utils.ExecutorMaxConcurrentRequests,
&utils.Limbo,
&utils.AllowFreeTransactions,
&utils.RejectLowGasPriceTransactions,
&utils.AllowPreEIP155Transactions,
&utils.EffectiveGasPriceForEthTransfer,
&utils.EffectiveGasPriceForErc20Transfer,
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
92 changes: 47 additions & 45 deletions turbo/jsonrpc/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down
4 changes: 4 additions & 0 deletions turbo/jsonrpc/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 54db35b

Please sign in to comment.