The storage runtime interface should not enforce a hash type (#4231)

* The storage runtime interface should not enforce a hash type

Currently the runtime interface enforces `H256` as hash type, but in the
future people could use whatever they want as hash type. The hash type
always needs to match between the runtime and the node, but that is
already required.

* Update primitives/externalities/src/lib.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Bastian Köcher
2019-11-28 01:00:29 +01:00
committed by Gavin Wood
parent 39388b826b
commit 3e26fceda4
29 changed files with 253 additions and 165 deletions
@@ -21,7 +21,7 @@
use std::{fmt, result, collections::HashMap, panic::UnwindSafe, marker::PhantomData};
use log::{warn, trace};
use hash_db::Hasher;
use codec::{Decode, Encode};
use codec::{Decode, Encode, Codec};
use primitives::{
storage::well_known_keys, NativeOrEncoded, NeverNativeValue,
traits::CodeExecutor, hexdisplay::HexDisplay, hash::H256,
@@ -567,7 +567,7 @@ pub fn prove_child_read<B, H, I>(
where
B: Backend<H>,
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -584,7 +584,7 @@ pub fn prove_read_on_trie_backend<S, H, I>(
where
S: trie_backend_essence::TrieBackendStorage<H>,
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -606,7 +606,7 @@ pub fn prove_child_read_on_trie_backend<S, H, I>(
where
S: trie_backend_essence::TrieBackendStorage<H>,
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -627,7 +627,7 @@ pub fn read_proof_check<H, I>(
) -> Result<HashMap<Vec<u8>, Option<Vec<u8>>>, Box<dyn Error>>
where
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -649,7 +649,7 @@ pub fn read_child_proof_check<H, I>(
) -> Result<HashMap<Vec<u8>, Option<Vec<u8>>>, Box<dyn Error>>
where
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
I: IntoIterator,
I::Item: AsRef<[u8]>,
{
@@ -673,7 +673,7 @@ pub fn read_proof_check_on_proving_backend<H>(
) -> Result<Option<Vec<u8>>, Box<dyn Error>>
where
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
{
proving_backend.storage(key).map_err(|e| Box::new(e) as Box<dyn Error>)
}
@@ -686,7 +686,7 @@ pub fn read_child_proof_check_on_proving_backend<H>(
) -> Result<Option<Vec<u8>>, Box<dyn Error>>
where
H: Hasher,
H::Out: Ord,
H::Out: Ord + Codec,
{
proving_backend.child_storage(storage_key, key).map_err(|e| Box::new(e) as Box<dyn Error>)
}