From 469d44379deb26c4536ceb2e4d1f66c9b5188bf6 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:27:26 +0530 Subject: [PATCH] fix(gas_price_service): service name and unused trait impl (#2317) ## Linked Issues/PRs - none ## Description Unused trait impl `RunnableService` moved to tests where it's actually used. ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] 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] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --- .../gas_price_service/src/v0/service.rs | 60 ++++++++++--------- .../src/v0/uninitialized_task.rs | 7 ++- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/crates/services/gas_price_service/src/v0/service.rs b/crates/services/gas_price_service/src/v0/service.rs index 00df5bb8a68..04254f67cb5 100644 --- a/crates/services/gas_price_service/src/v0/service.rs +++ b/crates/services/gas_price_service/src/v0/service.rs @@ -10,7 +10,6 @@ use crate::{ use anyhow::anyhow; use async_trait::async_trait; use fuel_core_services::{ - RunnableService, RunnableTask, StateWatcher, }; @@ -116,32 +115,6 @@ where } } -#[async_trait] -impl RunnableService for GasPriceServiceV0 -where - L2: L2BlockSource, - Metadata: MetadataStorage, -{ - const NAME: &'static str = "GasPriceServiceV0"; - type SharedData = SharedV0Algorithm; - type Task = Self; - type TaskParams = (); - - fn shared_data(&self) -> Self::SharedData { - self.shared_algo.clone() - } - - async fn into_task( - mut self, - _state_watcher: &StateWatcher, - _params: Self::TaskParams, - ) -> anyhow::Result { - let algorithm = self.algorithm_updater.algorithm(); - self.shared_algo.update(algorithm).await; - Ok(self) - } -} - #[async_trait] impl RunnableTask for GasPriceServiceV0 where @@ -194,17 +167,48 @@ mod tests { v0::{ metadata::V0Metadata, service::GasPriceServiceV0, - uninitialized_task::initialize_algorithm, + uninitialized_task::{ + initialize_algorithm, + SharedV0Algorithm, + }, }, }; use fuel_core_services::{ + RunnableService, Service, ServiceRunner, + StateWatcher, }; use fuel_core_types::fuel_types::BlockHeight; use std::sync::Arc; use tokio::sync::mpsc; + #[async_trait::async_trait] + impl RunnableService for GasPriceServiceV0 + where + L2: L2BlockSource, + Metadata: MetadataStorage, + { + const NAME: &'static str = "GasPriceServiceV0"; + type SharedData = SharedV0Algorithm; + type Task = Self; + type TaskParams = (); + + fn shared_data(&self) -> Self::SharedData { + self.shared_algo.clone() + } + + async fn into_task( + mut self, + _state_watcher: &StateWatcher, + _params: Self::TaskParams, + ) -> anyhow::Result { + let algorithm = self.algorithm_updater.algorithm(); + self.shared_algo.update(algorithm).await; + Ok(self) + } + } + struct FakeL2BlockSource { l2_block: mpsc::Receiver, } diff --git a/crates/services/gas_price_service/src/v0/uninitialized_task.rs b/crates/services/gas_price_service/src/v0/uninitialized_task.rs index b21c82635a9..bd58db174c7 100644 --- a/crates/services/gas_price_service/src/v0/uninitialized_task.rs +++ b/crates/services/gas_price_service/src/v0/uninitialized_task.rs @@ -190,7 +190,7 @@ where GasPriceData + Modifiable + KeyValueInspect + Clone, SettingsProvider: GasPriceSettingsProvider, { - const NAME: &'static str = "UninitializedGasPriceServiceV0"; + const NAME: &'static str = "GasPriceServiceV0"; type SharedData = SharedV0Algorithm; type Task = GasPriceServiceV0< FuelL2BlockSource, @@ -360,7 +360,8 @@ where GasPriceData + Modifiable + KeyValueInspect + Clone, SettingsProvider: GasPriceSettingsProvider, { - let gas_price_init = UninitializedTask::new( + // lazy initialization of gas price service, delegate to parent + let gas_price_uninit = UninitializedTask::new( config, genesis_block_height, settings, @@ -368,5 +369,5 @@ where gas_price_db, on_chain_db, )?; - Ok(ServiceRunner::new(gas_price_init)) + Ok(ServiceRunner::new(gas_price_uninit)) }