referrerpolicy=no-referrer-when-downgrade

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