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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new FuelGasPriceProvider #1889

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

MitchTurner
Copy link
Member

@MitchTurner MitchTurner commented May 8, 2024

Part of: #1624

Introduce a new type to replace StaticGasPrice that will actually calculate new gas prices based on historical data. For now we're just faking all the input sources to show that the algorithm can work.

This work is largely exploratory since we don't know exactly what the algorithm will land on. This means that the algorithm might need to be moved to a versioned subtype before this work is done. But hopefully we can either land on a good MVP algorithm or unearth more specifications for our algorithm through this work 馃

The current design separates the algorithm from the FuelBlockProvider. This helps identify what behavior is independent of the specifc algorithm we end up choosing and helps us determine the minimum set of variables the algorithm requires. It's possible that we will need more or fewer params. Currently the algorithm looks like this:

pub trait GasPriceAlgorithm {
    fn calculate_gas_price(
        &self,
        previous_gas_price: u64,
        total_production_reward: u64,
        total_da_recording_cost: u64,
        block_fullness: BlockFullness,
    ) -> u64;

    fn maximum_next_gas_price(&self, previous_gas_price: u64) -> u64;
}

Taking the total of both reward and cost could instead be a profitablility ratio, but that robs the control loop of information about the magnitude of the difference in the units of gas_price. i.e. being 20% away from the target profitability is much different if it's accrued over 100 blocks or 100,000 blocks. It's still TBD.

The actual impllementation of the FuelGasPriceAlgo for now is going to take inspiration from a PID control loop, but ideally as simple as possible and as deterministic as possible (we don't want to use floats in places like BlockFullness).

Architecture Diagram (WIP, I'll try to update as it changes). CLICK IF NOT SHOWING UP PROPERLY IN DARK MODE:
image

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@MitchTurner MitchTurner changed the title Create FuelGasPriceProvider Add new FuelGasPriceProvider May 9, 2024
@MitchTurner MitchTurner self-assigned this May 13, 2024
@MitchTurner
Copy link
Member Author

We might want to take into account the average number of txs per block. Or we could get a similar result with an "I" value (PID).

*self.profitablility_totals.totaled_block_height.borrow()
}

fn update_totals(&self, latest_block_height: BlockHeight) -> Result<()> {
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to take into account the fact that DA recording has some lag to it. Possibly 12-24 blocks? How does that effect the gas_price calculation? The current design doesn't take that into account.

Comment on lines +139 to +142
let new_gas_price = core::cmp::min(
new_gas_price_candidate,
self.algorithm.maximum_next_gas_price(previous_gas_price),
);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is kinda a smell. I'm not sure if this should be in the provider or the algo. I'm getting a feeling like the provider and the algo abstractions could be merged some, especially when we start looking at the estimation trait impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant