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

Create uninitialized task for v1 gas price service #2442

Merged
merged 54 commits into from
Dec 6, 2024

Conversation

MitchTurner
Copy link
Member

@MitchTurner MitchTurner commented Nov 18, 2024

Linked Issues/PRs

part of #2140

Description

Adding the UninitializedTask with minimum test coverage.

Because of how we are organizing #2415, I don't believe we need to do any syncing of the DA Cost service before startup. If it's "behind" somehow, then the old values it provides will just be ignored. It might result in a little error in the profit value early on, but it will get washed out pretty quickly.

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 base branch from master to feature/allow-DA-blocks-to-be-received-out-of-order November 19, 2024 02:45
netrome
netrome previously approved these changes Nov 20, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

let start = read_algo.next_gas_price();
let mut watcher = StateWatcher::started();
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason this isn't StateWatcher::default()?

Copy link
Member Author

Choose a reason for hiding this comment

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

There were some places that process_l2_block_res wasn't getting called because of get_l2_block yielding a result, but because the service was shutting down (and we always check if there is an l2 block available before shutting down).

I added the started in a few places that it was shutting down early.

That being said, this isn't doing what the test says it's doing next__new_l2_block_saves_old_metadata. It's checking the gas price:

    // then
    let new = read_algo.next_gas_price();
    assert_ne!(start, new);

So I'll fix that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -141,13 +141,15 @@ where
Metadata: MetadataStorage,
{
async fn run(&mut self, watcher: &mut StateWatcher) -> TaskNextAction {
tracing::debug!("Starting gas price service");
Copy link
Contributor

Choose a reason for hiding this comment

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

We might not want to log a "sunny day" events on the debug! level. Please consider using trace!.

Reference: this comment (and a couple of other comments in the linked PR).

@rymnc rymnc self-requested a review November 28, 2024 08:08
rymnc
rymnc previously approved these changes Nov 28, 2024
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

LGTM

Base automatically changed from feature/allow-DA-blocks-to-be-received-out-of-order to master November 29, 2024 00:14
@MitchTurner MitchTurner dismissed stale reviews from rymnc and netrome November 29, 2024 00:14

The base branch was changed.

@rymnc rymnc self-requested a review November 29, 2024 22:18
rymnc
rymnc previously approved these changes Nov 29, 2024
crates/services/gas_price_service/src/v0/service.rs Outdated Show resolved Hide resolved
@@ -92,7 +92,9 @@ impl From<&V1AlgorithmConfig> for AlgorithmUpdaterV1 {
.map(|size| u128::from(*size))
.sum();
Self {
new_scaled_exec_price: value.new_exec_gas_price,
new_scaled_exec_price: value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we multiple by the gas_price_factor here? And what is gas_price_factor? I don't see where this value comes from and it is not clear what is the purpose of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

The gas_price_factor is just a scaling factor to make sure we can track the change between small values. Like we do for gas costs. If the gas price is 1, it is stored as 100 as the scaled value, then we can increase it by 10% or 5% under the hood but it will still be returned as 1 until it crosses 150 or whatever.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The gas price factor can be different on different heights. Do we take it into account?

I though we work with Wei and because of that we don't need to scale gas price.

Copy link
Member Author

@MitchTurner MitchTurner Dec 6, 2024

Choose a reason for hiding this comment

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

What if the price is 1 Wei, which it often is? Possibly less so in the future, but still.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a TODO to remove this with this issue:
#2481

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better if you added todo for the field of the config instead of here=)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll move it in my next pr. Gonna merge.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved here:
abf0cca

pub block_stream: BoxStream<SharedImportResult>,
pub(crate) shared_algo: SharedV1Algorithm,
pub(crate) algo_updater: AlgorithmUpdaterV1,
pub(crate) metadata_storage: Metadata,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is metadata generic? We agreed in the past that the V1 service will work with V1 metadata. In this case, we don't need to over-abstract things and can work directly with the right type that belongs to the service.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or is it MetadataStorage? Then why do we have MetadataStorage and gas_price_db? Maybe gas_price_db could be transactional there associated type Transaction implements MetadataStorage trait?

Copy link
Member Author

Choose a reason for hiding this comment

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

Working on this in the next PR for the unrecorded blocks stuff.

config: V1AlgorithmConfig,
genesis_block_height: BlockHeight,
settings: SettingsProvider,
block_stream: BoxStream<SharedImportResult>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is better to have stream here, because we plan to work with the stream. We could use generic for the stream, but it means one more generic in the already complicated definition.

Boxed stream doesn't hurt the performance here, because we receive event about block each second.

Metadata: MetadataStorage,
DA: DaBlockCostsSource,
{
let v1_config = config.v1().ok_or(anyhow::anyhow!("Expected V1 config"))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

fuel-core should pass GasPriceV1Config based on the variant of the GasPriceConfig enum

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you saying that we should pass GasPriceV0Config in some cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm saying the new_gas_price_service_v1 should expect V1AlgorithmConfig to avoid config.v1().ok_or(anyhow::anyhow!("Expected V1 config"))? conversion.

The fuel-core should decided which gas price to use(0 or 1) based on the enum variant for the GasPriceServiceConfig.

@MitchTurner MitchTurner enabled auto-merge (squash) December 6, 2024 21:54
@MitchTurner MitchTurner merged commit e1ff8d4 into master Dec 6, 2024
31 checks passed
@MitchTurner MitchTurner deleted the feature/init-task-for-v1-gas-price-service branch December 6, 2024 22:56
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.

5 participants