Skip to content

Commit

Permalink
tolerance for rejecting transactions based on gas price (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Dec 4, 2024
1 parent feca211 commit c87f9bb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ type APIImpl struct {
L1GasPrice L1GasPrice
VirtualCountersSmtReduction float64
RejectLowGasPriceTransactions bool
RejectLowGasPriceTolerance float64
}

// NewEthAPI returns APIImpl instance
Expand Down Expand Up @@ -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,
}
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/rpcdaemon/commands/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -88,6 +88,7 @@ type Zk struct {
SealBatchImmediatelyOnOverflow bool
MockWitnessGeneration bool
RejectLowGasPriceTransactions bool
RejectLowGasPriceTolerance float64
}

var DefaultZkConfig = &Zk{}
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 @@ -241,4 +241,5 @@ var DefaultFlags = []cli.Flag{
&utils.SealBatchImmediatelyOnOverflow,
&utils.MockWitnessGeneration,
&utils.RejectLowGasPriceTransactions,
&utils.RejectLowGasPriceTolerance,
}
1 change: 1 addition & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c87f9bb

Please sign in to comment.