Skip to content

Commit

Permalink
Rename trait to be more domain specific
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Dec 9, 2024
1 parent f26b024 commit 7863eec
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use crate::{
},
},
ports::{
GasPriceServiceAtomicStorage,
GetDaSequenceNumber,
GetMetadataStorage,
SetDaSequenceNumber,
SetMetadataStorage,
TransactionableStorage,
},
};
use anyhow::anyhow;
Expand Down Expand Up @@ -116,7 +116,7 @@ where
}
}

impl<Storage> TransactionableStorage for Storage
impl<Storage> GasPriceServiceAtomicStorage for Storage
where
Storage: 'static,
Storage: GetMetadataStorage + GetDaSequenceNumber,
Expand Down
2 changes: 1 addition & 1 deletion crates/services/gas_price_service/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait GetDaSequenceNumber: Send + Sync {
fn get_sequence_number(&self, block_height: &BlockHeight) -> Result<Option<u32>>;
}

pub trait TransactionableStorage
pub trait GasPriceServiceAtomicStorage
where
Self: 'static,
Self: Send + Sync,
Expand Down
23 changes: 11 additions & 12 deletions crates/services/gas_price_service/src/v1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::{
},
},
ports::{
GasPriceServiceAtomicStorage,
GetMetadataStorage,
SetDaSequenceNumber,
SetMetadataStorage,
TransactionableStorage,
},
v0::metadata::V0Metadata,
v1::{
Expand Down Expand Up @@ -77,11 +77,11 @@ pub struct GasPriceServiceV1<L2, DA, StorageTxProvider> {
storage_tx_provider: StorageTxProvider,
}

impl<L2, DA, StorageTxProvider> GasPriceServiceV1<L2, DA, StorageTxProvider>
impl<L2, DA, AtomicStorage> GasPriceServiceV1<L2, DA, AtomicStorage>
where
L2: L2BlockSource,
DA: DaBlockCostsSource,
StorageTxProvider: TransactionableStorage,
AtomicStorage: GasPriceServiceAtomicStorage,
{
async fn commit_block_data_to_algorithm(
&mut self,
Expand All @@ -96,17 +96,17 @@ where
}
}

impl<L2, DA, StorageTxProvider> GasPriceServiceV1<L2, DA, StorageTxProvider>
impl<L2, DA, AtomicStorage> GasPriceServiceV1<L2, DA, AtomicStorage>
where
DA: DaBlockCostsSource,
StorageTxProvider: TransactionableStorage,
AtomicStorage: GasPriceServiceAtomicStorage,
{
pub fn new(
l2_block_source: L2,
shared_algo: SharedV1Algorithm,
algorithm_updater: AlgorithmUpdaterV1,
da_source_adapter_handle: DaSourceService<DA>,
storage_tx_provider: StorageTxProvider,
storage_tx_provider: AtomicStorage,
) -> Self {
let da_source_channel =
da_source_adapter_handle.shared_data().clone().subscribe();
Expand All @@ -130,7 +130,7 @@ where
}

#[cfg(test)]
pub fn storage_tx_provider(&self) -> &StorageTxProvider {
pub fn storage_tx_provider(&self) -> &AtomicStorage {
&self.storage_tx_provider
}

Expand Down Expand Up @@ -185,7 +185,7 @@ where
storage_tx
.set_metadata(&metadata)
.map_err(|err| anyhow!(err))?;
StorageTxProvider::commit_transaction(storage_tx)?;
AtomicStorage::commit_transaction(storage_tx)?;
let new_algo = self.algorithm_updater.algorithm();
self.shared_algo.update(new_algo).await;
Ok(())
Expand All @@ -200,7 +200,7 @@ where
let metadata: UpdaterMetadata = self.algorithm_updater.clone().into();
let mut tx = self.storage_tx_provider.begin_transaction()?;
tx.set_metadata(&metadata).map_err(|err| anyhow!(err))?;
StorageTxProvider::commit_transaction(tx)?;
AtomicStorage::commit_transaction(tx)?;
let new_algo = self.algorithm_updater.algorithm();
// self.update(new_algo).await;
self.shared_algo.update(new_algo).await;
Expand Down Expand Up @@ -228,12 +228,11 @@ where
}

#[async_trait]
impl<L2, DA, StorageTxProvider> RunnableTask
for GasPriceServiceV1<L2, DA, StorageTxProvider>
impl<L2, DA, AtomicStorage> RunnableTask for GasPriceServiceV1<L2, DA, AtomicStorage>
where
L2: L2BlockSource,
DA: DaBlockCostsSource,
StorageTxProvider: TransactionableStorage,
AtomicStorage: GasPriceServiceAtomicStorage,
{
async fn run(&mut self, watcher: &mut StateWatcher) -> TaskNextAction {
tokio::select! {
Expand Down
4 changes: 2 additions & 2 deletions crates/services/gas_price_service/src/v1/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use crate::{
},
ports::{
GasPriceData,
GasPriceServiceAtomicStorage,
GetDaSequenceNumber,
GetMetadataStorage,
L2Data,
SetDaSequenceNumber,
SetMetadataStorage,
TransactionableStorage,
},
v1::{
algorithm::SharedV1Algorithm,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl GetDaSequenceNumber for ErroringPersistedData {

struct UnimplementedStorageTx;

impl TransactionableStorage for ErroringPersistedData {
impl GasPriceServiceAtomicStorage for ErroringPersistedData {
type Transaction<'a> = UnimplementedStorageTx;

fn begin_transaction(&mut self) -> GasPriceResult<Self::Transaction<'_>> {
Expand Down
42 changes: 21 additions & 21 deletions crates/services/gas_price_service/src/v1/uninitialized_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use crate::{
},
ports::{
GasPriceData,
GasPriceServiceAtomicStorage,
GasPriceServiceConfig,
GetDaSequenceNumber,
GetMetadataStorage,
L2Data,
SetDaSequenceNumber,
SetMetadataStorage,
TransactionableStorage,
},
v1::{
algorithm::SharedV1Algorithm,
Expand Down Expand Up @@ -94,12 +94,12 @@ pub struct UninitializedTask<L2DataStoreView, GasPriceStore, DA, SettingsProvide
pub(crate) da_source: DA,
}

impl<L2DataStore, L2DataStoreView, GasPriceStore, DA, SettingsProvider>
UninitializedTask<L2DataStoreView, GasPriceStore, DA, SettingsProvider>
impl<L2DataStore, L2DataStoreView, AtomicStorage, DA, SettingsProvider>
UninitializedTask<L2DataStoreView, AtomicStorage, DA, SettingsProvider>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: TransactionableStorage,
AtomicStorage: GasPriceServiceAtomicStorage,
DA: DaBlockCostsSource,
SettingsProvider: GasPriceSettingsProvider,
{
Expand All @@ -110,7 +110,7 @@ where
genesis_block_height: BlockHeight,
settings: SettingsProvider,
block_stream: BoxStream<SharedImportResult>,
gas_price_db: GasPriceStore,
gas_price_db: AtomicStorage,
da_source: DA,
on_chain_db: L2DataStoreView,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -141,7 +141,7 @@ where
pub async fn init(
mut self,
) -> anyhow::Result<
GasPriceServiceV1<FuelL2BlockSource<SettingsProvider>, DA, GasPriceStore>,
GasPriceServiceV1<FuelL2BlockSource<SettingsProvider>, DA, AtomicStorage>,
> {
let mut first_run = false;
let latest_block_height: u32 = self
Expand Down Expand Up @@ -212,18 +212,18 @@ where
}

#[async_trait::async_trait]
impl<L2DataStore, L2DataStoreView, GasPriceStore, DA, SettingsProvider> RunnableService
for UninitializedTask<L2DataStoreView, GasPriceStore, DA, SettingsProvider>
impl<L2DataStore, L2DataStoreView, AtomicStorage, DA, SettingsProvider> RunnableService
for UninitializedTask<L2DataStoreView, AtomicStorage, DA, SettingsProvider>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
GasPriceStore: TransactionableStorage + GasPriceData,
AtomicStorage: GasPriceServiceAtomicStorage + GasPriceData,
DA: DaBlockCostsSource + 'static,
SettingsProvider: GasPriceSettingsProvider + 'static,
{
const NAME: &'static str = "GasPriceServiceV1";
type SharedData = SharedV1Algorithm;
type Task = GasPriceServiceV1<FuelL2BlockSource<SettingsProvider>, DA, GasPriceStore>;
type Task = GasPriceServiceV1<FuelL2BlockSource<SettingsProvider>, DA, AtomicStorage>;
type TaskParams = ();

fn shared_data(&self) -> Self::SharedData {
Expand All @@ -243,20 +243,20 @@ fn sync_gas_price_db_with_on_chain_storage<
L2DataStore,
L2DataStoreView,
SettingsProvider,
PersistedData,
AtomicStorage,
>(
settings: &SettingsProvider,
config: &V1AlgorithmConfig,
on_chain_db: &L2DataStoreView,
metadata_height: u32,
latest_block_height: u32,
persisted_data: &mut PersistedData,
persisted_data: &mut AtomicStorage,
) -> anyhow::Result<()>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
SettingsProvider: GasPriceSettingsProvider,
PersistedData: TransactionableStorage,
AtomicStorage: GasPriceServiceAtomicStorage,
{
let metadata = persisted_data
.get_metadata(&metadata_height.into())?
Expand Down Expand Up @@ -284,19 +284,19 @@ where
Ok(())
}

fn sync_v1_metadata<L2DataStore, L2DataStoreView, SettingsProvider, StorageTxGenerator>(
fn sync_v1_metadata<L2DataStore, L2DataStoreView, SettingsProvider, AtomicStorage>(
settings: &SettingsProvider,
on_chain_db: &L2DataStoreView,
metadata_height: u32,
latest_block_height: u32,
updater: &mut AlgorithmUpdaterV1,
da_storage: &mut StorageTxGenerator,
da_storage: &mut AtomicStorage,
) -> anyhow::Result<()>
where
L2DataStore: L2Data,
L2DataStoreView: AtomicView<LatestView = L2DataStore>,
SettingsProvider: GasPriceSettingsProvider,
StorageTxGenerator: TransactionableStorage,
AtomicStorage: GasPriceServiceAtomicStorage,
{
let first = metadata_height.saturating_add(1);
let view = on_chain_db.latest_view()?;
Expand Down Expand Up @@ -334,27 +334,27 @@ where
let metadata: UpdaterMetadata = updater.clone().into();
tx.set_metadata(&metadata)?;
}
StorageTxGenerator::commit_transaction(tx)?;
AtomicStorage::commit_transaction(tx)?;

Ok(())
}

#[allow(clippy::type_complexity)]
pub fn new_gas_price_service_v1<L2DataStore, GasPriceStore, DA, SettingsProvider>(
pub fn new_gas_price_service_v1<L2DataStore, AtomicStorage, DA, SettingsProvider>(
v1_config: V1AlgorithmConfig,
genesis_block_height: BlockHeight,
settings: SettingsProvider,
block_stream: BoxStream<SharedImportResult>,
gas_price_db: GasPriceStore,
gas_price_db: AtomicStorage,
da_source: DA,
on_chain_db: L2DataStore,
) -> anyhow::Result<
ServiceRunner<UninitializedTask<L2DataStore, GasPriceStore, DA, SettingsProvider>>,
ServiceRunner<UninitializedTask<L2DataStore, AtomicStorage, DA, SettingsProvider>>,
>
where
L2DataStore: AtomicView,
L2DataStore::LatestView: L2Data,
GasPriceStore: TransactionableStorage + GasPriceData,
AtomicStorage: GasPriceServiceAtomicStorage + GasPriceData,
SettingsProvider: GasPriceSettingsProvider,
DA: DaBlockCostsSource,
{
Expand Down

0 comments on commit 7863eec

Please sign in to comment.