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

Node info stats backport #2573

Merged
merged 13 commits into from
Jan 15, 2025
3 changes: 2 additions & 1 deletion .cargo/audit.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[advisories]
ignore = [
"RUSTSEC-2024-0336" # https://github.com/FuelLabs/fuel-core/issues/1843
"RUSTSEC-2024-0336", # https://github.com/FuelLabs/fuel-core/issues/1843
"RUSTSEC-2024-0421" # https://github.com/FuelLabs/fuel-core/issues/2488
]
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ jobs:
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions-rs/audit-check@v1
- run: cargo install cargo-audit --locked
- uses: rustsec/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/nightly-cargo-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/audit-check@v1
- run: cargo install cargo-audit --locked
- uses: rustsec/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- [2573](https://github.com/FuelLabs/fuel-core/pull/2573): Add txpool stats to the `node_info` GraphQL endpoint

## [Version 0.40.2]

### Fixed
Expand Down Expand Up @@ -425,7 +429,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
The change has many minor improvements in different areas related to the state transition bytecode:
- The state transition bytecode lies in its own file(`state_transition_bytecode.wasm`) along with the chain config file. The `ChainConfig` loads it automatically when `ChainConfig::load` is called and pushes it back when `ChainConfig::write` is called.
- The `fuel-core` release bundle also contains the `fuel-core-wasm-executor.wasm` file of the corresponding executor version.
- The regenesis process now considers the last block produced by the previous network. When we create a (re)genesis block of a new network, it has the `height = last_block_of_old_netowkr + 1`. It continues the old network and doesn't overlap blocks(before, we had `old_block.height == new_genesis_block.hegiht`).
- The regenesis process now considers the last block produced by the previous network. When we create a (re)genesis block of a new network, it has the `height = last_block_of_old_netowkr + 1`. It continues the old network and doesn't overlap blocks(before, we had `old_block.height == new_genesis_block.height`).
- Along with the new block height, the regenesis process also increases the state transition bytecode and consensus parameters versions. It guarantees that a new network doesn't use values from the previous network and allows us not to migrate `StateTransitionBytecodeVersions` and `ConsensusParametersVersions` tables.
- Added a new CLI argument, `native-executor-version,` that allows overriding of the default version of the native executor. It can be useful for side rollups that have their own history of executor upgrades.
- Replaced:
Expand Down
18 changes: 18 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,11 @@ type NodeInfo {
utxoValidation: Boolean!
vmBacktrace: Boolean!
maxTx: U64!
maxGas: U64!
maxSize: U64!
maxDepth: U64!
nodeVersion: String!
txPoolStats: TxPoolStats!
peers: [PeerInfo!]!
}

Expand Down Expand Up @@ -1259,6 +1262,21 @@ enum TxParametersVersion {

scalar TxPointer

type TxPoolStats {
"""
The number of transactions in the pool
"""
txCount: U64!
"""
The total size of the transactions in the pool
"""
totalSize: U64!
"""
The total gas of the transactions in the pool
"""
totalGas: U64!
}

scalar U16

scalar U32
Expand Down
11 changes: 11 additions & 0 deletions crates/client/src/client/schema/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ pub struct NodeInfo {
pub utxo_validation: bool,
pub vm_backtrace: bool,
pub max_tx: U64,
pub max_gas: U64,
pub max_size: U64,
pub max_depth: U64,
pub node_version: String,
pub tx_pool_stats: TxPoolStats,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
Expand Down Expand Up @@ -77,6 +80,14 @@ impl From<PeerInfo> for fuel_core_types::services::p2p::PeerInfo {
}
}

#[derive(cynic::QueryFragment, Clone, Debug, PartialEq, Eq)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct TxPoolStats {
pub tx_count: U64,
pub total_gas: U64,
pub total_size: U64,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
---
source: crates/client/src/client/schema/node_info.rs
expression: operation.query
snapshot_kind: text
---
query {
nodeInfo {
utxoValidation
vmBacktrace
maxTx
maxGas
maxSize
maxDepth
nodeVersion
txPoolStats {
txCount
totalGas
totalSize
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion crates/client/src/client/types/node_info.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use crate::client::schema;
use crate::client::schema::{
self,
node_info::TxPoolStats,
};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NodeInfo {
pub utxo_validation: bool,
pub vm_backtrace: bool,
pub max_tx: u64,
pub max_gas: u64,
pub max_size: u64,
pub max_depth: u64,
pub node_version: String,
pub tx_pool_stats: TxPoolStats,
}

// GraphQL Translation
Expand All @@ -17,8 +23,11 @@ impl From<schema::node_info::NodeInfo> for NodeInfo {
utxo_validation: value.utxo_validation,
vm_backtrace: value.vm_backtrace,
max_tx: value.max_tx.into(),
max_gas: value.max_gas.into(),
max_size: value.max_size.into(),
max_depth: value.max_depth.into(),
node_version: value.node_version,
tx_pool_stats: value.tx_pool_stats,
}
}
}
2 changes: 2 additions & 0 deletions crates/fuel-core/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Config {
pub debug: bool,
pub vm_backtrace: bool,
pub max_tx: usize,
pub max_gas: u64,
pub max_size: usize,
pub max_txpool_dependency_chain_length: usize,
pub chain_name: String,
}
Expand Down
7 changes: 6 additions & 1 deletion crates/fuel-core/src/graphql_api/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use fuel_core_storage::{
StorageInspect,
StorageRead,
};
use fuel_core_txpool::TxStatusMessage;
use fuel_core_txpool::{
TxPoolStats,
TxStatusMessage,
};
use fuel_core_types::{
blockchain::{
block::CompressedBlock,
Expand Down Expand Up @@ -206,6 +209,8 @@ pub trait TxPoolPort: Send + Sync {
&self,
tx_id: TxId,
) -> anyhow::Result<BoxStream<TxStatusMessage>>;

fn latest_pool_stats(&self) -> TxPoolStats;
}

#[async_trait]
Expand Down
50 changes: 47 additions & 3 deletions crates/fuel-core/src/schema/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use super::scalars::{
U32,
U64,
};
use crate::fuel_core_graphql_api::{
query_costs,
Config as GraphQLConfig,
use crate::{
fuel_core_graphql_api::{
query_costs,
Config as GraphQLConfig,
},
graphql_api::api_service::TxPool,
};
use async_graphql::{
Context,
Expand All @@ -16,6 +19,8 @@ pub struct NodeInfo {
utxo_validation: bool,
vm_backtrace: bool,
max_tx: U64,
max_gas: U64,
max_size: U64,
max_depth: U64,
node_version: String,
}
Expand All @@ -34,6 +39,14 @@ impl NodeInfo {
self.max_tx
}

async fn max_gas(&self) -> U64 {
self.max_gas
}

async fn max_size(&self) -> U64 {
self.max_size
}

async fn max_depth(&self) -> U64 {
self.max_depth
}
Expand All @@ -42,6 +55,15 @@ impl NodeInfo {
self.node_version.to_owned()
}

#[graphql(complexity = "query_costs().storage_read + child_complexity")]
async fn tx_pool_stats(
&self,
ctx: &Context<'_>,
) -> async_graphql::Result<TxPoolStats> {
let tx_pool = ctx.data_unchecked::<TxPool>();
Ok(TxPoolStats(tx_pool.latest_pool_stats()))
}

#[graphql(complexity = "query_costs().get_peers + child_complexity")]
async fn peers(&self, _ctx: &Context<'_>) -> async_graphql::Result<Vec<PeerInfo>> {
#[cfg(feature = "p2p")]
Expand Down Expand Up @@ -76,6 +98,8 @@ impl NodeQuery {
utxo_validation: config.utxo_validation,
vm_backtrace: config.vm_backtrace,
max_tx: (config.max_tx as u64).into(),
max_gas: config.max_gas.into(),
max_size: (config.max_size as u64).into(),
max_depth: (config.max_txpool_dependency_chain_length as u64).into(),
node_version: VERSION.to_owned(),
})
Expand Down Expand Up @@ -124,3 +148,23 @@ impl PeerInfo {
self.0.app_score
}
}

struct TxPoolStats(fuel_core_txpool::TxPoolStats);

#[Object]
impl TxPoolStats {
/// The number of transactions in the pool
async fn tx_count(&self) -> U64 {
self.0.tx_count.into()
}

/// The total size of the transactions in the pool
async fn total_size(&self) -> U64 {
self.0.total_size.into()
}

/// The total gas of the transactions in the pool
async fn total_gas(&self) -> U64 {
self.0.total_gas.into()
}
}
9 changes: 8 additions & 1 deletion crates/fuel-core/src/service/adapters/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use crate::{
use async_trait::async_trait;
use fuel_core_services::stream::BoxStream;
use fuel_core_storage::Result as StorageResult;
use fuel_core_txpool::TxStatusMessage;
use fuel_core_txpool::{
TxPoolStats,
TxStatusMessage,
};
use fuel_core_types::{
blockchain::header::ConsensusParametersVersion,
entities::relayer::message::MerkleProof,
Expand Down Expand Up @@ -96,6 +99,10 @@ impl TxPoolPort for TxPoolAdapter {
) -> anyhow::Result<BoxStream<TxStatusMessage>> {
self.service.tx_update_subscribe(id)
}

fn latest_pool_stats(&self) -> TxPoolStats {
self.service.latest_stats()
}
}

impl DatabaseMessageProof for OnChainIterableKeyValueView {
Expand Down
2 changes: 2 additions & 0 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ pub fn init_sub_services(
debug: config.debug,
vm_backtrace: config.vm.backtrace,
max_tx: config.txpool.pool_limits.max_txs,
max_gas: config.txpool.pool_limits.max_gas,
max_size: config.txpool.pool_limits.max_bytes_size,
max_txpool_dependency_chain_length: config.txpool.max_txs_chain_count,
chain_name,
};
Expand Down
1 change: 1 addition & 0 deletions crates/services/txpool_v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod tests;
fuel_core_trace::enable_tracing!();

use fuel_core_types::fuel_asm::Word;
pub use pool::TxPoolStats;
pub use selection_algorithms::Constraints;
pub use service::{
new_service,
Expand Down
Loading
Loading