Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix volatile eth_gasPrice #2006

Merged
merged 7 commits into from
Dec 30, 2024
Merged

Fix volatile eth_gasPrice #2006

merged 7 commits into from
Dec 30, 2024

Conversation

jewei1997
Copy link
Contributor

@jewei1997 jewei1997 commented Dec 28, 2024

Describe your changes and provide context

Our current eth_gasPrice uses the reward of the 50th percentile tx in the latest block as part of the calculation. This works decently well if the previous block is congested. However, if the previous block had only 1 tx where the user dramatically overpriced their tx, it will return a very high reward. This often causes our eth_gasPrice endpoint to jump around erratically.

This change uses the previous block's total gas used to determine if the block is congested. If the previous block is congested, we will use the previous logic of 50% of reward. Otherwise, eth_gasPrice now pulls the latest base fee and increases it by 10% to ensure the user's tx can be included in a timely manner without dramatically overpaying.

This also makes a similar adjustment to eth_maxPriorityFeePerGas where if the chain is not congested, a default priority fee of 1gwei is returned to the user.

Testing performed to validate your change

existing unit testing + manually patched it onto an RPC node.

Copy link

codecov bot commented Dec 28, 2024

Codecov Report

Attention: Patch coverage is 67.30769% with 17 lines in your changes missing coverage. Please review.

Project coverage is 61.34%. Comparing base (2dc5cc9) to head (6a39936).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
evmrpc/info.go 67.30% 11 Missing and 6 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2006      +/-   ##
==========================================
- Coverage   61.36%   61.34%   -0.02%     
==========================================
  Files         263      263              
  Lines       24483    24525      +42     
==========================================
+ Hits        15024    15045      +21     
- Misses       8341     8358      +17     
- Partials     1118     1122       +4     
Files with missing lines Coverage Δ
evmrpc/info.go 71.01% <67.30%> (-1.11%) ⬇️

... and 1 file with indirect coverage changes

@jewei1997 jewei1997 requested a review from codchen December 30, 2024 03:38
continue
}
// okay to get from latest since receipt is immutable
receipt, err := i.keeper.GetReceipt(i.ctxProvider(LatestCtxHeight), ethtx.Hash())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to check if receipt.BlockHeight matches height in block, and ignore if mismatch

@jewei1997 jewei1997 merged commit b125a1a into main Dec 30, 2024
49 checks passed
@jewei1997 jewei1997 deleted the eth-gas-price-fix branch December 30, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants