diff --git a/CHANGELOG.md b/CHANGELOG.md index e54ce4cc901..7548587bdca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - [2630](https://github.com/FuelLabs/fuel-core/pull/2630): Removed some noisy `tracing::info!` logs +### Fixed +- [2632](https://github.com/FuelLabs/fuel-core/pull/2632): Improved performance of certain async trait impls in the gas price service. + ## [Version 0.41.4] ### Fixed diff --git a/crates/fuel-core/src/service/adapters/fuel_gas_price_provider.rs b/crates/fuel-core/src/service/adapters/fuel_gas_price_provider.rs index 3401e100d4e..8b13f058615 100644 --- a/crates/fuel-core/src/service/adapters/fuel_gas_price_provider.rs +++ b/crates/fuel-core/src/service/adapters/fuel_gas_price_provider.rs @@ -53,16 +53,15 @@ impl FuelGasPriceProvider { } } -#[async_trait::async_trait] impl ProducerGasPriceProvider for FuelGasPriceProvider where A: GasPriceAlgorithm + Send + Sync, { - async fn production_gas_price(&self) -> anyhow::Result { + fn production_gas_price(&self) -> anyhow::Result { Ok(self.algorithm.next_gas_price()) } - async fn dry_run_gas_price(&self) -> anyhow::Result { + fn dry_run_gas_price(&self) -> anyhow::Result { let price = self.latest_gas_price.inner_next_gas_price(); Ok(price) } diff --git a/crates/fuel-core/src/service/adapters/fuel_gas_price_provider/tests/producer_gas_price_tests.rs b/crates/fuel-core/src/service/adapters/fuel_gas_price_provider/tests/producer_gas_price_tests.rs index 6d9bc797002..f84fea71416 100644 --- a/crates/fuel-core/src/service/adapters/fuel_gas_price_provider/tests/producer_gas_price_tests.rs +++ b/crates/fuel-core/src/service/adapters/fuel_gas_price_provider/tests/producer_gas_price_tests.rs @@ -5,8 +5,8 @@ use fuel_core_gas_price_service::{ }; use fuel_core_producer::block_producer::gas_price::GasPriceProvider; -#[tokio::test] -async fn production_gas_price__if_requested_block_height_is_latest_return_gas_price() { +#[test] +fn production_gas_price__if_requested_block_height_is_latest_return_gas_price() { // given let price = 33; let algo = StaticAlgorithm::new(price); @@ -14,14 +14,14 @@ async fn production_gas_price__if_requested_block_height_is_latest_return_gas_pr // when let expected_price = algo.next_gas_price(); - let actual_price = gas_price_provider.production_gas_price().await.unwrap(); + let actual_price = gas_price_provider.production_gas_price().unwrap(); // then assert_eq!(expected_price, actual_price); } -#[tokio::test] -async fn _dry_run_gas_price__calculates_correctly_based_on_percentage() { +#[test] +fn dry_run_gas_price__calculates_correctly_based_on_percentage() { // given let height = 123; let price = 33; @@ -30,7 +30,7 @@ async fn _dry_run_gas_price__calculates_correctly_based_on_percentage() { let gas_price_provider = build_provider(algo.clone(), height, price, percentage); // when - let actual = gas_price_provider.dry_run_gas_price().await.unwrap(); + let actual = gas_price_provider.dry_run_gas_price().unwrap(); // then let change_amount = price.saturating_mul(percentage as u64).saturating_div(100); diff --git a/crates/fuel-core/src/service/adapters/producer.rs b/crates/fuel-core/src/service/adapters/producer.rs index a16b0d74227..759e7e38263 100644 --- a/crates/fuel-core/src/service/adapters/producer.rs +++ b/crates/fuel-core/src/service/adapters/producer.rs @@ -248,13 +248,12 @@ impl fuel_core_producer::ports::BlockProducerDatabase for OnChainIterableKeyValu } } -#[async_trait::async_trait] impl GasPriceProvider for StaticGasPrice { - async fn production_gas_price(&self) -> anyhow::Result { + fn production_gas_price(&self) -> anyhow::Result { Ok(self.gas_price) } - async fn dry_run_gas_price(&self) -> anyhow::Result { + fn dry_run_gas_price(&self) -> anyhow::Result { Ok(self.gas_price) } } diff --git a/crates/services/gas_price_service/src/common/l2_block_source.rs b/crates/services/gas_price_service/src/common/l2_block_source.rs index 5896ed183f7..d53a489bcbc 100644 --- a/crates/services/gas_price_service/src/common/l2_block_source.rs +++ b/crates/services/gas_price_service/src/common/l2_block_source.rs @@ -19,11 +19,11 @@ use fuel_core_types::{ fuel_types::BlockHeight, services::block_importer::SharedImportResult, }; +use std::future::Future; use tokio_stream::StreamExt; -#[async_trait::async_trait] pub trait L2BlockSource: Send + Sync { - async fn get_l2_block(&mut self) -> GasPriceResult; + fn get_l2_block(&mut self) -> impl Future> + Send; } pub struct FuelL2BlockSource { @@ -46,7 +46,6 @@ impl FuelL2BlockSource { } } -#[async_trait::async_trait] impl L2BlockSource for FuelL2BlockSource where Settings: GasPriceSettingsProvider + Send + Sync, diff --git a/crates/services/gas_price_service/src/v0/service.rs b/crates/services/gas_price_service/src/v0/service.rs index e0a794c0da9..62f4706aa6e 100644 --- a/crates/services/gas_price_service/src/v0/service.rs +++ b/crates/services/gas_price_service/src/v0/service.rs @@ -203,7 +203,6 @@ mod tests { l2_block: mpsc::Receiver, } - #[async_trait::async_trait] impl L2BlockSource for FakeL2BlockSource { async fn get_l2_block(&mut self) -> GasPriceResult { let block = self.l2_block.recv().await.unwrap(); diff --git a/crates/services/gas_price_service/src/v0/tests.rs b/crates/services/gas_price_service/src/v0/tests.rs index 85aeb4fe36a..51b9b49c415 100644 --- a/crates/services/gas_price_service/src/v0/tests.rs +++ b/crates/services/gas_price_service/src/v0/tests.rs @@ -67,7 +67,6 @@ struct FakeL2BlockSource { l2_block: Receiver, } -#[async_trait::async_trait] impl L2BlockSource for FakeL2BlockSource { async fn get_l2_block(&mut self) -> GasPriceResult { let block = self.l2_block.recv().await.unwrap(); diff --git a/crates/services/gas_price_service/src/v1/service.rs b/crates/services/gas_price_service/src/v1/service.rs index c0f5e2eb5c4..6f66bf74ad1 100644 --- a/crates/services/gas_price_service/src/v1/service.rs +++ b/crates/services/gas_price_service/src/v1/service.rs @@ -521,7 +521,6 @@ mod tests { l2_block: mpsc::Receiver, } - #[async_trait::async_trait] impl L2BlockSource for FakeL2BlockSource { async fn get_l2_block(&mut self) -> GasPriceResult { let block = self.l2_block.recv().await.unwrap(); diff --git a/crates/services/gas_price_service/src/v1/tests.rs b/crates/services/gas_price_service/src/v1/tests.rs index 7474e0d7eec..81edb427ff4 100644 --- a/crates/services/gas_price_service/src/v1/tests.rs +++ b/crates/services/gas_price_service/src/v1/tests.rs @@ -116,7 +116,6 @@ struct FakeL2BlockSource { l2_block: Receiver, } -#[async_trait::async_trait] impl L2BlockSource for FakeL2BlockSource { async fn get_l2_block(&mut self) -> GasPriceResult { let block = self.l2_block.recv().await.unwrap(); diff --git a/crates/services/producer/src/block_producer.rs b/crates/services/producer/src/block_producer.rs index 4a8972a187b..d8dd3bcf133 100644 --- a/crates/services/producer/src/block_producer.rs +++ b/crates/services/producer/src/block_producer.rs @@ -247,14 +247,12 @@ where async fn production_gas_price(&self) -> anyhow::Result { self.gas_price_provider .production_gas_price() - .await .map_err(|e| anyhow!("No gas price found: {e:?}")) } async fn dry_run_gas_price(&self) -> anyhow::Result { self.gas_price_provider .dry_run_gas_price() - .await .map_err(|e| anyhow!("No gas price found: {e:?}")) } } diff --git a/crates/services/producer/src/block_producer/gas_price.rs b/crates/services/producer/src/block_producer/gas_price.rs index d4026b59bc6..8f5c3af679b 100644 --- a/crates/services/producer/src/block_producer/gas_price.rs +++ b/crates/services/producer/src/block_producer/gas_price.rs @@ -1,13 +1,12 @@ use fuel_core_types::blockchain::header::ConsensusParametersVersion; use std::sync::Arc; -#[async_trait::async_trait] /// Interface for retrieving the gas price for a block pub trait GasPriceProvider { /// The gas price for all transactions in the block. - async fn production_gas_price(&self) -> anyhow::Result; + fn production_gas_price(&self) -> anyhow::Result; - async fn dry_run_gas_price(&self) -> anyhow::Result; + fn dry_run_gas_price(&self) -> anyhow::Result; } /// Interface for retrieving the consensus parameters. diff --git a/crates/services/producer/src/block_producer/tests.rs b/crates/services/producer/src/block_producer/tests.rs index 84dde81cc73..371602633ef 100644 --- a/crates/services/producer/src/block_producer/tests.rs +++ b/crates/services/producer/src/block_producer/tests.rs @@ -70,14 +70,13 @@ impl MockProducerGasPrice { } } -#[async_trait::async_trait] impl GasPriceProvider for MockProducerGasPrice { - async fn production_gas_price(&self) -> anyhow::Result { + fn production_gas_price(&self) -> anyhow::Result { self.gas_price .ok_or_else(|| anyhow::anyhow!("Gas price not provided")) } - async fn dry_run_gas_price(&self) -> anyhow::Result { + fn dry_run_gas_price(&self) -> anyhow::Result { self.gas_price .ok_or_else(|| anyhow::anyhow!("Gas price not provided")) }