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: edge case divide by zero #8912

Merged
merged 2 commits into from
Jun 18, 2024
Merged

fix: edge case divide by zero #8912

merged 2 commits into from
Jun 18, 2024

Conversation

prestwich
Copy link
Collaborator

@prestwich prestwich commented Jun 17, 2024

Fixes an edge case in fee history endpoint that results in invalid serialization.

  • if gaslimit is 0, there's a divide-by-zero in the fee history endpoint
  • IEEE754 specifies division by 0.0 to yield infinity (or -infinity for -0.0)
  • serde_json serializes infinity as null
  • serde_json cannot deserialize null to infinity
  • in this weird edge case, reth can produce serialized FeeHistory structs that cannot be deserialized

It may seem like this would never occur as blocks cannot have a 0 limit in real life, but genesis files sometimes use 0 placeholders for gas limit, so this would be triggered on fresh nodes using such a genesis

Fix is to check for infinite values and set ratio to 1.0
NaN values are ruled out by casting from an integer

@prestwich prestwich self-assigned this Jun 17, 2024
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

oof, fix looks good though

@onbjerg onbjerg added C-bug An unexpected or incorrect behavior A-rpc Related to the RPC implementation labels Jun 18, 2024
@mattsse mattsse added this pull request to the merge queue Jun 18, 2024
@mattsse mattsse removed this pull request from the merge queue due to a manual request Jun 18, 2024
@mattsse mattsse enabled auto-merge June 18, 2024 11:20
@mattsse mattsse added this pull request to the merge queue Jun 18, 2024
Merged via the queue into main with commit d865e44 Jun 18, 2024
30 checks passed
@mattsse mattsse deleted the prestwich/remove-zero-div branch June 18, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants