Skip to content

Commit

Permalink
chore(gas_price_service_v0): remove unused trait impl (#2410)
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 -->
`RunnableService` didn't need to be implemented for `GasPriceServiceV0`
even in the tests.

## 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
- [x] 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 30, 2024
1 parent 7605a2a commit ba304f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 54 deletions.
47 changes: 9 additions & 38 deletions crates/services/gas_price_service/src/v0/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,48 +165,19 @@ mod tests {
},
ports::MetadataStorage,
v0::{
algorithm::SharedV0Algorithm,
metadata::V0AlgorithmConfig,
service::GasPriceServiceV0,
uninitialized_task::initialize_algorithm,
},
};
use fuel_core_services::{
RunnableService,
Service,
ServiceRunner,
RunnableTask,
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 Expand Up @@ -255,10 +226,12 @@ mod tests {
gas_used: 60,
block_gas_capacity: 100,
};

let (l2_block_sender, l2_block_receiver) = mpsc::channel(1);
let l2_block_source = FakeL2BlockSource {
l2_block: l2_block_receiver,
};

let metadata_storage = FakeMetadata::empty();
let l2_block_height = 0;
let config = V0AlgorithmConfig {
Expand All @@ -269,25 +242,23 @@ mod tests {
};
let (algo_updater, shared_algo) =
initialize_algorithm(&config, l2_block_height, &metadata_storage).unwrap();

let service = GasPriceServiceV0::new(
let mut service = GasPriceServiceV0::new(
l2_block_source,
metadata_storage,
shared_algo,
algo_updater,
);
let read_algo = service.next_block_algorithm();
let service = ServiceRunner::new(service);
let prev = read_algo.next_gas_price();
let mut watcher = StateWatcher::default();
let initial_price = read_algo.next_gas_price();

// when
service.start_and_await().await.unwrap();
service.run(&mut watcher).await.unwrap();
l2_block_sender.send(l2_block).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
service.shutdown().await.unwrap();

// then
let actual_price = read_algo.next_gas_price();
assert_ne!(prev, actual_price);
service.stop_and_await().await.unwrap();
assert_ne!(initial_price, actual_price);
}
}
34 changes: 18 additions & 16 deletions crates/services/gas_price_service/src/v0/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use fuel_core_services::{
BoxStream,
IntoBoxStream,
},
Service,
ServiceRunner,
RunnableTask,
StateWatcher,
};
use fuel_core_storage::{
transactional::AtomicView,
Expand All @@ -59,7 +59,6 @@ use fuel_core_types::{
use std::{
ops::Deref,
sync::Arc,
time::Duration,
};
use tokio::sync::mpsc::Receiver;

Expand Down Expand Up @@ -159,25 +158,25 @@ async fn next_gas_price__affected_by_new_l2_block() {
let height = 0;
let (algo_updater, shared_algo) =
initialize_algorithm(&config, height, &metadata_storage).unwrap();
let service = GasPriceServiceV0::new(
let mut service = GasPriceServiceV0::new(
l2_block_source,
metadata_storage,
shared_algo,
algo_updater,
);
let service = ServiceRunner::new(service);
let shared = service.shared.clone();
let initial = shared.next_gas_price();

let read_algo = service.next_block_algorithm();
let initial = read_algo.next_gas_price();
let mut watcher = StateWatcher::default();

// when
service.start_and_await().await.unwrap();
service.run(&mut watcher).await.unwrap();
l2_block_sender.send(l2_block).await.unwrap();
tokio::time::sleep(Duration::from_millis(10)).await;
service.shutdown().await.unwrap();

// then
let new = shared.next_gas_price();
let new = read_algo.next_gas_price();
assert_ne!(initial, new);
service.stop_and_await().await.unwrap();
}

#[tokio::test]
Expand All @@ -202,22 +201,25 @@ async fn next__new_l2_block_saves_old_metadata() {
let (algo_updater, shared_algo) =
initialize_algorithm(&config, height, &metadata_storage).unwrap();

let service = GasPriceServiceV0::new(
let mut service = GasPriceServiceV0::new(
l2_block_source,
metadata_storage,
shared_algo,
algo_updater,
);

// when
let service = ServiceRunner::new(service);
let read_algo = service.next_block_algorithm();
let mut watcher = StateWatcher::default();
let start = read_algo.next_gas_price();

service.start_and_await().await.unwrap();
service.run(&mut watcher).await.unwrap();
l2_block_sender.send(l2_block).await.unwrap();
tokio::time::sleep(Duration::from_millis(10)).await;
service.shutdown().await.unwrap();

// then
assert!(metadata_inner.lock().unwrap().is_some());
let new = read_algo.next_gas_price();
assert_ne!(start, new);
}

#[derive(Clone)]
Expand Down

0 comments on commit ba304f3

Please sign in to comment.