Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag to reject transactions below default config #1602

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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