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

Notify telemetry only every second about the tx pool status #6605

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cumulus/client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ workspace = true

[dependencies]
futures = { workspace = true }
futures-timer = { workspace = true }

# Substrate
sc-client-api = { workspace = true, default-features = true }
Expand Down
58 changes: 41 additions & 17 deletions substrate/client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
start_rpc_servers, BuildGenesisBlock, GenesisBlockBuilder, RpcHandlers, SpawnTaskHandle,
TaskManager, TransactionPoolAdapter,
};
use futures::{future::ready, FutureExt, StreamExt};
use futures::{select, FutureExt, StreamExt};
use jsonrpsee::RpcModule;
use log::info;
use prometheus_endpoint::Registry;
Expand Down Expand Up @@ -90,7 +90,11 @@ use sp_consensus::block_validation::{
use sp_core::traits::{CodeExecutor, SpawnNamed};
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, BlockIdTo, NumberFor, Zero};
use std::{str::FromStr, sync::Arc, time::SystemTime};
use std::{
str::FromStr,
sync::Arc,
time::{Duration, SystemTime},
};

/// Full client type.
pub type TFullClient<TBl, TRtApi, TExec> =
Expand Down Expand Up @@ -577,22 +581,42 @@ pub async fn propagate_transaction_notifications<Block, ExPool>(
Block: BlockT,
ExPool: MaintainedTransactionPool<Block = Block, Hash = <Block as BlockT>::Hash>,
{
const TELEMETRY_INTERVAL: Duration = Duration::from_secs(1);

// transaction notifications
transaction_pool
.import_notification_stream()
.for_each(move |hash| {
tx_handler_controller.propagate_transaction(hash);
let status = transaction_pool.status();
telemetry!(
telemetry;
SUBSTRATE_INFO;
"txpool.import";
"ready" => status.ready,
"future" => status.future,
);
ready(())
})
.await;
let mut notifications = transaction_pool.import_notification_stream().fuse();
let mut timer = futures_timer::Delay::new(TELEMETRY_INTERVAL).fuse();
let mut tx_imported = false;

loop {
select! {
notification = notifications.next() => {
let Some(hash) = notification else { return };

tx_handler_controller.propagate_transaction(hash);

tx_imported = true;
},
_ = timer => {
timer = futures_timer::Delay::new(TELEMETRY_INTERVAL).fuse();

if !tx_imported {
bkchr marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

tx_imported = false;
let status = transaction_pool.status();

telemetry!(
telemetry;
SUBSTRATE_INFO;
"txpool.import";
"ready" => status.ready,
"future" => status.future,
);
}
}
}
}

/// Initialize telemetry with provided configuration and return telemetry handle
Expand Down
Loading