Skip to main content

soil_cli/commands/
check_block_cmd.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
7use crate::{
8	error,
9	params::{BlockNumberOrHash, ImportParams, SharedParams},
10	CliConfiguration,
11};
12use clap::Parser;
13use soil_client::client_api::{BlockBackend, HeaderBackend};
14use std::{fmt::Debug, str::FromStr, sync::Arc};
15use subsoil::runtime::traits::{Block as BlockT, Header as HeaderT};
16
17/// The `check-block` command used to validate blocks.
18#[derive(Debug, Clone, Parser)]
19pub struct CheckBlockCmd {
20	/// Block hash or number.
21	#[arg(value_name = "HASH or NUMBER")]
22	pub input: BlockNumberOrHash,
23
24	/// The default number of 64KB pages to ever allocate for Wasm execution.
25	/// Don't alter this unless you know what you're doing.
26	#[arg(long, value_name = "COUNT")]
27	pub default_heap_pages: Option<u32>,
28
29	#[allow(missing_docs)]
30	#[clap(flatten)]
31	pub shared_params: SharedParams,
32
33	#[allow(missing_docs)]
34	#[clap(flatten)]
35	pub import_params: ImportParams,
36}
37
38impl CheckBlockCmd {
39	/// Run the check-block command
40	pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
41	where
42		B: BlockT + for<'de> serde::Deserialize<'de>,
43		C: BlockBackend<B> + HeaderBackend<B> + Send + Sync + 'static,
44		IQ: soil_service::ImportQueue<B> + 'static,
45		<B::Hash as FromStr>::Err: Debug,
46		<<B::Header as HeaderT>::Number as FromStr>::Err: Debug,
47	{
48		let start = std::time::Instant::now();
49		soil_service::chain_ops::check_block(client, import_queue, self.input.parse()?).await?;
50		println!("Completed in {} ms.", start.elapsed().as_millis());
51
52		Ok(())
53	}
54}
55
56impl CliConfiguration for CheckBlockCmd {
57	fn shared_params(&self) -> &SharedParams {
58		&self.shared_params
59	}
60
61	fn import_params(&self) -> Option<&ImportParams> {
62		Some(&self.import_params)
63	}
64}