Skip to content

Commit

Permalink
Merge branch 'master' into feature/prepare-graphql-for-async
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx authored Oct 14, 2024
2 parents 5a752bc + 469d443 commit e414046
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
60 changes: 32 additions & 28 deletions crates/services/gas_price_service/src/v0/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
use anyhow::anyhow;
use async_trait::async_trait;
use fuel_core_services::{
RunnableService,
RunnableTask,
StateWatcher,
};
Expand Down Expand Up @@ -116,32 +115,6 @@ where
}
}

#[async_trait]
impl<L2, Metadata> RunnableService for GasPriceServiceV0<L2, Metadata>
where
L2: L2BlockSource,
Metadata: MetadataStorage,
{
const NAME: &'static str = "GasPriceServiceV0";
type SharedData = SharedV0Algorithm;
type Task = Self;
type TaskParams = ();

fn shared_data(&self) -> Self::SharedData {
self.shared_algo.clone()
}

async fn into_task(
mut self,
_state_watcher: &StateWatcher,
_params: Self::TaskParams,
) -> anyhow::Result<Self::Task> {
let algorithm = self.algorithm_updater.algorithm();
self.shared_algo.update(algorithm).await;
Ok(self)
}
}

#[async_trait]
impl<L2, Metadata> RunnableTask for GasPriceServiceV0<L2, Metadata>
where
Expand Down Expand Up @@ -194,17 +167,48 @@ mod tests {
v0::{
metadata::V0Metadata,
service::GasPriceServiceV0,
uninitialized_task::initialize_algorithm,
uninitialized_task::{
initialize_algorithm,
SharedV0Algorithm,
},
},
};
use fuel_core_services::{
RunnableService,
Service,
ServiceRunner,
StateWatcher,
};
use fuel_core_types::fuel_types::BlockHeight;
use std::sync::Arc;
use tokio::sync::mpsc;

#[async_trait::async_trait]
impl<L2, Metadata> RunnableService for GasPriceServiceV0<L2, Metadata>
where
L2: L2BlockSource,
Metadata: MetadataStorage,
{
const NAME: &'static str = "GasPriceServiceV0";
type SharedData = SharedV0Algorithm;
type Task = Self;
type TaskParams = ();

fn shared_data(&self) -> Self::SharedData {
self.shared_algo.clone()
}

async fn into_task(
mut self,
_state_watcher: &StateWatcher,
_params: Self::TaskParams,
) -> anyhow::Result<Self::Task> {
let algorithm = self.algorithm_updater.algorithm();
self.shared_algo.update(algorithm).await;
Ok(self)
}
}

struct FakeL2BlockSource {
l2_block: mpsc::Receiver<BlockInfo>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ where
GasPriceData + Modifiable + KeyValueInspect<Column = GasPriceColumn> + Clone,
SettingsProvider: GasPriceSettingsProvider,
{
const NAME: &'static str = "UninitializedGasPriceServiceV0";
const NAME: &'static str = "GasPriceServiceV0";
type SharedData = SharedV0Algorithm;
type Task = GasPriceServiceV0<
FuelL2BlockSource<SettingsProvider>,
Expand Down Expand Up @@ -360,13 +360,14 @@ where
GasPriceData + Modifiable + KeyValueInspect<Column = GasPriceColumn> + Clone,
SettingsProvider: GasPriceSettingsProvider,
{
let gas_price_init = UninitializedTask::new(
// lazy initialization of gas price service, delegate to parent
let gas_price_uninit = UninitializedTask::new(
config,
genesis_block_height,
settings,
block_stream,
gas_price_db,
on_chain_db,
)?;
Ok(ServiceRunner::new(gas_price_init))
Ok(ServiceRunner::new(gas_price_uninit))
}

0 comments on commit e414046

Please sign in to comment.