From ed5c8b4690aa430c3a84b67ae0460d7aed90e87f Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:41:05 +0530 Subject: [PATCH 1/2] chore(gas_price_service): use port for GasPriceSettings instead of concrete type --- .../service/sub_services/algorithm_updater.rs | 54 ++++++++++++------- .../fuel_core_storage_adapter.rs | 2 +- .../l2_source_tests.rs | 1 + 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/crates/fuel-core/src/service/sub_services/algorithm_updater.rs b/crates/fuel-core/src/service/sub_services/algorithm_updater.rs index c7a3f61d9d0..a6f37fa0d17 100644 --- a/crates/fuel-core/src/service/sub_services/algorithm_updater.rs +++ b/crates/fuel-core/src/service/sub_services/algorithm_updater.rs @@ -1,5 +1,3 @@ -use crate::service::adapters::ConsensusParametersProvider; - use fuel_core_gas_price_service::{ fuel_gas_price_updater::{ da_source_adapter::{ @@ -51,16 +49,16 @@ use fuel_core_types::{ services::block_importer::SharedImportResult, }; -type Updater = FuelGasPriceUpdater< - FuelL2BlockSource, +type Updater = FuelGasPriceUpdater< + FuelL2BlockSource, StructuredStorage, DaBlockCostsSharedState, >; -pub struct InitializeTask { +pub struct InitializeTask { pub config: GasPriceServiceConfig, pub genesis_block_height: BlockHeight, - pub settings: ConsensusParametersProvider, + pub settings: SettingsProvider, pub gas_price_db: GasPriceStore, pub on_chain_db: L2DataStoreView, pub block_stream: BoxStream, @@ -68,19 +66,21 @@ pub struct InitializeTask { pub da_block_costs_provider: DaBlockCostsProvider, } -type Task = GasPriceService>; +type Task = + GasPriceService>; -impl - InitializeTask +impl + InitializeTask where L2DataStore: L2Data, L2DataStoreView: AtomicView, GasPriceStore: GasPriceData + MetadataStorage, + SettingsProvider: GasPriceSettingsProvider, { pub fn new( config: GasPriceServiceConfig, genesis_block_height: BlockHeight, - settings: ConsensusParametersProvider, + settings: SettingsProvider, block_stream: BoxStream, gas_price_db: GasPriceStore, on_chain_db: L2DataStoreView, @@ -144,8 +144,8 @@ where Ok(algo) } #[async_trait::async_trait] -impl RunnableService - for InitializeTask +impl RunnableService + for InitializeTask where L2DataStore: L2Data, L2DataStoreView: AtomicView, @@ -153,10 +153,11 @@ where + MetadataStorage + KeyValueInspect + Modifiable, + SettingsProvider: GasPriceSettingsProvider, { const NAME: &'static str = "GasPriceUpdater"; type SharedData = SharedGasPriceAlgo; - type Task = Task; + type Task = Task; type TaskParams = (); fn shared_data(&self) -> Self::SharedData { @@ -191,15 +192,20 @@ where } } -pub fn get_synced_gas_price_updater( +pub fn get_synced_gas_price_updater< + L2DataStore, + L2DataStoreView, + GasPriceStore, + SettingsProvider, +>( config: GasPriceServiceConfig, genesis_block_height: BlockHeight, - settings: ConsensusParametersProvider, + settings: SettingsProvider, mut gas_price_db: GasPriceStore, on_chain_db: &L2DataStoreView, block_stream: BoxStream, da_block_costs: DaBlockCostsSharedState, -) -> anyhow::Result> +) -> anyhow::Result> where L2DataStore: L2Data, L2DataStoreView: AtomicView, @@ -207,6 +213,7 @@ where + MetadataStorage + KeyValueInspect + Modifiable, + SettingsProvider: GasPriceSettingsProvider, { let mut first_run = false; let latest_block_height: u32 = on_chain_db @@ -262,8 +269,13 @@ where } } -fn sync_gas_price_db_with_on_chain_storage( - settings: &ConsensusParametersProvider, +fn sync_gas_price_db_with_on_chain_storage< + L2DataStore, + L2DataStoreView, + GasPriceStore, + SettingsProvider, +>( + settings: &SettingsProvider, gas_price_db: &mut GasPriceStore, on_chain_db: &L2DataStoreView, metadata_height: u32, @@ -273,6 +285,7 @@ where L2DataStore: L2Data, L2DataStoreView: AtomicView, GasPriceStore: MetadataStorage, + SettingsProvider: GasPriceSettingsProvider, { let metadata = gas_price_db @@ -299,8 +312,8 @@ where Ok(()) } -fn sync_v0_metadata( - settings: &ConsensusParametersProvider, +fn sync_v0_metadata( + settings: &SettingsProvider, on_chain_db: &L2DataStoreView, metadata_height: u32, latest_block_height: u32, @@ -311,6 +324,7 @@ where L2DataStore: L2Data, L2DataStoreView: AtomicView, GasPriceStore: MetadataStorage, + SettingsProvider: GasPriceSettingsProvider, { let first = metadata_height.saturating_add(1); let view = on_chain_db.latest_view()?; diff --git a/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter.rs b/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter.rs index 3b64c17c68a..93fb0f7551c 100644 --- a/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter.rs +++ b/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter.rs @@ -113,7 +113,7 @@ pub struct GasPriceSettings { pub gas_price_factor: u64, pub block_gas_limit: u64, } -pub trait GasPriceSettingsProvider { +pub trait GasPriceSettingsProvider: Send + Sync + Clone { fn settings( &self, param_version: &ConsensusParametersVersion, diff --git a/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter/l2_source_tests.rs b/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter/l2_source_tests.rs index 06bc49b342e..8d25fcb0c59 100644 --- a/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter/l2_source_tests.rs +++ b/crates/services/gas_price_service/src/fuel_gas_price_updater/fuel_core_storage_adapter/l2_source_tests.rs @@ -34,6 +34,7 @@ use std::{ }; use tokio_stream::wrappers::ReceiverStream; +#[derive(Clone)] struct FakeSettings { gas_price_factor: u64, block_gas_limit: u64, From 42b3550a9c485a615c73f8f4e670eafab8f42bc4 Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:58:47 +0530 Subject: [PATCH 2/2] fix: lint --- .../fuel-core/src/service/sub_services/algorithm_updater.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fuel-core/src/service/sub_services/algorithm_updater.rs b/crates/fuel-core/src/service/sub_services/algorithm_updater.rs index 3baff4bb406..d067c2a6929 100644 --- a/crates/fuel-core/src/service/sub_services/algorithm_updater.rs +++ b/crates/fuel-core/src/service/sub_services/algorithm_updater.rs @@ -278,7 +278,7 @@ fn sync_gas_price_db_with_on_chain_storage< where L2DataStore: L2Data, L2DataStoreView: AtomicView, - GasPriceStore: GasPriceData + Modifiable + KeyValueInspect,, + GasPriceStore: GasPriceData + Modifiable + KeyValueInspect, SettingsProvider: GasPriceSettingsProvider, { let metadata = metadata_storage @@ -316,7 +316,7 @@ fn sync_v0_metadata, - GasPriceStore: GasPriceData + Modifiable + KeyValueInspect,, + GasPriceStore: GasPriceData + Modifiable + KeyValueInspect, SettingsProvider: GasPriceSettingsProvider, { let first = metadata_height.saturating_add(1);