[core]: fix: Cap suggested gas price to 500 gwei

...and set suggested gas percentile to 40 instead of 60.

Recently, the recommended gas price requested via `eth_gasPrice`,
`hmy_gasPrice` or `hmyv2_gasPrice` has been fairly high (think 100k
gwei). This patch changes the maximum suggested gas price via these APIs
to be capped at 500 gwei. Users are still allowed to change the gas
price manually to be higher than this, for faster execution.

The occurence of these extremely high gas prices can be attributed to
the self reinforcing mechanism of this implementation. If some 20 blocks
are produced with extremely high gas prices for all transactions, the
API queries the transactions and returns the (erstwhile) 60th percentile
from them. This then results in a feedback loop for the following
blocks. This loop continues until transactions which do not use the
suggested gas price become part of the following blocks - which in
itself is unlikely, since transactions are sorted by gas price for
inclusion.
pull/4134/head
MaxMustermann2 3 years ago committed by Leo Chen
parent cea90ca4c2
commit c9ec957b4f
  1. 2
      hmy/gasprice.go
  2. 6
      hmy/hmy.go

@ -34,7 +34,7 @@ import (
const sampleNumber = 3 // Number of transactions sampled in a block
var DefaultMaxPrice = big.NewInt(1 * params.Ether)
var DefaultMaxPrice = big.NewInt(5e11) // 500 gwei is the max suggested limit
type GasPriceConfig struct {
Blocks int

@ -151,9 +151,9 @@ func New(
// Setup gas price oracle
gpoParams := GasPriceConfig{
Blocks: 20,
Percentile: 60,
Default: big.NewInt(3e10),
Blocks: 20, // take all eligible txs past 20 blocks and sort them
Percentile: 40, // get the 40th percentile when sorted in an ascending manner
Default: big.NewInt(3e10), // minimum of 30 gwei
}
gpo := NewOracle(backend, gpoParams)
backend.gpo = gpo

Loading…
Cancel
Save