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

Expose indexation status in NodeInfo endpoint #2595

Merged
merged 15 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

### Changed
- [2603](https://github.com/FuelLabs/fuel-core/pull/2603): Sets the latest recorded height on initialization, not just when DA costs are received
Expand Down
16 changes: 16 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -764,6 +779,7 @@ type NodeInfo {
maxSize: U64!
maxDepth: U64!
nodeVersion: String!
indexation: Indexation!
txPoolStats: TxPoolStats!
peers: [PeerInfo!]!
}
Expand Down
9 changes: 9 additions & 0 deletions crates/client/src/client/schema/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ query QueryNodeInfo {
maxSize
maxDepth
nodeVersion
indexation {
balances
coinsToSpend
assetMetadata
}
txPoolStats {
txCount
totalGas
Expand Down
7 changes: 6 additions & 1 deletion crates/client/src/client/types/node_info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::client::schema::{
self,
node_info::TxPoolStats,
node_info::{
Indexation,
TxPoolStats,
},
};

#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -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,
}

Expand All @@ -27,6 +31,7 @@ impl From<schema::node_info::NodeInfo> 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,
}
}
Expand Down
93 changes: 92 additions & 1 deletion crates/fuel-core/src/schema/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ 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 strum::IntoEnumIterator;

pub struct NodeInfo {
utxo_validation: bool,
Expand All @@ -23,6 +28,7 @@ pub struct NodeInfo {
max_size: U64,
max_depth: U64,
node_version: String,
indexation: Indexation,
}

#[Object]
Expand Down Expand Up @@ -55,6 +61,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,
Expand Down Expand Up @@ -94,6 +104,28 @@ impl NodeQuery {

const VERSION: &str = env!("CARGO_PKG_VERSION");

let db = ctx.data_unchecked::<ReadDatabase>();
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);
}
}
}
AurelienFT marked this conversation as resolved.
Show resolved Hide resolved
}
Ok(NodeInfo {
utxo_validation: config.utxo_validation,
vm_backtrace: config.vm_backtrace,
Expand All @@ -102,6 +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,
})
}
}
Expand Down Expand Up @@ -168,3 +201,61 @@ impl TxPoolStats {
self.0.total_gas.into()
}
}

#[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 {
/// Is balances indexation enabled
async fn balances(&self) -> bool {
self.contains(&IndexationKind::Balances)
}

/// Is coins to spend indexation enabled
async fn coins_to_spend(&self) -> bool {
self.contains(&IndexationKind::CoinsToSpend)
}

/// Is asset metadata indexation enabled
async fn asset_metadata(&self) -> bool {
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));
}
Loading