From e33b3566b3424a73209528c71c75d3aedc3097c0 Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 5 Feb 2024 15:37:05 -0800 Subject: [PATCH 01/17] Add LatestGasPrice to schema --- crates/client/assets/schema.sdl | 5 +++ crates/client/src/client.rs | 6 ++++ crates/client/src/client/schema.rs | 2 ++ crates/client/src/client/schema/gas_price.rs | 29 +++++++++++++++ crates/client/src/client/types.rs | 2 ++ crates/client/src/client/types/gas_price.rs | 16 +++++++++ crates/fuel-core/src/schema.rs | 3 ++ crates/fuel-core/src/schema/gas_price.rs | 37 ++++++++++++++++++++ 8 files changed, 100 insertions(+) create mode 100644 crates/client/src/client/schema/gas_price.rs create mode 100644 crates/client/src/client/types/gas_price.rs create mode 100644 crates/fuel-core/src/schema/gas_price.rs diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 03d1f6efb7..0c8cda687a 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -518,6 +518,10 @@ type InputMessage { } +type LatestGasPrice { + gasPrice: U64! +} + type LightOperation { base: U64! unitsPerGas: U64! @@ -806,6 +810,7 @@ type Query { contractBalance(contract: ContractId!, asset: AssetId!): ContractBalance! contractBalances(filter: ContractBalanceFilterInput!, first: Int, after: String, last: Int, before: String): ContractBalanceConnection! nodeInfo: NodeInfo! + latestGasPrice: LatestGasPrice! message(nonce: Nonce!): Message messages(owner: Address, first: Int, after: String, last: Int, before: String): MessageConnection! messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index a6b8ab0dbf..64c85098a3 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -12,6 +12,7 @@ use crate::client::{ TransactionId, }, types::{ + gas_price::LatestGasPrice, message::MessageStatus, primitives::{ Address, @@ -348,6 +349,11 @@ impl FuelClient { self.query(query).await.map(|r| r.node_info.into()) } + pub async fn latest_gas_price(&self) -> io::Result { + let query = schema::gas_price::QueryLatestGasPrice::build(()); + self.query(query).await.map(|r| r.latest_gas_price.into()) + } + pub async fn connected_peers_info(&self) -> io::Result> { let query = schema::node_info::QueryPeersInfo::build(()); self.query(query) diff --git a/crates/client/src/client/schema.rs b/crates/client/src/client/schema.rs index 11de7251d2..1cacc5a8bb 100644 --- a/crates/client/src/client/schema.rs +++ b/crates/client/src/client/schema.rs @@ -33,6 +33,8 @@ pub mod coins; pub mod contract; pub mod message; pub mod node_info; + +pub mod gas_price; pub mod primitives; pub mod tx; diff --git a/crates/client/src/client/schema/gas_price.rs b/crates/client/src/client/schema/gas_price.rs new file mode 100644 index 0000000000..33db0f0b00 --- /dev/null +++ b/crates/client/src/client/schema/gas_price.rs @@ -0,0 +1,29 @@ +use crate::client::schema::{ + schema, + U64, +}; + +#[derive(cynic::QueryFragment, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub struct LatestGasPrice { + pub gas_price: U64, + // pub block_height: U64, +} + +#[derive(cynic::QueryFragment, Debug)] +#[cynic(schema_path = "./assets/schema.sdl", graphql_type = "Query")] +pub struct QueryLatestGasPrice { + pub latest_gas_price: LatestGasPrice, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn latest_gas_price_query_gql_output() { + use cynic::QueryBuilder; + let operation = QueryLatestGasPrice::build(()); + insta::assert_snapshot!(operation.query) + } +} diff --git a/crates/client/src/client/types.rs b/crates/client/src/client/types.rs index ab656627f3..5cbab01afc 100644 --- a/crates/client/src/client/types.rs +++ b/crates/client/src/client/types.rs @@ -4,6 +4,8 @@ pub mod chain_info; pub mod coins; pub mod contract; pub mod gas_costs; + +pub mod gas_price; pub mod merkle_proof; pub mod message; pub mod node_info; diff --git a/crates/client/src/client/types/gas_price.rs b/crates/client/src/client/types/gas_price.rs new file mode 100644 index 0000000000..7749ab9d3a --- /dev/null +++ b/crates/client/src/client/types/gas_price.rs @@ -0,0 +1,16 @@ +use crate::client::schema; + +pub struct LatestGasPrice { + pub gas_price: u64, + // pub block_height: u64, +} + +// GraphQL Translation +impl From for LatestGasPrice { + fn from(value: schema::gas_price::LatestGasPrice) -> Self { + Self { + gas_price: value.gas_price.into(), + // block_height: value.block_height.into(), + } + } +} diff --git a/crates/fuel-core/src/schema.rs b/crates/fuel-core/src/schema.rs index 8258980950..e0d4997311 100644 --- a/crates/fuel-core/src/schema.rs +++ b/crates/fuel-core/src/schema.rs @@ -28,6 +28,8 @@ pub mod dap; pub mod health; pub mod message; pub mod node_info; + +pub mod gas_price; pub mod scalars; pub mod tx; @@ -43,6 +45,7 @@ pub struct Query( contract::ContractQuery, contract::ContractBalanceQuery, node_info::NodeQuery, + gas_price::LatestGasPriceQuery, message::MessageQuery, ); diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs new file mode 100644 index 0000000000..ad6d2b57ad --- /dev/null +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -0,0 +1,37 @@ +use super::scalars::U64; +use crate::fuel_core_graphql_api::Config as GraphQLConfig; +use async_graphql::{ + Context, + Object, +}; + +pub struct LatestGasPrice { + pub gas_price: U64, + // pub block_height: u64, +} + +#[Object] +impl LatestGasPrice { + async fn gas_price(&self) -> U64 { + self.gas_price + } + + // async fn block_height(&self) -> u64 { + // self.block_height + // } +} + +#[derive(Default)] +pub struct LatestGasPriceQuery {} + +#[Object] +impl LatestGasPriceQuery { + async fn latest_gas_price(&self, ctx: &Context<'_>) -> LatestGasPrice { + let config = ctx.data_unchecked::(); + + LatestGasPrice { + gas_price: config.min_gas_price.into(), + // block_height: config.block_height.into(), + } + } +} From c8c66edf149bfcecdae4f79cd4d42ed4feea0eda Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 5 Feb 2024 16:29:00 -0800 Subject: [PATCH 02/17] Add block height --- crates/client/assets/schema.sdl | 1 + crates/client/src/client/schema/gas_price.rs | 2 +- ...ts__latest_gas_price_query_gql_output.snap | 12 +++++++ crates/client/src/client/types/gas_price.rs | 4 +-- crates/fuel-core/src/schema/gas_price.rs | 32 +++++++++++++------ 5 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__latest_gas_price_query_gql_output.snap diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 0c8cda687a..09c6b9945d 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -520,6 +520,7 @@ type InputMessage { type LatestGasPrice { gasPrice: U64! + blockHeight: U64! } type LightOperation { diff --git a/crates/client/src/client/schema/gas_price.rs b/crates/client/src/client/schema/gas_price.rs index 33db0f0b00..45462bc3d7 100644 --- a/crates/client/src/client/schema/gas_price.rs +++ b/crates/client/src/client/schema/gas_price.rs @@ -7,7 +7,7 @@ use crate::client::schema::{ #[cynic(schema_path = "./assets/schema.sdl")] pub struct LatestGasPrice { pub gas_price: U64, - // pub block_height: U64, + pub block_height: U64, } #[derive(cynic::QueryFragment, Debug)] diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__latest_gas_price_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__latest_gas_price_query_gql_output.snap new file mode 100644 index 0000000000..c39679de79 --- /dev/null +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__latest_gas_price_query_gql_output.snap @@ -0,0 +1,12 @@ +--- +source: crates/client/src/client/schema/gas_price.rs +expression: operation.query +--- +query { + latestGasPrice { + gasPrice + blockHeight + } +} + + diff --git a/crates/client/src/client/types/gas_price.rs b/crates/client/src/client/types/gas_price.rs index 7749ab9d3a..b0371667b0 100644 --- a/crates/client/src/client/types/gas_price.rs +++ b/crates/client/src/client/types/gas_price.rs @@ -2,7 +2,7 @@ use crate::client::schema; pub struct LatestGasPrice { pub gas_price: u64, - // pub block_height: u64, + pub block_height: u64, } // GraphQL Translation @@ -10,7 +10,7 @@ impl From for LatestGasPrice { fn from(value: schema::gas_price::LatestGasPrice) -> Self { Self { gas_price: value.gas_price.into(), - // block_height: value.block_height.into(), + block_height: value.block_height.into(), } } } diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index ad6d2b57ad..ebe6b924b0 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -1,13 +1,20 @@ use super::scalars::U64; -use crate::fuel_core_graphql_api::Config as GraphQLConfig; +use crate::{ + fuel_core_graphql_api::{ + database::ReadView, + Config as GraphQLConfig, + }, + query::BlockQueryData, +}; use async_graphql::{ Context, Object, }; +use fuel_core_types::blockchain::block::Block; pub struct LatestGasPrice { pub gas_price: U64, - // pub block_height: u64, + pub block_height: U64, } #[Object] @@ -16,9 +23,9 @@ impl LatestGasPrice { self.gas_price } - // async fn block_height(&self) -> u64 { - // self.block_height - // } + async fn block_height(&self) -> U64 { + self.block_height + } } #[derive(Default)] @@ -26,12 +33,19 @@ pub struct LatestGasPriceQuery {} #[Object] impl LatestGasPriceQuery { - async fn latest_gas_price(&self, ctx: &Context<'_>) -> LatestGasPrice { + async fn latest_gas_price( + &self, + ctx: &Context<'_>, + ) -> async_graphql::Result { let config = ctx.data_unchecked::(); - LatestGasPrice { + let query: &ReadView = ctx.data_unchecked(); + let latest_block: Block<_> = query.latest_block()?.into(); + let block_height: u64 = u32::from(*latest_block.header().height()).into(); + + Ok(LatestGasPrice { gas_price: config.min_gas_price.into(), - // block_height: config.block_height.into(), - } + block_height: block_height.into(), + }) } } From b01503f19ec0634a3400aa33639c557920e90352 Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 5 Feb 2024 16:32:56 -0800 Subject: [PATCH 03/17] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1482cf545..d4596bbac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Description of the upcoming release here. ### Changed +- [#1649](https://github.com/FuelLabs/fuel-core/pull/1649): Add api endpoint for getting latest gas price - [#1600](https://github.com/FuelLabs/fuel-core/pull/1640): Upgrade to fuel-vm 0.45.0 - [#1633](https://github.com/FuelLabs/fuel-core/pull/1633): Notify services about importing of the genesis block. - [#1625](https://github.com/FuelLabs/fuel-core/pull/1625): Making relayer independent from the executor and preparation for the force transaction inclusion. From 21e0bbe67043595834a757fecbab99d9da59787f Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 5 Feb 2024 16:39:27 -0800 Subject: [PATCH 04/17] Appease Clippy-sama --- crates/fuel-core/src/schema/gas_price.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index ebe6b924b0..5f733020cd 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -40,7 +40,7 @@ impl LatestGasPriceQuery { let config = ctx.data_unchecked::(); let query: &ReadView = ctx.data_unchecked(); - let latest_block: Block<_> = query.latest_block()?.into(); + let latest_block: Block<_> = query.latest_block()?; let block_height: u64 = u32::from(*latest_block.header().height()).into(); Ok(LatestGasPrice { From 12051cd46feeee251cfb73ddd2da6bcd2d451b26 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 13:59:41 -0800 Subject: [PATCH 05/17] Add integ test --- tests/tests/gas_price.rs | 18 ++++++++++++++++++ tests/tests/lib.rs | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 tests/tests/gas_price.rs diff --git a/tests/tests/gas_price.rs b/tests/tests/gas_price.rs new file mode 100644 index 0000000000..ce432ee70e --- /dev/null +++ b/tests/tests/gas_price.rs @@ -0,0 +1,18 @@ +use fuel_core::service::{ + Config, + FuelService, +}; +use fuel_core_client::client::{ + types::gas_price::LatestGasPrice, + FuelClient, +}; + +#[tokio::test] +async fn latest_gas_price() { + let node_config = Config::local_node(); + let srv = FuelService::new_node(node_config.clone()).await.unwrap(); + let client = FuelClient::from(srv.bound_address); + + let LatestGasPrice { gas_price, .. } = client.latest_gas_price().await.unwrap(); + assert_eq!(gas_price, node_config.txpool.min_gas_price); +} diff --git a/tests/tests/lib.rs b/tests/tests/lib.rs index 8d834d0b5d..005c78dc0b 100644 --- a/tests/tests/lib.rs +++ b/tests/tests/lib.rs @@ -11,6 +11,8 @@ mod dap; mod debugger; mod deployment; mod fee_collection_contract; + +mod gas_price; mod health; mod helpers; mod messages; From e4946a40040b08a6441dee5fe2e757a47c4718b7 Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 8 Feb 2024 15:12:53 -0800 Subject: [PATCH 06/17] Use u32 for block height --- crates/client/assets/schema.sdl | 2 +- crates/client/src/client/schema/gas_price.rs | 3 ++- crates/client/src/client/types/gas_price.rs | 2 +- crates/fuel-core/src/schema/gas_price.rs | 11 +++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 09c6b9945d..712f906da1 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -520,7 +520,7 @@ type InputMessage { type LatestGasPrice { gasPrice: U64! - blockHeight: U64! + blockHeight: U32! } type LightOperation { diff --git a/crates/client/src/client/schema/gas_price.rs b/crates/client/src/client/schema/gas_price.rs index 45462bc3d7..c9ad7e598b 100644 --- a/crates/client/src/client/schema/gas_price.rs +++ b/crates/client/src/client/schema/gas_price.rs @@ -1,5 +1,6 @@ use crate::client::schema::{ schema, + U32, U64, }; @@ -7,7 +8,7 @@ use crate::client::schema::{ #[cynic(schema_path = "./assets/schema.sdl")] pub struct LatestGasPrice { pub gas_price: U64, - pub block_height: U64, + pub block_height: U32, } #[derive(cynic::QueryFragment, Debug)] diff --git a/crates/client/src/client/types/gas_price.rs b/crates/client/src/client/types/gas_price.rs index b0371667b0..748c90518c 100644 --- a/crates/client/src/client/types/gas_price.rs +++ b/crates/client/src/client/types/gas_price.rs @@ -2,7 +2,7 @@ use crate::client::schema; pub struct LatestGasPrice { pub gas_price: u64, - pub block_height: u64, + pub block_height: u32, } // GraphQL Translation diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index 5f733020cd..2fa7947e86 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -1,4 +1,7 @@ -use super::scalars::U64; +use super::scalars::{ + U32, + U64, +}; use crate::{ fuel_core_graphql_api::{ database::ReadView, @@ -14,7 +17,7 @@ use fuel_core_types::blockchain::block::Block; pub struct LatestGasPrice { pub gas_price: U64, - pub block_height: U64, + pub block_height: U32, } #[Object] @@ -23,7 +26,7 @@ impl LatestGasPrice { self.gas_price } - async fn block_height(&self) -> U64 { + async fn block_height(&self) -> U32 { self.block_height } } @@ -41,7 +44,7 @@ impl LatestGasPriceQuery { let query: &ReadView = ctx.data_unchecked(); let latest_block: Block<_> = query.latest_block()?; - let block_height: u64 = u32::from(*latest_block.header().height()).into(); + let block_height = u32::from(*latest_block.header().height()); Ok(LatestGasPrice { gas_price: config.min_gas_price.into(), From b53b6907772400433cdae3d0352d756ecaa25245 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 12:43:16 -0800 Subject: [PATCH 07/17] Create schemas for getting gas price estimate --- crates/client/assets/schema.sdl | 5 +++ crates/client/src/client.rs | 13 +++++++- crates/client/src/client/schema/gas_price.rs | 22 +++++++++++++ crates/client/src/client/types/gas_price.rs | 12 +++++++ crates/fuel-core/src/schema.rs | 1 + crates/fuel-core/src/schema/gas_price.rs | 34 ++++++++++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 712f906da1..c49b70531a 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -272,6 +272,10 @@ type DryRunTransactionExecutionStatus { union DryRunTransactionStatus = DryRunSuccessStatus | DryRunFailureStatus +type EstimateGasPrice { + gasPrice: U64! +} + input ExcludeInput { """ Utxos to exclude from the selection. @@ -812,6 +816,7 @@ type Query { contractBalances(filter: ContractBalanceFilterInput!, first: Int, after: String, last: Int, before: String): ContractBalanceConnection! nodeInfo: NodeInfo! latestGasPrice: LatestGasPrice! + estimateGasPrice(blockHorizon: U64): EstimateGasPrice! message(nonce: Nonce!): Message messages(owner: Address, first: Int, after: String, last: Int, before: String): MessageConnection! messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 64c85098a3..09d6b3ab62 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -12,7 +12,10 @@ use crate::client::{ TransactionId, }, types::{ - gas_price::LatestGasPrice, + gas_price::{ + EstimateGasPrice, + LatestGasPrice, + }, message::MessageStatus, primitives::{ Address, @@ -354,6 +357,14 @@ impl FuelClient { self.query(query).await.map(|r| r.latest_gas_price.into()) } + pub async fn estimate_gas_price( + &self, + block_horizon: u32, + ) -> io::Result { + let query = schema::gas_price::QueryEstimateGasPrice::build(block_horizon.into()); + self.query(query).await.map(|r| r.estimate_gas_price) + } + pub async fn connected_peers_info(&self) -> io::Result> { let query = schema::node_info::QueryPeersInfo::build(()); self.query(query) diff --git a/crates/client/src/client/schema/gas_price.rs b/crates/client/src/client/schema/gas_price.rs index c9ad7e598b..9a3173f27c 100644 --- a/crates/client/src/client/schema/gas_price.rs +++ b/crates/client/src/client/schema/gas_price.rs @@ -17,6 +17,28 @@ pub struct QueryLatestGasPrice { pub latest_gas_price: LatestGasPrice, } +#[derive(cynic::QueryFragment, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub struct EstimateGasPrice { + pub gas_price: U64, +} + +#[derive(cynic::QueryVariables, Debug)] +pub struct BlockHorizonArgs { + pub block_horizon: Option, +} + +#[derive(cynic::QueryFragment, Debug)] +#[cynic( + schema_path = "./assets/schema.sdl", + graphql_type = "Query", + variables = "BlockHorizonArgs" +)] +pub struct QueryEstimateGasPrice { + #[arguments(block_horizon: $block_horizon)] + pub estimate_gas_price: EstimateGasPrice, +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/client/src/client/types/gas_price.rs b/crates/client/src/client/types/gas_price.rs index 748c90518c..33b81787b6 100644 --- a/crates/client/src/client/types/gas_price.rs +++ b/crates/client/src/client/types/gas_price.rs @@ -14,3 +14,15 @@ impl From for LatestGasPrice { } } } + +pub struct EstimateGasPrice { + pub gas_price: u64, +} + +impl From for EstimateGasPrice { + fn from(value: schema::gas_price::EstimateGasPrice) -> Self { + Self { + gas_price: value.gas_price.into(), + } + } +} diff --git a/crates/fuel-core/src/schema.rs b/crates/fuel-core/src/schema.rs index e0d4997311..f1df9c6d4f 100644 --- a/crates/fuel-core/src/schema.rs +++ b/crates/fuel-core/src/schema.rs @@ -46,6 +46,7 @@ pub struct Query( contract::ContractBalanceQuery, node_info::NodeQuery, gas_price::LatestGasPriceQuery, + gas_price::EstimateGasPriceQuery, message::MessageQuery, ); diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index 2fa7947e86..03ac5e67ea 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -52,3 +52,37 @@ impl LatestGasPriceQuery { }) } } + +pub struct EstimateGasPrice { + pub gas_price: U64, +} + +#[Object] +impl EstimateGasPrice { + async fn gas_price(&self) -> U64 { + self.gas_price + } +} + +#[derive(Default)] +pub struct EstimateGasPriceQuery {} + +#[Object] +impl EstimateGasPriceQuery { + async fn estimate_gas_price( + &self, + ctx: &Context<'_>, + #[graphql( + desc = "Number of blocks into the future to estimate the gas price for" + )] + block_horizon: Option, + ) -> async_graphql::Result { + // TODO: implement this using the `block_horizon` parameter + let _ = block_horizon; + + let config = ctx.data_unchecked::(); + let gas_price = config.min_gas_price.into(); + + Ok(EstimateGasPrice { gas_price }) + } +} From 06138b6a55a5b579b182a7a56f94dcb76ecf6966 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 14:18:24 -0800 Subject: [PATCH 08/17] Fix most of errors --- crates/client/src/client.rs | 6 ++---- crates/client/src/client/schema/gas_price.rs | 10 +++++++++- crates/fuel-core/src/schema/gas_price.rs | 2 +- tests/tests/gas_price.rs | 18 +++++++++++++++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 09d6b3ab62..03bb0b7c06 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -6,16 +6,14 @@ use crate::client::{ SpendQueryElementInput, }, contract::ContractBalanceQueryArgs, + gas_price::EstimateGasPrice, message::MessageStatusArgs, tx::DryRunArg, Tai64Timestamp, TransactionId, }, types::{ - gas_price::{ - EstimateGasPrice, - LatestGasPrice, - }, + gas_price::LatestGasPrice, message::MessageStatus, primitives::{ Address, diff --git a/crates/client/src/client/schema/gas_price.rs b/crates/client/src/client/schema/gas_price.rs index 9a3173f27c..dd6801de63 100644 --- a/crates/client/src/client/schema/gas_price.rs +++ b/crates/client/src/client/schema/gas_price.rs @@ -28,6 +28,14 @@ pub struct BlockHorizonArgs { pub block_horizon: Option, } +impl From for BlockHorizonArgs { + fn from(block_horizon: u32) -> Self { + Self { + block_horizon: Some(block_horizon.into()), + } + } +} + #[derive(cynic::QueryFragment, Debug)] #[cynic( schema_path = "./assets/schema.sdl", @@ -35,7 +43,7 @@ pub struct BlockHorizonArgs { variables = "BlockHorizonArgs" )] pub struct QueryEstimateGasPrice { - #[arguments(block_horizon: $block_horizon)] + #[arguments(blockHorizon: $block_horizon)] pub estimate_gas_price: EstimateGasPrice, } diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index 03ac5e67ea..8a8a1095fa 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -77,7 +77,7 @@ impl EstimateGasPriceQuery { )] block_horizon: Option, ) -> async_graphql::Result { - // TODO: implement this using the `block_horizon` parameter + // TODO: implement dynamic calculation based on block horizon let _ = block_horizon; let config = ctx.data_unchecked::(); diff --git a/tests/tests/gas_price.rs b/tests/tests/gas_price.rs index ce432ee70e..5b4a79db38 100644 --- a/tests/tests/gas_price.rs +++ b/tests/tests/gas_price.rs @@ -3,7 +3,10 @@ use fuel_core::service::{ FuelService, }; use fuel_core_client::client::{ - types::gas_price::LatestGasPrice, + types::gas_price::{ + EstimateGasPrice, + LatestGasPrice, + }, FuelClient, }; @@ -16,3 +19,16 @@ async fn latest_gas_price() { let LatestGasPrice { gas_price, .. } = client.latest_gas_price().await.unwrap(); assert_eq!(gas_price, node_config.txpool.min_gas_price); } + +#[tokio::test] +async fn estimate_gas_price() { + let node_config = Config::local_node(); + let srv = FuelService::new_node(node_config.clone()).await.unwrap(); + let client = FuelClient::from(srv.bound_address); + + let arbitrary_horizon = 10; + + let EstimateGasPrice { gas_price } = + client.estimate_gas_price(arbitrary_horizon).await.unwrap(); + assert_eq!(gas_price, node_config.txpool.min_gas_price); +} From b84284c22af86159d325e59932e6d0822db76d9b Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 15:39:50 -0800 Subject: [PATCH 09/17] Fix wrong type --- crates/client/assets/schema.sdl | 2 +- crates/fuel-core/src/schema/gas_price.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index c49b70531a..507b4829a2 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -816,7 +816,7 @@ type Query { contractBalances(filter: ContractBalanceFilterInput!, first: Int, after: String, last: Int, before: String): ContractBalanceConnection! nodeInfo: NodeInfo! latestGasPrice: LatestGasPrice! - estimateGasPrice(blockHorizon: U64): EstimateGasPrice! + estimateGasPrice(blockHorizon: U32): EstimateGasPrice! message(nonce: Nonce!): Message messages(owner: Address, first: Int, after: String, last: Int, before: String): MessageConnection! messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index 8a8a1095fa..766967fc1f 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -75,7 +75,7 @@ impl EstimateGasPriceQuery { #[graphql( desc = "Number of blocks into the future to estimate the gas price for" )] - block_horizon: Option, + block_horizon: Option, ) -> async_graphql::Result { // TODO: implement dynamic calculation based on block horizon let _ = block_horizon; From c7794c4025100c21360d6e36ca2d53f70047e832 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 15:42:21 -0800 Subject: [PATCH 10/17] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4596bbac9..821819493c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Description of the upcoming release here. ### Changed +- [#1650](https://github.com/FuelLabs/fuel-core/pull/1650): Add api endpoint for getting estimates for future gas prices - [#1649](https://github.com/FuelLabs/fuel-core/pull/1649): Add api endpoint for getting latest gas price - [#1600](https://github.com/FuelLabs/fuel-core/pull/1640): Upgrade to fuel-vm 0.45.0 - [#1633](https://github.com/FuelLabs/fuel-core/pull/1633): Notify services about importing of the genesis block. From 8036459501834c19f3d5cd723c4911d4a7116c1a Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 15:52:01 -0800 Subject: [PATCH 11/17] Add snaphot test --- crates/client/src/client/schema/gas_price.rs | 8 ++++++++ ...e__tests__estimate_gas_price_query_gql_output.snap | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__estimate_gas_price_query_gql_output.snap diff --git a/crates/client/src/client/schema/gas_price.rs b/crates/client/src/client/schema/gas_price.rs index dd6801de63..7032b6ad32 100644 --- a/crates/client/src/client/schema/gas_price.rs +++ b/crates/client/src/client/schema/gas_price.rs @@ -57,4 +57,12 @@ mod tests { let operation = QueryLatestGasPrice::build(()); insta::assert_snapshot!(operation.query) } + + #[test] + fn estimate_gas_price_query_gql_output() { + use cynic::QueryBuilder; + let arbitrary_horizon = 10; + let operation = QueryEstimateGasPrice::build(arbitrary_horizon.into()); + insta::assert_snapshot!(operation.query) + } } diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__estimate_gas_price_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__estimate_gas_price_query_gql_output.snap new file mode 100644 index 0000000000..854f7608ef --- /dev/null +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__gas_price__tests__estimate_gas_price_query_gql_output.snap @@ -0,0 +1,11 @@ +--- +source: crates/client/src/client/schema/gas_price.rs +expression: operation.query +--- +query($blockHorizon: U32) { + estimateGasPrice(blockHorizon: $blockHorizon) { + gasPrice + } +} + + From 3299927f1329afd9f8ba86a07b778f38b7f50757 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 6 Feb 2024 16:10:25 -0800 Subject: [PATCH 12/17] Fix test --- tests/tests/gas_price.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/tests/gas_price.rs b/tests/tests/gas_price.rs index 5b4a79db38..08a13fc268 100644 --- a/tests/tests/gas_price.rs +++ b/tests/tests/gas_price.rs @@ -3,10 +3,8 @@ use fuel_core::service::{ FuelService, }; use fuel_core_client::client::{ - types::gas_price::{ - EstimateGasPrice, - LatestGasPrice, - }, + schema::gas_price::EstimateGasPrice, + types::gas_price::LatestGasPrice, FuelClient, }; @@ -30,5 +28,5 @@ async fn estimate_gas_price() { let EstimateGasPrice { gas_price } = client.estimate_gas_price(arbitrary_horizon).await.unwrap(); - assert_eq!(gas_price, node_config.txpool.min_gas_price); + assert_eq!(u64::from(gas_price), node_config.txpool.min_gas_price); } From d0380946ac8f42d6ae3d632228c0ea1287c22bbf Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 8 Feb 2024 15:25:21 -0800 Subject: [PATCH 13/17] Include issue on TODO --- crates/fuel-core/src/schema/gas_price.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index 766967fc1f..29e80dae1a 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -78,6 +78,7 @@ impl EstimateGasPriceQuery { block_horizon: Option, ) -> async_graphql::Result { // TODO: implement dynamic calculation based on block horizon + // https://github.com/FuelLabs/fuel-core/issues/1653 let _ = block_horizon; let config = ctx.data_unchecked::(); From c3b4733c0243a1e3d8e2944b50c7f461916eabf4 Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 8 Feb 2024 15:50:20 -0800 Subject: [PATCH 14/17] Update schema --- crates/client/assets/schema.sdl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 6a471f0020..507b4829a2 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -522,6 +522,11 @@ type InputMessage { } +type LatestGasPrice { + gasPrice: U64! + blockHeight: U32! +} + type LightOperation { base: U64! unitsPerGas: U64! @@ -810,6 +815,8 @@ type Query { contractBalance(contract: ContractId!, asset: AssetId!): ContractBalance! contractBalances(filter: ContractBalanceFilterInput!, first: Int, after: String, last: Int, before: String): ContractBalanceConnection! nodeInfo: NodeInfo! + latestGasPrice: LatestGasPrice! + estimateGasPrice(blockHorizon: U32): EstimateGasPrice! message(nonce: Nonce!): Message messages(owner: Address, first: Int, after: String, last: Int, before: String): MessageConnection! messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof From 295ecb0ff7f24eecce4bdafef69b52b37b4a1672 Mon Sep 17 00:00:00 2001 From: mitchell Date: Fri, 9 Feb 2024 10:57:33 -0800 Subject: [PATCH 15/17] Bump rust docker version --- deployment/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/Dockerfile b/deployment/Dockerfile index f201b3ee60..55fa5536fa 100644 --- a/deployment/Dockerfile +++ b/deployment/Dockerfile @@ -1,6 +1,6 @@ # Stage 1: Build FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx -FROM --platform=$BUILDPLATFORM rust:1.73.0 AS chef +FROM --platform=$BUILDPLATFORM rust:1.74.0 AS chef ARG TARGETPLATFORM RUN cargo install cargo-chef From 63fc74d5a1e1350a322e4647b471d69e63107e6d Mon Sep 17 00:00:00 2001 From: mitchell Date: Fri, 9 Feb 2024 11:22:20 -0800 Subject: [PATCH 16/17] Empty From 3d094a33789f4c39cdcdfd207dd4e365d53c277d Mon Sep 17 00:00:00 2001 From: mitchell Date: Fri, 9 Feb 2024 14:38:51 -0800 Subject: [PATCH 17/17] Empty