Skip to content

Commit

Permalink
fix(gas_price_service): service name and unused trait impl (#2317)
Browse files Browse the repository at this point in the history
## Linked Issues/PRs
<!-- List of related issues/PRs -->
- none

## Description
<!-- List of detailed changes -->
Unused trait impl `RunnableService` moved to tests where it's actually
used.

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [ ] I have created follow-up issues caused by this PR and linked them
here

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Sway compiler](https://github.com/FuelLabs/sway/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)
- [ ] Someone else?
  • Loading branch information
rymnc authored Oct 14, 2024
1 parent 5e272eb commit 469d443
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 469d443

Please sign in to comment.