Skip to content

Commit

Permalink
Add dev_getBlockStats RPC (#489)
Browse files Browse the repository at this point in the history
* Add "dev_getBlockStats" RPC

* build fix
  • Loading branch information
athei authored Mar 22, 2022
1 parent d941573 commit 82f3040
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions subxt/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ pub struct ReadProof<Hash> {
pub proof: Vec<Bytes>,
}

/// Statistics of a block returned by the `dev_getBlockStats` RPC.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockStats {
/// The length in bytes of the storage proof produced by executing the block.
pub witness_len: u64,
/// The length in bytes of the storage proof after compaction.
pub witness_compact_len: u64,
/// Length of the block in bytes.
///
/// This information can also be acquired by downloading the whole block. This merely
/// saves some complexity on the client side.
pub block_len: u64,
/// Number of extrinsics in the block.
///
/// This information can also be acquired by downloading the whole block. This merely
/// saves some complexity on the client side.
pub num_extrinsics: u64,
}

/// Client for substrate rpc interfaces
pub struct Rpc<T: Config> {
/// Rpc client for sending requests.
Expand Down Expand Up @@ -374,6 +394,20 @@ impl<T: Config> Rpc<T> {
Ok(block)
}

/// Reexecute the specified `block_hash` and gather statistics while doing so.
///
/// This function requires the specified block and its parent to be available
/// at the queried node. If either the specified block or the parent is pruned,
/// this function will return `None`.
pub async fn block_stats(
&self,
block_hash: T::Hash,
) -> Result<Option<BlockStats>, BasicError> {
let params = rpc_params![block_hash];
let stats = self.client.request("dev_getBlockStats", params).await?;
Ok(stats)
}

/// Get proof of storage entries at a specific block's state.
pub async fn read_proof(
&self,
Expand Down

0 comments on commit 82f3040

Please sign in to comment.