From 96e52c2cc0752e4c0783d6412599bde291002528 Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:32:13 +0530 Subject: [PATCH] chore(gas_price_service): remove dependency on Config from fuel-core --- .../service/adapters/gas_price_adapters.rs | 21 ++++++++++++++--- crates/fuel-core/src/service/sub_services.rs | 2 +- .../service/sub_services/algorithm_updater.rs | 17 +++++++------- .../services/gas_price_service/src/ports.rs | 23 +++++++++++++++++++ 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/crates/fuel-core/src/service/adapters/gas_price_adapters.rs b/crates/fuel-core/src/service/adapters/gas_price_adapters.rs index 8e499c844b0..3be9c142e42 100644 --- a/crates/fuel-core/src/service/adapters/gas_price_adapters.rs +++ b/crates/fuel-core/src/service/adapters/gas_price_adapters.rs @@ -15,6 +15,7 @@ use fuel_core_gas_price_service::{ }, ports::{ GasPriceData, + GasPriceServiceConfig, L2Data, MetadataStorage, }, @@ -37,9 +38,12 @@ use fuel_core_types::{ fuel_types::BlockHeight, }; -use crate::database::{ - database_description::gas_price::GasPriceDatabase, - Database, +use crate::{ + database::{ + database_description::gas_price::GasPriceDatabase, + Database, + }, + service::Config, }; #[cfg(test)] @@ -96,6 +100,17 @@ impl MetadataStorage for Database { } } +impl From for GasPriceServiceConfig { + fn from(value: Config) -> Self { + GasPriceServiceConfig::new( + value.min_gas_price, + value.starting_gas_price, + value.gas_price_change_percent, + value.gas_price_threshold_percent, + ) + } +} + impl GasPriceSettingsProvider for ConsensusParametersProvider { fn settings( &self, diff --git a/crates/fuel-core/src/service/sub_services.rs b/crates/fuel-core/src/service/sub_services.rs index 5c4aaf05e23..cf56ccf4193 100644 --- a/crates/fuel-core/src/service/sub_services.rs +++ b/crates/fuel-core/src/service/sub_services.rs @@ -201,7 +201,7 @@ pub fn init_sub_services( let block_stream = importer_adapter.events_shared_result(); let gas_price_init = algorithm_updater::InitializeTask::new( - config.clone(), + config.clone().into(), genesis_block_height, settings, block_stream, 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 326792f7c9d..c7a3f61d9d0 100644 --- a/crates/fuel-core/src/service/sub_services/algorithm_updater.rs +++ b/crates/fuel-core/src/service/sub_services/algorithm_updater.rs @@ -1,7 +1,4 @@ -use crate::service::{ - adapters::ConsensusParametersProvider, - Config, -}; +use crate::service::adapters::ConsensusParametersProvider; use fuel_core_gas_price_service::{ fuel_gas_price_updater::{ @@ -27,6 +24,7 @@ use fuel_core_gas_price_service::{ }, ports::{ GasPriceData, + GasPriceServiceConfig, L2Data, MetadataStorage, }, @@ -60,7 +58,7 @@ type Updater = FuelGasPriceUpdater< >; pub struct InitializeTask { - pub config: Config, + pub config: GasPriceServiceConfig, pub genesis_block_height: BlockHeight, pub settings: ConsensusParametersProvider, pub gas_price_db: GasPriceStore, @@ -80,7 +78,7 @@ where GasPriceStore: GasPriceData + MetadataStorage, { pub fn new( - config: Config, + config: GasPriceServiceConfig, genesis_block_height: BlockHeight, settings: ConsensusParametersProvider, block_stream: BoxStream, @@ -113,7 +111,10 @@ where } } -fn get_default_metadata(config: &Config, latest_block_height: u32) -> UpdaterMetadata { +fn get_default_metadata( + config: &GasPriceServiceConfig, + latest_block_height: u32, +) -> UpdaterMetadata { UpdaterMetadata::V0(V0Metadata { new_exec_price: config.starting_gas_price.max(config.min_gas_price), min_exec_gas_price: config.min_gas_price, @@ -191,7 +192,7 @@ where } pub fn get_synced_gas_price_updater( - config: Config, + config: GasPriceServiceConfig, genesis_block_height: BlockHeight, settings: ConsensusParametersProvider, mut gas_price_db: GasPriceStore, diff --git a/crates/services/gas_price_service/src/ports.rs b/crates/services/gas_price_service/src/ports.rs index 868fd8d9815..420fd8c673e 100644 --- a/crates/services/gas_price_service/src/ports.rs +++ b/crates/services/gas_price_service/src/ports.rs @@ -26,3 +26,26 @@ pub trait MetadataStorage: Send + Sync { pub trait GasPriceData: Send + Sync { fn latest_height(&self) -> Option; } + +pub struct GasPriceServiceConfig { + pub min_gas_price: u64, + pub starting_gas_price: u64, + pub gas_price_change_percent: u64, + pub gas_price_threshold_percent: u64, +} + +impl GasPriceServiceConfig { + pub fn new( + min_gas_price: u64, + starting_gas_price: u64, + gas_price_change_percent: u64, + gas_price_threshold_percent: u64, + ) -> Self { + Self { + min_gas_price, + starting_gas_price, + gas_price_change_percent, + gas_price_threshold_percent, + } + } +}