Skip to content

Commit

Permalink
Add current pool gas to the node info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Jan 13, 2025
1 parent bc91cb5 commit f5e1114
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ type NodeInfo {
maxTx: U64!
maxDepth: U64!
nodeVersion: String!
currentPoolGas: U64!
peers: [PeerInfo!]!
}

Expand Down
1 change: 1 addition & 0 deletions crates/client/src/client/schema/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct NodeInfo {
pub max_tx: U64,
pub max_depth: U64,
pub node_version: String,
pub current_pool_gas: U64,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions crates/client/src/client/types/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct NodeInfo {
pub max_tx: u64,
pub max_depth: u64,
pub node_version: String,
pub current_pool_gas: u64,
}

// GraphQL Translation
Expand All @@ -19,6 +20,7 @@ impl From<schema::node_info::NodeInfo> for NodeInfo {
max_tx: value.max_tx.into(),
max_depth: value.max_depth.into(),
node_version: value.node_version,
current_pool_gas: value.current_pool_gas.into(),
}
}
}
2 changes: 2 additions & 0 deletions crates/fuel-core/src/graphql_api/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ pub trait TxPoolPort: Send + Sync {
&self,
tx_id: TxId,
) -> anyhow::Result<BoxStream<TxStatusMessage>>;

fn current_pool_gas(&self) -> u64;
}

#[async_trait]
Expand Down
16 changes: 13 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 @@ -18,6 +21,7 @@ pub struct NodeInfo {
max_tx: U64,
max_depth: U64,
node_version: String,
current_pool_gas: U64,
}

#[Object]
Expand All @@ -42,6 +46,10 @@ impl NodeInfo {
self.node_version.to_owned()
}

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

#[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 @@ -69,6 +77,7 @@ impl NodeQuery {
#[graphql(complexity = "query_costs().storage_read + child_complexity")]
async fn node_info(&self, ctx: &Context<'_>) -> async_graphql::Result<NodeInfo> {
let config = ctx.data_unchecked::<GraphQLConfig>();
let txpool = ctx.data_unchecked::<TxPool>();

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

Expand All @@ -78,6 +87,7 @@ impl NodeQuery {
max_tx: (config.max_tx as u64).into(),
max_depth: (config.max_txpool_dependency_chain_length as u64).into(),
node_version: VERSION.to_owned(),
current_pool_gas: txpool.current_pool_gas().into(),
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/fuel-core/src/service/adapters/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ impl TxPoolPort for TxPoolAdapter {
) -> anyhow::Result<BoxStream<TxStatusMessage>> {
self.service.tx_update_subscribe(id)
}

fn current_pool_gas(&self) -> u64 {
self.service.current_pool_gas()
}
}

impl DatabaseMessageProof for OnChainIterableKeyValueView {
Expand Down
6 changes: 5 additions & 1 deletion crates/services/txpool_v2/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub struct Pool<S, SI, CM, SA> {
pub(crate) current_gas: u64,
/// Current pool size in bytes.
pub(crate) current_bytes_size: usize,
/// The current pool gas.
pub(crate) current_pool_gas_sender: tokio::sync::watch::Sender<u64>,
}

impl<S, SI, CM, SA> Pool<S, SI, CM, SA> {
Expand All @@ -75,6 +77,7 @@ impl<S, SI, CM, SA> Pool<S, SI, CM, SA> {
collision_manager: CM,
selection_algorithm: SA,
config: Config,
current_pool_gas_sender: tokio::sync::watch::Sender<u64>,
) -> Self {
Pool {
storage,
Expand All @@ -84,6 +87,7 @@ impl<S, SI, CM, SA> Pool<S, SI, CM, SA> {
tx_id_to_storage_id: HashMap::new(),
current_gas: 0,
current_bytes_size: 0,
current_pool_gas_sender,
}
}

Expand Down Expand Up @@ -183,7 +187,7 @@ where
.into_iter()
.map(|data| data.transaction)
.collect::<Vec<_>>();

let _ = self.current_pool_gas_sender.send(self.current_gas);
Ok(removed_transactions)
}

Expand Down
4 changes: 4 additions & 0 deletions crates/services/txpool_v2/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ where
mpsc::channel(1);
let (read_pool_requests_sender, read_pool_requests_receiver) =
mpsc::channel(config.service_channel_limits.max_pending_read_pool_requests);
let (current_pool_gas_sender, current_pool_gas_receiver) =
tokio::sync::watch::channel(0);
let tx_status_sender = TxStatusChange::new(
config.max_tx_update_subscriptions,
// The connection should be closed automatically after the `SqueezedOut` event.
Expand All @@ -774,6 +776,7 @@ where
select_transactions_requests_sender,
read_pool_requests_sender,
new_txs_notifier,
latest_pool_gas_info: current_pool_gas_receiver,
};

let subscriptions = Subscriptions {
Expand Down Expand Up @@ -824,6 +827,7 @@ where
BasicCollisionManager::new(),
RatioTipGasSelection::new(),
config,
current_pool_gas_sender,
);

Service::new(Task {
Expand Down
5 changes: 5 additions & 0 deletions crates/services/txpool_v2/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct SharedState {
pub(crate) read_pool_requests_sender: mpsc::Sender<ReadPoolRequest>,
pub(crate) tx_status_sender: TxStatusChange,
pub(crate) new_txs_notifier: tokio::sync::watch::Sender<()>,
pub(crate) latest_pool_gas_info: tokio::sync::watch::Receiver<u64>,
}

impl SharedState {
Expand Down Expand Up @@ -178,4 +179,8 @@ impl SharedState {
.write_pool_requests_sender
.try_send(WritePoolRequest::RemoveCoinDependents { transactions });
}

pub fn current_pool_gas(&self) -> u64 {
*self.latest_pool_gas_info.borrow()
}
}

0 comments on commit f5e1114

Please sign in to comment.