From c87f9bb6b70a7f6926dbc2ee7e38bf44180dbc59 Mon Sep 17 00:00:00 2001 From: Scott Fairclough <70711990+hexoscott@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:33:28 +0000 Subject: [PATCH] tolerance for rejecting transactions based on gas price (#1540) --- cmd/rpcdaemon/commands/eth_api.go | 2 ++ cmd/rpcdaemon/commands/send_transaction.go | 8 ++++++++ cmd/utils/flags.go | 5 +++++ eth/ethconfig/config_zkevm.go | 1 + turbo/cli/default_flags.go | 1 + turbo/cli/flags_zkevm.go | 1 + 6 files changed, 18 insertions(+) diff --git a/cmd/rpcdaemon/commands/eth_api.go b/cmd/rpcdaemon/commands/eth_api.go index d38b50140c0..4f5b75665b3 100644 --- a/cmd/rpcdaemon/commands/eth_api.go +++ b/cmd/rpcdaemon/commands/eth_api.go @@ -349,6 +349,7 @@ type APIImpl struct { L1GasPrice L1GasPrice VirtualCountersSmtReduction float64 RejectLowGasPriceTransactions bool + RejectLowGasPriceTolerance float64 } // NewEthAPI returns APIImpl instance @@ -377,6 +378,7 @@ func NewEthAPI(base *BaseAPI, db kv.RoDB, eth rpchelper.ApiBackend, txPool txpoo L1GasPrice: L1GasPrice{}, VirtualCountersSmtReduction: ethCfg.VirtualCountersSmtReduction, RejectLowGasPriceTransactions: ethCfg.RejectLowGasPriceTransactions, + RejectLowGasPriceTolerance: ethCfg.RejectLowGasPriceTolerance, } } diff --git a/cmd/rpcdaemon/commands/send_transaction.go b/cmd/rpcdaemon/commands/send_transaction.go index 9c3202d196a..1f24b2b48af 100644 --- a/cmd/rpcdaemon/commands/send_transaction.go +++ b/cmd/rpcdaemon/commands/send_transaction.go @@ -59,6 +59,14 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutility return common.Hash{}, err } networkPrice256, _ := uint256.FromBig(networkPrice.ToInt()) + + // drop the network price by the tolerance factor to account for fluctuations + if api.RejectLowGasPriceTolerance > 0 { + modifier := new(uint256.Int).SetUint64(uint64(100 - api.RejectLowGasPriceTolerance*100)) + networkPrice256.Mul(networkPrice256, modifier) + networkPrice256.Div(networkPrice256, uint256.NewInt(100)) + } + if txnPrice.Cmp(networkPrice256) < 0 { return common.Hash{}, fmt.Errorf("transaction price is lower than the current network price") } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ff79848e931..61baf4a72de 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -698,6 +698,11 @@ var ( Usage: "Reject transactions with a gas price lower than the current network price", Value: false, } + RejectLowGasPriceTolerance = cli.Float64Flag{ + Name: "zkevm.reject-low-gas-price-tolerance", + Usage: "Percentage to drop the network price by when rejecting low gas price transactions, 0 means no tolerance, value should be between 0 and 1", + Value: 0, + } ACLPrintHistory = cli.IntFlag{ Name: "acl.print-history", Usage: "Number of entries to print from the ACL history on node start up", diff --git a/eth/ethconfig/config_zkevm.go b/eth/ethconfig/config_zkevm.go index 3c191441d31..c032e905e83 100644 --- a/eth/ethconfig/config_zkevm.go +++ b/eth/ethconfig/config_zkevm.go @@ -88,6 +88,7 @@ type Zk struct { SealBatchImmediatelyOnOverflow bool MockWitnessGeneration bool RejectLowGasPriceTransactions bool + RejectLowGasPriceTolerance float64 } var DefaultZkConfig = &Zk{} diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 62de47bf9f2..bda4e9882d3 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -241,4 +241,5 @@ var DefaultFlags = []cli.Flag{ &utils.SealBatchImmediatelyOnOverflow, &utils.MockWitnessGeneration, &utils.RejectLowGasPriceTransactions, + &utils.RejectLowGasPriceTolerance, } diff --git a/turbo/cli/flags_zkevm.go b/turbo/cli/flags_zkevm.go index 745f069031c..9aa1c0637d5 100644 --- a/turbo/cli/flags_zkevm.go +++ b/turbo/cli/flags_zkevm.go @@ -197,6 +197,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) { SealBatchImmediatelyOnOverflow: ctx.Bool(utils.SealBatchImmediatelyOnOverflow.Name), MockWitnessGeneration: ctx.Bool(utils.MockWitnessGeneration.Name), RejectLowGasPriceTransactions: ctx.Bool(utils.RejectLowGasPriceTransactions.Name), + RejectLowGasPriceTolerance: ctx.Float64(utils.RejectLowGasPriceTolerance.Name), } utils2.EnableTimer(cfg.DebugTimers)