sc_rpc_api/dev/mod.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Substrate dev API containing RPCs that are mainly meant for debugging and stats collection for
20//! developers. The endpoints in this RPC module are not meant to be available to non-local users
21//! and are all marked `unsafe`.
22
23pub mod error;
24
25use codec::{Decode, Encode};
26use error::Error;
27use jsonrpsee::proc_macros::rpc;
28use scale_info::TypeInfo;
29use serde::{Deserialize, Serialize};
30
31/// Statistics of a block returned by the `dev_getBlockStats` RPC.
32#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug, TypeInfo, Serialize, Deserialize)]
33#[serde(rename_all = "camelCase")]
34pub struct BlockStats {
35 /// The length in bytes of the storage proof produced by executing the block.
36 pub witness_len: u64,
37 /// The length in bytes of the storage proof after compaction.
38 pub witness_compact_len: u64,
39 /// Length of the block in bytes.
40 ///
41 /// This information can also be acquired by downloading the whole block. This merely
42 /// saves some complexity on the client side.
43 pub block_len: u64,
44 /// Number of extrinsics in the block.
45 ///
46 /// This information can also be acquired by downloading the whole block. This merely
47 /// saves some complexity on the client side.
48 pub num_extrinsics: u64,
49}
50
51/// Substrate dev API.
52///
53/// This API contains unstable and unsafe methods only meant for development nodes. They
54/// are all flagged as unsafe for this reason.
55#[rpc(client, server)]
56pub trait DevApi<Hash> {
57 /// Reexecute the specified `block_hash` and gather statistics while doing so.
58 ///
59 /// This function requires the specified block and its parent to be available
60 /// at the queried node. If either the specified block or the parent is pruned,
61 /// this function will return `None`.
62 #[method(name = "dev_getBlockStats", with_extensions)]
63 fn block_stats(&self, block_hash: Hash) -> Result<Option<BlockStats>, Error>;
64}