referrerpolicy=no-referrer-when-downgrade

frame_benchmarking_cli/pallet/
types.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Various types used by this crate.
19
20use sc_cli::Result;
21use sp_core::traits::{RuntimeCode, WrappedRuntimeCode};
22use sp_runtime::traits::Hash;
23
24/// A runtime blob that was either fetched from genesis storage or loaded from a file.
25// NOTE: This enum is only needed for the annoying lifetime bounds on `RuntimeCode`. Otherwise we
26// could just directly return the blob.
27pub enum FetchedCode<'a, B, H> {
28	FromGenesis { state: sp_state_machine::backend::BackendRuntimeCode<'a, B, H> },
29	FromFile { wrapped_code: WrappedRuntimeCode<'a>, heap_pages: Option<u64>, hash: Vec<u8> },
30}
31
32impl<'a, B, H> FetchedCode<'a, B, H>
33where
34	H: Hash,
35	B: sc_client_api::StateBackend<H>,
36{
37	/// The runtime blob.
38	pub fn code(&'a self) -> Result<RuntimeCode<'a>> {
39		match self {
40			Self::FromGenesis { state } => state.runtime_code().map_err(Into::into),
41			Self::FromFile { wrapped_code, heap_pages, hash } => Ok(RuntimeCode {
42				code_fetcher: wrapped_code,
43				heap_pages: *heap_pages,
44				hash: hash.clone(),
45			}),
46		}
47	}
48}
49
50/// Maps a (pallet, benchmark) to its component ranges.
51pub(crate) type ComponentRangeMap =
52	std::collections::HashMap<(String, String), Vec<ComponentRange>>;
53
54/// The inclusive range of a component.
55#[derive(serde::Serialize, Debug, Clone, Eq, PartialEq)]
56pub(crate) struct ComponentRange {
57	/// Name of the component.
58	pub(crate) name: String,
59	/// Minimal valid value of the component.
60	pub(crate) min: u32,
61	/// Maximal valid value of the component.
62	pub(crate) max: u32,
63}