1// This file is part of Substrate.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
56// 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.
1011// 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.
1516// 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/>.
1819use 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};
2829/// 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")]
34pub input: BlockNumberOrHash,
3536/// 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")]
39pub default_heap_pages: Option<u32>,
4041#[allow(missing_docs)]
42 #[clap(flatten)]
43pub shared_params: SharedParams,
4445#[allow(missing_docs)]
46 #[clap(flatten)]
47pub import_params: ImportParams,
48}
4950impl CheckBlockCmd {
51/// Run the check-block command
52pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
53where
54B: 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 {
60let start = std::time::Instant::now();
61 sc_service::chain_ops::check_block(client, import_queue, self.input.parse()?).await?;
62println!("Completed in {} ms.", start.elapsed().as_millis());
6364Ok(())
65 }
66}
6768impl CliConfiguration for CheckBlockCmd {
69fn shared_params(&self) -> &SharedParams {
70&self.shared_params
71 }
7273fn import_params(&self) -> Option<&ImportParams> {
74Some(&self.import_params)
75 }
76}