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

fix(gas_price_service): service name and unused trait impl #2317

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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>
rymnc marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

@xgreenx xgreenx Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a point of testing code that is not used anywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not testing the RunnableService it's just a helper for testing the logic within the task.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see why do you need to implement RunnableService. The type already implements RunnableTask, and you need to test this one=)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we need to add a comment that it should be removed I the mentioned PR=)

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))
}
Loading