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

chore(gas_price_service_v0): remove unused trait impl #2410

Merged
merged 1 commit into from
Oct 30, 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
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
Loading