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): use port for GasPriceSettings instead of concrete type #2245

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
54 changes: 34 additions & 20 deletions crates/fuel-core/src/service/sub_services/algorithm_updater.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::service::adapters::ConsensusParametersProvider;

use fuel_core_gas_price_service::{
fuel_gas_price_updater::{
da_source_adapter::{
Expand Down Expand Up @@ -51,36 +49,38 @@ use fuel_core_types::{
services::block_importer::SharedImportResult,
};

type Updater<GasPriceStore> = FuelGasPriceUpdater<
FuelL2BlockSource<ConsensusParametersProvider>,
type Updater<GasPriceStore, SettingsProvider> = FuelGasPriceUpdater<
FuelL2BlockSource<SettingsProvider>,
StructuredStorage<GasPriceStore>,
DaBlockCostsSharedState,
>;

pub struct InitializeTask<L2DataStoreView, GasPriceStore> {
pub struct InitializeTask<L2DataStoreView, GasPriceStore, SettingsProvider> {
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<SharedImportResult>,
pub shared_algo: SharedGasPriceAlgo<Algorithm>,
pub da_block_costs_provider: DaBlockCostsProvider<DummyDaBlockCosts>,
}

type Task<GasPriceStore> = GasPriceService<Algorithm, Updater<GasPriceStore>>;
type Task<GasPriceStore, SettingsProvider> =
GasPriceService<Algorithm, Updater<GasPriceStore, SettingsProvider>>;

impl<L2DataStore, L2DataStoreView, GasPriceStore>
InitializeTask<L2DataStoreView, GasPriceStore>
impl<L2DataStore, L2DataStoreView, GasPriceStore, SettingsProvider>
InitializeTask<L2DataStoreView, GasPriceStore, SettingsProvider>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: GasPriceData + MetadataStorage,
SettingsProvider: GasPriceSettingsProvider,
{
pub fn new(
config: GasPriceServiceConfig,
genesis_block_height: BlockHeight,
settings: ConsensusParametersProvider,
settings: SettingsProvider,
block_stream: BoxStream<SharedImportResult>,
gas_price_db: GasPriceStore,
on_chain_db: L2DataStoreView,
Expand Down Expand Up @@ -144,19 +144,20 @@ where
Ok(algo)
}
#[async_trait::async_trait]
impl<L2DataStore, L2DataStoreView, GasPriceStore> RunnableService
for InitializeTask<L2DataStoreView, GasPriceStore>
impl<L2DataStore, L2DataStoreView, GasPriceStore, SettingsProvider> RunnableService
for InitializeTask<L2DataStoreView, GasPriceStore, SettingsProvider>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: GasPriceData
+ MetadataStorage
+ KeyValueInspect<Column = GasPriceColumn>
+ Modifiable,
SettingsProvider: GasPriceSettingsProvider,
{
const NAME: &'static str = "GasPriceUpdater";
type SharedData = SharedGasPriceAlgo<Algorithm>;
type Task = Task<GasPriceStore>;
type Task = Task<GasPriceStore, SettingsProvider>;
type TaskParams = ();

fn shared_data(&self) -> Self::SharedData {
Expand Down Expand Up @@ -191,22 +192,28 @@ where
}
}

pub fn get_synced_gas_price_updater<L2DataStore, L2DataStoreView, GasPriceStore>(
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<SharedImportResult>,
da_block_costs: DaBlockCostsSharedState,
) -> anyhow::Result<Updater<GasPriceStore>>
) -> anyhow::Result<Updater<GasPriceStore, SettingsProvider>>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: GasPriceData
+ MetadataStorage
+ KeyValueInspect<Column = GasPriceColumn>
+ Modifiable,
SettingsProvider: GasPriceSettingsProvider,
{
let mut first_run = false;
let latest_block_height: u32 = on_chain_db
Expand Down Expand Up @@ -262,8 +269,13 @@ where
}
}

fn sync_gas_price_db_with_on_chain_storage<L2DataStore, L2DataStoreView, GasPriceStore>(
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,
Expand All @@ -273,6 +285,7 @@ where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: MetadataStorage,
SettingsProvider: GasPriceSettingsProvider,
{
let metadata =
gas_price_db
Expand All @@ -299,8 +312,8 @@ where
Ok(())
}

fn sync_v0_metadata<L2DataStore, L2DataStoreView, GasPriceStore>(
settings: &ConsensusParametersProvider,
fn sync_v0_metadata<L2DataStore, L2DataStoreView, GasPriceStore, SettingsProvider>(
settings: &SettingsProvider,
on_chain_db: &L2DataStoreView,
metadata_height: u32,
latest_block_height: u32,
Expand All @@ -311,6 +324,7 @@ where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: MetadataStorage,
SettingsProvider: GasPriceSettingsProvider,
{
let first = metadata_height.saturating_add(1);
let view = on_chain_db.latest_view()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::{
};
use tokio_stream::wrappers::ReceiverStream;

#[derive(Clone)]
struct FakeSettings {
gas_price_factor: u64,
block_gas_limit: u64,
Expand Down
Loading