mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
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:
committed by
Gavin Wood
parent
39388b826b
commit
3e26fceda4
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
use parking_lot::RwLock;
|
||||
use codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode, Codec};
|
||||
use log::debug;
|
||||
use hash_db::{Hasher, HashDB, EMPTY_PREFIX, Prefix};
|
||||
use trie::{
|
||||
@@ -119,6 +119,7 @@ impl<'a, S, H> ProvingBackendRecorder<'a, S, H>
|
||||
where
|
||||
S: TrieBackendStorage<H>,
|
||||
H: Hasher,
|
||||
H::Out: Codec,
|
||||
{
|
||||
/// Produce proof for a key query.
|
||||
pub fn storage(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>, String> {
|
||||
@@ -145,6 +146,7 @@ impl<'a, S, H> ProvingBackendRecorder<'a, S, H>
|
||||
key: &[u8]
|
||||
) -> Result<Option<Vec<u8>>, String> {
|
||||
let root = self.storage(storage_key)?
|
||||
.and_then(|r| Decode::decode(&mut &r[..]).ok())
|
||||
.unwrap_or(default_child_trie_root::<Layout<H>>(storage_key));
|
||||
|
||||
let mut read_overlay = S::Overlay::default();
|
||||
@@ -158,7 +160,7 @@ impl<'a, S, H> ProvingBackendRecorder<'a, S, H>
|
||||
read_child_trie_value_with::<Layout<H>, _, _>(
|
||||
storage_key,
|
||||
&eph,
|
||||
&root,
|
||||
&root.as_ref(),
|
||||
key,
|
||||
&mut *self.proof_recorder
|
||||
).map_err(map_e)
|
||||
@@ -199,7 +201,9 @@ pub struct ProofRecorderBackend<'a, S: 'a + TrieBackendStorage<H>, H: 'a + Hashe
|
||||
proof_recorder: ProofRecorder<H>,
|
||||
}
|
||||
|
||||
impl<'a, S: 'a + TrieBackendStorage<H>, H: 'a + Hasher> ProvingBackend<'a, S, H> {
|
||||
impl<'a, S: 'a + TrieBackendStorage<H>, H: 'a + Hasher> ProvingBackend<'a, S, H>
|
||||
where H::Out: Codec
|
||||
{
|
||||
/// Create new proving backend.
|
||||
pub fn new(backend: &'a TrieBackend<S, H>) -> Self {
|
||||
let proof_recorder = Default::default();
|
||||
@@ -254,7 +258,7 @@ impl<'a, S, H> Backend<H> for ProvingBackend<'a, S, H>
|
||||
where
|
||||
S: 'a + TrieBackendStorage<H>,
|
||||
H: 'a + Hasher,
|
||||
H::Out: Ord,
|
||||
H::Out: Ord + Codec,
|
||||
{
|
||||
type Error = String;
|
||||
type Transaction = S::Overlay;
|
||||
@@ -302,7 +306,7 @@ impl<'a, S, H> Backend<H> for ProvingBackend<'a, S, H>
|
||||
self.0.storage_root(delta)
|
||||
}
|
||||
|
||||
fn child_storage_root<I>(&self, storage_key: &[u8], delta: I) -> (Vec<u8>, bool, Self::Transaction)
|
||||
fn child_storage_root<I>(&self, storage_key: &[u8], delta: I) -> (H::Out, bool, Self::Transaction)
|
||||
where
|
||||
I: IntoIterator<Item=(Vec<u8>, Option<Vec<u8>>)>,
|
||||
H::Out: Ord
|
||||
@@ -318,6 +322,7 @@ pub fn create_proof_check_backend<H>(
|
||||
) -> Result<TrieBackend<MemoryDB<H>, H>, Box<dyn Error>>
|
||||
where
|
||||
H: Hasher,
|
||||
H::Out: Codec,
|
||||
{
|
||||
let db = create_proof_check_backend_storage(proof);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user