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

Open
wants to merge 15 commits into
base: feature/allow-DA-blocks-to-be-received-out-of-order
Choose a base branch
from

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
@MitchTurner MitchTurner marked this pull request as ready for review November 20, 2024 08:54
@MitchTurner MitchTurner self-assigned this Nov 20, 2024
DA: DaBlockCostsSource,
SettingsProvider: GasPriceSettingsProvider,
{
const NAME: &'static str = "GasPriceServiceV0";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const NAME: &'static str = "GasPriceServiceV0";
const NAME: &'static str = "GasPriceServiceV1";

Comment on lines 218 to 241
pub fn initialize_algorithm<Metadata>(
config: &V1AlgorithmConfig,
latest_block_height: u32,
metadata_storage: &Metadata,
) -> GasPriceResult<(AlgorithmUpdaterV1, SharedV1Algorithm)>
where
Metadata: MetadataStorage,
{
let algorithm_updater;
if let Some(updater_metadata) = metadata_storage
.get_metadata(&latest_block_height.into())
.map_err(|err| GasPriceError::CouldNotInitUpdater(anyhow::anyhow!(err)))?
{
let previous_metadata: V1Metadata = updater_metadata.try_into()?;
algorithm_updater = v1_algorithm_from_metadata(previous_metadata, config);
} else {
algorithm_updater = config.into();
}

let shared_algo =
SharedGasPriceAlgo::new_with_algorithm(algorithm_updater.algorithm());

Ok((algorithm_updater, shared_algo))
}
Copy link
Member

Choose a reason for hiding this comment

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

i think this is a dupe of initialize_algorithm from the v1/service.rs file, right?

Copy link
Member

Choose a reason for hiding this comment

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

@MitchTurner
Copy link
Member Author

There is also the case where we have unrecorded blocks in the metadata that the committer has already reported. In that case we might want to recursively ask for batches of our smallest heights. The problem is we can't be sure we've got all the correct batches since the lowest height might be skipped.

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

Choose a reason for hiding this comment

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

Do we need to box this stream? Can't we just be generic over the stream here to be more flexible for e.g. tests?

};
use fuel_gas_price_algorithm::v1::AlgorithmUpdaterV1;

pub struct UninitializedTask<
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following why we need a separate UninitializedTask. As I read this, the purpose of this type is to separate task creation (UninitializedTask::new) and initialization UninitializedTask::init. I don't see any extra information being provided during initialization, so what's the benefit of doing this over having a single function that returns GasPriceServiceV1 directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Resolved offline.

Copy link
Contributor

Choose a reason for hiding this comment

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

Summary: The initialization logic depends on database concepts (getting blocks at different heights etc.) that we don't want the gas price algo to be aware of, to maintain a good separation between domain and integration logic. Ideally this initialization logic shouldn't even be here but rather closer to the fuel-core code that starts the services, but for the time being it's better to keep it isolated to this particular task.

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()?

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.

3 participants