Skip to content

cumulus/metrics: Measure the time of including a tx in a backed block #8902

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Jun 18, 2025

This PR introduces a metric in Cumulus to measure the time it took a transaction received on the RPC layer to be included a backed block.

  • A new TransactionMonitorHandle is exposed from the transaction RPC V2 API to listen on monitoring events emitted by substrate
  • The monitoring event contains the block of the transaction with the timestamp associated
  • A cumulus task is added to group the backed events from the relay chain with the monitoring events exposed by the RPC layer
  • The spawning of RPC spawn_tasks now returns the additional TransactionMonitorHandle
  • The metric is exposed under the following histogram: parachain_transaction_backed_duration

Testing Done

  • Started a small network with 2 validators and 2 collators (charlie and dave -- using small_network.toml as base)
  • Used subxt with a minimal working code to send a transaction to charlie
  • Used the RPC-V2 API (ie ChainHeadBackend)
use std::sync::Arc;
use subxt::{
    OnlineClient, PolkadotConfig,
    backend::{chain_head::ChainHeadBackend, rpc::RpcClient},
};
use subxt_signer::sr25519::dev;

#[subxt::subxt(runtime_metadata_insecure_url = "ws://127.0.0.1:44919")]
pub mod polkadot {}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rpc = RpcClient::from_url("ws://127.0.0.1:44919".to_string()).await?;
    let backend = ChainHeadBackend::builder().build_with_background_driver(rpc.clone());
    let api: OnlineClient<PolkadotConfig> = OnlineClient::from_backend(Arc::new(backend)).await?;

    let from = dev::charlie();
    let dest = dev::dave().public_key().into();
    let tx = Box::new(polkadot::tx().balances().transfer_allow_death(dest, 10_000));
    api.tx()
        .sign_and_submit_then_watch_default(&tx, &from)
        .await?
        .wait_for_finalized_success()
        .await?;

    Ok(())
}
  • After the transaction gets finalized:
parachain_transaction_backed_duration_sum{chain="asset-hub-rococo-local"} 13.097583666
parachain_transaction_backed_duration_count{chain="asset-hub-rococo-local"} 1

Closes #8383

cc @paritytech/sdk-node

lexnv added 14 commits June 16, 2025 17:10
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
@lexnv lexnv self-assigned this Jun 18, 2025
@lexnv lexnv added the T0-node This PR/Issue is related to the topic “node”. label Jun 18, 2025
@lexnv
Copy link
Contributor Author

lexnv commented Jun 19, 2025

/cmd prdoc --audience node_dev,node_operator --bump patch

@lexnv
Copy link
Contributor Author

lexnv commented Jun 20, 2025

/cmd prdoc --audience node_dev --bump patch

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/15775302503
Failed job name: build-templates-node

@sandreim
Copy link
Contributor

sandreim commented Jun 20, 2025

Getting it in a backed block is half way, and it is useful. Can we also add a metric to measure the transaction time to finality? This is for example what Mythical is measuring as latency.

@lexnv
Copy link
Contributor Author

lexnv commented Jun 23, 2025

Getting it in a backed block is half way, and it is useful. Can we also add a metric to measure the transaction time to finality? This is for example what Mythical is measuring as latency.

The tx time to transition into different states (including finality) should be solved by:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RPC: Add backed event to the metrics
4 participants