fix(gas-manager): keep legacy gas price history per chain - #222
Merged
Conversation
getGasPrice pushed every chain's gas price into one shared rolling history and took the median across it. Chains served by the same node differ by orders of magnitude, so that median is meaningless, and the outlier checks then discard a chain's real price in favour of it: ratio < 50% -> "stale/broken", use the median ratio > 500% -> "outlier", use the median Observed on the staging node: Avalanche Fuji reports 160 wei, but was priced at 2,751,100,000,000 wei, which is the Chiliz median plus the 10% standard buffer. Production shows the inverse, with the cheap chains dominating the median: Chiliz real 2501 gwei priced 0.0387 gwei Polygon real 281 gwei priced 0.0698 gwei Monad real 102 gwei priced 0.0387 gwei Apechain real 102 gwei priced 0.0550 gwei Sonic/Sei real 55 gwei priced 0.0387 gwei Key the history by chainId so each chain's median is computed from its own samples. Adds a regression test covering both directions of the mixture.
vr16x
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GasManagerService.getGasPricemaintained a single rolling history shared by every chain the node serves:Gas prices across our chains differ by orders of magnitude, so the median of that mixture is meaningless. The outlier checks then throw away a chain's real price in favour of the mixture's median:
The result is that a chain gets priced using an unrelated chain's gas price.
Impact observed on live nodes
Staging — Chiliz Spicy dominates traffic (2,925 log lines vs 18 for Fuji in one window), so it sets the median:
That value is exactly the Chiliz median plus the 10% standard buffer (
2501 gwei x 1.10). A client hit this as repeated execution failures on Fuji.Production — the cheap chains dominate instead, so expensive chains are badly underpriced:
Ethereum and Base look correct only because they sit near the mixture's median.
Fix
Key the history by
chainIdso each chain's median is computed from its own samples. No change to the buffering or outlier logic itself.Tests
New
gas-manager.service.test.tscovers both directions:Verified the tests fail on the previous behaviour, reproducing the exact production value:
Follow-up worth considering (not in this PR)
The
currentToMedianRatio < 50nbranch treats a genuinely low price as "stale/broken". Now that history is per chain that is much safer, but a real sustained drop (as Avalanche had post-ACP-176) would still be discarded for a while. Worth revisiting separately.