Skip to main content

soil_rpc/api/dev/
mod.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Substrate dev API containing RPCs that are mainly meant for debugging and stats collection for
8//! developers. The endpoints in this RPC module are not meant to be available to non-local users
9//! and are all marked `unsafe`.
10
11pub mod error;
12
13use codec::{Decode, Encode};
14use error::Error;
15use jsonrpsee::proc_macros::rpc;
16use scale_info::TypeInfo;
17use serde::{Deserialize, Serialize};
18
19/// Statistics of a block returned by the `dev_getBlockStats` RPC.
20#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug, TypeInfo, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct BlockStats {
23	/// The length in bytes of the storage proof produced by executing the block.
24	pub witness_len: u64,
25	/// The length in bytes of the storage proof after compaction.
26	pub witness_compact_len: u64,
27	/// Length of the block in bytes.
28	///
29	/// This information can also be acquired by downloading the whole block. This merely
30	/// saves some complexity on the client side.
31	pub block_len: u64,
32	/// Number of extrinsics in the block.
33	///
34	/// This information can also be acquired by downloading the whole block. This merely
35	/// saves some complexity on the client side.
36	pub num_extrinsics: u64,
37}
38
39/// Substrate dev API.
40///
41/// This API contains unstable and unsafe methods only meant for development nodes. They
42/// are all flagged as unsafe for this reason.
43#[rpc(client, server)]
44pub trait DevApi<Hash> {
45	/// Reexecute the specified `block_hash` and gather statistics while doing so.
46	///
47	/// This function requires the specified block and its parent to be available
48	/// at the queried node. If either the specified block or the parent is pruned,
49	/// this function will return `None`.
50	#[method(name = "dev_getBlockStats", with_extensions)]
51	fn block_stats(&self, block_hash: Hash) -> Result<Option<BlockStats>, Error>;
52}