Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove PoC-1 back-compat hacks (#709)
Browse files Browse the repository at this point in the history
* Remove PoC-1 back-compat hacks

* Fix lingering Keccak references

* More keccak exorcism

* Fix test

* Final fixes
  • Loading branch information
gavofyork authored Sep 11, 2018
1 parent 1ea42fc commit 82e9c83
Show file tree
Hide file tree
Showing 66 changed files with 241 additions and 354 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions demo/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)?)
Expand Down
24 changes: 12 additions & 12 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -262,7 +262,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("efdd1840ae46b687fc59fc730892d412a0fb051ef120f9e6dfcf1c416d0fc2cb").into(),
hex!("c2fcc528c92b3c958b0e0914f26e05f151903ed43c87f29b20f9c8f0450d7484").into(),
vec![
CheckedExtrinsic {
signed: None,
Expand All @@ -282,7 +282,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("e360ad4a43929e521fd41cdabf8d772eb39f9cbf71fe95bada685e24bd3bbbbb").into(),
hex!("62e5879f10338fa6136161c60ae0ffc35936f7b8c3fdb38095ddd0e044309762").into(),
vec![
CheckedExtrinsic {
signed: None,
Expand All @@ -307,7 +307,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("989ebec4920fe4a99edcd3766eee35a31de92dff20427920ae68d15471afba9a").into(),
hex!("789b19bc7beaa83ae70412f65ad0ac02435fd79e0226ba3394865a052e56fbd8").into(),
vec![
CheckedExtrinsic {
signed: None,
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand Down
1 change: 0 additions & 1 deletion demo/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions demo/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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> {
Expand Down
20 changes: 10 additions & 10 deletions substrate/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand All @@ -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)?);
Expand Down Expand Up @@ -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;
Expand All @@ -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(())
}
Expand All @@ -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))
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/db/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()));

Expand Down
8 changes: 4 additions & 4 deletions substrate/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions substrate/client/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions substrate/client/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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());
}
}
Loading

0 comments on commit 82e9c83

Please sign in to comment.