mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 07:11:06 +00:00
Remove PoC-1 back-compat hacks (#709)
* Remove PoC-1 back-compat hacks * Fix lingering Keccak references * More keccak exorcism * Fix test * Final fixes
This commit is contained in:
Generated
+1
-2
@@ -2574,7 +2574,6 @@ dependencies = [
|
||||
"substrate-runtime-version 0.1.0",
|
||||
"substrate-serializer 0.1.0",
|
||||
"substrate-state-machine 0.1.0",
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"triehash 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -2619,6 +2618,7 @@ dependencies = [
|
||||
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-primitives 0.1.0",
|
||||
"subtle 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -2710,7 +2710,6 @@ dependencies = [
|
||||
"substrate-codec-derive 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-serializer 0.1.0",
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -33,7 +33,7 @@ use primitives::{
|
||||
AccountId, Block, BlockId, Hash, Index, InherentData,
|
||||
SessionKey, Timestamp, UncheckedExtrinsic,
|
||||
};
|
||||
use substrate_primitives::{KeccakHasher, RlpCodec};
|
||||
use substrate_primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
/// Build new blocks.
|
||||
pub trait BlockBuilder {
|
||||
@@ -81,10 +81,10 @@ pub trait Api {
|
||||
fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<UncheckedExtrinsic>>;
|
||||
}
|
||||
|
||||
impl<B, E> BlockBuilder for ClientBlockBuilder<B, E, Block, KeccakHasher, RlpCodec>
|
||||
impl<B, E> BlockBuilder for ClientBlockBuilder<B, E, Block, Blake2Hasher, RlpCodec>
|
||||
where
|
||||
B: Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>+ Clone,
|
||||
B: Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>+ Clone,
|
||||
{
|
||||
fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
|
||||
self.push(extrinsic).map_err(Into::into)
|
||||
@@ -98,10 +98,10 @@ where
|
||||
|
||||
impl<B, E> Api for Client<B, E, Block>
|
||||
where
|
||||
B: Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec> + Clone,
|
||||
B: Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec> + Clone,
|
||||
{
|
||||
type BlockBuilder = ClientBlockBuilder<B, E, Block, KeccakHasher, RlpCodec>;
|
||||
type BlockBuilder = ClientBlockBuilder<B, E, Block, Blake2Hasher, RlpCodec>;
|
||||
|
||||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
|
||||
Ok(self.authorities_at(at)?)
|
||||
|
||||
@@ -51,7 +51,7 @@ mod tests {
|
||||
use keyring::Keyring;
|
||||
use runtime_support::{Hashable, StorageValue, StorageMap};
|
||||
use state_machine::{CodeExecutor, TestExternalities};
|
||||
use primitives::{twox_128, KeccakHasher};
|
||||
use primitives::{twox_128, Blake2Hasher};
|
||||
use demo_primitives::{Hash, BlockNumber, AccountId};
|
||||
use runtime_primitives::traits::Header as HeaderT;
|
||||
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult};
|
||||
@@ -117,7 +117,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn panic_execution_with_foreign_code_gives_error() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![70u8; 8],
|
||||
@@ -137,7 +137,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![70u8; 8],
|
||||
@@ -157,7 +157,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
|
||||
@@ -181,7 +181,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_foreign_code_gives_ok() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
|
||||
@@ -203,7 +203,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
fn new_test_ext() -> TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> TestExternalities<Blake2Hasher> {
|
||||
use keyring::Keyring::*;
|
||||
let three = [3u8; 32].into();
|
||||
GenesisConfig {
|
||||
@@ -244,7 +244,7 @@ mod tests {
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
let extrinsics = extrinsics.into_iter().map(sign).collect::<Vec<_>>();
|
||||
let extrinsics_root = ordered_trie_root::<KeccakHasher, _, _>(extrinsics.iter().map(Encode::encode)).0.into();
|
||||
let extrinsics_root = ordered_trie_root::<Blake2Hasher, _, _>(extrinsics.iter().map(Encode::encode)).0.into();
|
||||
|
||||
let header = Header {
|
||||
parent_hash,
|
||||
@@ -262,7 +262,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
[69u8; 32].into(),
|
||||
hex!("efdd1840ae46b687fc59fc730892d412a0fb051ef120f9e6dfcf1c416d0fc2cb").into(),
|
||||
hex!("c2fcc528c92b3c958b0e0914f26e05f151903ed43c87f29b20f9c8f0450d7484").into(),
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
@@ -282,7 +282,7 @@ mod tests {
|
||||
construct_block(
|
||||
2,
|
||||
block1().1,
|
||||
hex!("e360ad4a43929e521fd41cdabf8d772eb39f9cbf71fe95bada685e24bd3bbbbb").into(),
|
||||
hex!("62e5879f10338fa6136161c60ae0ffc35936f7b8c3fdb38095ddd0e044309762").into(),
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
@@ -307,7 +307,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
[69u8; 32].into(),
|
||||
hex!("989ebec4920fe4a99edcd3766eee35a31de92dff20427920ae68d15471afba9a").into(),
|
||||
hex!("789b19bc7beaa83ae70412f65ad0ac02435fd79e0226ba3394865a052e56fbd8").into(),
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
@@ -478,7 +478,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn panic_execution_gives_error() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![70u8; 8],
|
||||
@@ -499,7 +499,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_gives_ok() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
|
||||
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
|
||||
|
||||
Generated
-1
@@ -609,7 +609,6 @@ dependencies = [
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-codec-derive 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
@@ -49,7 +49,7 @@ use client::Client;
|
||||
use demo_network::{Protocol as DemoProtocol, consensus::ConsensusNetwork};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use service::FactoryFullConfiguration;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
pub use service::{Roles, PruningMode, ExtrinsicPoolOptions,
|
||||
ErrorKind, Error, ComponentBlock, LightComponents, FullComponents};
|
||||
@@ -66,9 +66,9 @@ pub trait Components: service::Components {
|
||||
/// Demo API.
|
||||
type Api: 'static + Api + Send + Sync;
|
||||
/// Client backend.
|
||||
type Backend: 'static + client::backend::Backend<Block, KeccakHasher, RlpCodec>;
|
||||
type Backend: 'static + client::backend::Backend<Block, Blake2Hasher, RlpCodec>;
|
||||
/// Client executor.
|
||||
type Executor: 'static + client::CallExecutor<Block, KeccakHasher, RlpCodec> + Send + Sync;
|
||||
type Executor: 'static + client::CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync;
|
||||
}
|
||||
|
||||
impl Components for service::LightComponents<Factory> {
|
||||
|
||||
@@ -55,7 +55,7 @@ use hashdb::Hasher;
|
||||
use kvdb::{KeyValueDB, DBTransaction};
|
||||
use memorydb::MemoryDB;
|
||||
use parking_lot::RwLock;
|
||||
use primitives::{H256, AuthorityId, KeccakHasher, RlpCodec};
|
||||
use primitives::{H256, AuthorityId, Blake2Hasher, RlpCodec};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::bft::Justification;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hash, HashFor, NumberFor, Zero};
|
||||
@@ -71,7 +71,7 @@ pub use state_db::PruningMode;
|
||||
const FINALIZATION_WINDOW: u64 = 32;
|
||||
|
||||
/// DB-backed patricia trie state, transaction type is an overlay of changes to commit.
|
||||
pub type DbState = state_machine::TrieBackend<KeccakHasher, RlpCodec>;
|
||||
pub type DbState = state_machine::TrieBackend<Blake2Hasher, RlpCodec>;
|
||||
|
||||
/// Database settings.
|
||||
pub struct DatabaseSettings {
|
||||
@@ -92,7 +92,7 @@ pub fn new_client<E, S, Block>(
|
||||
) -> Result<client::Client<Backend<Block>, client::LocalCallExecutor<Backend<Block>, E>, Block>, client::error::Error>
|
||||
where
|
||||
Block: BlockT,
|
||||
E: CodeExecutor<KeccakHasher> + RuntimeInfo,
|
||||
E: CodeExecutor<Blake2Hasher> + RuntimeInfo,
|
||||
S: BuildStorage,
|
||||
{
|
||||
let backend = Arc::new(Backend::new(settings, FINALIZATION_WINDOW)?);
|
||||
@@ -234,8 +234,8 @@ pub struct BlockImportOperation<Block: BlockT, H: Hasher> {
|
||||
pending_block: Option<PendingBlock<Block>>,
|
||||
}
|
||||
|
||||
impl<Block> client::backend::BlockImportOperation<Block, KeccakHasher, RlpCodec>
|
||||
for BlockImportOperation<Block, KeccakHasher>
|
||||
impl<Block> client::backend::BlockImportOperation<Block, Blake2Hasher, RlpCodec>
|
||||
for BlockImportOperation<Block, Blake2Hasher>
|
||||
where Block: BlockT,
|
||||
{
|
||||
type State = DbState;
|
||||
@@ -259,7 +259,7 @@ where Block: BlockT,
|
||||
// currently authorities are not cached on full nodes
|
||||
}
|
||||
|
||||
fn update_storage(&mut self, update: MemoryDB<KeccakHasher>) -> Result<(), client::error::Error> {
|
||||
fn update_storage(&mut self, update: MemoryDB<Blake2Hasher>) -> Result<(), client::error::Error> {
|
||||
self.updates = update;
|
||||
Ok(())
|
||||
}
|
||||
@@ -277,7 +277,7 @@ struct StorageDb<Block: BlockT> {
|
||||
pub state_db: StateDb<Block::Hash, H256>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> state_machine::Storage<KeccakHasher> for StorageDb<Block> {
|
||||
impl<Block: BlockT> state_machine::Storage<Blake2Hasher> for StorageDb<Block> {
|
||||
fn get(&self, key: &H256) -> Result<Option<DBValue>, String> {
|
||||
self.state_db.get(&key.0.into(), self).map(|r| r.map(|v| DBValue::from_slice(&v)))
|
||||
.map_err(|e| format!("Database backend error: {:?}", e))
|
||||
@@ -351,8 +351,8 @@ fn apply_state_commit(transaction: &mut DBTransaction, commit: state_db::CommitS
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block> client::backend::Backend<Block, KeccakHasher, RlpCodec> for Backend<Block> where Block: BlockT {
|
||||
type BlockImportOperation = BlockImportOperation<Block, KeccakHasher>;
|
||||
impl<Block> client::backend::Backend<Block, Blake2Hasher, RlpCodec> for Backend<Block> where Block: BlockT {
|
||||
type BlockImportOperation = BlockImportOperation<Block, Blake2Hasher>;
|
||||
type Blockchain = BlockchainDb<Block>;
|
||||
type State = DbState;
|
||||
|
||||
@@ -476,7 +476,7 @@ impl<Block> client::backend::Backend<Block, KeccakHasher, RlpCodec> for Backend<
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block> client::backend::LocalBackend<Block, KeccakHasher, RlpCodec> for Backend<Block>
|
||||
impl<Block> client::backend::LocalBackend<Block, Blake2Hasher, RlpCodec> for Backend<Block>
|
||||
where Block: BlockT {}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -27,7 +27,7 @@ use client::cht;
|
||||
use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use client::light::blockchain::Storage as LightBlockchainStorage;
|
||||
use codec::{Decode, Encode};
|
||||
use primitives::{AuthorityId, H256, KeccakHasher};
|
||||
use primitives::{AuthorityId, H256, Blake2Hasher};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash, HashFor,
|
||||
Zero, One, As, NumberFor};
|
||||
@@ -203,7 +203,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
// build new CHT if required
|
||||
if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) {
|
||||
let new_cht_start: NumberFor<Block> = cht::start_number(cht::SIZE, new_cht_number);
|
||||
let new_cht_root: Option<Block::Hash> = cht::compute_root::<Block::Header, KeccakHasher, _>(
|
||||
let new_cht_root: Option<Block::Hash> = cht::compute_root::<Block::Header, Blake2Hasher, _>(
|
||||
cht::SIZE, new_cht_number, (new_cht_start.as_()..)
|
||||
.map(|num| self.hash(As::sa(num)).unwrap_or_default()));
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ use runtime_primitives::generic::BlockId;
|
||||
use {backend, error, Client, CallExecutor};
|
||||
use runtime_primitives::{ApplyResult, ApplyOutcome};
|
||||
use patricia_trie::NodeCodec;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use hashdb::Hasher;
|
||||
use rlp::Encodable;
|
||||
|
||||
@@ -45,10 +45,10 @@ where
|
||||
changes: state_machine::OverlayedChanges,
|
||||
}
|
||||
|
||||
impl<B, E, Block> BlockBuilder<B, E, Block, KeccakHasher, RlpCodec>
|
||||
impl<B, E, Block> BlockBuilder<B, E, Block, Blake2Hasher, RlpCodec>
|
||||
where
|
||||
B: backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec> + Clone,
|
||||
B: backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec> + Clone,
|
||||
Block: BlockT,
|
||||
{
|
||||
/// Create a new instance of builder from the given client, building on the latest block.
|
||||
|
||||
@@ -25,7 +25,7 @@ use patricia_trie::NodeCodec;
|
||||
use hashdb::Hasher;
|
||||
use rlp::Encodable;
|
||||
use codec::Decode;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
use backend;
|
||||
use error;
|
||||
@@ -115,10 +115,10 @@ impl<B, E> Clone for LocalCallExecutor<B, E> where E: Clone {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, Block> CallExecutor<Block, KeccakHasher, RlpCodec> for LocalCallExecutor<B, E>
|
||||
impl<B, E, Block> CallExecutor<Block, Blake2Hasher, RlpCodec> for LocalCallExecutor<B, E>
|
||||
where
|
||||
B: backend::LocalBackend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CodeExecutor<KeccakHasher> + RuntimeInfo,
|
||||
B: backend::LocalBackend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CodeExecutor<Blake2Hasher> + RuntimeInfo,
|
||||
Block: BlockT,
|
||||
{
|
||||
type Error = E::Error;
|
||||
@@ -157,7 +157,7 @@ where
|
||||
}
|
||||
|
||||
fn call_at_state<
|
||||
S: state_machine::Backend<KeccakHasher, RlpCodec>,
|
||||
S: state_machine::Backend<Blake2Hasher, RlpCodec>,
|
||||
F: FnOnce(Result<Vec<u8>, Self::Error>, Result<Vec<u8>, Self::Error>) -> Result<Vec<u8>, Self::Error>,
|
||||
>(&self,
|
||||
state: &S,
|
||||
@@ -176,7 +176,7 @@ where
|
||||
).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn prove_at_state<S: state_machine::Backend<KeccakHasher, RlpCodec>>(&self,
|
||||
fn prove_at_state<S: state_machine::Backend<Blake2Hasher, RlpCodec>>(&self,
|
||||
state: S,
|
||||
changes: &mut OverlayedChanges,
|
||||
method: &str,
|
||||
|
||||
@@ -213,7 +213,7 @@ pub fn decode_cht_value<Hash: From<H256>>(value: &[u8]) -> Option<Hash> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use test_client::runtime::Header;
|
||||
use super::*;
|
||||
|
||||
@@ -257,18 +257,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn compute_root_works() {
|
||||
assert!(compute_root::<Header, KeccakHasher, _>(SIZE, 42, vec![Some(1.into()); SIZE as usize]).is_some());
|
||||
assert!(compute_root::<Header, Blake2Hasher, _>(SIZE, 42, vec![Some(1.into()); SIZE as usize]).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_proof_fails_when_querying_wrong_block() {
|
||||
assert!(build_proof::<Header, KeccakHasher, RlpCodec, _>(
|
||||
assert!(build_proof::<Header, Blake2Hasher, RlpCodec, _>(
|
||||
SIZE, 0, (SIZE * 1000) as u64, vec![Some(1.into()); SIZE as usize]).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_proof_works() {
|
||||
assert!(build_proof::<Header, KeccakHasher, RlpCodec, _>(
|
||||
assert!(build_proof::<Header, Blake2Hasher, RlpCodec, _>(
|
||||
SIZE, 0, (SIZE / 2) as u64, vec![Some(1.into()); SIZE as usize]).is_some());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ use runtime_primitives::{bft::Justification, generic::{BlockId, SignedBlock, Blo
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, As, NumberFor};
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_support::metadata::JSONMetadataDecodable;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use primitives::storage::{StorageKey, StorageData};
|
||||
use codec::{Encode, Decode};
|
||||
use state_machine::{
|
||||
@@ -165,9 +165,9 @@ impl<Block: BlockT> JustifiedHeader<Block> {
|
||||
pub fn new_in_mem<E, Block, S>(
|
||||
executor: E,
|
||||
genesis_storage: S,
|
||||
) -> error::Result<Client<in_mem::Backend<Block, KeccakHasher, RlpCodec>, LocalCallExecutor<in_mem::Backend<Block, KeccakHasher, RlpCodec>, E>, Block>>
|
||||
) -> error::Result<Client<in_mem::Backend<Block, Blake2Hasher, RlpCodec>, LocalCallExecutor<in_mem::Backend<Block, Blake2Hasher, RlpCodec>, E>, Block>>
|
||||
where
|
||||
E: CodeExecutor<KeccakHasher> + RuntimeInfo,
|
||||
E: CodeExecutor<Blake2Hasher> + RuntimeInfo,
|
||||
S: BuildStorage,
|
||||
Block: BlockT,
|
||||
{
|
||||
@@ -177,8 +177,8 @@ pub fn new_in_mem<E, Block, S>(
|
||||
}
|
||||
|
||||
impl<B, E, Block> Client<B, E, Block> where
|
||||
B: backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
B: backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
Block: BlockT,
|
||||
{
|
||||
/// Creates new Substrate Client with given blockchain and code executor.
|
||||
@@ -303,7 +303,7 @@ impl<B, E, Block> Client<B, E, Block> where
|
||||
let cht_num = cht::block_to_cht_number(cht_size, block_num).ok_or_else(proof_error)?;
|
||||
let cht_start = cht::start_number(cht_size, cht_num);
|
||||
let headers = (cht_start.as_()..).map(|num| self.block_hash(As::sa(num)).unwrap_or_default());
|
||||
let proof = cht::build_proof::<Block::Header, KeccakHasher, RlpCodec, _>(cht_size, cht_num, block_num, headers)
|
||||
let proof = cht::build_proof::<Block::Header, Blake2Hasher, RlpCodec, _>(cht_size, cht_num, block_num, headers)
|
||||
.ok_or_else(proof_error)?;
|
||||
Ok((header, proof))
|
||||
}
|
||||
@@ -326,14 +326,14 @@ impl<B, E, Block> Client<B, E, Block> where
|
||||
}
|
||||
|
||||
/// Create a new block, built on the head of the chain.
|
||||
pub fn new_block(&self) -> error::Result<block_builder::BlockBuilder<B, E, Block, KeccakHasher, RlpCodec>>
|
||||
pub fn new_block(&self) -> error::Result<block_builder::BlockBuilder<B, E, Block, Blake2Hasher, RlpCodec>>
|
||||
where E: Clone
|
||||
{
|
||||
block_builder::BlockBuilder::new(self)
|
||||
}
|
||||
|
||||
/// Create a new block, built on top of `parent`.
|
||||
pub fn new_block_at(&self, parent: &BlockId<Block>) -> error::Result<block_builder::BlockBuilder<B, E, Block, KeccakHasher, RlpCodec>>
|
||||
pub fn new_block_at(&self, parent: &BlockId<Block>) -> error::Result<block_builder::BlockBuilder<B, E, Block, Blake2Hasher, RlpCodec>>
|
||||
where E: Clone
|
||||
{
|
||||
block_builder::BlockBuilder::at_block(parent, &self)
|
||||
@@ -595,8 +595,8 @@ impl<B, E, Block> Client<B, E, Block> where
|
||||
|
||||
impl<B, E, Block> bft::BlockImport<Block> for Client<B, E, Block>
|
||||
where
|
||||
B: backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
B: backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn import_block(
|
||||
@@ -618,8 +618,8 @@ impl<B, E, Block> bft::BlockImport<Block> for Client<B, E, Block>
|
||||
|
||||
impl<B, E, Block> bft::Authorities<Block> for Client<B, E, Block>
|
||||
where
|
||||
B: backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
B: backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn authorities(&self, at: &BlockId<Block>) -> Result<Vec<AuthorityId>, bft::Error> {
|
||||
@@ -641,7 +641,7 @@ impl<B, E, Block> bft::Authorities<Block> for Client<B, E, Block>
|
||||
|
||||
impl<B, E, Block> BlockchainEvents<Block> for Client<B, E, Block>
|
||||
where
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
Block: BlockT,
|
||||
{
|
||||
/// Get block import event stream.
|
||||
@@ -659,8 +659,8 @@ where
|
||||
|
||||
impl<B, E, Block> ChainHead<Block> for Client<B, E, Block>
|
||||
where
|
||||
B: backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
B: backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn best_block_header(&self) -> error::Result<<Block as BlockT>::Header> {
|
||||
@@ -670,8 +670,8 @@ where
|
||||
|
||||
impl<B, E, Block> BlockBody<Block> for Client<B, E, Block>
|
||||
where
|
||||
B: backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
B: backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn block_body(&self, id: &BlockId<Block>) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
|
||||
|
||||
@@ -51,7 +51,7 @@ mod tests {
|
||||
use test_client::runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
|
||||
use test_client::runtime::{Hash, Transfer, Block, BlockNumber, Header, Digest, Extrinsic};
|
||||
use ed25519::{Public, Pair};
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
native_executor_instance!(Executor, test_client::runtime::api::dispatch, test_client::runtime::VERSION, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm"));
|
||||
|
||||
@@ -59,7 +59,7 @@ mod tests {
|
||||
NativeExecutionDispatch::new()
|
||||
}
|
||||
|
||||
fn construct_block(backend: &InMemory<KeccakHasher, RlpCodec>, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec<Transfer>) -> (Vec<u8>, Hash) {
|
||||
fn construct_block(backend: &InMemory<Blake2Hasher, RlpCodec>, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec<Transfer>) -> (Vec<u8>, Hash) {
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
let transactions = txs.into_iter().map(|tx| {
|
||||
@@ -69,7 +69,7 @@ mod tests {
|
||||
Extrinsic { transfer: tx, signature }
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let extrinsics_root = ordered_trie_root::<KeccakHasher, _, _>(transactions.iter().map(Encode::encode)).into();
|
||||
let extrinsics_root = ordered_trie_root::<Blake2Hasher, _, _>(transactions.iter().map(Encode::encode)).into();
|
||||
|
||||
println!("root before: {:?}", extrinsics_root);
|
||||
let mut header = Header {
|
||||
@@ -116,7 +116,7 @@ mod tests {
|
||||
(vec![].and(&Block { header, extrinsics: transactions }), hash)
|
||||
}
|
||||
|
||||
fn block1(genesis_hash: Hash, backend: &InMemory<KeccakHasher, RlpCodec>) -> (Vec<u8>, Hash) {
|
||||
fn block1(genesis_hash: Hash, backend: &InMemory<Blake2Hasher, RlpCodec>) -> (Vec<u8>, Hash) {
|
||||
construct_block(
|
||||
backend,
|
||||
1,
|
||||
|
||||
@@ -187,7 +187,7 @@ pub mod tests {
|
||||
use in_mem::{Blockchain as InMemoryBlockchain};
|
||||
use light::fetcher::{Fetcher, FetchChecker, LightDataChecker,
|
||||
RemoteCallRequest, RemoteHeaderRequest};
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use state_machine::Backend;
|
||||
use super::*;
|
||||
@@ -213,7 +213,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
fn prepare_for_read_proof_check() -> (
|
||||
LightDataChecker<executor::NativeExecutor<test_client::LocalExecutor>, KeccakHasher, RlpCodec>,
|
||||
LightDataChecker<executor::NativeExecutor<test_client::LocalExecutor>, Blake2Hasher, RlpCodec>,
|
||||
Header, Vec<Vec<u8>>, usize)
|
||||
{
|
||||
// prepare remote client
|
||||
@@ -236,7 +236,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
fn prepare_for_header_proof_check(insert_cht: bool) -> (
|
||||
LightDataChecker<executor::NativeExecutor<test_client::LocalExecutor>, KeccakHasher, RlpCodec>,
|
||||
LightDataChecker<executor::NativeExecutor<test_client::LocalExecutor>, Blake2Hasher, RlpCodec>,
|
||||
Hash, Header, Vec<Vec<u8>>)
|
||||
{
|
||||
// prepare remote client
|
||||
@@ -254,7 +254,7 @@ pub mod tests {
|
||||
|
||||
// check remote read proof locally
|
||||
let local_storage = InMemoryBlockchain::<Block>::new();
|
||||
let local_cht_root = cht::compute_root::<Header, KeccakHasher, _>(4, 0, local_headers_hashes.into_iter()).unwrap();
|
||||
let local_cht_root = cht::compute_root::<Header, Blake2Hasher, _>(4, 0, local_headers_hashes.into_iter()).unwrap();
|
||||
if insert_cht {
|
||||
local_storage.insert_cht_root(1, local_cht_root);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ pub mod fetcher;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_primitives::traits::Block as BlockT;
|
||||
use state_machine::{CodeExecutor, ExecutionStrategy};
|
||||
@@ -53,7 +53,7 @@ pub fn new_light<B, S, F, GS>(
|
||||
backend: Arc<Backend<S, F>>,
|
||||
fetcher: Arc<F>,
|
||||
genesis_storage: GS,
|
||||
) -> ClientResult<Client<Backend<S, F>, RemoteCallExecutor<Blockchain<S, F>, F, KeccakHasher, RlpCodec>, B>>
|
||||
) -> ClientResult<Client<Backend<S, F>, RemoteCallExecutor<Blockchain<S, F>, F, Blake2Hasher, RlpCodec>, B>>
|
||||
where
|
||||
B: BlockT,
|
||||
S: BlockchainStorage<B>,
|
||||
|
||||
@@ -22,7 +22,6 @@ lazy_static = "1.0"
|
||||
parking_lot = "*"
|
||||
log = "0.3"
|
||||
hashdb = "0.2.1"
|
||||
tiny-keccak = "1.4"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.1"
|
||||
|
||||
@@ -45,7 +45,6 @@ extern crate triehash;
|
||||
extern crate parking_lot;
|
||||
extern crate twox_hash;
|
||||
extern crate hashdb;
|
||||
extern crate tiny_keccak;
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
@@ -78,7 +77,7 @@ pub use native_executor::{with_native_environment, NativeExecutor, NativeExecuti
|
||||
pub use state_machine::Externalities;
|
||||
pub use runtime_version::RuntimeVersion;
|
||||
pub use codec::Codec;
|
||||
use primitives::KeccakHasher;
|
||||
use primitives::Blake2Hasher;
|
||||
|
||||
/// Provides runtime information.
|
||||
pub trait RuntimeInfo {
|
||||
@@ -86,7 +85,7 @@ pub trait RuntimeInfo {
|
||||
const NATIVE_VERSION: Option<RuntimeVersion>;
|
||||
|
||||
/// Extract RuntimeVersion of given :code block
|
||||
fn runtime_version<E: Externalities<KeccakHasher>> (
|
||||
fn runtime_version<E: Externalities<Blake2Hasher>> (
|
||||
&self,
|
||||
ext: &mut E,
|
||||
heap_pages: usize,
|
||||
|
||||
@@ -24,7 +24,7 @@ use codec::Decode;
|
||||
use primitives::hashing::blake2_256;
|
||||
use parking_lot::{Mutex, MutexGuard};
|
||||
use RuntimeInfo;
|
||||
use primitives::KeccakHasher;
|
||||
use primitives::Blake2Hasher;
|
||||
|
||||
// For the internal Runtime Cache:
|
||||
// Is it compatible enough to run this natively or do we need to fall back on the WasmModule
|
||||
@@ -51,7 +51,7 @@ fn gen_cache_key(code: &[u8]) -> [u8; 32] {
|
||||
/// fetch a runtime version from the cache or if there is no cached version yet, create
|
||||
/// the runtime version entry for `code`, determines whether `Compatibility::IsCompatible`
|
||||
/// can be used by comparing returned RuntimeVersion to `ref_version`
|
||||
fn fetch_cached_runtime_version<'a, E: Externalities<KeccakHasher>>(
|
||||
fn fetch_cached_runtime_version<'a, E: Externalities<Blake2Hasher>>(
|
||||
wasm_executor: &WasmExecutor,
|
||||
cache: &'a mut MutexGuard<CacheType>,
|
||||
ext: &mut E,
|
||||
@@ -90,7 +90,7 @@ fn safe_call<F, U>(f: F) -> Result<U>
|
||||
/// Set up the externalities and safe calling environment to execute calls to a native runtime.
|
||||
///
|
||||
/// If the inner closure panics, it will be caught and return an error.
|
||||
pub fn with_native_environment<F, U>(ext: &mut Externalities<KeccakHasher>, f: F) -> Result<U>
|
||||
pub fn with_native_environment<F, U>(ext: &mut Externalities<Blake2Hasher>, f: F) -> Result<U>
|
||||
where F: ::std::panic::UnwindSafe + FnOnce() -> U
|
||||
{
|
||||
::runtime_io::with_externalities(ext, move || safe_call(f))
|
||||
@@ -104,7 +104,7 @@ pub trait NativeExecutionDispatch: Send + Sync {
|
||||
/// Dispatch a method and input data to be executed natively. Returns `Some` result or `None`
|
||||
/// if the `method` is unknown. Panics if there's an unrecoverable error.
|
||||
// fn dispatch<H: hashdb::Hasher>(ext: &mut Externalities<H>, method: &str, data: &[u8]) -> Result<Vec<u8>>;
|
||||
fn dispatch(ext: &mut Externalities<KeccakHasher>, method: &str, data: &[u8]) -> Result<Vec<u8>>;
|
||||
fn dispatch(ext: &mut Externalities<Blake2Hasher>, method: &str, data: &[u8]) -> Result<Vec<u8>>;
|
||||
|
||||
/// Get native runtime version.
|
||||
const VERSION: RuntimeVersion;
|
||||
@@ -147,7 +147,7 @@ impl<D: NativeExecutionDispatch> Clone for NativeExecutor<D> {
|
||||
impl<D: NativeExecutionDispatch> RuntimeInfo for NativeExecutor<D> {
|
||||
const NATIVE_VERSION: Option<RuntimeVersion> = Some(D::VERSION);
|
||||
|
||||
fn runtime_version<E: Externalities<KeccakHasher>>(
|
||||
fn runtime_version<E: Externalities<Blake2Hasher>>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
heap_pages: usize,
|
||||
@@ -157,10 +157,10 @@ impl<D: NativeExecutionDispatch> RuntimeInfo for NativeExecutor<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: NativeExecutionDispatch> CodeExecutor<KeccakHasher> for NativeExecutor<D> {
|
||||
impl<D: NativeExecutionDispatch> CodeExecutor<Blake2Hasher> for NativeExecutor<D> {
|
||||
type Error = Error;
|
||||
|
||||
fn call<E: Externalities<KeccakHasher>>(
|
||||
fn call<E: Externalities<Blake2Hasher>>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
heap_pages: usize,
|
||||
@@ -203,7 +203,7 @@ macro_rules! native_executor_instance {
|
||||
};
|
||||
(IMPL $name:ident, $dispatcher:path, $version:path, $code:expr) => {
|
||||
// TODO: this is not so great – I think I should go back to have dispatch take a type param and modify this macro to accept a type param and then pass it in from the test-client instead
|
||||
use primitives::KeccakHasher as _KeccakHasher;
|
||||
use primitives::Blake2Hasher as _Blake2Hasher;
|
||||
impl $crate::NativeExecutionDispatch for $name {
|
||||
const VERSION: $crate::RuntimeVersion = $version;
|
||||
fn native_equivalent() -> &'static [u8] {
|
||||
@@ -211,7 +211,7 @@ macro_rules! native_executor_instance {
|
||||
// get a proper build script, this must be strictly adhered to or things will go wrong.
|
||||
$code
|
||||
}
|
||||
fn dispatch(ext: &mut $crate::Externalities<_KeccakHasher>, method: &str, data: &[u8]) -> $crate::error::Result<Vec<u8>> {
|
||||
fn dispatch(ext: &mut $crate::Externalities<_Blake2Hasher>, method: &str, data: &[u8]) -> $crate::error::Result<Vec<u8>> {
|
||||
$crate::with_native_environment(ext, move || $dispatcher(method, data))?
|
||||
.ok_or_else(|| $crate::error::ErrorKind::MethodNotFound(method.to_owned()).into())
|
||||
}
|
||||
|
||||
@@ -30,10 +30,9 @@ use wasm_utils::UserError;
|
||||
use primitives::{blake2_256, twox_128, twox_256};
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use primitives::sandbox as sandbox_primitives;
|
||||
use primitives::KeccakHasher;
|
||||
use primitives::Blake2Hasher;
|
||||
use triehash::ordered_trie_root;
|
||||
use sandbox;
|
||||
use tiny_keccak::keccak256;
|
||||
|
||||
|
||||
struct Heap {
|
||||
@@ -75,7 +74,7 @@ macro_rules! debug_trace {
|
||||
( $( $x:tt )* ) => ()
|
||||
}
|
||||
|
||||
struct FunctionExecutor<'e, E: Externalities<KeccakHasher> + 'e> {
|
||||
struct FunctionExecutor<'e, E: Externalities<Blake2Hasher> + 'e> {
|
||||
sandbox_store: sandbox::Store,
|
||||
heap: Heap,
|
||||
memory: MemoryRef,
|
||||
@@ -84,7 +83,7 @@ struct FunctionExecutor<'e, E: Externalities<KeccakHasher> + 'e> {
|
||||
hash_lookup: HashMap<Vec<u8>, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl<'e, E: Externalities<KeccakHasher>> FunctionExecutor<'e, E> {
|
||||
impl<'e, E: Externalities<Blake2Hasher>> FunctionExecutor<'e, E> {
|
||||
fn new(m: MemoryRef, heap_pages: usize, t: Option<TableRef>, e: &'e mut E) -> Result<Self> {
|
||||
Ok(FunctionExecutor {
|
||||
sandbox_store: sandbox::Store::new(),
|
||||
@@ -97,7 +96,7 @@ impl<'e, E: Externalities<KeccakHasher>> FunctionExecutor<'e, E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'e, E: Externalities<KeccakHasher>> sandbox::SandboxCapabilities for FunctionExecutor<'e, E> {
|
||||
impl<'e, E: Externalities<Blake2Hasher>> sandbox::SandboxCapabilities for FunctionExecutor<'e, E> {
|
||||
fn store(&self) -> &sandbox::Store {
|
||||
&self.sandbox_store
|
||||
}
|
||||
@@ -293,7 +292,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
this.memory.set(result, r.as_ref()).map_err(|_| UserError("Invalid attempt to set memory in ext_storage_root"))?;
|
||||
Ok(())
|
||||
},
|
||||
ext_keccak_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8) => {
|
||||
ext_blake2_256_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8) => {
|
||||
let values = (0..lens_len)
|
||||
.map(|i| this.memory.read_primitive(lens_data + i * 4))
|
||||
.collect::<::std::result::Result<Vec<u32>, UserError>>()?
|
||||
@@ -301,11 +300,11 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
.scan(0u32, |acc, v| { let o = *acc; *acc += v; Some((o, v)) })
|
||||
.map(|(offset, len)|
|
||||
this.memory.get(values_data + offset, len as usize)
|
||||
.map_err(|_| UserError("Invalid attempt to get memory in ext_keccak_enumerated_trie_root"))
|
||||
.map_err(|_| UserError("Invalid attempt to get memory in ext_blake2_256_enumerated_trie_root"))
|
||||
)
|
||||
.collect::<::std::result::Result<Vec<_>, UserError>>()?;
|
||||
let r = ordered_trie_root::<KeccakHasher, _, _>(values.into_iter());
|
||||
this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_keccak_enumerated_trie_root"))?;
|
||||
let r = ordered_trie_root::<Blake2Hasher, _, _>(values.into_iter());
|
||||
this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_blake2_256_enumerated_trie_root"))?;
|
||||
Ok(())
|
||||
},
|
||||
ext_chain_id() -> u64 => {
|
||||
@@ -353,15 +352,6 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
this.memory.set(out, &result).map_err(|_| UserError("Invalid attempt to set result in ext_blake2_256"))?;
|
||||
Ok(())
|
||||
},
|
||||
ext_keccak256(data: *const u8, len: u32, out: *mut u8) => {
|
||||
let result = if len == 0 {
|
||||
keccak256(&[0u8; 0])
|
||||
} else {
|
||||
keccak256(&this.memory.get(data, len as usize).map_err(|_| UserError("Invalid attempt to get data in ext_keccak256"))?)
|
||||
};
|
||||
this.memory.set(out, &result).map_err(|_| UserError("Invalid attempt to set result in ext_keccak256"))?;
|
||||
Ok(())
|
||||
},
|
||||
ext_ed25519_verify(msg_data: *const u8, msg_len: u32, sig_data: *const u8, pubkey_data: *const u8) -> u32 => {
|
||||
let mut sig = [0u8; 64];
|
||||
this.memory.get_into(sig_data, &mut sig[..]).map_err(|_| UserError("Invalid attempt to get signature in ext_ed25519_verify"))?;
|
||||
@@ -396,25 +386,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
this.sandbox_store.instance_teardown(instance_idx)?;
|
||||
Ok(())
|
||||
},
|
||||
ext_sandbox_invoke(instance_idx: u32, export_ptr: *const u8, export_len: usize, state: usize) -> u32 => {
|
||||
trace!(target: "runtime-sandbox", "invoke, instance_idx={}", instance_idx);
|
||||
let export = this.memory.get(export_ptr, export_len as usize)
|
||||
.map_err(|_| UserError("Sandbox error"))
|
||||
.and_then(|b|
|
||||
String::from_utf8(b)
|
||||
.map_err(|_| UserError("Sandbox error"))
|
||||
)?;
|
||||
|
||||
let instance = this.sandbox_store.instance(instance_idx)?;
|
||||
let result = instance.invoke(&export, &[], this, state);
|
||||
match result {
|
||||
Ok(None) => Ok(sandbox_primitives::ERR_OK),
|
||||
Ok(_) => unimplemented!(),
|
||||
Err(_) => Ok(sandbox_primitives::ERR_EXECUTION),
|
||||
}
|
||||
},
|
||||
// TODO: Remove the old 'ext_sandbox_invoke' and rename this to it.
|
||||
ext_sandbox_invoke_poc2(instance_idx: u32, export_ptr: *const u8, export_len: usize, args_ptr: *const u8, args_len: usize, return_val_ptr: *const u8, return_val_len: usize, state: usize) -> u32 => {
|
||||
ext_sandbox_invoke(instance_idx: u32, export_ptr: *const u8, export_len: usize, args_ptr: *const u8, args_len: usize, return_val_ptr: *const u8, return_val_len: usize, state: usize) -> u32 => {
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
trace!(target: "runtime-sandbox", "invoke, instance_idx={}", instance_idx);
|
||||
@@ -490,7 +462,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
this.sandbox_store.memory_teardown(memory_idx)?;
|
||||
Ok(())
|
||||
},
|
||||
=> <'e, E: Externalities<KeccakHasher> + 'e>
|
||||
=> <'e, E: Externalities<Blake2Hasher> + 'e>
|
||||
);
|
||||
|
||||
/// Wasm rust executor for contracts.
|
||||
@@ -509,7 +481,7 @@ impl WasmExecutor {
|
||||
|
||||
/// Call a given method in the given code.
|
||||
/// This should be used for tests only.
|
||||
pub fn call<E: Externalities<KeccakHasher>>(
|
||||
pub fn call<E: Externalities<Blake2Hasher>>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
heap_pages: usize,
|
||||
@@ -522,7 +494,7 @@ impl WasmExecutor {
|
||||
}
|
||||
|
||||
/// Call a given method in the given wasm-module runtime.
|
||||
pub fn call_in_wasm_module<E: Externalities<KeccakHasher>>(
|
||||
pub fn call_in_wasm_module<E: Externalities<Blake2Hasher>>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
heap_pages: usize,
|
||||
@@ -740,7 +712,7 @@ mod tests {
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_enumerated_trie_root", &[]).unwrap(),
|
||||
ordered_trie_root::<KeccakHasher, _, _>(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()]).0.encode()
|
||||
ordered_trie_root::<Blake2Hasher, _, _>(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()]).0.encode()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ impl_stubs!(
|
||||
[ed25519_verify(&sig, &msg[..], &pubkey) as u8].to_vec()
|
||||
},
|
||||
test_enumerated_trie_root NO_DECODE => |_| {
|
||||
enumerated_trie_root::<substrate_primitives::KeccakHasher>(&[&b"zero"[..], &b"one"[..], &b"two"[..]]).to_vec()
|
||||
enumerated_trie_root::<substrate_primitives::Blake2Hasher>(&[&b"zero"[..], &b"one"[..], &b"two"[..]]).to_vec()
|
||||
},
|
||||
test_sandbox NO_DECODE => |code: &[u8]| {
|
||||
let ok = execute_sandboxed(code, &[]).is_ok();
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
substrate-primitives = { path = "../primitives" }
|
||||
parity-crypto = { version = "0.1", default_features = false }
|
||||
ed25519 = { path = "../ed25519" }
|
||||
error-chain = "0.12"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
//! Keystore (and session key management) for ed25519 based chains like Polkadot.
|
||||
// end::description[]
|
||||
|
||||
extern crate substrate_primitives;
|
||||
extern crate parity_crypto as crypto;
|
||||
extern crate subtle;
|
||||
extern crate ed25519;
|
||||
@@ -40,7 +41,7 @@ use std::path::PathBuf;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crypto::Keccak256;
|
||||
use substrate_primitives::hashing::blake2_256;
|
||||
use ed25519::{Pair, Public, PKCS_LEN};
|
||||
|
||||
pub use crypto::KEY_ITERATIONS;
|
||||
@@ -96,8 +97,8 @@ impl EncryptedKey {
|
||||
crypto::aes::encrypt_128_ctr(&derived_left_bits, &iv, plain, &mut *ciphertext)
|
||||
.expect("input lengths of key and iv are both 16; qed");
|
||||
|
||||
// KECCAK(DK[16..31] ++ <ciphertext>), where DK[16..31] - derived_right_bits
|
||||
let mac = crypto::derive_mac(&derived_right_bits, &*ciphertext).keccak256();
|
||||
// Blake2_256(DK[16..31] ++ <ciphertext>), where DK[16..31] - derived_right_bits
|
||||
let mac = blake2_256(&crypto::derive_mac(&derived_right_bits, &*ciphertext));
|
||||
|
||||
EncryptedKey {
|
||||
salt,
|
||||
@@ -112,7 +113,7 @@ impl EncryptedKey {
|
||||
let (derived_left_bits, derived_right_bits) =
|
||||
crypto::derive_key_iterations(password.as_bytes(), &self.salt, self.iterations);
|
||||
|
||||
let mac = crypto::derive_mac(&derived_right_bits, &self.ciphertext).keccak256();
|
||||
let mac = blake2_256(&crypto::derive_mac(&derived_right_bits, &self.ciphertext));
|
||||
|
||||
if subtle::slices_equal(&mac[..], &self.mac[..]) != 1 {
|
||||
return Err(ErrorKind::InvalidPassword.into());
|
||||
|
||||
@@ -21,7 +21,7 @@ use client::error::Error;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::bft::Justification;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
/// Local client abstraction for the network.
|
||||
pub trait Client<Block: BlockT>: Send + Sync {
|
||||
@@ -57,8 +57,8 @@ pub trait Client<Block: BlockT>: Send + Sync {
|
||||
}
|
||||
|
||||
impl<B, E, Block> Client<Block> for SubstrateClient<B, E, Block> where
|
||||
B: client::backend::Backend<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
B: client::backend::Backend<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn import(&self, origin: BlockOrigin, header: Block::Header, justification: Justification<Block::Hash>, body: Option<Vec<Block::Extrinsic>>) -> Result<ImportResult, Error> {
|
||||
|
||||
@@ -26,7 +26,7 @@ use runtime_primitives::traits::Block as BlockT;
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use io::SyncIo;
|
||||
use protocol::{Context, Protocol};
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use config::ProtocolConfig;
|
||||
use service::TransactionPool;
|
||||
use network_libp2p::{NodeIndex, SessionInfo, Severity};
|
||||
@@ -174,7 +174,7 @@ impl Peer {
|
||||
}
|
||||
|
||||
fn generate_blocks<F>(&self, count: usize, mut edit_block: F)
|
||||
where F: FnMut(&mut BlockBuilder<test_client::Backend, test_client::Executor, Block, KeccakHasher, RlpCodec>)
|
||||
where F: FnMut(&mut BlockBuilder<test_client::Backend, test_client::Executor, Block, Blake2Hasher, RlpCodec>)
|
||||
{
|
||||
for _ in 0 .. count {
|
||||
let mut builder = self.client.new_block().unwrap();
|
||||
|
||||
@@ -23,8 +23,6 @@ patricia-trie = { version = "0.2.1", optional = true }
|
||||
plain_hasher = { version = "0.2", default_features = false }
|
||||
|
||||
blake2-rfc = { version = "0.2.18", optional = true }
|
||||
# Switch back to Blake after PoC-3 is out and remove this
|
||||
tiny-keccak = { version = "1.4", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-serializer = { path = "../serializer" }
|
||||
@@ -45,7 +43,6 @@ std = [
|
||||
"rustc-hex/std",
|
||||
"twox-hash",
|
||||
"blake2-rfc",
|
||||
"tiny-keccak",
|
||||
"serde_derive",
|
||||
"byteorder/std",
|
||||
"patricia-trie",
|
||||
|
||||
@@ -20,69 +20,34 @@ use hashdb::Hasher;
|
||||
use plain_hasher::PlainHasher;
|
||||
use hash::H256;
|
||||
|
||||
// Use this when switching to Blake2 after PoC-3
|
||||
// pub mod blake {
|
||||
// use super::{Hasher, PlainHasher, H256};
|
||||
// #[cfg(feature = "std")]
|
||||
// use hashing::blake2_256;
|
||||
|
||||
// #[cfg(not(feature = "std"))]
|
||||
// extern "C" {
|
||||
// fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8);
|
||||
// }
|
||||
// #[cfg(not(feature = "std"))]
|
||||
// fn blake2_256(data: &[u8]) -> [u8; 32] {
|
||||
// let mut result: [u8; 32] = Default::default();
|
||||
// unsafe {
|
||||
// ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
|
||||
// }
|
||||
// result
|
||||
// }
|
||||
|
||||
// /// Concrete implementation of Hasher using Blake2b 256-bit hashes
|
||||
// #[derive(Debug)]
|
||||
// pub struct BlakeHasher;
|
||||
|
||||
// impl Hasher for BlakeHasher {
|
||||
// type Out = H256;
|
||||
// type StdHasher = PlainHasher;
|
||||
// const LENGTH:usize = 32;
|
||||
// fn hash(x: &[u8]) -> Self::Out {
|
||||
// blake2_256(x).into()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
pub mod keccak {
|
||||
pub mod blake2 {
|
||||
use super::{Hasher, PlainHasher, H256};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use tiny_keccak::keccak256;
|
||||
use hashing::blake2_256;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern "C" {
|
||||
fn ext_keccak256(data: *const u8, len: u32, out: *mut u8);
|
||||
fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn keccak256(data: &[u8]) -> [u8; 32] {
|
||||
fn blake2_256(data: &[u8]) -> [u8; 32] {
|
||||
let mut result: [u8; 32] = Default::default();
|
||||
unsafe {
|
||||
ext_keccak256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
|
||||
ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Concrete implementation of Hasher using Keccak 256-bit hashes
|
||||
/// Concrete implementation of Hasher using Blake2b 256-bit hashes
|
||||
#[derive(Debug)]
|
||||
pub struct KeccakHasher;
|
||||
pub struct Blake2Hasher;
|
||||
|
||||
impl Hasher for KeccakHasher {
|
||||
impl Hasher for Blake2Hasher {
|
||||
type Out = H256;
|
||||
type StdHasher = PlainHasher;
|
||||
const LENGTH : usize = 32;
|
||||
const LENGTH:usize = 32;
|
||||
fn hash(x: &[u8]) -> Self::Out {
|
||||
keccak256(x).into()
|
||||
blake2_256(x).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,6 @@ extern crate twox_hash;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate blake2_rfc;
|
||||
// Switch back to Blake after PoC-3 is out
|
||||
#[cfg(feature = "std")]
|
||||
extern crate tiny_keccak;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
@@ -114,7 +111,7 @@ pub use authority_id::AuthorityId;
|
||||
|
||||
// Switch back to Blake after PoC-3 is out
|
||||
// pub use self::hasher::blake::BlakeHasher;
|
||||
pub use self::hasher::keccak::KeccakHasher;
|
||||
pub use self::hasher::blake2::Blake2Hasher;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use self::rlp_codec::RlpCodec;
|
||||
|
||||
@@ -23,23 +23,17 @@ use core::marker::PhantomData;
|
||||
use patricia_trie::{NibbleSlice, NodeCodec, node::Node, ChildReference};
|
||||
|
||||
use hash::H256;
|
||||
// When switching to Blake2, use this instead:
|
||||
// use BlakeHasher;
|
||||
use KeccakHasher;
|
||||
use Blake2Hasher;
|
||||
|
||||
/// Concrete implementation of a `NodeCodec` with Rlp encoding, generic over the `Hasher`
|
||||
pub struct RlpNodeCodec<H: Hasher> {mark: PhantomData<H>}
|
||||
|
||||
/// Convenience type for a Keccak/Rlp flavoured NodeCodec
|
||||
pub type RlpCodec = RlpNodeCodec<KeccakHasher>;
|
||||
// When switching to Blake2, use this instead:
|
||||
// pub type RlpCodec = RlpNodeCodec<BlakeHasher>;
|
||||
/// Convenience type for a Blake2_256/Rlp flavoured NodeCodec
|
||||
pub type RlpCodec = RlpNodeCodec<Blake2Hasher>;
|
||||
|
||||
impl NodeCodec<KeccakHasher> for RlpCodec {
|
||||
impl NodeCodec<Blake2Hasher> for RlpCodec {
|
||||
type Error = DecoderError;
|
||||
// When switching to Blake2, use this null node
|
||||
// const HASHED_NULL_NODE : H256 = H256( [0x45, 0xb0, 0xcf, 0xc2, 0x20, 0xce, 0xec, 0x5b, 0x7c, 0x1c, 0x62, 0xc4, 0xd4, 0x19, 0x3d, 0x38, 0xe4, 0xeb, 0xa4, 0x8e, 0x88, 0x15, 0x72, 0x9c, 0xe7, 0x5f, 0x9c, 0xa, 0xb0, 0xe4, 0xc1, 0xc0] );
|
||||
const HASHED_NULL_NODE : H256 = H256( [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21] );
|
||||
const HASHED_NULL_NODE : H256 = H256( [0x45, 0xb0, 0xcf, 0xc2, 0x20, 0xce, 0xec, 0x5b, 0x7c, 0x1c, 0x62, 0xc4, 0xd4, 0x19, 0x3d, 0x38, 0xe4, 0xeb, 0xa4, 0x8e, 0x88, 0x15, 0x72, 0x9c, 0xe7, 0x5f, 0x9c, 0xa, 0xb0, 0xe4, 0xc1, 0xc0] );
|
||||
fn decode(data: &[u8]) -> ::std::result::Result<Node, Self::Error> {
|
||||
let r = Rlp::new(data);
|
||||
match r.prototype()? {
|
||||
@@ -66,9 +60,9 @@ impl NodeCodec<KeccakHasher> for RlpCodec {
|
||||
_ => Err(DecoderError::Custom("Rlp is not valid."))
|
||||
}
|
||||
}
|
||||
fn try_decode_hash(data: &[u8]) -> Option<<KeccakHasher as Hasher>::Out> {
|
||||
fn try_decode_hash(data: &[u8]) -> Option<<Blake2Hasher as Hasher>::Out> {
|
||||
let r = Rlp::new(data);
|
||||
if r.is_data() && r.size() == KeccakHasher::LENGTH {
|
||||
if r.is_data() && r.size() == Blake2Hasher::LENGTH {
|
||||
Some(r.as_val().expect("Hash is the correct size; qed"))
|
||||
} else {
|
||||
None
|
||||
@@ -90,7 +84,7 @@ impl NodeCodec<KeccakHasher> for RlpCodec {
|
||||
stream.drain()
|
||||
}
|
||||
|
||||
fn ext_node(partial: &[u8], child_ref: ChildReference<<KeccakHasher as Hasher>::Out>) -> ElasticArray1024<u8> {
|
||||
fn ext_node(partial: &[u8], child_ref: ChildReference<<Blake2Hasher as Hasher>::Out>) -> ElasticArray1024<u8> {
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append(&partial);
|
||||
match child_ref {
|
||||
@@ -104,7 +98,7 @@ impl NodeCodec<KeccakHasher> for RlpCodec {
|
||||
}
|
||||
|
||||
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> ElasticArray1024<u8>
|
||||
where I: IntoIterator<Item=Option<ChildReference<<KeccakHasher as Hasher>::Out>>>
|
||||
where I: IntoIterator<Item=Option<ChildReference<<Blake2Hasher as Hasher>::Out>>>
|
||||
{
|
||||
let mut stream = RlpStream::new_list(17);
|
||||
for child_ref in children {
|
||||
|
||||
@@ -32,7 +32,7 @@ use extrinsic_pool::{
|
||||
};
|
||||
use jsonrpc_macros::pubsub;
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
use primitives::{Bytes, KeccakHasher, RlpCodec};
|
||||
use primitives::{Bytes, Blake2Hasher, RlpCodec};
|
||||
use rpc::futures::{Sink, Stream, Future};
|
||||
use runtime_primitives::{generic, traits};
|
||||
use subscriptions::Subscriptions;
|
||||
@@ -100,8 +100,8 @@ impl<B, E, P> Author<B, E, P> where
|
||||
}
|
||||
|
||||
impl<B, E, P> AuthorApi<ExHash<P>, ExtrinsicFor<P>, AllExtrinsics<P>> for Author<B, E, P> where
|
||||
B: client::backend::Backend<<P as PoolChainApi>::Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<<P as PoolChainApi>::Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
B: client::backend::Backend<<P as PoolChainApi>::Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<<P as PoolChainApi>::Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
P: PoolChainApi + Sync + Send + 'static,
|
||||
P::Error: 'static,
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ use runtime_primitives::generic::{BlockId, SignedBlock};
|
||||
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
|
||||
use runtime_version::RuntimeVersion;
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
use subscriptions::Subscriptions;
|
||||
|
||||
@@ -92,8 +92,8 @@ impl<B, E, Block: BlockT> Chain<B, E, Block> {
|
||||
|
||||
impl<B, E, Block> Chain<B, E, Block> where
|
||||
Block: BlockT + 'static,
|
||||
B: client::backend::Backend<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
B: client::backend::Backend<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
{
|
||||
fn unwrap_or_best(&self, hash: Trailing<Block::Hash>) -> Result<Block::Hash> {
|
||||
Ok(match hash.into() {
|
||||
@@ -105,8 +105,8 @@ impl<B, E, Block> Chain<B, E, Block> where
|
||||
|
||||
impl<B, E, Block> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, Block::Extrinsic> for Chain<B, E, Block> where
|
||||
Block: BlockT + 'static,
|
||||
B: client::backend::Backend<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
B: client::backend::Backend<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: client::CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
{
|
||||
type Metadata = ::metadata::Metadata;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ fn should_return_header() {
|
||||
parent_hash: 0.into(),
|
||||
number: 0,
|
||||
state_root: x.state_root.clone(),
|
||||
extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(),
|
||||
extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(),
|
||||
digest: Default::default(),
|
||||
}
|
||||
);
|
||||
@@ -47,7 +47,7 @@ fn should_return_header() {
|
||||
parent_hash: 0.into(),
|
||||
number: 0,
|
||||
state_root: x.state_root.clone(),
|
||||
extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(),
|
||||
extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(),
|
||||
digest: Default::default(),
|
||||
}
|
||||
);
|
||||
@@ -86,7 +86,7 @@ fn should_return_a_block() {
|
||||
parent_hash: api.client.genesis_hash(),
|
||||
number: 1,
|
||||
state_root: x.block.header.state_root.clone(),
|
||||
extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(),
|
||||
extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(),
|
||||
digest: Default::default(),
|
||||
},
|
||||
extrinsics: vec![],
|
||||
@@ -100,7 +100,7 @@ fn should_return_a_block() {
|
||||
parent_hash: api.client.genesis_hash(),
|
||||
number: 1,
|
||||
state_root: x.block.header.state_root.clone(),
|
||||
extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(),
|
||||
extrinsics_root: "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0".into(),
|
||||
digest: Default::default(),
|
||||
},
|
||||
extrinsics: vec![],
|
||||
|
||||
@@ -27,7 +27,7 @@ use jsonrpc_macros::pubsub;
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use primitives::storage::{StorageKey, StorageData, StorageChangeSet};
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use rpc::Result as RpcResult;
|
||||
use rpc::futures::{stream, Future, Sink, Stream};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
@@ -107,8 +107,8 @@ impl<B, E, Block: BlockT> State<B, E, Block> {
|
||||
|
||||
impl<B, E, Block> State<B, E, Block> where
|
||||
Block: BlockT,
|
||||
B: client::backend::Backend<Block, KeccakHasher, RlpCodec>,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec>,
|
||||
B: client::backend::Backend<Block, Blake2Hasher, RlpCodec>,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec>,
|
||||
{
|
||||
fn unwrap_or_best(&self, hash: Trailing<Block::Hash>) -> Result<Block::Hash> {
|
||||
::helpers::unwrap_or_else(|| Ok(self.client.info()?.chain.best_hash), hash)
|
||||
@@ -117,8 +117,8 @@ impl<B, E, Block> State<B, E, Block> where
|
||||
|
||||
impl<B, E, Block> StateApi<Block::Hash> for State<B, E, Block> where
|
||||
Block: BlockT + 'static,
|
||||
B: client::backend::Backend<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block, KeccakHasher, RlpCodec> + Send + Sync + 'static,
|
||||
B: client::backend::Backend<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync + 'static,
|
||||
{
|
||||
type Metadata = ::metadata::Metadata;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ pub extern crate substrate_codec as codec;
|
||||
// re-export hashing functions.
|
||||
pub use primitives::{blake2_256, twox_128, twox_256};
|
||||
|
||||
pub use primitives::KeccakHasher;
|
||||
pub use primitives::Blake2Hasher;
|
||||
// Switch to this after PoC-3
|
||||
// pub use primitives::BlakeHasher;
|
||||
pub use substrate_state_machine::{Externalities, TestExternalities};
|
||||
@@ -42,7 +42,7 @@ use rlp::Encodable;
|
||||
|
||||
// TODO: use the real error, not NoError.
|
||||
|
||||
environmental!(ext: trait Externalities<KeccakHasher>);
|
||||
environmental!(ext: trait Externalities<Blake2Hasher>);
|
||||
|
||||
/// Get `key` from storage and return a `Vec`, empty if there's a problem.
|
||||
pub fn storage(key: &[u8]) -> Option<Vec<u8>> {
|
||||
@@ -145,7 +145,7 @@ pub fn ed25519_verify<P: AsRef<[u8]>>(sig: &[u8; 64], msg: &[u8], pubkey: P) ->
|
||||
/// Execute the given closure with global function available whose functionality routes into the
|
||||
/// externalities `ext`. Forwards the value that the closure returns.
|
||||
// NOTE: need a concrete hasher here due to limitations of the `environmental!` macro, otherwise a type param would have been fine I think.
|
||||
pub fn with_externalities<R, F: FnOnce() -> R>(ext: &mut Externalities<KeccakHasher>, f: F) -> R {
|
||||
pub fn with_externalities<R, F: FnOnce() -> R>(ext: &mut Externalities<Blake2Hasher>, f: F) -> R {
|
||||
ext::using(ext, f)
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ mod std_tests {
|
||||
|
||||
#[test]
|
||||
fn storage_works() {
|
||||
let mut t = TestExternalities::<KeccakHasher>::new();
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new();
|
||||
assert!(with_externalities(&mut t, || {
|
||||
assert_eq!(storage(b"hello"), None);
|
||||
set_storage(b"hello", b"world");
|
||||
@@ -232,7 +232,7 @@ mod std_tests {
|
||||
|
||||
#[test]
|
||||
fn read_storage_works() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
b":test".to_vec() => b"\x0b\0\0\0Hello world".to_vec()
|
||||
];
|
||||
|
||||
@@ -248,7 +248,7 @@ mod std_tests {
|
||||
|
||||
#[test]
|
||||
fn clear_prefix_works() {
|
||||
let mut t: TestExternalities<KeccakHasher> = map![
|
||||
let mut t: TestExternalities<Blake2Hasher> = map![
|
||||
b":a".to_vec() => b"\x0b\0\0\0Hello world".to_vec(),
|
||||
b":abcd".to_vec() => b"\x0b\0\0\0Hello world".to_vec(),
|
||||
b":abc".to_vec() => b"\x0b\0\0\0Hello world".to_vec(),
|
||||
|
||||
@@ -27,7 +27,7 @@ pub extern crate substrate_codec as codec;
|
||||
use core::intrinsics;
|
||||
use rstd::vec::Vec;
|
||||
use hashdb::Hasher;
|
||||
use primitives::KeccakHasher;
|
||||
use primitives::Blake2Hasher;
|
||||
pub use rstd::{mem, slice};
|
||||
|
||||
#[panic_handler]
|
||||
@@ -64,7 +64,7 @@ extern "C" {
|
||||
fn ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8;
|
||||
fn ext_get_storage_into(key_data: *const u8, key_len: u32, value_data: *mut u8, value_len: u32, value_offset: u32) -> u32;
|
||||
fn ext_storage_root(result: *mut u8);
|
||||
fn ext_keccak_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8);
|
||||
fn ext_blake2_256_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8);
|
||||
fn ext_chain_id() -> u64;
|
||||
fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8);
|
||||
fn ext_twox_128(data: *const u8, len: u32, out: *mut u8);
|
||||
@@ -77,14 +77,14 @@ pub trait ExternTrieCrypto {
|
||||
fn enumerated_trie_root(values: &[&[u8]]) -> [u8; 32];
|
||||
}
|
||||
|
||||
// Ensures we use a Keccak-flavoured Hasher when calling into native
|
||||
impl ExternTrieCrypto for KeccakHasher {
|
||||
// Ensures we use a Blake2_256-flavoured Hasher when calling into native
|
||||
impl ExternTrieCrypto for Blake2Hasher {
|
||||
fn enumerated_trie_root(values: &[&[u8]]) -> [u8; 32] {
|
||||
let lengths = values.iter().map(|v| (v.len() as u32).to_le()).collect::<Vec<_>>();
|
||||
let values = values.iter().fold(Vec::new(), |mut acc, sl| { acc.extend_from_slice(sl); acc });
|
||||
let mut result: [u8; 32] = Default::default();
|
||||
unsafe {
|
||||
ext_keccak_enumerated_trie_root(
|
||||
ext_blake2_256_enumerated_trie_root(
|
||||
values.as_ptr(),
|
||||
lengths.as_ptr(),
|
||||
lengths.len() as u32,
|
||||
|
||||
@@ -57,8 +57,7 @@ mod ffi {
|
||||
imports_len: usize,
|
||||
state: usize,
|
||||
) -> u32;
|
||||
// TODO: Rename it back to 'ext_sandbox_invoke'.
|
||||
pub fn ext_sandbox_invoke_poc2(
|
||||
pub fn ext_sandbox_invoke(
|
||||
instance_idx: u32,
|
||||
export_ptr: *const u8,
|
||||
export_len: usize,
|
||||
@@ -272,7 +271,7 @@ impl<T> Instance<T> {
|
||||
let mut return_val = vec![0u8; sandbox_primitives::ReturnValue::ENCODED_MAX_SIZE];
|
||||
|
||||
let result = unsafe {
|
||||
ffi::ext_sandbox_invoke_poc2(
|
||||
ffi::ext_sandbox_invoke(
|
||||
self.instance_idx,
|
||||
name.as_ptr(),
|
||||
name.len(),
|
||||
|
||||
@@ -40,22 +40,6 @@ impl<'a> Input for IncrementalInput<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: only introduce this wrapper for types where it makes sense, ideally have it within the module declaration.
|
||||
|
||||
struct AppendZeroes<'a, I: Input + 'a> {
|
||||
input: &'a mut I,
|
||||
}
|
||||
|
||||
impl<'a, I: Input + 'a> Input for AppendZeroes<'a, I> {
|
||||
fn read(&mut self, into: &mut [u8]) -> usize {
|
||||
let r = self.input.read(into);
|
||||
for z in &mut into[r..] {
|
||||
*z = 0;
|
||||
};
|
||||
into.len()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
|
||||
pub fn get<T: Codec + Sized>(key: &[u8]) -> Option<T> {
|
||||
let key = twox_128(key);
|
||||
@@ -64,7 +48,7 @@ pub fn get<T: Codec + Sized>(key: &[u8]) -> Option<T> {
|
||||
key: &key[..],
|
||||
pos: 0,
|
||||
};
|
||||
Decode::decode(&mut AppendZeroes { input: &mut input } ).expect("storage is not null, therefore must be a valid type")
|
||||
Decode::decode(&mut input).expect("storage is not null, therefore must be a valid type")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ use rstd::prelude::*;
|
||||
use codec::Encode;
|
||||
use runtime_support::{StorageValue, StorageMap};
|
||||
use primitives::traits::{Zero, As};
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
use {runtime_io, primitives};
|
||||
use super::{Trait, ENUM_SET_SIZE, EnumSet, NextEnumSet, CreationFee, TransferFee,
|
||||
ReclaimRebate, ExistentialDeposit, TransactionByteFee, TransactionBaseFee, TotalIssuance,
|
||||
@@ -60,7 +60,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
fn build_storage(self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
|
||||
let total_issuance: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n);
|
||||
|
||||
let mut r: runtime_io::TestExternalities<KeccakHasher> = map![
|
||||
let mut r: runtime_io::TestExternalities<Blake2Hasher> = map![
|
||||
Self::hash(<NextEnumSet<T>>::key()).to_vec() => T::AccountIndex::sa(self.balances.len() / ENUM_SET_SIZE).encode(),
|
||||
Self::hash(<TransactionBaseFee<T>>::key()).to_vec() => self.transaction_base_fee.encode(),
|
||||
Self::hash(<TransactionByteFee<T>>::key()).to_vec() => self.transaction_byte_fee.encode(),
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use primitives::BuildStorage;
|
||||
use primitives::testing::{Digest, Header};
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use runtime_io;
|
||||
use {GenesisConfig, Module, Trait, system};
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Trait for Runtime {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
pub fn new_test_ext(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
pub fn new_test_ext(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
|
||||
let balance_factor = if ext_deposit > 0 {
|
||||
256
|
||||
|
||||
@@ -51,7 +51,7 @@ use primitives::bft::MisbehaviorReport;
|
||||
use system::{ensure_signed, ensure_inherent, ensure_root};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -257,7 +257,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
fn build_storage(self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
|
||||
use codec::{Encode, KeyedVec};
|
||||
let auth_count = self.authorities.len() as u32;
|
||||
let mut r: runtime_io::TestExternalities<KeccakHasher> = self.authorities.into_iter().enumerate().map(|(i, v)|
|
||||
let mut r: runtime_io::TestExternalities<Blake2Hasher> = self.authorities.into_iter().enumerate().map(|(i, v)|
|
||||
((i as u32).to_keyed_vec(AUTHORITY_AT), v.encode())
|
||||
).collect();
|
||||
r.insert(AUTHORITY_COUNT.to_vec(), auth_count.encode());
|
||||
|
||||
@@ -25,7 +25,7 @@ use runtime_io::{self, twox_128};
|
||||
use runtime_support::StorageValue;
|
||||
use codec::Encode;
|
||||
use std::collections::HashMap;
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -41,7 +41,7 @@ pub struct GenesisConfig<T: Trait> {
|
||||
|
||||
impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T> {
|
||||
fn build_storage(self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
|
||||
let r: runtime_io::TestExternalities<KeccakHasher> = map![
|
||||
let r: runtime_io::TestExternalities<Blake2Hasher> = map![
|
||||
twox_128(<ContractFee<T>>::key()).to_vec() => self.contract_fee.encode(),
|
||||
twox_128(<CallBaseFee<T>>::key()).to_vec() => self.call_base_fee.encode(),
|
||||
twox_128(<CreateBaseFee<T>>::key()).to_vec() => self.create_base_fee.encode(),
|
||||
|
||||
@@ -20,7 +20,7 @@ use runtime_primitives::testing::{Digest, H256, Header};
|
||||
use runtime_primitives::traits::{BlakeTwo256};
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_support::StorageMap;
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
use wabt;
|
||||
use {
|
||||
runtime_io, balances, system, CodeOf, ContractAddressFor,
|
||||
@@ -93,7 +93,7 @@ impl ExtBuilder {
|
||||
self.block_gas_limit = block_gas_limit;
|
||||
self
|
||||
}
|
||||
fn build(self) -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default()
|
||||
.build_storage()
|
||||
.unwrap();
|
||||
|
||||
@@ -133,7 +133,7 @@ mod tests {
|
||||
pub use primitives::BuildStorage;
|
||||
pub use primitives::traits::{BlakeTwo256};
|
||||
pub use primitives::testing::{Digest, Header};
|
||||
pub use substrate_primitives::KeccakHasher;
|
||||
pub use substrate_primitives::Blake2Hasher;
|
||||
pub use {seats, motions, voting};
|
||||
|
||||
impl_outer_origin! {
|
||||
@@ -192,7 +192,7 @@ mod tests {
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(balances::GenesisConfig::<Test>{
|
||||
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
|
||||
|
||||
@@ -628,7 +628,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = new_test_ext(false);
|
||||
with_externalities(&mut t, || {
|
||||
<Candidates<Test>>::put(vec![0, 0, 1]);
|
||||
|
||||
@@ -374,7 +374,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
mod tests {
|
||||
use super::*;
|
||||
use runtime_io::with_externalities;
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use primitives::BuildStorage;
|
||||
use primitives::traits::{BlakeTwo256};
|
||||
use primitives::testing::{Digest, Header};
|
||||
@@ -416,7 +416,7 @@ mod tests {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(balances::GenesisConfig::<Test>{
|
||||
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
|
||||
|
||||
@@ -331,7 +331,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
use runtime_io::with_externalities;
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_primitives::traits::{BlakeTwo256};
|
||||
|
||||
@@ -373,7 +373,7 @@ mod tests {
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
// We use default for brevity, but you can configure as desired if needed.
|
||||
t.extend(balances::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
|
||||
@@ -217,7 +217,7 @@ mod tests {
|
||||
use super::*;
|
||||
use balances::Call;
|
||||
use runtime_io::with_externalities;
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use primitives::BuildStorage;
|
||||
use primitives::traits::{Header as HeaderT, BlakeTwo256, Lookup};
|
||||
use primitives::testing::{Digest, Header, Block};
|
||||
@@ -290,7 +290,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
|
||||
t.extend(balances::GenesisConfig::<Runtime>::default().build_storage().unwrap());
|
||||
t.into()
|
||||
@@ -303,11 +303,8 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
// Blake
|
||||
// state_root: hex!("02532989c613369596025dfcfc821339fc9861987003924913a5a1382f87034a").into(),
|
||||
// Keccak
|
||||
state_root: hex!("14a253cb1c5f38beeec8bee962a941b2ba0773b7593564fbe62b9c3a46784df5").into(),
|
||||
extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
|
||||
state_root: hex!("d1d3da2b1efb1a6ef740b8cdef52e4cf3c6dade6f8a360969fd7ef0034c53b54").into(),
|
||||
extrinsics_root: hex!("45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
},
|
||||
extrinsics: vec![],
|
||||
@@ -324,7 +321,7 @@ mod tests {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: [0u8; 32].into(),
|
||||
extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
|
||||
extrinsics_root: hex!("45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
},
|
||||
extrinsics: vec![],
|
||||
@@ -340,7 +337,7 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: hex!("14a253cb1c5f38beeec8bee962a941b2ba0773b7593564fbe62b9c3a46784df5").into(),
|
||||
state_root: hex!("d1d3da2b1efb1a6ef740b8cdef52e4cf3c6dade6f8a360969fd7ef0034c53b54").into(),
|
||||
extrinsics_root: [0u8; 32].into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ use runtime_io;
|
||||
#[cfg(feature = "std")] use std::fmt::{Debug, Display};
|
||||
#[cfg(feature = "std")] use serde::{Serialize, de::DeserializeOwned};
|
||||
use substrate_primitives;
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
use codec::{Codec, Encode};
|
||||
pub use integer_sqrt::IntegerSquareRoot;
|
||||
pub use num_traits::{Zero, One, Bounded};
|
||||
@@ -257,20 +257,20 @@ impl Hash for BlakeTwo256 {
|
||||
runtime_io::blake2_256(s).into()
|
||||
}
|
||||
fn enumerated_trie_root(items: &[&[u8]]) -> Self::Output {
|
||||
runtime_io::enumerated_trie_root::<KeccakHasher>(items).into()
|
||||
runtime_io::enumerated_trie_root::<Blake2Hasher>(items).into()
|
||||
}
|
||||
fn trie_root<
|
||||
I: IntoIterator<Item = (A, B)>,
|
||||
A: AsRef<[u8]> + Ord,
|
||||
B: AsRef<[u8]>
|
||||
>(input: I) -> Self::Output {
|
||||
runtime_io::trie_root::<KeccakHasher, _, _, _>(input).into()
|
||||
runtime_io::trie_root::<Blake2Hasher, _, _, _>(input).into()
|
||||
}
|
||||
fn ordered_trie_root<
|
||||
I: IntoIterator<Item = A>,
|
||||
A: AsRef<[u8]>
|
||||
>(input: I) -> Self::Output {
|
||||
runtime_io::ordered_trie_root::<KeccakHasher, _, _>(input).into()
|
||||
runtime_io::ordered_trie_root::<Blake2Hasher, _, _>(input).into()
|
||||
}
|
||||
fn storage_root() -> Self::Output {
|
||||
runtime_io::storage_root().into()
|
||||
|
||||
@@ -286,7 +286,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
mod tests {
|
||||
use super::*;
|
||||
use runtime_io::with_externalities;
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use primitives::BuildStorage;
|
||||
use primitives::traits::{Identity, BlakeTwo256};
|
||||
use primitives::testing::{Digest, Header};
|
||||
@@ -328,7 +328,7 @@ mod tests {
|
||||
type Consensus = consensus::Module<Test>;
|
||||
type Session = Module<Test>;
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
|
||||
@@ -23,7 +23,7 @@ use rstd::prelude::*;
|
||||
use codec::Encode;
|
||||
use runtime_support::StorageValue;
|
||||
use primitives::traits::As;
|
||||
use substrate_primitives::KeccakHasher;
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
use {runtime_io, primitives};
|
||||
use super::{Trait, Intentions, CurrentEra, OfflineSlashGrace, MinimumValidatorCount,
|
||||
BondingDuration, SessionsPerEra, ValidatorCount, SessionReward, OfflineSlash};
|
||||
@@ -61,7 +61,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
fn build_storage(self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
|
||||
let r: runtime_io::TestExternalities<KeccakHasher> = map![
|
||||
let r: runtime_io::TestExternalities<Blake2Hasher> = map![
|
||||
Self::hash(<Intentions<T>>::key()).to_vec() => self.intentions.encode(),
|
||||
Self::hash(<SessionsPerEra<T>>::key()).to_vec() => self.sessions_per_era.encode(),
|
||||
Self::hash(<ValidatorCount<T>>::key()).to_vec() => self.validator_count.encode(),
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use primitives::BuildStorage;
|
||||
use primitives::traits::{Identity};
|
||||
use primitives::testing::{Digest, Header};
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use runtime_io;
|
||||
use {GenesisConfig, Module, Trait, consensus, session, system, timestamp, balances};
|
||||
|
||||
@@ -70,7 +70,7 @@ impl Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
let balance_factor = if ext_deposit > 0 {
|
||||
256
|
||||
|
||||
@@ -55,7 +55,7 @@ use rstd::marker::PhantomData;
|
||||
use codec::Encode;
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use runtime_io::{twox_128, TestExternalities, KeccakHasher};
|
||||
use runtime_io::{twox_128, TestExternalities, Blake2Hasher};
|
||||
|
||||
/// Compute the extrinsics root of a list of extrinsics.
|
||||
pub fn extrinsics_root<H: Hash, E: codec::Encode>(extrinsics: &[E]) -> H::Output {
|
||||
@@ -261,7 +261,7 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
/// Get the basic externalities for this module, useful for tests.
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub fn externalities() -> TestExternalities<KeccakHasher> {
|
||||
pub fn externalities() -> TestExternalities<Blake2Hasher> {
|
||||
map![
|
||||
twox_128(&<BlockHash<T>>::key_for(T::BlockNumber::zero())).to_vec() => [69u8; 32].encode(), // TODO: replace with Hash::default().encode
|
||||
twox_128(<Number<T>>::key()).to_vec() => T::BlockNumber::one().encode(),
|
||||
@@ -395,7 +395,7 @@ mod tests {
|
||||
|
||||
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
GenesisConfig::<Test>::default().build_storage().unwrap().into()
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +335,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
use runtime_io::with_externalities;
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_primitives::traits::{BlakeTwo256};
|
||||
use runtime_primitives::testing::{Digest, Header};
|
||||
@@ -372,7 +372,7 @@ mod tests {
|
||||
type Balances = balances::Module<Test>;
|
||||
type Treasury = Module<Test>;
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(balances::GenesisConfig::<Test>{
|
||||
balances: vec![(0, 100), (1, 99), (2, 1)],
|
||||
|
||||
@@ -29,7 +29,7 @@ use substrate_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use extrinsic_pool::{self, Options as ExtrinsicPoolOptions, Pool as ExtrinsicPool};
|
||||
use runtime_primitives::{traits::Block as BlockT, traits::Header as HeaderT, BuildStorage};
|
||||
use config::Configuration;
|
||||
use primitives::{KeccakHasher, RlpCodec, H256};
|
||||
use primitives::{Blake2Hasher, RlpCodec, H256};
|
||||
|
||||
// Type aliases.
|
||||
// These exist mainly to avoid typing `<F as Factory>::Foo` all over the code.
|
||||
@@ -65,7 +65,7 @@ pub type LightExecutor<F> = client::light::call_executor::RemoteCallExecutor<
|
||||
network::OnDemand<<F as ServiceFactory>::Block, NetworkService<F>>
|
||||
>,
|
||||
network::OnDemand<<F as ServiceFactory>::Block, NetworkService<F>>,
|
||||
KeccakHasher,
|
||||
Blake2Hasher,
|
||||
RlpCodec,
|
||||
>;
|
||||
|
||||
@@ -153,9 +153,9 @@ pub trait Components: 'static {
|
||||
/// Associated service factory.
|
||||
type Factory: ServiceFactory;
|
||||
/// Client backend.
|
||||
type Backend: 'static + client::backend::Backend<FactoryBlock<Self::Factory>, KeccakHasher, RlpCodec>;
|
||||
type Backend: 'static + client::backend::Backend<FactoryBlock<Self::Factory>, Blake2Hasher, RlpCodec>;
|
||||
/// Client executor.
|
||||
type Executor: 'static + client::CallExecutor<FactoryBlock<Self::Factory>, KeccakHasher, RlpCodec> + Send + Sync;
|
||||
type Executor: 'static + client::CallExecutor<FactoryBlock<Self::Factory>, Blake2Hasher, RlpCodec> + Send + Sync;
|
||||
/// Extrinsic pool type.
|
||||
type ExtrinsicPoolApi: 'static + extrinsic_pool::ChainApi<Hash=<Self::Factory as ServiceFactory>::ExtrinsicHash, Block=FactoryBlock<Self::Factory>>;
|
||||
|
||||
@@ -241,7 +241,7 @@ impl<Factory: ServiceFactory> Components for LightComponents<Factory>
|
||||
};
|
||||
let db_storage = client_db::light::LightStorage::new(db_settings)?;
|
||||
let light_blockchain = client::light::new_light_blockchain(db_storage);
|
||||
let fetch_checker = Arc::new(client::light::new_fetch_checker::<_, KeccakHasher, RlpCodec>(executor));
|
||||
let fetch_checker = Arc::new(client::light::new_fetch_checker::<_, Blake2Hasher, RlpCodec>(executor));
|
||||
let fetcher = Arc::new(network::OnDemand::new(fetch_checker));
|
||||
let client_backend = client::light::new_light_backend(light_blockchain, fetcher.clone());
|
||||
let client = client::light::new_light(client_backend, fetcher.clone(), &config.chain_spec)?;
|
||||
|
||||
@@ -484,7 +484,7 @@ mod tests {
|
||||
use super::*;
|
||||
use super::backend::InMemory;
|
||||
use super::ext::Ext;
|
||||
use primitives::{KeccakHasher, RlpCodec, H256};
|
||||
use primitives::{Blake2Hasher, RlpCodec, H256};
|
||||
|
||||
struct DummyCodeExecutor {
|
||||
native_available: bool,
|
||||
@@ -557,7 +557,7 @@ mod tests {
|
||||
b"dogglesworth".to_vec() => b"catXXX".to_vec(),
|
||||
b"doug".to_vec() => b"notadog".to_vec()
|
||||
];
|
||||
let backend = InMemory::<KeccakHasher, RlpCodec>::from(initial);
|
||||
let backend = InMemory::<Blake2Hasher, RlpCodec>::from(initial);
|
||||
let mut overlay = OverlayedChanges {
|
||||
committed: map![
|
||||
b"dog".to_vec() => Some(b"puppy".to_vec()),
|
||||
@@ -570,10 +570,7 @@ mod tests {
|
||||
],
|
||||
};
|
||||
let mut ext = Ext::new(&mut overlay, &backend);
|
||||
// Blake
|
||||
// const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b");
|
||||
// Keccak
|
||||
const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3");
|
||||
const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b");
|
||||
assert_eq!(ext.storage_root(), H256(ROOT));
|
||||
}
|
||||
|
||||
@@ -630,7 +627,7 @@ mod tests {
|
||||
&mut Default::default(), &executor, "test", &[]).unwrap();
|
||||
|
||||
// check proof locally
|
||||
let (local_result, _) = execution_proof_check::<KeccakHasher, RlpCodec,_,>(remote_root, remote_proof,
|
||||
let (local_result, _) = execution_proof_check::<Blake2Hasher, RlpCodec,_,>(remote_root, remote_proof,
|
||||
&mut Default::default(), &executor, "test", &[]).unwrap();
|
||||
|
||||
// check that both results are correct
|
||||
@@ -646,7 +643,7 @@ mod tests {
|
||||
b"abc".to_vec() => b"2".to_vec(),
|
||||
b"bbb".to_vec() => b"3".to_vec()
|
||||
];
|
||||
let backend = InMemory::<KeccakHasher, RlpCodec>::from(initial).try_into_trie_backend().unwrap();
|
||||
let backend = InMemory::<Blake2Hasher, RlpCodec>::from(initial).try_into_trie_backend().unwrap();
|
||||
let mut overlay = OverlayedChanges {
|
||||
committed: map![
|
||||
b"aba".to_vec() => Some(b"1312".to_vec()),
|
||||
@@ -685,8 +682,8 @@ mod tests {
|
||||
let remote_root = remote_backend.storage_root(::std::iter::empty()).0;
|
||||
let remote_proof = prove_read(remote_backend, b"value2").unwrap().1;
|
||||
// check proof locally
|
||||
let local_result1 = read_proof_check::<KeccakHasher, RlpCodec>(remote_root, remote_proof.clone(), b"value2").unwrap();
|
||||
let local_result2 = read_proof_check::<KeccakHasher, RlpCodec>(remote_root, remote_proof.clone(), &[0xff]).is_ok();
|
||||
let local_result1 = read_proof_check::<Blake2Hasher, RlpCodec>(remote_root, remote_proof.clone(), b"value2").unwrap();
|
||||
let local_result2 = read_proof_check::<Blake2Hasher, RlpCodec>(remote_root, remote_proof.clone(), &[0xff]).is_ok();
|
||||
// check that results are correct
|
||||
assert_eq!(local_result1, Some(vec![24]));
|
||||
assert_eq!(local_result2, false);
|
||||
|
||||
@@ -123,9 +123,9 @@ mod tests {
|
||||
use backend::{InMemory};
|
||||
use trie_backend::tests::test_trie;
|
||||
use super::*;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
fn test_proving() -> ProvingBackend<KeccakHasher, RlpCodec> {
|
||||
fn test_proving() -> ProvingBackend<Blake2Hasher, RlpCodec> {
|
||||
ProvingBackend::new(test_trie())
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn proof_is_invalid_when_does_not_contains_root() {
|
||||
assert!(create_proof_check_backend::<KeccakHasher, RlpCodec>(1.into(), vec![]).is_err());
|
||||
assert!(create_proof_check_backend::<Blake2Hasher, RlpCodec>(1.into(), vec![]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -162,7 +162,7 @@ mod tests {
|
||||
#[test]
|
||||
fn proof_recorded_and_checked() {
|
||||
let contents = (0..64).map(|i| (vec![i], Some(vec![i]))).collect::<Vec<_>>();
|
||||
let in_memory = InMemory::<KeccakHasher, RlpCodec>::default();
|
||||
let in_memory = InMemory::<Blake2Hasher, RlpCodec>::default();
|
||||
let in_memory = in_memory.update(contents);
|
||||
let in_memory_root = in_memory.storage_root(::std::iter::empty()).0;
|
||||
(0..64).for_each(|i| assert_eq!(in_memory.storage(&[i]).unwrap().unwrap(), vec![i]));
|
||||
@@ -177,7 +177,7 @@ mod tests {
|
||||
|
||||
let proof = proving.extract_proof();
|
||||
|
||||
let proof_check = create_proof_check_backend::<KeccakHasher, RlpCodec>(in_memory_root.into(), proof).unwrap();
|
||||
let proof_check = create_proof_check_backend::<Blake2Hasher, RlpCodec>(in_memory_root.into(), proof).unwrap();
|
||||
assert_eq!(proof_check.storage(&[42]).unwrap().unwrap(), vec![42]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,18 +104,15 @@ impl<H: Hasher> Externalities<H> for TestExternalities<H> where H::Out: Ord + En
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use primitives::{KeccakHasher, H256};
|
||||
use primitives::{Blake2Hasher, H256};
|
||||
|
||||
#[test]
|
||||
fn commit_should_work() {
|
||||
let mut ext = TestExternalities::<KeccakHasher>::new();
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::new();
|
||||
ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec());
|
||||
ext.set_storage(b"dog".to_vec(), b"puppy".to_vec());
|
||||
ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec());
|
||||
// Blake
|
||||
// const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b");
|
||||
// Keccak
|
||||
const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3");
|
||||
const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b");
|
||||
assert_eq!(ext.storage_root(), H256(ROOT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,11 +280,11 @@ impl<H: Hasher> TrieBackendStorage<H> {
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashSet;
|
||||
use primitives::{KeccakHasher, RlpCodec, H256};
|
||||
use primitives::{Blake2Hasher, RlpCodec, H256};
|
||||
|
||||
fn test_db() -> (MemoryDB<KeccakHasher>, H256) {
|
||||
fn test_db() -> (MemoryDB<Blake2Hasher>, H256) {
|
||||
let mut root = H256::default();
|
||||
let mut mdb = MemoryDB::<KeccakHasher>::new();
|
||||
let mut mdb = MemoryDB::<Blake2Hasher>::new();
|
||||
{
|
||||
let mut trie = TrieDBMut::<_, RlpCodec>::new(&mut mdb, &mut root);
|
||||
trie.insert(b"key", b"value").expect("insert failed");
|
||||
@@ -298,7 +298,7 @@ pub mod tests {
|
||||
(mdb, root)
|
||||
}
|
||||
|
||||
pub(crate) fn test_trie() -> TrieBackend<KeccakHasher, RlpCodec> {
|
||||
pub(crate) fn test_trie() -> TrieBackend<Blake2Hasher, RlpCodec> {
|
||||
let (mdb, root) = test_db();
|
||||
TrieBackend::with_memorydb(mdb, root)
|
||||
}
|
||||
@@ -320,7 +320,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn pairs_are_empty_on_empty_storage() {
|
||||
let db = TrieBackend::<KeccakHasher, RlpCodec>::with_memorydb(
|
||||
let db = TrieBackend::<Blake2Hasher, RlpCodec>::with_memorydb(
|
||||
MemoryDB::new(),
|
||||
Default::default()
|
||||
);
|
||||
|
||||
@@ -22,7 +22,7 @@ use keyring;
|
||||
use runtime;
|
||||
|
||||
use {Backend, Executor};
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
/// Extension trait for test block builder.
|
||||
pub trait BlockBuilderExt {
|
||||
@@ -30,7 +30,7 @@ pub trait BlockBuilderExt {
|
||||
fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error>;
|
||||
}
|
||||
|
||||
impl BlockBuilderExt for client::block_builder::BlockBuilder<Backend, Executor, runtime::Block, KeccakHasher, RlpCodec> {
|
||||
impl BlockBuilderExt for client::block_builder::BlockBuilder<Backend, Executor, runtime::Block, Blake2Hasher, RlpCodec> {
|
||||
fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error> {
|
||||
self.push(sign_tx(transfer))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ mod block_builder_ext;
|
||||
pub use client_ext::TestClient;
|
||||
pub use block_builder_ext::BlockBuilderExt;
|
||||
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
mod local_executor {
|
||||
#![allow(missing_docs)]
|
||||
@@ -52,7 +52,7 @@ mod local_executor {
|
||||
pub use local_executor::LocalExecutor;
|
||||
|
||||
/// Test client database backend.
|
||||
pub type Backend = client::in_mem::Backend<runtime::Block, KeccakHasher, RlpCodec>;
|
||||
pub type Backend = client::in_mem::Backend<runtime::Block, Blake2Hasher, RlpCodec>;
|
||||
|
||||
/// Test client executor.
|
||||
pub type Executor = client::LocalCallExecutor<
|
||||
|
||||
@@ -24,7 +24,7 @@ use runtime_primitives::traits::{Hash as HashT, BlakeTwo256};
|
||||
use runtime_primitives::{ApplyError, ApplyOutcome, ApplyResult};
|
||||
use codec::{KeyedVec, Encode};
|
||||
use super::{AccountId, BlockNumber, Extrinsic, H256 as Hash, Block, Header};
|
||||
use primitives::KeccakHasher;
|
||||
use primitives::Blake2Hasher;
|
||||
|
||||
const NONCE_OF: &[u8] = b"nonce:";
|
||||
const BALANCE_OF: &[u8] = b"balance:";
|
||||
@@ -69,7 +69,7 @@ pub fn execute_block(block: Block) {
|
||||
// check transaction trie root represents the transactions.
|
||||
let txs = block.extrinsics.iter().map(Encode::encode).collect::<Vec<_>>();
|
||||
let txs = txs.iter().map(Vec::as_slice).collect::<Vec<_>>();
|
||||
let txs_root = enumerated_trie_root::<KeccakHasher>(&txs).into();
|
||||
let txs_root = enumerated_trie_root::<Blake2Hasher>(&txs).into();
|
||||
info_expect_equal_hash(&txs_root, &header.extrinsics_root);
|
||||
assert!(txs_root == header.extrinsics_root, "Transaction trie root must be valid.");
|
||||
|
||||
@@ -96,7 +96,7 @@ pub fn finalise_block() -> Header {
|
||||
let extrinsic_index = ExtrinsicIndex::take();
|
||||
let txs: Vec<_> = (0..extrinsic_index).map(ExtrinsicData::take).collect();
|
||||
let txs = txs.iter().map(Vec::as_slice).collect::<Vec<_>>();
|
||||
let extrinsics_root = enumerated_trie_root::<KeccakHasher>(&txs).into();
|
||||
let extrinsics_root = enumerated_trie_root::<Blake2Hasher>(&txs).into();
|
||||
|
||||
let number = <Number>::take();
|
||||
let parent_hash = <ParentHash>::take();
|
||||
@@ -172,9 +172,9 @@ mod tests {
|
||||
use codec::{Joiner, KeyedVec};
|
||||
use keyring::Keyring;
|
||||
use ::{Header, Digest, Extrinsic, Transfer};
|
||||
use primitives::KeccakHasher;
|
||||
use primitives::Blake2Hasher;
|
||||
|
||||
fn new_test_ext() -> TestExternalities<KeccakHasher> {
|
||||
fn new_test_ext() -> TestExternalities<Blake2Hasher> {
|
||||
map![
|
||||
twox_128(b"latest").to_vec() => vec![69u8; 32],
|
||||
twox_128(b":auth:len").to_vec() => vec![].and(&3u32),
|
||||
@@ -197,11 +197,8 @@ mod tests {
|
||||
let h = Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
// Blake
|
||||
// state_root: hex!("0c22599e15fb5e052c84f79a2aab179ba6bb238218fd86bdd4a74ebcc87adfcd").into(),
|
||||
// Keccak
|
||||
state_root: hex!("97dfcd1f8cbf8845fcb544f89332f1a94c1137f7d1b199ef0b0a6ed217015c3e").into(),
|
||||
extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(),
|
||||
state_root: hex!("0c22599e15fb5e052c84f79a2aab179ba6bb238218fd86bdd4a74ebcc87adfcd").into(),
|
||||
extrinsics_root: hex!("45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
};
|
||||
|
||||
@@ -228,11 +225,8 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
// Blake
|
||||
// state_root: hex!("0425393fd07e2a806cfd7e990ee91dc92fe6bba34eab2bf45d5be7d67e24d467").into(),
|
||||
// Keccak
|
||||
state_root: hex!("0dd8210adaf581464cc68555814a787ed491f8c608d0a0dbbf2208a6d44190b1").into(),
|
||||
extrinsics_root: hex!("951508f2cc0071500a74765ab0fb2f280fdcdd329d5f989dda675010adee99d6").into(),
|
||||
state_root: hex!("0425393fd07e2a806cfd7e990ee91dc92fe6bba34eab2bf45d5be7d67e24d467").into(),
|
||||
extrinsics_root: hex!("83fd59e8fe7cee53d7421713a09fe0abae1aec5f4db94fe5193737b12195f013").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
},
|
||||
extrinsics: vec![
|
||||
@@ -256,11 +250,8 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: b.header.hash(),
|
||||
number: 2,
|
||||
// Blake
|
||||
// state_root: hex!("e32dd1d84d9133ca48078d2d83f2b0db19f9d47229ba98bf5ced0e9f86fac2c7").into(),
|
||||
// Keccak
|
||||
state_root: hex!("c93f2fd494c386fa32ee76b6198a7ccf5db12c02c3a79755fd2d4646ec2bf8d7").into(),
|
||||
extrinsics_root: hex!("3563642676d7e042c894eedc579ba2d6eeedf9a6c66d9d557599effc9f674372").into(),
|
||||
state_root: hex!("e32dd1d84d9133ca48078d2d83f2b0db19f9d47229ba98bf5ced0e9f86fac2c7").into(),
|
||||
extrinsics_root: hex!("5d2d0a93201744f0df878c33b07da40cd38e24ac2358cc2811ea640835c31b68").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
},
|
||||
extrinsics: vec![
|
||||
|
||||
@@ -541,7 +541,6 @@ dependencies = [
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-codec-derive 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user