diff --git a/substrate/bin/node/inspect/src/command.rs b/substrate/bin/node/inspect/src/command.rs index 9702576833..dcecfd7882 100644 --- a/substrate/bin/node/inspect/src/command.rs +++ b/substrate/bin/node/inspect/src/command.rs @@ -25,14 +25,12 @@ use crate::{ use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams}; use sc_service::{Configuration, NativeExecutionDispatch}; use sp_runtime::traits::Block; -use std::str::FromStr; impl InspectCmd { /// Run the inspect command, passing the inspector. pub fn run(&self, config: Configuration) -> Result<()> where B: Block, - B::Hash: FromStr, RA: Send + Sync + 'static, D: NativeExecutionDispatch + 'static, { diff --git a/substrate/client/api/src/in_mem.rs b/substrate/client/api/src/in_mem.rs index 7c87b479de..9ea5169d78 100644 --- a/substrate/client/api/src/in_mem.rs +++ b/substrate/client/api/src/in_mem.rs @@ -487,10 +487,7 @@ pub struct BlockImportOperation { set_head: Option, } -impl BlockImportOperation -where - Block::Hash: Ord, -{ +impl BlockImportOperation { fn apply_storage( &mut self, storage: Storage, @@ -519,10 +516,7 @@ where } } -impl backend::BlockImportOperation for BlockImportOperation -where - Block::Hash: Ord, -{ +impl backend::BlockImportOperation for BlockImportOperation { type State = InMemoryBackend>; fn state(&self) -> sp_blockchain::Result> { @@ -611,20 +605,14 @@ where /// /// > **Warning**: Doesn't support all the features necessary for a proper database. Only use this /// > struct for testing purposes. Do **NOT** use in production. -pub struct Backend -where - Block::Hash: Ord, -{ +pub struct Backend { states: RwLock>>>, blockchain: Blockchain, import_lock: RwLock<()>, pinned_blocks: RwLock>, } -impl Backend -where - Block::Hash: Ord, -{ +impl Backend { /// Create a new instance of in-mem backend. /// /// # Warning @@ -650,10 +638,7 @@ where } } -impl backend::AuxStore for Backend -where - Block::Hash: Ord, -{ +impl backend::AuxStore for Backend { fn insert_aux< 'a, 'b: 'a, @@ -673,10 +658,7 @@ where } } -impl backend::Backend for Backend -where - Block::Hash: Ord, -{ +impl backend::Backend for Backend { type BlockImportOperation = BlockImportOperation; type Blockchain = Blockchain; type State = InMemoryBackend>; @@ -809,7 +791,7 @@ where } } -impl backend::LocalBackend for Backend where Block::Hash: Ord {} +impl backend::LocalBackend for Backend {} /// Check that genesis storage is valid. pub fn check_genesis_storage(storage: &Storage) -> sp_blockchain::Result<()> { diff --git a/substrate/client/cli/src/commands/check_block_cmd.rs b/substrate/client/cli/src/commands/check_block_cmd.rs index ba20376d99..dc63d46bd1 100644 --- a/substrate/client/cli/src/commands/check_block_cmd.rs +++ b/substrate/client/cli/src/commands/check_block_cmd.rs @@ -54,7 +54,6 @@ impl CheckBlockCmd { B: BlockT + for<'de> serde::Deserialize<'de>, C: BlockBackend + HeaderBackend + Send + Sync + 'static, IQ: sc_service::ImportQueue + 'static, - B::Hash: FromStr, ::Err: Debug, <::Number as FromStr>::Err: Debug, { diff --git a/substrate/client/cli/src/commands/export_state_cmd.rs b/substrate/client/cli/src/commands/export_state_cmd.rs index 45196c1192..4f9e625d70 100644 --- a/substrate/client/cli/src/commands/export_state_cmd.rs +++ b/substrate/client/cli/src/commands/export_state_cmd.rs @@ -59,7 +59,6 @@ impl ExportStateCmd { B: BlockT, C: UsageProvider + StorageProvider + HeaderBackend, BA: sc_client_api::backend::Backend, - B::Hash: FromStr, ::Err: Debug, <::Number as FromStr>::Err: Debug, { diff --git a/substrate/client/cli/src/params/mod.rs b/substrate/client/cli/src/params/mod.rs index 247ffc0e04..a73bd8844f 100644 --- a/substrate/client/cli/src/params/mod.rs +++ b/substrate/client/cli/src/params/mod.rs @@ -113,7 +113,6 @@ impl BlockNumberOrHash { /// Parse the inner value as `BlockId`. pub fn parse(&self) -> Result, String> where - B::Hash: FromStr, ::Err: std::fmt::Debug, NumberFor: FromStr, as FromStr>::Err: std::fmt::Debug, diff --git a/substrate/client/consensus/grandpa/src/lib.rs b/substrate/client/consensus/grandpa/src/lib.rs index c11e873eca..9c0aa60c24 100644 --- a/substrate/client/consensus/grandpa/src/lib.rs +++ b/substrate/client/consensus/grandpa/src/lib.rs @@ -718,7 +718,6 @@ pub fn run_grandpa_voter( grandpa_params: GrandpaParams, ) -> sp_blockchain::Result + Send> where - Block::Hash: Ord, BE: Backend + 'static, N: NetworkT + Sync + 'static, S: SyncingT + Sync + 'static, diff --git a/substrate/client/db/src/bench.rs b/substrate/client/db/src/bench.rs index b1fe3f206f..5bec03cb10 100644 --- a/substrate/client/db/src/bench.rs +++ b/substrate/client/db/src/bench.rs @@ -423,10 +423,7 @@ impl StateBackend> for BenchmarkingState { &self, delta: impl Iterator)>, state_version: StateVersion, - ) -> (B::Hash, Self::Transaction) - where - B::Hash: Ord, - { + ) -> (B::Hash, Self::Transaction) { self.state .borrow() .as_ref() @@ -438,10 +435,7 @@ impl StateBackend> for BenchmarkingState { child_info: &ChildInfo, delta: impl Iterator)>, state_version: StateVersion, - ) -> (B::Hash, bool, Self::Transaction) - where - B::Hash: Ord, - { + ) -> (B::Hash, bool, Self::Transaction) { self.state .borrow() .as_ref() diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index 43cef1f6e5..69d8d8cfc3 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -243,10 +243,7 @@ impl StateBackend> for RefTrackingState { &self, delta: impl Iterator)>, state_version: StateVersion, - ) -> (B::Hash, Self::Transaction) - where - B::Hash: Ord, - { + ) -> (B::Hash, Self::Transaction) { self.state.storage_root(delta, state_version) } @@ -255,10 +252,7 @@ impl StateBackend> for RefTrackingState { child_info: &ChildInfo, delta: impl Iterator)>, state_version: StateVersion, - ) -> (B::Hash, bool, Self::Transaction) - where - B::Hash: Ord, - { + ) -> (B::Hash, bool, Self::Transaction) { self.state.child_storage_root(child_info, delta, state_version) } diff --git a/substrate/client/db/src/record_stats_state.rs b/substrate/client/db/src/record_stats_state.rs index 2776802dde..f794717902 100644 --- a/substrate/client/db/src/record_stats_state.rs +++ b/substrate/client/db/src/record_stats_state.rs @@ -171,10 +171,7 @@ impl>, B: BlockT> StateBackend> for Record &self, delta: impl Iterator)>, state_version: StateVersion, - ) -> (B::Hash, Self::Transaction) - where - B::Hash: Ord, - { + ) -> (B::Hash, Self::Transaction) { self.state.storage_root(delta, state_version) } @@ -183,10 +180,7 @@ impl>, B: BlockT> StateBackend> for Record child_info: &ChildInfo, delta: impl Iterator)>, state_version: StateVersion, - ) -> (B::Hash, bool, Self::Transaction) - where - B::Hash: Ord, - { + ) -> (B::Hash, bool, Self::Transaction) { self.state.child_storage_root(child_info, delta, state_version) } diff --git a/substrate/primitives/runtime/src/generic/header.rs b/substrate/primitives/runtime/src/generic/header.rs index 7c1faaefb4..6fdf43ac08 100644 --- a/substrate/primitives/runtime/src/generic/header.rs +++ b/substrate/primitives/runtime/src/generic/header.rs @@ -22,8 +22,8 @@ use crate::{ generic::Digest, scale_info::TypeInfo, traits::{ - self, AtLeast32BitUnsigned, Hash as HashT, MaybeDisplay, MaybeSerialize, - MaybeSerializeDeserialize, Member, SimpleBitOps, + self, AtLeast32BitUnsigned, Hash as HashT, MaybeDisplay, MaybeFromStr, + MaybeSerializeDeserialize, Member, }, }; #[cfg(feature = "serde")] @@ -79,6 +79,7 @@ impl traits::Header for Header where Number: Member + MaybeSerializeDeserialize + + MaybeFromStr + Debug + sp_std::hash::Hash + MaybeDisplay @@ -86,48 +87,47 @@ where + Codec + Copy + Into - + TryFrom - + sp_std::str::FromStr, + + TryFrom, Hash: HashT, - Hash::Output: Default - + sp_std::hash::Hash - + Copy - + Member - + Ord - + MaybeSerialize - + Debug - + MaybeDisplay - + SimpleBitOps - + Codec, { type Number = Number; type Hash = ::Output; type Hashing = Hash; + fn new( + number: Self::Number, + extrinsics_root: Self::Hash, + state_root: Self::Hash, + parent_hash: Self::Hash, + digest: Digest, + ) -> Self { + Self { number, extrinsics_root, state_root, parent_hash, digest } + } fn number(&self) -> &Self::Number { &self.number } + fn set_number(&mut self, num: Self::Number) { self.number = num } - fn extrinsics_root(&self) -> &Self::Hash { &self.extrinsics_root } + fn set_extrinsics_root(&mut self, root: Self::Hash) { self.extrinsics_root = root } - fn state_root(&self) -> &Self::Hash { &self.state_root } + fn set_state_root(&mut self, root: Self::Hash) { self.state_root = root } - fn parent_hash(&self) -> &Self::Hash { &self.parent_hash } + fn set_parent_hash(&mut self, hash: Self::Hash) { self.parent_hash = hash } @@ -141,16 +141,6 @@ where log::debug!(target: "header", "Retrieving mutable reference to digest"); &mut self.digest } - - fn new( - number: Self::Number, - extrinsics_root: Self::Hash, - state_root: Self::Hash, - parent_hash: Self::Hash, - digest: Digest, - ) -> Self { - Self { number, extrinsics_root, state_root, parent_hash, digest } - } } impl Header @@ -164,8 +154,6 @@ where + Into + TryFrom, Hash: HashT, - Hash::Output: - Default + sp_std::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Codec, { /// Convenience helper for computing the hash of the header without having /// to import the trait. diff --git a/substrate/primitives/runtime/src/traits.rs b/substrate/primitives/runtime/src/traits.rs index 5bd7358e4f..a6155e6a4f 100644 --- a/substrate/primitives/runtime/src/traits.rs +++ b/substrate/primitives/runtime/src/traits.rs @@ -932,19 +932,7 @@ pub trait Hash: + Hasher::Output> { /// The hash type produced. - type Output: Member - + MaybeSerializeDeserialize - + Debug - + sp_std::hash::Hash - + AsRef<[u8]> - + AsMut<[u8]> - + Copy - + Default - + Encode - + Decode - + EncodeLike - + MaxEncodedLen - + TypeInfo; + type Output: HashOutput; /// Produce the hash of some byte-slice. fn hash(s: &[u8]) -> Self::Output { @@ -963,6 +951,47 @@ pub trait Hash: fn trie_root(input: Vec<(Vec, Vec)>, state_version: StateVersion) -> Self::Output; } +/// Super trait with all the attributes for a hashing output. +pub trait HashOutput: + Member + + MaybeSerializeDeserialize + + MaybeDisplay + + MaybeFromStr + + Debug + + sp_std::hash::Hash + + AsRef<[u8]> + + AsMut<[u8]> + + Copy + + Ord + + Default + + Encode + + Decode + + EncodeLike + + MaxEncodedLen + + TypeInfo +{ +} + +impl HashOutput for T where + T: Member + + MaybeSerializeDeserialize + + MaybeDisplay + + MaybeFromStr + + Debug + + sp_std::hash::Hash + + AsRef<[u8]> + + AsMut<[u8]> + + Copy + + Ord + + Default + + Encode + + Decode + + EncodeLike + + MaxEncodedLen + + TypeInfo +{ +} + /// Blake2-256 Hash implementation. #[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -981,13 +1010,13 @@ impl Hasher for BlakeTwo256 { impl Hash for BlakeTwo256 { type Output = sp_core::H256; - fn trie_root(input: Vec<(Vec, Vec)>, version: StateVersion) -> Self::Output { - sp_io::trie::blake2_256_root(input, version) - } - fn ordered_trie_root(input: Vec>, version: StateVersion) -> Self::Output { sp_io::trie::blake2_256_ordered_root(input, version) } + + fn trie_root(input: Vec<(Vec, Vec)>, version: StateVersion) -> Self::Output { + sp_io::trie::blake2_256_root(input, version) + } } /// Keccak-256 Hash implementation. @@ -1008,13 +1037,13 @@ impl Hasher for Keccak256 { impl Hash for Keccak256 { type Output = sp_core::H256; - fn trie_root(input: Vec<(Vec, Vec)>, version: StateVersion) -> Self::Output { - sp_io::trie::keccak_256_root(input, version) - } - fn ordered_trie_root(input: Vec>, version: StateVersion) -> Self::Output { sp_io::trie::keccak_256_ordered_root(input, version) } + + fn trie_root(input: Vec<(Vec, Vec)>, version: StateVersion) -> Self::Output { + sp_io::trie::keccak_256_root(input, version) + } } /// Something that can be checked for equality and printed out to a debug channel if bad. @@ -1102,27 +1131,15 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerialize + Debug + 's /// Header number. type Number: Member + MaybeSerializeDeserialize + + MaybeFromStr + Debug + sp_std::hash::Hash + Copy + MaybeDisplay + AtLeast32BitUnsigned - + Codec - + sp_std::str::FromStr; + + Codec; /// Header hash type - type Hash: Member - + MaybeSerializeDeserialize - + Debug - + sp_std::hash::Hash - + Ord - + Copy - + MaybeDisplay - + Default - + SimpleBitOps - + Codec - + AsRef<[u8]> - + AsMut<[u8]> - + TypeInfo; + type Hash: HashOutput; /// Hashing algorithm type Hashing: Hash; @@ -1176,19 +1193,7 @@ pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerialize + Debug + 'st /// Header type. type Header: Header; /// Block hash type. - type Hash: Member - + MaybeSerializeDeserialize - + Debug - + sp_std::hash::Hash - + Ord - + Copy - + MaybeDisplay - + Default - + SimpleBitOps - + Codec - + AsRef<[u8]> - + AsMut<[u8]> - + TypeInfo; + type Hash: HashOutput; /// Returns a reference to the header. fn header(&self) -> &Self::Header; diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index 08bcf3ee5a..702ec27561 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -147,7 +147,6 @@ impl PalletCmd { where BB: BlockT + Debug, <<::Header as HeaderT>::Number as std::str::FromStr>::Err: std::fmt::Debug, - ::Hash: std::str::FromStr, ExecDispatch: NativeExecutionDispatch + 'static, { if let Some(output_path) = &self.output { diff --git a/substrate/utils/frame/try-runtime/cli/src/commands/create_snapshot.rs b/substrate/utils/frame/try-runtime/cli/src/commands/create_snapshot.rs index 87855c1d6b..102336d644 100644 --- a/substrate/utils/frame/try-runtime/cli/src/commands/create_snapshot.rs +++ b/substrate/utils/frame/try-runtime/cli/src/commands/create_snapshot.rs @@ -41,7 +41,7 @@ pub(crate) async fn create_snapshot( ) -> sc_cli::Result<()> where Block: BlockT + serde::de::DeserializeOwned, - Block::Hash: FromStr + serde::de::DeserializeOwned, + Block::Hash: serde::de::DeserializeOwned, Block::Header: serde::de::DeserializeOwned, ::Err: Debug, NumberFor: FromStr, diff --git a/substrate/utils/frame/try-runtime/cli/src/commands/execute_block.rs b/substrate/utils/frame/try-runtime/cli/src/commands/execute_block.rs index 48dab6b9bd..1f1b6ec7d9 100644 --- a/substrate/utils/frame/try-runtime/cli/src/commands/execute_block.rs +++ b/substrate/utils/frame/try-runtime/cli/src/commands/execute_block.rs @@ -68,7 +68,6 @@ pub struct ExecuteBlockCmd { impl ExecuteBlockCmd { fn block_ws_uri(&self) -> String where - Block::Hash: FromStr, ::Err: Debug, { match (&self.block_ws_uri, &self.state) { @@ -91,7 +90,6 @@ pub(crate) async fn execute_block( ) -> sc_cli::Result<()> where Block: BlockT + serde::de::DeserializeOwned, - Block::Hash: FromStr, ::Err: Debug, Block::Hash: serde::de::DeserializeOwned, Block::Header: serde::de::DeserializeOwned, diff --git a/substrate/utils/frame/try-runtime/cli/src/commands/fast_forward.rs b/substrate/utils/frame/try-runtime/cli/src/commands/fast_forward.rs index 0c517c02fb..ea3ae532ca 100644 --- a/substrate/utils/frame/try-runtime/cli/src/commands/fast_forward.rs +++ b/substrate/utils/frame/try-runtime/cli/src/commands/fast_forward.rs @@ -211,7 +211,6 @@ pub(crate) async fn fast_forward( ) -> Result<()> where Block: BlockT + DeserializeOwned, - Block::Hash: FromStr, Block::Header: DeserializeOwned, ::Err: Debug, NumberFor: FromStr, diff --git a/substrate/utils/frame/try-runtime/cli/src/commands/follow_chain.rs b/substrate/utils/frame/try-runtime/cli/src/commands/follow_chain.rs index d5c68978eb..cfcdb4654c 100644 --- a/substrate/utils/frame/try-runtime/cli/src/commands/follow_chain.rs +++ b/substrate/utils/frame/try-runtime/cli/src/commands/follow_chain.rs @@ -84,7 +84,6 @@ pub(crate) async fn follow_chain( ) -> sc_cli::Result<()> where Block: BlockT + DeserializeOwned, - Block::Hash: FromStr, Block::Header: DeserializeOwned, ::Err: Debug, NumberFor: FromStr, diff --git a/substrate/utils/frame/try-runtime/cli/src/commands/offchain_worker.rs b/substrate/utils/frame/try-runtime/cli/src/commands/offchain_worker.rs index 4da6f07836..ac95384fb8 100644 --- a/substrate/utils/frame/try-runtime/cli/src/commands/offchain_worker.rs +++ b/substrate/utils/frame/try-runtime/cli/src/commands/offchain_worker.rs @@ -46,7 +46,6 @@ pub struct OffchainWorkerCmd { impl OffchainWorkerCmd { fn header_ws_uri(&self) -> String where - Block::Hash: FromStr, ::Err: Debug, { match (&self.header_ws_uri, &self.state) { @@ -70,7 +69,6 @@ pub(crate) async fn offchain_worker( where Block: BlockT + serde::de::DeserializeOwned, Block::Header: serde::de::DeserializeOwned, - Block::Hash: FromStr, ::Err: Debug, NumberFor: FromStr, as FromStr>::Err: Debug, diff --git a/substrate/utils/frame/try-runtime/cli/src/commands/on_runtime_upgrade.rs b/substrate/utils/frame/try-runtime/cli/src/commands/on_runtime_upgrade.rs index 948ff9c030..df21bad09b 100644 --- a/substrate/utils/frame/try-runtime/cli/src/commands/on_runtime_upgrade.rs +++ b/substrate/utils/frame/try-runtime/cli/src/commands/on_runtime_upgrade.rs @@ -54,7 +54,6 @@ pub(crate) async fn on_runtime_upgrade( ) -> sc_cli::Result<()> where Block: BlockT + serde::de::DeserializeOwned, - Block::Hash: FromStr, ::Err: Debug, Block::Header: serde::de::DeserializeOwned, NumberFor: FromStr, diff --git a/substrate/utils/frame/try-runtime/cli/src/lib.rs b/substrate/utils/frame/try-runtime/cli/src/lib.rs index 3c60184adb..fb4a644e20 100644 --- a/substrate/utils/frame/try-runtime/cli/src/lib.rs +++ b/substrate/utils/frame/try-runtime/cli/src/lib.rs @@ -618,9 +618,7 @@ impl State { try_runtime_check: bool, ) -> sc_cli::Result> where - Block::Hash: FromStr, Block::Header: DeserializeOwned, - Block::Hash: DeserializeOwned, ::Err: Debug, { let builder = match self { @@ -732,7 +730,6 @@ impl TryRuntimeCmd { where Block: BlockT + DeserializeOwned, Block::Header: DeserializeOwned, - Block::Hash: FromStr, ::Err: Debug, as FromStr>::Err: Debug, as TryInto>::Error: Debug, @@ -798,7 +795,6 @@ impl CliConfiguration for TryRuntimeCmd { /// Get the hash type of the generic `Block` from a `hash_str`. pub(crate) fn hash_of(hash_str: &str) -> sc_cli::Result where - Block::Hash: FromStr, ::Err: Debug, { hash_str