Reorganising the repository - external renames and moves (#4074)

* Adding first rough ouline of the repository structure

* Remove old CI stuff

* add title

* formatting fixes

* move node-exits job's script to scripts dir

* Move docs into subdir

* move to bin

* move maintainence scripts, configs and helpers into its own dir

* add .local to ignore

* move core->client

* start up 'test' area

* move test client

* move test runtime

* make test move compile

* Add dependencies rule enforcement.

* Fix indexing.

* Update docs to reflect latest changes

* Moving /srml->/paint

* update docs

* move client/sr-* -> primitives/

* clean old readme

* remove old broken code in rhd

* update lock

* Step 1.

* starting to untangle client

* Fix after merge.

* start splitting out client interfaces

* move children and blockchain interfaces

* Move trie and state-machine to primitives.

* Fix WASM builds.

* fixing broken imports

* more interface moves

* move backend and light to interfaces

* move CallExecutor

* move cli off client

* moving around more interfaces

* re-add consensus crates into the mix

* fix subkey path

* relieve client from executor

* starting to pull out client from grandpa

* move is_decendent_of out of client

* grandpa still depends on client directly

* lemme tests pass

* rename srml->paint

* Make it compile.

* rename interfaces->client-api

* Move keyring to primitives.

* fixup libp2p dep

* fix broken use

* allow dependency enforcement to fail

* move fork-tree

* Moving wasm-builder

* make env

* move build-script-utils

* fixup broken crate depdencies and names

* fix imports for authority discovery

* fix typo

* update cargo.lock

* fixing imports

* Fix paths and add missing crates

* re-add missing crates
This commit is contained in:
Benjamin Kampmann
2019-11-14 21:51:17 +01:00
committed by Bastian Köcher
parent becc3b0a4f
commit 60e5011c72
809 changed files with 7801 additions and 6464 deletions
+243
View File
@@ -0,0 +1,243 @@
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Tool for creating the genesis block.
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, Zero};
/// Create a genesis block, given the initial storage.
pub fn construct_genesis_block<
Block: BlockT
> (
state_root: Block::Hash
) -> Block {
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
Vec::new(),
);
Block::new(
<<Block as BlockT>::Header as HeaderT>::new(
Zero::zero(),
extrinsics_root,
state_root,
Default::default(),
Default::default()
),
Default::default()
)
}
#[cfg(test)]
mod tests {
use codec::{Encode, Decode, Joiner};
use executor::native_executor_instance;
use state_machine::{
StateMachine, OverlayedChanges, ExecutionStrategy, InMemoryChangesTrieStorage,
};
use state_machine::backend::InMemory;
use test_client::{
runtime::genesismap::{GenesisConfig, insert_genesis_block},
runtime::{Hash, Transfer, Block, BlockNumber, Header, Digest},
AccountKeyring, Sr25519Keyring,
};
use primitives::{Blake2Hasher, map};
use hex_literal::*;
native_executor_instance!(
Executor,
test_client::runtime::api::dispatch,
test_client::runtime::native_version
);
fn executor() -> executor::NativeExecutor<Executor> {
executor::NativeExecutor::new(executor::WasmExecutionMethod::Interpreted, None)
}
fn construct_block(
backend: &InMemory<Blake2Hasher>,
number: BlockNumber,
parent_hash: Hash,
state_root: Hash,
txs: Vec<Transfer>
) -> (Vec<u8>, Hash) {
use trie::{TrieConfiguration, trie_types::Layout};
let transactions = txs.into_iter().map(|tx| tx.into_signed_tx()).collect::<Vec<_>>();
let iter = transactions.iter().map(Encode::encode);
let extrinsics_root = Layout::<Blake2Hasher>::ordered_trie_root(iter).into();
let mut header = Header {
parent_hash,
number,
state_root,
extrinsics_root,
digest: Digest { logs: vec![], },
};
let hash = header.hash();
let mut overlay = OverlayedChanges::default();
StateMachine::new(
backend,
Some(&InMemoryChangesTrieStorage::<_, u64>::new()),
None,
&mut overlay,
&executor(),
"Core_initialize_block",
&header.encode(),
None,
).execute(
ExecutionStrategy::NativeElseWasm,
).unwrap();
for tx in transactions.iter() {
StateMachine::new(
backend,
Some(&InMemoryChangesTrieStorage::<_, u64>::new()),
None,
&mut overlay,
&executor(),
"BlockBuilder_apply_extrinsic",
&tx.encode(),
None,
).execute(
ExecutionStrategy::NativeElseWasm,
).unwrap();
}
let (ret_data, _, _) = StateMachine::new(
backend,
Some(&InMemoryChangesTrieStorage::<_, u64>::new()),
None,
&mut overlay,
&executor(),
"BlockBuilder_finalize_block",
&[],
None,
).execute(
ExecutionStrategy::NativeElseWasm,
).unwrap();
header = Header::decode(&mut &ret_data[..]).unwrap();
(vec![].and(&Block { header, extrinsics: transactions }), hash)
}
fn block1(genesis_hash: Hash, backend: &InMemory<Blake2Hasher>) -> (Vec<u8>, Hash) {
construct_block(
backend,
1,
genesis_hash,
hex!("25e5b37074063ab75c889326246640729b40d0c86932edc527bc80db0e04fe5c").into(),
vec![Transfer {
from: AccountKeyring::One.into(),
to: AccountKeyring::Two.into(),
amount: 69,
nonce: 0,
}]
)
}
#[test]
fn construct_genesis_should_work_with_native() {
let mut storage = GenesisConfig::new(false,
vec![Sr25519Keyring::One.public().into(), Sr25519Keyring::Two.public().into()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000,
None,
map![],
map![],
).genesis_map();
let genesis_hash = insert_genesis_block(&mut storage);
let backend = InMemory::from(storage);
let (b1data, _b1hash) = block1(genesis_hash, &backend);
let mut overlay = OverlayedChanges::default();
let _ = StateMachine::new(
&backend,
Some(&InMemoryChangesTrieStorage::<_, u64>::new()),
None,
&mut overlay,
&executor(),
"Core_execute_block",
&b1data,
None,
).execute(
ExecutionStrategy::NativeElseWasm,
).unwrap();
}
#[test]
fn construct_genesis_should_work_with_wasm() {
let mut storage = GenesisConfig::new(false,
vec![Sr25519Keyring::One.public().into(), Sr25519Keyring::Two.public().into()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000,
None,
map![],
map![],
).genesis_map();
let genesis_hash = insert_genesis_block(&mut storage);
let backend = InMemory::from(storage);
let (b1data, _b1hash) = block1(genesis_hash, &backend);
let mut overlay = OverlayedChanges::default();
let _ = StateMachine::new(
&backend,
Some(&InMemoryChangesTrieStorage::<_, u64>::new()),
None,
&mut overlay,
&executor(),
"Core_execute_block",
&b1data,
None,
).execute(
ExecutionStrategy::AlwaysWasm,
).unwrap();
}
#[test]
fn construct_genesis_with_bad_transaction_should_panic() {
let mut storage = GenesisConfig::new(false,
vec![Sr25519Keyring::One.public().into(), Sr25519Keyring::Two.public().into()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
68,
None,
map![],
map![],
).genesis_map();
let genesis_hash = insert_genesis_block(&mut storage);
let backend = InMemory::from(storage);
let (b1data, _b1hash) = block1(genesis_hash, &backend);
let mut overlay = OverlayedChanges::default();
let r = StateMachine::new(
&backend,
Some(&InMemoryChangesTrieStorage::<_, u64>::new()),
None,
&mut overlay,
&executor(),
"Core_execute_block",
&b1data,
None,
).execute(
ExecutionStrategy::NativeElseWasm,
);
assert!(r.is_err());
}
}