From 79ba8d58730830c7c5a899c39672fe0ec23913ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Chabowski?= Date: Fri, 17 Jan 2025 16:21:45 +0100 Subject: [PATCH 1/9] Expose indexation status in `NodeInfo` endpoint --- crates/client/assets/schema.sdl | 16 +++++++ crates/fuel-core/src/schema/node_info.rs | 59 +++++++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 6829d9d3953..7ce6f040c65 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -580,6 +580,21 @@ type HeavyOperation { scalar HexString +type Indexation { + """ + Is balances indexation enabled + """ + balances: Boolean! + """ + Is coins to spend indexation enabled + """ + coinsToSpend: Boolean! + """ + Is asset metadata indexation enabled + """ + assetMetadata: Boolean! +} + union Input = InputCoin | InputContract | InputMessage type InputCoin { @@ -764,6 +779,7 @@ type NodeInfo { maxSize: U64! maxDepth: U64! nodeVersion: String! + indexation: Indexation! txPoolStats: TxPoolStats! peers: [PeerInfo!]! } diff --git a/crates/fuel-core/src/schema/node_info.rs b/crates/fuel-core/src/schema/node_info.rs index d02070b361b..22afa226d85 100644 --- a/crates/fuel-core/src/schema/node_info.rs +++ b/crates/fuel-core/src/schema/node_info.rs @@ -3,17 +3,24 @@ use super::scalars::{ U64, }; use crate::{ + database::database_description::IndexationKind, fuel_core_graphql_api::{ query_costs, Config as GraphQLConfig, }, - graphql_api::api_service::TxPool, + graphql_api::{ + api_service::TxPool, + database::ReadDatabase, + }, }; use async_graphql::{ Context, Object, }; -use std::time::UNIX_EPOCH; +use std::{ + collections::HashSet, + time::UNIX_EPOCH, +}; pub struct NodeInfo { utxo_validation: bool, @@ -23,6 +30,7 @@ pub struct NodeInfo { max_size: U64, max_depth: U64, node_version: String, + indexation: Indexation, } #[Object] @@ -55,6 +63,10 @@ impl NodeInfo { self.node_version.to_owned() } + async fn indexation(&self) -> &Indexation { + &self.indexation + } + #[graphql(complexity = "query_costs().storage_read + child_complexity")] async fn tx_pool_stats( &self, @@ -94,6 +106,27 @@ impl NodeQuery { const VERSION: &str = env!("CARGO_PKG_VERSION"); + let db = ctx.data_unchecked::(); + let read_view = db.view()?; + let indexation = HashSet::from_iter( + [ + ( + read_view.balances_indexation_enabled, + IndexationKind::Balances, + ), + ( + read_view.coins_to_spend_indexation_enabled, + IndexationKind::CoinsToSpend, + ), + ( + read_view.asset_metadata_indexation_enabled, + IndexationKind::AssetMetadata, + ), + ] + .into_iter() + .filter_map(|(enabled, kind)| enabled.then_some(kind)), + ); + Ok(NodeInfo { utxo_validation: config.utxo_validation, vm_backtrace: config.vm_backtrace, @@ -102,6 +135,7 @@ impl NodeQuery { max_size: (config.max_size as u64).into(), max_depth: (config.max_txpool_dependency_chain_length as u64).into(), node_version: VERSION.to_owned(), + indexation: Indexation(indexation), }) } } @@ -168,3 +202,24 @@ impl TxPoolStats { self.0.total_gas.into() } } + +#[derive(Clone)] +struct Indexation(HashSet); + +#[Object] +impl Indexation { + /// Is balances indexation enabled + async fn balances(&self) -> bool { + self.0.contains(&IndexationKind::Balances) + } + + /// Is coins to spend indexation enabled + async fn coins_to_spend(&self) -> bool { + self.0.contains(&IndexationKind::CoinsToSpend) + } + + /// Is asset metadata indexation enabled + async fn asset_metadata(&self) -> bool { + self.0.contains(&IndexationKind::AssetMetadata) + } +} From 26dd46bcf71ad50e5a327b3565a3ad06df3b90ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Chabowski?= Date: Fri, 17 Jan 2025 16:44:18 +0100 Subject: [PATCH 2/9] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0513c5eb1e0..7d07b134989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - [2551](https://github.com/FuelLabs/fuel-core/pull/2551): Enhanced the DA compressed block header to include block id. +- [2595](https://github.com/FuelLabs/fuel-core/pull/2595): Added `indexation` field to the `nodeInfo` GraphQL endpoint to allow checking if a specific indexation is enabled. ## [Version 0.41.0] From 5b77da5eef3a1ef993e94d9050629eacc1c45199 Mon Sep 17 00:00:00 2001 From: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Date: Wed, 22 Jan 2025 08:13:29 +0100 Subject: [PATCH 3/9] Propose new idea to store the indexation info (#2604) --- crates/fuel-core/src/schema/node_info.rs | 92 ++++++++++++++++-------- 1 file changed, 64 insertions(+), 28 deletions(-) diff --git a/crates/fuel-core/src/schema/node_info.rs b/crates/fuel-core/src/schema/node_info.rs index 22afa226d85..e2285ad3d2d 100644 --- a/crates/fuel-core/src/schema/node_info.rs +++ b/crates/fuel-core/src/schema/node_info.rs @@ -17,10 +17,8 @@ use async_graphql::{ Context, Object, }; -use std::{ - collections::HashSet, - time::UNIX_EPOCH, -}; +use std::time::UNIX_EPOCH; +use strum::IntoEnumIterator; pub struct NodeInfo { utxo_validation: bool, @@ -108,25 +106,26 @@ impl NodeQuery { let db = ctx.data_unchecked::(); let read_view = db.view()?; - let indexation = HashSet::from_iter( - [ - ( - read_view.balances_indexation_enabled, - IndexationKind::Balances, - ), - ( - read_view.coins_to_spend_indexation_enabled, - IndexationKind::CoinsToSpend, - ), - ( - read_view.asset_metadata_indexation_enabled, - IndexationKind::AssetMetadata, - ), - ] - .into_iter() - .filter_map(|(enabled, kind)| enabled.then_some(kind)), - ); - + let mut indexation = Indexation::new(); + for kind in IndexationKind::iter() { + match kind { + IndexationKind::Balances => { + if read_view.balances_indexation_enabled { + indexation.insert(kind); + } + } + IndexationKind::CoinsToSpend => { + if read_view.coins_to_spend_indexation_enabled { + indexation.insert(kind); + } + } + IndexationKind::AssetMetadata => { + if read_view.asset_metadata_indexation_enabled { + indexation.insert(kind); + } + } + } + } Ok(NodeInfo { utxo_validation: config.utxo_validation, vm_backtrace: config.vm_backtrace, @@ -135,7 +134,7 @@ impl NodeQuery { max_size: (config.max_size as u64).into(), max_depth: (config.max_txpool_dependency_chain_length as u64).into(), node_version: VERSION.to_owned(), - indexation: Indexation(indexation), + indexation, }) } } @@ -204,22 +203,59 @@ impl TxPoolStats { } #[derive(Clone)] -struct Indexation(HashSet); +struct Indexation(u8); + +impl Indexation { + pub fn new() -> Self { + Self(0) + } + + pub fn contains(&self, kind: &IndexationKind) -> bool { + self.0 & (1 << *kind as u8) != 0 + } + + pub fn insert(&mut self, kind: IndexationKind) { + self.0 |= 1 << kind as u8; + } +} #[Object] impl Indexation { /// Is balances indexation enabled async fn balances(&self) -> bool { - self.0.contains(&IndexationKind::Balances) + self.contains(&IndexationKind::Balances) } /// Is coins to spend indexation enabled async fn coins_to_spend(&self) -> bool { - self.0.contains(&IndexationKind::CoinsToSpend) + self.contains(&IndexationKind::CoinsToSpend) } /// Is asset metadata indexation enabled async fn asset_metadata(&self) -> bool { - self.0.contains(&IndexationKind::AssetMetadata) + self.contains(&IndexationKind::AssetMetadata) } } + +#[test] +fn test_indexation() { + let mut indexation = Indexation::new(); + assert_eq!(indexation.contains(&IndexationKind::Balances), false); + assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), false); + assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), false); + + indexation.insert(IndexationKind::Balances); + assert_eq!(indexation.contains(&IndexationKind::Balances), true); + assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), false); + assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), false); + + indexation.insert(IndexationKind::CoinsToSpend); + assert_eq!(indexation.contains(&IndexationKind::Balances), true); + assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), true); + assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), false); + + indexation.insert(IndexationKind::AssetMetadata); + assert_eq!(indexation.contains(&IndexationKind::Balances), true); + assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), true); + assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), true); +} From e4d2e078faa95e6d66c78a38a86f57c661d89206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Chabowski?= Date: Wed, 22 Jan 2025 09:58:33 +0100 Subject: [PATCH 4/9] Satisfy Clippy --- crates/fuel-core/src/schema/node_info.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/fuel-core/src/schema/node_info.rs b/crates/fuel-core/src/schema/node_info.rs index e2285ad3d2d..cce05a6e197 100644 --- a/crates/fuel-core/src/schema/node_info.rs +++ b/crates/fuel-core/src/schema/node_info.rs @@ -240,22 +240,22 @@ impl Indexation { #[test] fn test_indexation() { let mut indexation = Indexation::new(); - assert_eq!(indexation.contains(&IndexationKind::Balances), false); - assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), false); - assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), false); + assert!(!indexation.contains(&IndexationKind::Balances)); + assert!(!indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(!indexation.contains(&IndexationKind::AssetMetadata)); indexation.insert(IndexationKind::Balances); - assert_eq!(indexation.contains(&IndexationKind::Balances), true); - assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), false); - assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), false); + assert!(indexation.contains(&IndexationKind::Balances)); + assert!(!indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(!indexation.contains(&IndexationKind::AssetMetadata)); indexation.insert(IndexationKind::CoinsToSpend); - assert_eq!(indexation.contains(&IndexationKind::Balances), true); - assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), true); - assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), false); + assert!(indexation.contains(&IndexationKind::Balances)); + assert!(indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(!indexation.contains(&IndexationKind::AssetMetadata)); indexation.insert(IndexationKind::AssetMetadata); - assert_eq!(indexation.contains(&IndexationKind::Balances), true); - assert_eq!(indexation.contains(&IndexationKind::CoinsToSpend), true); - assert_eq!(indexation.contains(&IndexationKind::AssetMetadata), true); + assert!(indexation.contains(&IndexationKind::Balances)); + assert!(indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(indexation.contains(&IndexationKind::AssetMetadata)); } From d369bf9035b315547467c1268a0a2fe4b9b07336 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 22 Jan 2025 17:14:23 +0100 Subject: [PATCH 5/9] Update client to support new fields in node_info --- crates/client/src/client/schema/node_info.rs | 9 +++++++++ ...ma__node_info__tests__node_info_query_gql_output.snap | 5 +++++ crates/client/src/client/types/node_info.rs | 7 ++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/client/src/client/schema/node_info.rs b/crates/client/src/client/schema/node_info.rs index 1a3e7b5d859..6a23e299d96 100644 --- a/crates/client/src/client/schema/node_info.rs +++ b/crates/client/src/client/schema/node_info.rs @@ -27,6 +27,7 @@ pub struct NodeInfo { pub max_size: U64, pub max_depth: U64, pub node_version: String, + pub indexation: Indexation, pub tx_pool_stats: TxPoolStats, } @@ -88,6 +89,14 @@ pub struct TxPoolStats { pub total_size: U64, } +#[derive(cynic::QueryFragment, Clone, Debug, PartialEq, Eq)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub struct Indexation { + pub balances: bool, + pub coins_to_spend: bool, + pub asset_metadata: bool, +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__node_info__tests__node_info_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__node_info__tests__node_info_query_gql_output.snap index d4f70ba6e26..aac8e698201 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__node_info__tests__node_info_query_gql_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__node_info__tests__node_info_query_gql_output.snap @@ -12,6 +12,11 @@ query QueryNodeInfo { maxSize maxDepth nodeVersion + indexation { + balances + coinsToSpend + assetMetadata + } txPoolStats { txCount totalGas diff --git a/crates/client/src/client/types/node_info.rs b/crates/client/src/client/types/node_info.rs index dce6a6a1174..56b261a0998 100644 --- a/crates/client/src/client/types/node_info.rs +++ b/crates/client/src/client/types/node_info.rs @@ -1,6 +1,9 @@ use crate::client::schema::{ self, - node_info::TxPoolStats, + node_info::{ + Indexation, + TxPoolStats, + }, }; #[derive(Clone, Debug, PartialEq, Eq)] @@ -12,6 +15,7 @@ pub struct NodeInfo { pub max_size: u64, pub max_depth: u64, pub node_version: String, + pub indexation: Indexation, pub tx_pool_stats: TxPoolStats, } @@ -27,6 +31,7 @@ impl From for NodeInfo { max_size: value.max_size.into(), max_depth: value.max_depth.into(), node_version: value.node_version, + indexation: value.indexation, tx_pool_stats: value.tx_pool_stats, } } From 58e2cb50423f8e23be94a37d7430c1445b42618c Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 22 Jan 2025 17:52:27 +0100 Subject: [PATCH 6/9] Create an indexation flag that provide genericity on indexation enabled check at the readatabase level --- crates/fuel-core/src/graphql_api/database.rs | 100 ++++++++++++++----- crates/fuel-core/src/query/assets.rs | 6 +- crates/fuel-core/src/query/balance.rs | 5 +- crates/fuel-core/src/schema/balance.rs | 5 +- crates/fuel-core/src/schema/coins.rs | 5 +- crates/fuel-core/src/schema/node_info.rs | 74 ++------------ 6 files changed, 98 insertions(+), 97 deletions(-) diff --git a/crates/fuel-core/src/graphql_api/database.rs b/crates/fuel-core/src/graphql_api/database.rs index d7234b5b880..2f9c852afc3 100644 --- a/crates/fuel-core/src/graphql_api/database.rs +++ b/crates/fuel-core/src/graphql_api/database.rs @@ -1,8 +1,11 @@ -use crate::fuel_core_graphql_api::{ - database::arc_wrapper::ArcWrapper, - ports::{ - OffChainDatabase, - OnChainDatabase, +use crate::{ + database::database_description::IndexationKind, + fuel_core_graphql_api::{ + database::arc_wrapper::ArcWrapper, + ports::{ + OffChainDatabase, + OnChainDatabase, + }, }, }; use fuel_core_services::yield_stream::StreamYieldExt; @@ -67,6 +70,7 @@ use std::{ borrow::Cow, sync::Arc, }; +use strum::IntoEnumIterator; use super::ports::worker; @@ -88,12 +92,25 @@ pub struct ReadDatabase { on_chain: Box>, /// The off-chain database view provider. off_chain: Box>, - /// The flag that indicates whether the Balances indexation is enabled. - balances_indexation_enabled: bool, - /// The flag that indicates whether the CoinsToSpend indexation is enabled. - coins_to_spend_indexation_enabled: bool, - /// The flag that indicates whether the AssetMetadata indexation is enabled. - asset_metadata_indexation_enabled: bool, + /// The flag indicating which indexation is enabled. + indexation_flags: IndexationFlags, +} + +#[derive(Clone)] +pub struct IndexationFlags(u8); + +impl IndexationFlags { + pub fn new() -> Self { + Self(0) + } + + pub fn contains(&self, kind: &IndexationKind) -> bool { + self.0 & (1 << *kind as u8) != 0 + } + + pub fn insert(&mut self, kind: IndexationKind) { + self.0 |= 1 << kind as u8; + } } impl ReadDatabase { @@ -110,20 +127,32 @@ impl ReadDatabase { OnChain::LatestView: OnChainDatabase, OffChain::LatestView: OffChainDatabase, { - let balances_indexation_enabled = off_chain.balances_indexation_enabled()?; - let coins_to_spend_indexation_enabled = - off_chain.coins_to_spend_indexation_enabled()?; - let asset_metadata_indexation_enabled = - off_chain.asset_metadata_indexation_enabled()?; - + let mut indexation_flags = IndexationFlags::new(); + for kind in IndexationKind::iter() { + match kind { + IndexationKind::Balances => { + if off_chain.balances_indexation_enabled()? { + indexation_flags.insert(kind); + } + } + IndexationKind::CoinsToSpend => { + if off_chain.coins_to_spend_indexation_enabled()? { + indexation_flags.insert(kind); + } + } + IndexationKind::AssetMetadata => { + if off_chain.asset_metadata_indexation_enabled()? { + indexation_flags.insert(kind); + } + } + } + } Ok(Self { batch_size, genesis_height, on_chain: Box::new(ArcWrapper::new(on_chain)), off_chain: Box::new(ArcWrapper::new(off_chain)), - balances_indexation_enabled, - coins_to_spend_indexation_enabled, - asset_metadata_indexation_enabled, + indexation_flags, }) } @@ -137,9 +166,7 @@ impl ReadDatabase { genesis_height: self.genesis_height, on_chain: self.on_chain.latest_view()?, off_chain: self.off_chain.latest_view()?, - balances_indexation_enabled: self.balances_indexation_enabled, - coins_to_spend_indexation_enabled: self.coins_to_spend_indexation_enabled, - asset_metadata_indexation_enabled: self.asset_metadata_indexation_enabled, + indexation_flags: self.indexation_flags.clone(), }) } @@ -155,9 +182,7 @@ pub struct ReadView { pub(crate) genesis_height: BlockHeight, pub(crate) on_chain: OnChainView, pub(crate) off_chain: OffChainView, - pub(crate) balances_indexation_enabled: bool, - pub(crate) coins_to_spend_indexation_enabled: bool, - pub(crate) asset_metadata_indexation_enabled: bool, + pub(crate) indexation_flags: IndexationFlags, } impl ReadView { @@ -408,3 +433,26 @@ impl ReadView { self.off_chain.message_is_spent(nonce) } } + +#[test] +fn test_indexation_flags() { + let mut indexation = IndexationFlags::new(); + assert!(!indexation.contains(&IndexationKind::Balances)); + assert!(!indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(!indexation.contains(&IndexationKind::AssetMetadata)); + + indexation.insert(IndexationKind::Balances); + assert!(indexation.contains(&IndexationKind::Balances)); + assert!(!indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(!indexation.contains(&IndexationKind::AssetMetadata)); + + indexation.insert(IndexationKind::CoinsToSpend); + assert!(indexation.contains(&IndexationKind::Balances)); + assert!(indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(!indexation.contains(&IndexationKind::AssetMetadata)); + + indexation.insert(IndexationKind::AssetMetadata); + assert!(indexation.contains(&IndexationKind::Balances)); + assert!(indexation.contains(&IndexationKind::CoinsToSpend)); + assert!(indexation.contains(&IndexationKind::AssetMetadata)); +} diff --git a/crates/fuel-core/src/query/assets.rs b/crates/fuel-core/src/query/assets.rs index b6270763d7b..975cdb1409d 100644 --- a/crates/fuel-core/src/query/assets.rs +++ b/crates/fuel-core/src/query/assets.rs @@ -1,4 +1,5 @@ use crate::{ + database::database_description::IndexationKind, fuel_core_graphql_api::database::ReadView, graphql_api::storage::assets::AssetDetails, }; @@ -10,7 +11,10 @@ use fuel_core_types::fuel_tx::AssetId; impl ReadView { pub fn get_asset_details(&self, id: &AssetId) -> StorageResult { - if self.asset_metadata_indexation_enabled { + if self + .indexation_flags + .contains(&IndexationKind::AssetMetadata) + { Ok(self .off_chain .asset_info(id)? diff --git a/crates/fuel-core/src/query/balance.rs b/crates/fuel-core/src/query/balance.rs index b98f6bc9635..8902da6dcf8 100644 --- a/crates/fuel-core/src/query/balance.rs +++ b/crates/fuel-core/src/query/balance.rs @@ -4,6 +4,7 @@ use std::{ }; use crate::{ + database::database_description::IndexationKind, fuel_core_graphql_api::database::ReadView, graphql_api::storage::balances::TotalBalanceAmount, }; @@ -41,7 +42,7 @@ impl ReadView { asset_id: AssetId, base_asset_id: AssetId, ) -> StorageResult { - let amount = if self.balances_indexation_enabled { + let amount = if self.indexation_flags.contains(&IndexationKind::Balances) { self.off_chain.balance(&owner, &asset_id, &base_asset_id)? } else { AssetQuery::new( @@ -73,7 +74,7 @@ impl ReadView { direction: IterDirection, base_asset_id: &'a AssetId, ) -> impl Stream> + 'a { - if self.balances_indexation_enabled { + if self.indexation_flags.contains(&IndexationKind::Balances) { futures::future::Either::Left(self.balances_with_cache( owner, start, diff --git a/crates/fuel-core/src/schema/balance.rs b/crates/fuel-core/src/schema/balance.rs index 694b60d7c97..53ae03071b7 100644 --- a/crates/fuel-core/src/schema/balance.rs +++ b/crates/fuel-core/src/schema/balance.rs @@ -1,4 +1,5 @@ use crate::{ + database::database_description::IndexationKind, fuel_core_graphql_api::{ api_service::ConsensusProvider, query_costs, @@ -111,7 +112,9 @@ impl BalanceQuery { ) -> async_graphql::Result> { let query = ctx.read_view()?; - if !query.balances_indexation_enabled && (before.is_some() || after.is_some()) { + if !query.indexation_flags.contains(&IndexationKind::Balances) + && (before.is_some() || after.is_some()) + { return Err(anyhow!( "Can not use pagination when balances indexation is not available" ) diff --git a/crates/fuel-core/src/schema/coins.rs b/crates/fuel-core/src/schema/coins.rs index b7a1cc765d0..9f0a3bea1a0 100644 --- a/crates/fuel-core/src/schema/coins.rs +++ b/crates/fuel-core/src/schema/coins.rs @@ -8,6 +8,7 @@ use crate::{ ExcludedCoinIds, SpendQuery, }, + database::database_description::IndexationKind, fuel_core_graphql_api::{ query_costs, storage::coins::CoinsToSpendIndexKey, @@ -289,7 +290,9 @@ impl CoinQuery { query_per_asset.truncate(max_input as usize); let read_view = ctx.read_view()?; - let indexation_available = read_view.coins_to_spend_indexation_enabled; + let indexation_available = read_view + .indexation_flags + .contains(&IndexationKind::CoinsToSpend); if indexation_available { coins_to_spend_with_cache( owner, diff --git a/crates/fuel-core/src/schema/node_info.rs b/crates/fuel-core/src/schema/node_info.rs index cce05a6e197..4015dcaf412 100644 --- a/crates/fuel-core/src/schema/node_info.rs +++ b/crates/fuel-core/src/schema/node_info.rs @@ -10,7 +10,10 @@ use crate::{ }, graphql_api::{ api_service::TxPool, - database::ReadDatabase, + database::{ + IndexationFlags, + ReadDatabase, + }, }, }; use async_graphql::{ @@ -18,7 +21,6 @@ use async_graphql::{ Object, }; use std::time::UNIX_EPOCH; -use strum::IntoEnumIterator; pub struct NodeInfo { utxo_validation: bool, @@ -28,7 +30,7 @@ pub struct NodeInfo { max_size: U64, max_depth: U64, node_version: String, - indexation: Indexation, + indexation: IndexationFlags, } #[Object] @@ -61,7 +63,7 @@ impl NodeInfo { self.node_version.to_owned() } - async fn indexation(&self) -> &Indexation { + async fn indexation(&self) -> &IndexationFlags { &self.indexation } @@ -106,26 +108,6 @@ impl NodeQuery { let db = ctx.data_unchecked::(); let read_view = db.view()?; - let mut indexation = Indexation::new(); - for kind in IndexationKind::iter() { - match kind { - IndexationKind::Balances => { - if read_view.balances_indexation_enabled { - indexation.insert(kind); - } - } - IndexationKind::CoinsToSpend => { - if read_view.coins_to_spend_indexation_enabled { - indexation.insert(kind); - } - } - IndexationKind::AssetMetadata => { - if read_view.asset_metadata_indexation_enabled { - indexation.insert(kind); - } - } - } - } Ok(NodeInfo { utxo_validation: config.utxo_validation, vm_backtrace: config.vm_backtrace, @@ -134,7 +116,7 @@ impl NodeQuery { max_size: (config.max_size as u64).into(), max_depth: (config.max_txpool_dependency_chain_length as u64).into(), node_version: VERSION.to_owned(), - indexation, + indexation: read_view.indexation_flags, }) } } @@ -202,25 +184,8 @@ impl TxPoolStats { } } -#[derive(Clone)] -struct Indexation(u8); - -impl Indexation { - pub fn new() -> Self { - Self(0) - } - - pub fn contains(&self, kind: &IndexationKind) -> bool { - self.0 & (1 << *kind as u8) != 0 - } - - pub fn insert(&mut self, kind: IndexationKind) { - self.0 |= 1 << kind as u8; - } -} - #[Object] -impl Indexation { +impl IndexationFlags { /// Is balances indexation enabled async fn balances(&self) -> bool { self.contains(&IndexationKind::Balances) @@ -236,26 +201,3 @@ impl Indexation { self.contains(&IndexationKind::AssetMetadata) } } - -#[test] -fn test_indexation() { - let mut indexation = Indexation::new(); - assert!(!indexation.contains(&IndexationKind::Balances)); - assert!(!indexation.contains(&IndexationKind::CoinsToSpend)); - assert!(!indexation.contains(&IndexationKind::AssetMetadata)); - - indexation.insert(IndexationKind::Balances); - assert!(indexation.contains(&IndexationKind::Balances)); - assert!(!indexation.contains(&IndexationKind::CoinsToSpend)); - assert!(!indexation.contains(&IndexationKind::AssetMetadata)); - - indexation.insert(IndexationKind::CoinsToSpend); - assert!(indexation.contains(&IndexationKind::Balances)); - assert!(indexation.contains(&IndexationKind::CoinsToSpend)); - assert!(!indexation.contains(&IndexationKind::AssetMetadata)); - - indexation.insert(IndexationKind::AssetMetadata); - assert!(indexation.contains(&IndexationKind::Balances)); - assert!(indexation.contains(&IndexationKind::CoinsToSpend)); - assert!(indexation.contains(&IndexationKind::AssetMetadata)); -} From b3ecacf1ac7c56916206dffb6da56a35b64e81f7 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 22 Jan 2025 18:01:06 +0100 Subject: [PATCH 7/9] Update schema --- crates/client/assets/schema.sdl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 7ce6f040c65..016f7907af7 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -580,7 +580,7 @@ type HeavyOperation { scalar HexString -type Indexation { +type IndexationFlags { """ Is balances indexation enabled """ @@ -779,7 +779,7 @@ type NodeInfo { maxSize: U64! maxDepth: U64! nodeVersion: String! - indexation: Indexation! + indexation: IndexationFlags! txPoolStats: TxPoolStats! peers: [PeerInfo!]! } From aad1cbc326c8c9246d60b17a445b40416e039ca9 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 22 Jan 2025 18:07:35 +0100 Subject: [PATCH 8/9] Update client side types --- crates/client/src/client/schema/node_info.rs | 4 ++-- crates/client/src/client/types/node_info.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/client/src/client/schema/node_info.rs b/crates/client/src/client/schema/node_info.rs index 6a23e299d96..3422162519c 100644 --- a/crates/client/src/client/schema/node_info.rs +++ b/crates/client/src/client/schema/node_info.rs @@ -27,7 +27,7 @@ pub struct NodeInfo { pub max_size: U64, pub max_depth: U64, pub node_version: String, - pub indexation: Indexation, + pub indexation: IndexationFlags, pub tx_pool_stats: TxPoolStats, } @@ -91,7 +91,7 @@ pub struct TxPoolStats { #[derive(cynic::QueryFragment, Clone, Debug, PartialEq, Eq)] #[cynic(schema_path = "./assets/schema.sdl")] -pub struct Indexation { +pub struct IndexationFlags { pub balances: bool, pub coins_to_spend: bool, pub asset_metadata: bool, diff --git a/crates/client/src/client/types/node_info.rs b/crates/client/src/client/types/node_info.rs index 56b261a0998..4905437bb07 100644 --- a/crates/client/src/client/types/node_info.rs +++ b/crates/client/src/client/types/node_info.rs @@ -1,7 +1,7 @@ use crate::client::schema::{ self, node_info::{ - Indexation, + IndexationFlags, TxPoolStats, }, }; @@ -15,7 +15,7 @@ pub struct NodeInfo { pub max_size: u64, pub max_depth: u64, pub node_version: String, - pub indexation: Indexation, + pub indexation: IndexationFlags, pub tx_pool_stats: TxPoolStats, } From 3555d4b97187ab974b6b95d12e49b25b9814d24f Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 22 Jan 2025 18:17:21 +0100 Subject: [PATCH 9/9] Fix clippy --- crates/fuel-core/src/graphql_api/database.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/fuel-core/src/graphql_api/database.rs b/crates/fuel-core/src/graphql_api/database.rs index 2f9c852afc3..20ee054644d 100644 --- a/crates/fuel-core/src/graphql_api/database.rs +++ b/crates/fuel-core/src/graphql_api/database.rs @@ -113,6 +113,12 @@ impl IndexationFlags { } } +impl Default for IndexationFlags { + fn default() -> Self { + Self::new() + } +} + impl ReadDatabase { /// Creates a new [`ReadDatabase`] with the given on-chain and off-chain database view providers. pub fn new(