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

chore(gas_price_service): remove dependency on Config from fuel-core #2230

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions crates/fuel-core/src/service/adapters/gas_price_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use fuel_core_gas_price_service::{
},
ports::{
GasPriceData,
GasPriceServiceConfig,
L2Data,
MetadataStorage,
},
Expand All @@ -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)]
Expand Down Expand Up @@ -96,6 +100,17 @@ impl MetadataStorage for Database<GasPriceDatabase> {
}
}

impl From<Config> 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions crates/fuel-core/src/service/sub_services/algorithm_updater.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -27,6 +24,7 @@ use fuel_core_gas_price_service::{
},
ports::{
GasPriceData,
GasPriceServiceConfig,
L2Data,
MetadataStorage,
},
Expand Down Expand Up @@ -60,7 +58,7 @@ type Updater<GasPriceStore> = FuelGasPriceUpdater<
>;

pub struct InitializeTask<L2DataStoreView, GasPriceStore> {
pub config: Config,
pub config: GasPriceServiceConfig,
pub genesis_block_height: BlockHeight,
pub settings: ConsensusParametersProvider,
pub gas_price_db: GasPriceStore,
Expand All @@ -80,7 +78,7 @@ where
GasPriceStore: GasPriceData + MetadataStorage,
{
pub fn new(
config: Config,
config: GasPriceServiceConfig,
genesis_block_height: BlockHeight,
settings: ConsensusParametersProvider,
block_stream: BoxStream<SharedImportResult>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -191,7 +192,7 @@ where
}

pub fn get_synced_gas_price_updater<L2DataStore, L2DataStoreView, GasPriceStore>(
config: Config,
config: GasPriceServiceConfig,
genesis_block_height: BlockHeight,
settings: ConsensusParametersProvider,
mut gas_price_db: GasPriceStore,
Expand Down
23 changes: 23 additions & 0 deletions crates/services/gas_price_service/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,26 @@ pub trait MetadataStorage: Send + Sync {
pub trait GasPriceData: Send + Sync {
fn latest_height(&self) -> Option<BlockHeight>;
}

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 {
acerone85 marked this conversation as resolved.
Show resolved Hide resolved
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,
}
}
}
Loading