Try to fix the build

This commit is contained in:
Bastian Köcher
2019-09-29 02:05:49 +02:00
parent ce064775fc
commit bc4499b640
10 changed files with 2344 additions and 1446 deletions
+12 -11
View File
@@ -21,12 +21,13 @@ use runtime_primitives::traits::{
Block as BlockT, Header as HeaderT, Hash as HashT
};
use executive::ExecuteBlock;
use primitives::{Blake2Hasher, H256};
use substrate_trie::{MemoryDB, read_trie_value, delta_trie_root};
use substrate_trie::{MemoryDB, read_trie_value, delta_trie_root, Layout};
use rstd::{slice, ptr, cmp, vec::Vec, boxed::Box, mem};
use hash_db::HashDB;
use hash_db::{HashDB, EMPTY_PREFIX};
static mut STORAGE: Option<Box<dyn Storage>> = None;
/// The message to use as expect message while accessing the `STORAGE`.
@@ -55,7 +56,7 @@ trait Storage {
/// Validate a given parachain block on a validator.
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
pub fn validate_block<B: BlockT<Hash = H256>, E: ExecuteBlock<B>>(
mut arguments: &[u8],
) {
use codec::Decode;
@@ -90,12 +91,12 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(
/// The storage implementation used when validating a block that is using the
/// witness data as source.
struct WitnessStorage<B: BlockT> {
witness_data: MemoryDB<<HashingOf<B> as HashT>::Hasher>,
witness_data: MemoryDB<Blake2Hasher>,
overlay: hashbrown::HashMap<Vec<u8>, Option<Vec<u8>>>,
storage_root: B::Hash,
}
impl<B: BlockT> WitnessStorage<B> {
impl<B: BlockT<Hash = H256>> WitnessStorage<B> {
/// Initialize from the given witness data and storage root.
///
/// Returns an error if given storage root was not found in the witness data.
@@ -104,9 +105,9 @@ impl<B: BlockT> WitnessStorage<B> {
storage_root: B::Hash,
) -> Result<Self, &'static str> {
let mut db = MemoryDB::default();
data.into_iter().for_each(|i| { db.insert(&[], &i); });
data.into_iter().for_each(|i| { db.insert(EMPTY_PREFIX, &i); });
if !db.contains(&storage_root, &[]) {
if !db.contains(&storage_root, EMPTY_PREFIX) {
return Err("Witness data does not contain given storage root.")
}
@@ -118,10 +119,10 @@ impl<B: BlockT> WitnessStorage<B> {
}
}
impl<B: BlockT> Storage for WitnessStorage<B> {
impl<B: BlockT<Hash = H256>> Storage for WitnessStorage<B> {
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
self.overlay.get(key).cloned().or_else(|| {
read_trie_value(
read_trie_value::<Layout<Blake2Hasher>, _>(
&self.witness_data,
&self.storage_root,
key,
@@ -138,7 +139,7 @@ impl<B: BlockT> Storage for WitnessStorage<B> {
}
fn storage_root(&mut self) -> [u8; STORAGE_ROOT_LEN] {
let root = match delta_trie_root(
let root = match delta_trie_root::<Layout<Blake2Hasher>, _, _, _, _>(
&mut self.witness_data,
self.storage_root.clone(),
self.overlay.drain()
@@ -230,4 +231,4 @@ unsafe fn ext_storage_root(result: *mut u8) {
let res = STORAGE.as_mut().expect(STORAGE_SET_EXPECT).storage_root();
let result = slice::from_raw_parts_mut(result, STORAGE_ROOT_LEN);
result.copy_from_slice(&res);
}
}