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

Improve feeHistory performance #5108

Closed
mattsse opened this issue Oct 20, 2023 · 2 comments · Fixed by #5182
Closed

Improve feeHistory performance #5108

mattsse opened this issue Oct 20, 2023 · 2 comments · Fixed by #5182
Assignees
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@mattsse
Copy link
Collaborator

mattsse commented Oct 20, 2023

Describe the feature

currently the feeHistory implementation is very expensive:

it reads the entire recent header range:

let headers = self.provider().sealed_headers_range(start_block..=end_block)?;

and if reward percentiles are provided it computes the reward percentiles based on the request input:

// Percentiles were specified, so we need to collect reward percentile ino
if let Some(percentiles) = &reward_percentiles {
rewards.push(self.calculate_reward_percentiles(percentiles, header).await?);
}

There are two improvements we can make here:

  • cache the base fee per gas and gas used ration per block:
    base_fee_per_gas
    .push(U256::try_from(header.base_fee_per_gas.unwrap_or_default()).unwrap());
    gas_used_ratio.push(header.gas_used as f64 / header.gas_limit as f64);

Another improvement we could do is approximating the reward percentiles by computing the rewards with a certain resolution

Additional context

/// Stores the latest calculated price and its block hash and Cache stores the lowest effective
/// tip values of recent blocks
inner: Mutex<GasPriceOracleInner>,

@mattsse mattsse added C-enhancement New feature or request S-needs-triage This issue needs to be labelled D-good-first-issue Nice and easy! A great choice to get started A-rpc Related to the RPC implementation and removed S-needs-triage This issue needs to be labelled labels Oct 20, 2023
@allnil
Copy link
Contributor

allnil commented Oct 20, 2023

Hey!
Maybe I could do this?

@mattsse
Copy link
Collaborator Author

mattsse commented Oct 20, 2023

awesome,

the second part is probably a bit more complex, but I think we should be fine if we compute a percentiles range with maybe a 0.25 pt resolution so 400 percentile points, so we don't need to recompute them on a per request basis and instead can approximate them with sufficient accuracy.

ptal at the GasOracle, how we cache in there

@mattsse mattsse linked a pull request Oct 27, 2023 that will close this issue
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-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants