Submitted by berndartmueller, also found by deliriusz and p0wd3r
The median gas price used within ZetaChain may be inaccurate and lagging, causing outbound transactions to be underpriced and pending in the mempool and gas fees to be underpaid by users.
ZetaChain observers, i.e., zetaclients, watch the gas prices of the external chains and submit the current prices to ZetaChain by broadcasting the MsgGasPriceVoter message. This message is processed by the GasPriceVoter function in node/x/crosschain/keeper/keepergasprice.go#L125-L187.
Each observers gas price vote is stored in the GasPrice struct in the Prices array and the gas price is determined by using the median of the stored values in line 167.
The number of ZetaChain observers can increase or decrease over time, e.g., due to validator nodes exiting the network, slashing, or observers being removed/added by the admin.
This leads to an issue as there will be stale gas price vote entries in the GasPrice.Prices array that will affect the median calculation. As a result, the calculated gas price may be inaccurate and lag behind the actual gas price.
Consider the following example:
Given 9 observers and their gas price votes:
Sorting the gas prices in ascending order:
The median gas price is: 10 (from the observer with index 0)
Now, lets assume that 4 of the observers (observers 0, 1, 2, 3 - marked with *) are inactive and do not submit gas price votes anymore. The remaining observers continue to submit gas prices (gas price spiked)
Sorting the gas prices in ascending order:
The median gas price is: 40 (from the observer with index 4)
As observers 0, 1, 2, and 3 are inactive, their stale gas price votes are still considered in the median calculation, leading to a lagging gas price. If we would ignore the inactive observers, the median gas price would be 70.
This can be mitigated by using the block height of the submitted gas price vote, stored in GasPrice.BlockNums and ignoring stale votes.
Consider filtering out stale gas price votes based on the block height of the vote to prevent lagging gas prices.
lumtis (ZetaChain) confirmed
