From c9ec957b4f74fb41bfe32f219ab56ff141df2215 Mon Sep 17 00:00:00 2001 From: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com> Date: Mon, 11 Apr 2022 08:59:18 +0000 Subject: [PATCH] [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. --- hmy/gasprice.go | 2 +- hmy/hmy.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hmy/gasprice.go b/hmy/gasprice.go index 8c2693663..05cf6b7cd 100644 --- a/hmy/gasprice.go +++ b/hmy/gasprice.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 diff --git a/hmy/hmy.go b/hmy/hmy.go index 2af8d2655..537873030 100644 --- a/hmy/hmy.go +++ b/hmy/hmy.go @@ -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