Skip to content

Commit 34d6e65

Browse files
committed
Add --rpc.gaspricemultiplier option
This add command line option to adjust the multiplier in the gas price suggestion RPC endpoint.
1 parent a72fd91 commit 34d6e65

File tree

10 files changed

+51
-14
lines changed

10 files changed

+51
-14
lines changed

cmd/geth/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ var (
192192
utils.IPCPathFlag,
193193
utils.InsecureUnlockAllowedFlag,
194194
utils.RPCGlobalGasInflationRateFlag,
195+
utils.RPCGlobalGasPriceMultiplierFlag,
195196
utils.RPCGlobalGasCapFlag,
196197
utils.RPCGlobalTxFeeCapFlag,
197198
}

cmd/geth/usage.go

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
139139
utils.GraphQLCORSDomainFlag,
140140
utils.GraphQLVirtualHostsFlag,
141141
utils.RPCGlobalGasInflationRateFlag,
142+
utils.RPCGlobalGasPriceMultiplierFlag,
142143
utils.RPCGlobalGasCapFlag,
143144
utils.RPCGlobalTxFeeCapFlag,
144145
utils.JSpathFlag,

cmd/utils/flags.go

+15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io"
2424
"io/ioutil"
2525
"math"
26+
"math/big"
2627
"path/filepath"
2728
godebug "runtime/debug"
2829
"strconv"
@@ -445,6 +446,11 @@ var (
445446
Usage: "Multiplier applied to the gasEstimation rpc call (1 = gasEstimation, 1.3 = gasEstimation + 30%, etc. Defaults to 1.3)",
446447
Value: ethconfig.Defaults.RPCGasInflationRate,
447448
}
449+
RPCGlobalGasPriceMultiplierFlag = cli.Float64Flag{
450+
Name: "rpc.gaspricemultiplier",
451+
Usage: "Multiplier applied to the gasPrice rpc call (1 = gasPrice, 1.3 = gasPrice + 30%, etc. Defaults to 2.0)",
452+
Value: 2.0,
453+
}
448454
RPCGlobalGasCapFlag = cli.Uint64Flag{
449455
Name: "rpc.gascap",
450456
Usage: "Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)",
@@ -1746,6 +1752,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17461752
if ctx.GlobalIsSet(RPCGlobalGasInflationRateFlag.Name) {
17471753
cfg.RPCGasInflationRate = ctx.GlobalFloat64(RPCGlobalGasInflationRateFlag.Name)
17481754
}
1755+
if ctx.GlobalIsSet(RPCGlobalGasPriceMultiplierFlag.Name) {
1756+
floatMutliplier := ctx.GlobalFloat64(RPCGlobalGasPriceMultiplierFlag.Name)
1757+
if floatMutliplier <= 1.0 {
1758+
log.Warn("Too low RPCGasPriceMultiplier, setting to 1.0", "provided value", floatMutliplier)
1759+
floatMutliplier = 1.0
1760+
}
1761+
1762+
cfg.RPCGasPriceMultiplier = big.NewInt(int64(floatMutliplier * 100))
1763+
}
17491764
if cfg.RPCGasInflationRate < 1 {
17501765
Fatalf("The inflation rate shouldn't be less than 1: %f", cfg.RPCGasInflationRate)
17511766
}

contracts/gasprice_minimum/gasprice_minimum.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535

3636
var (
3737
FallbackGasPriceMinimum *big.Int = big.NewInt(0) // gas price minimum to return if unable to fetch from contract
38-
suggestionMultiplier *big.Int = big.NewInt(5) // The multiplier that we apply to the minimum when suggesting gas price
3938
)
4039

4140
const (
@@ -62,9 +61,12 @@ func GetGasTipCapSuggestion(vmRunner vm.EVMRunner, currencyAddress *common.Addre
6261

6362
// GetGasPriceSuggestion suggests a gas price the suggestionMultiplier times higher than the GPM in the appropriate currency.
6463
// TODO: Switch to using a caching GPM manager under high load.
65-
func GetGasPriceSuggestion(vmRunner vm.EVMRunner, currency *common.Address) (*big.Int, error) {
64+
func GetGasPriceSuggestion(vmRunner vm.EVMRunner, currency *common.Address, multiplier *big.Int) (*big.Int, error) {
6665
gasPriceMinimum, err := GetGasPriceMinimum(vmRunner, currency)
67-
return new(big.Int).Mul(gasPriceMinimum, suggestionMultiplier), err
66+
67+
gasPriceWithMultiplier := new(big.Int).Mul(gasPriceMinimum, multiplier)
68+
res := new(big.Int).Div(gasPriceWithMultiplier, big.NewInt(100))
69+
return res, err
6870
}
6971

7072
func GetGasPriceMinimum(vmRunner vm.EVMRunner, currency *common.Address) (*big.Int, error) {

contracts/gasprice_minimum/gasprice_minimum_test.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestGetGasPriceSuggestion(t *testing.T) {
1515
celoAddress := common.HexToAddress("0x076")
1616
gpmAddress := common.HexToAddress("0x090")
1717

18-
t.Run("should return gas price minimum multiplied by 5", func(t *testing.T) {
18+
t.Run("should return gas price minimum multiplied with factor", func(t *testing.T) {
1919
g := NewGomegaWithT(t)
2020

2121
runner := testutil.NewMockEVMRunner()
@@ -29,11 +29,18 @@ func TestGetGasPriceSuggestion(t *testing.T) {
2929
runner.RegisterContract(gpmAddress, contract)
3030
registry.AddContract(config.GasPriceMinimumRegistryId, gpmAddress)
3131

32-
suggestedGpm, err := GetGasPriceSuggestion(runner, nil)
32+
suggestedGpm, err := GetGasPriceSuggestion(runner, nil, big.NewInt(500))
3333
g.Expect(err).NotTo(HaveOccurred())
34-
3534
g.Expect(suggestedGpm.Uint64()).To(Equal(uint64(777777 * 5)))
3635

36+
suggestedGpm, err = GetGasPriceSuggestion(runner, nil, big.NewInt(100))
37+
g.Expect(err).NotTo(HaveOccurred())
38+
g.Expect(suggestedGpm.Uint64()).To(Equal(uint64(777777)))
39+
40+
suggestedGpm, err = GetGasPriceSuggestion(runner, nil, big.NewInt(110))
41+
g.Expect(err).NotTo(HaveOccurred())
42+
g.Expect(suggestedGpm.Uint64()).To(Equal(uint64(855554)))
43+
3744
})
3845
}
3946
func TestGetGasPriceMinimum(t *testing.T) {

eth/api_backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (b *EthAPIBackend) SuggestPrice(ctx context.Context, currencyAddress *commo
330330
if err != nil {
331331
return nil, err
332332
}
333-
return gpm.GetGasPriceSuggestion(vmRunner, currencyAddress)
333+
return gpm.GetGasPriceSuggestion(vmRunner, currencyAddress, b.eth.config.RPCGasPriceMultiplier)
334334
}
335335

336336
func (b *EthAPIBackend) GetBlockGasLimit(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) uint64 {

eth/ethconfig/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ type Config struct {
139139
// RPCGasInflationRate is a global multiplier applied to the gas estimations
140140
RPCGasInflationRate float64
141141

142+
// RPCGasPriceMultiplier is a global multiplier applied to the gas price
143+
// It's a percent value, e.g. 120 means a multiplication factor of 1.2
144+
RPCGasPriceMultiplier *big.Int
145+
142146
// RPCGasCap is the global gas cap for eth-call variants.
143147
RPCGasCap uint64
144148

eth/ethconfig/gen_config.go

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

les/api_backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (b *LesApiBackend) SuggestPrice(ctx context.Context, currencyAddress *commo
273273
if err != nil {
274274
return nil, err
275275
}
276-
return gpm.GetGasPriceSuggestion(vmRunner, currencyAddress)
276+
return gpm.GetGasPriceSuggestion(vmRunner, currencyAddress, b.eth.config.RPCGasPriceMultiplier)
277277
}
278278

279279
func (b *LesApiBackend) GetIntrinsicGasForAlternativeFeeCurrency(ctx context.Context) uint64 {

test/node.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ var (
5959
}
6060

6161
BaseEthConfig = &eth.Config{
62-
SyncMode: downloader.FullSync,
63-
MinSyncPeers: 1,
64-
DatabaseCache: 256,
65-
DatabaseHandles: 256,
66-
TxPool: core.DefaultTxPoolConfig,
67-
RPCEthCompatibility: true,
62+
SyncMode: downloader.FullSync,
63+
MinSyncPeers: 1,
64+
DatabaseCache: 256,
65+
DatabaseHandles: 256,
66+
TxPool: core.DefaultTxPoolConfig,
67+
RPCEthCompatibility: true,
68+
RPCGasPriceMultiplier: big.NewInt(100),
6869
Istanbul: istanbul.Config{
6970
Validator: true,
7071
// Set announce gossip period to 1 minute, if not set this results

0 commit comments

Comments
 (0)