Skip to content

Commit 1cd089f

Browse files
chore(gas_price_service_v0): remove unused trait impl (#2410)
## 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?
1 parent 262cbd7 commit 1cd089f

File tree

2 files changed

+27
-54
lines changed

2 files changed

+27
-54
lines changed

crates/services/gas_price_service/src/v0/service.rs

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -165,48 +165,19 @@ mod tests {
165165
},
166166
ports::MetadataStorage,
167167
v0::{
168-
algorithm::SharedV0Algorithm,
169168
metadata::V0AlgorithmConfig,
170169
service::GasPriceServiceV0,
171170
uninitialized_task::initialize_algorithm,
172171
},
173172
};
174173
use fuel_core_services::{
175-
RunnableService,
176-
Service,
177-
ServiceRunner,
174+
RunnableTask,
178175
StateWatcher,
179176
};
180177
use fuel_core_types::fuel_types::BlockHeight;
181178
use std::sync::Arc;
182179
use tokio::sync::mpsc;
183180

184-
#[async_trait::async_trait]
185-
impl<L2, Metadata> RunnableService for GasPriceServiceV0<L2, Metadata>
186-
where
187-
L2: L2BlockSource,
188-
Metadata: MetadataStorage,
189-
{
190-
const NAME: &'static str = "GasPriceServiceV0";
191-
type SharedData = SharedV0Algorithm;
192-
type Task = Self;
193-
type TaskParams = ();
194-
195-
fn shared_data(&self) -> Self::SharedData {
196-
self.shared_algo.clone()
197-
}
198-
199-
async fn into_task(
200-
mut self,
201-
_state_watcher: &StateWatcher,
202-
_params: Self::TaskParams,
203-
) -> anyhow::Result<Self::Task> {
204-
let algorithm = self.algorithm_updater.algorithm();
205-
self.shared_algo.update(algorithm).await;
206-
Ok(self)
207-
}
208-
}
209-
210181
struct FakeL2BlockSource {
211182
l2_block: mpsc::Receiver<BlockInfo>,
212183
}
@@ -255,10 +226,12 @@ mod tests {
255226
gas_used: 60,
256227
block_gas_capacity: 100,
257228
};
229+
258230
let (l2_block_sender, l2_block_receiver) = mpsc::channel(1);
259231
let l2_block_source = FakeL2BlockSource {
260232
l2_block: l2_block_receiver,
261233
};
234+
262235
let metadata_storage = FakeMetadata::empty();
263236
let l2_block_height = 0;
264237
let config = V0AlgorithmConfig {
@@ -269,25 +242,23 @@ mod tests {
269242
};
270243
let (algo_updater, shared_algo) =
271244
initialize_algorithm(&config, l2_block_height, &metadata_storage).unwrap();
272-
273-
let service = GasPriceServiceV0::new(
245+
let mut service = GasPriceServiceV0::new(
274246
l2_block_source,
275247
metadata_storage,
276248
shared_algo,
277249
algo_updater,
278250
);
279251
let read_algo = service.next_block_algorithm();
280-
let service = ServiceRunner::new(service);
281-
let prev = read_algo.next_gas_price();
252+
let mut watcher = StateWatcher::default();
253+
let initial_price = read_algo.next_gas_price();
282254

283255
// when
284-
service.start_and_await().await.unwrap();
256+
service.run(&mut watcher).await.unwrap();
285257
l2_block_sender.send(l2_block).await.unwrap();
286-
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
258+
service.shutdown().await.unwrap();
287259

288260
// then
289261
let actual_price = read_algo.next_gas_price();
290-
assert_ne!(prev, actual_price);
291-
service.stop_and_await().await.unwrap();
262+
assert_ne!(initial_price, actual_price);
292263
}
293264
}

crates/services/gas_price_service/src/v0/tests.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use fuel_core_services::{
3737
BoxStream,
3838
IntoBoxStream,
3939
},
40-
Service,
41-
ServiceRunner,
40+
RunnableTask,
41+
StateWatcher,
4242
};
4343
use fuel_core_storage::{
4444
transactional::AtomicView,
@@ -59,7 +59,6 @@ use fuel_core_types::{
5959
use std::{
6060
ops::Deref,
6161
sync::Arc,
62-
time::Duration,
6362
};
6463
use tokio::sync::mpsc::Receiver;
6564

@@ -159,25 +158,25 @@ async fn next_gas_price__affected_by_new_l2_block() {
159158
let height = 0;
160159
let (algo_updater, shared_algo) =
161160
initialize_algorithm(&config, height, &metadata_storage).unwrap();
162-
let service = GasPriceServiceV0::new(
161+
let mut service = GasPriceServiceV0::new(
163162
l2_block_source,
164163
metadata_storage,
165164
shared_algo,
166165
algo_updater,
167166
);
168-
let service = ServiceRunner::new(service);
169-
let shared = service.shared.clone();
170-
let initial = shared.next_gas_price();
167+
168+
let read_algo = service.next_block_algorithm();
169+
let initial = read_algo.next_gas_price();
170+
let mut watcher = StateWatcher::default();
171171

172172
// when
173-
service.start_and_await().await.unwrap();
173+
service.run(&mut watcher).await.unwrap();
174174
l2_block_sender.send(l2_block).await.unwrap();
175-
tokio::time::sleep(Duration::from_millis(10)).await;
175+
service.shutdown().await.unwrap();
176176

177177
// then
178-
let new = shared.next_gas_price();
178+
let new = read_algo.next_gas_price();
179179
assert_ne!(initial, new);
180-
service.stop_and_await().await.unwrap();
181180
}
182181

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

205-
let service = GasPriceServiceV0::new(
204+
let mut service = GasPriceServiceV0::new(
206205
l2_block_source,
207206
metadata_storage,
208207
shared_algo,
209208
algo_updater,
210209
);
211210

212211
// when
213-
let service = ServiceRunner::new(service);
212+
let read_algo = service.next_block_algorithm();
213+
let mut watcher = StateWatcher::default();
214+
let start = read_algo.next_gas_price();
214215

215-
service.start_and_await().await.unwrap();
216+
service.run(&mut watcher).await.unwrap();
216217
l2_block_sender.send(l2_block).await.unwrap();
217-
tokio::time::sleep(Duration::from_millis(10)).await;
218+
service.shutdown().await.unwrap();
218219

219220
// then
220-
assert!(metadata_inner.lock().unwrap().is_some());
221+
let new = read_algo.next_gas_price();
222+
assert_ne!(start, new);
221223
}
222224

223225
#[derive(Clone)]

0 commit comments

Comments
 (0)