Merge remote-tracking branch 'origin/master' into bkchr-collator

This commit is contained in:
Bastian Köcher
2019-10-08 08:57:07 +02:00
8 changed files with 280 additions and 1765 deletions
+4 -1
View File
@@ -1 +1,4 @@
**/target/
**/target/
.idea
.vscode
.DS_Store
+89
View File
@@ -0,0 +1,89 @@
# .gitlab-ci.yml
#
# cumulus
#
# pipelines can be triggered manually in the web
stages:
- test
- build
variables:
GIT_STRATEGY: fetch
CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}"
SCCACHE_DIR: "/ci-cache/${CI_PROJECT_NAME}/sccache"
CARGO_INCREMENTAL: 0
CI_SERVER_NAME: "GitLab CI"
.collect-artifacts: &collect-artifacts
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: on_success
expire_in: 7 days
paths:
- artifacts/
.docker-env: &docker-env
image: parity/rust-builder:latest
before_script:
- rustup show
- cargo --version
- sccache -s
only:
- master
- /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
- schedules
- web
- /^[0-9]+$/ # PRs
tags:
- linux-docker
#### stage: test
cargo-audit:
stage: test
<<: *docker-env
except:
- /^[0-9]+$/
script:
- cargo audit
allow_failure: true
test-linux-stable:
stage: test
<<: *docker-env
variables:
# Enable debug assertions since we are running optimized builds for testing
# but still want to have debug assertions.
RUSTFLAGS: -Cdebug-assertions=y
script:
- time cargo test --all --release --frozen |
tee output.log
- sccache -s
after_script:
- echo "___Collecting warnings for check_warnings job___"
- awk '/^warning:/,/^$/ { print }' output.log > ${CI_COMMIT_SHORT_SHA}_warnings.log
artifacts:
name: $CI_COMMIT_SHORT_SHA
expire_in: 24 hrs
paths:
- ${CI_COMMIT_SHORT_SHA}_warnings.log
#### stage: build
check_warnings:
stage: build
<<: *docker-env
variables:
GIT_STRATEGY: none
dependencies:
- test-linux-stable
script:
- if [ -s ${CI_COMMIT_SHORT_SHA}_warnings.log ]; then
cat ${CI_COMMIT_SHORT_SHA}_warnings.log;
exit 1;
else
echo "___No warnings___";
fi
allow_failure: true
+137 -1722
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -1,6 +1,5 @@
[workspace]
members = [
"collator",
"consensus",
"runtime",
"test/runtime",
+11 -4
View File
@@ -5,17 +5,23 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
# Other dependencies
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
memory-db = { version = "0.15.2", default-features = false }
hash-db = { version = "0.15.2", default-features = false }
trie-db = { version = "0.15.2", default-features = false }
hashbrown = "0.6.1"
# Substrate dependencies
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
rio = { package = "sr-io", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
substrate-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
memory-db = { version = "0.15.2", default-features = false }
hash-db = { version = "0.15.2", default-features = false }
trie-db = { version = "0.15.2", default-features = false }
hashbrown = "0.6.0"
# Polkadot dependencies
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch", default-features = false, features = [ "wasm-api" ] }
[dev-dependencies]
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
@@ -36,4 +42,5 @@ std = [
"hash-db/std",
"trie-db/std",
"substrate-trie/std",
"parachain/std",
]
@@ -17,9 +17,7 @@
//! The actual implementation of the validate block functionality.
use crate::WitnessData;
use runtime_primitives::traits::{
Block as BlockT, Header as HeaderT, Hash as HashT
};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
use executive::ExecuteBlock;
use primitives::{Blake2Hasher, H256};
@@ -29,15 +27,14 @@ use rstd::{slice, ptr, cmp, vec::Vec, boxed::Box, mem};
use hash_db::{HashDB, EMPTY_PREFIX};
use parachain::ValidationParams;
static mut STORAGE: Option<Box<dyn Storage>> = None;
/// The message to use as expect message while accessing the `STORAGE`.
const STORAGE_SET_EXPECT: &str =
"`STORAGE` needs to be set before calling this function.";
const STORAGE_ROOT_LEN: usize = 32;
/// Extract the hashing algorithm type from the given block type.
type HashingOf<B> = <<B as BlockT>::Header as HeaderT>::Hashing;
/// Abstract the storage into a trait without `Block` generic.
trait Storage {
/// Retrieve the value for the given key.
@@ -54,18 +51,20 @@ trait Storage {
}
/// Validate a given parachain block on a validator.
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub fn validate_block<B: BlockT<Hash = H256>, E: ExecuteBlock<B>>(
mut arguments: &[u8],
params: ValidationParams,
) {
use codec::Decode;
let (parent_hash, block_data): (B::Hash, crate::ParachainBlockData::<B>) = Decode::decode(&mut arguments)
.expect("Could not decode parachain block.");
let block_data = crate::ParachainBlockData::<B>::decode(&mut &params.block_data[..])
.expect("Invalid parachain block data");
let parent_head = B::Header::decode(&mut &params.parent_head[..]).expect("Invalid parent head");
// TODO: Add `PolkadotInherent`.
let block = B::new(block_data.header, block_data.extrinsics);
assert!(parent_hash == *block.header().parent_hash(), "Invalid parent hash");
assert!(parent_head.hash() == *block.header().parent_hash(), "Invalid parent hash");
let storage = WitnessStorage::<B>::new(
block_data.witness_data,
+8 -4
View File
@@ -22,6 +22,10 @@ mod tests;
#[doc(hidden)]
pub mod implementation;
#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub use parachain;
/// Register the `validate_block` function that is used by parachains to validate blocks on a validator.
///
/// Does *nothing* when `std` feature is enabled.
@@ -58,16 +62,16 @@ macro_rules! register_validate_block_impl {
#[no_mangle]
unsafe fn validate_block(
arguments: *const u8,
arguments_len: u64,
arguments_len: usize,
) {
let arguments = $crate::slice::from_raw_parts(
let params = $crate::validate_block::parachain::wasm_api::load_params(
arguments,
arguments_len as usize,
arguments_len,
);
$crate::validate_block::implementation::validate_block::<
$block, $block_executor
>(arguments);
>(params);
}
}
};
+21 -22
View File
@@ -19,16 +19,17 @@ use crate::{ParachainBlockData, WitnessData};
use rio::TestExternalities;
use keyring::AccountKeyring;
use runtime_primitives::{generic::BlockId, traits::{Block as BlockT, Header as HeaderT}};
use executor::{WasmExecutor, error::Result, wasmi::RuntimeValue::{I64, I32}};
use executor::{WasmExecutor, error::Result, wasmi::RuntimeValue::I32};
use test_client::{
TestClientBuilder, TestClientBuilderExt, DefaultTestClientBuilderExt, Client, LongestChain,
runtime::{Block, Transfer, Hash, WASM_BINARY}
runtime::{Block, Transfer, Hash, WASM_BINARY, Header}
};
use consensus_common::SelectChain;
use parachain::ValidationParams;
use codec::Encode;
fn call_validate_block(parent_hash: Hash, block_data: ParachainBlockData<Block>) -> Result<()> {
fn call_validate_block(parent_head: Header, block_data: ParachainBlockData<Block>) -> Result<()> {
let mut ext = TestExternalities::default();
WasmExecutor::new().call_with_custom_signature(
&mut ext,
@@ -36,13 +37,17 @@ fn call_validate_block(parent_hash: Hash, block_data: ParachainBlockData<Block>)
&WASM_BINARY,
"validate_block",
|alloc| {
let arguments = (parent_hash, block_data).encode();
let arguments_offset = alloc(&arguments)?;
let params = ValidationParams {
block_data: block_data.encode(),
parent_head: parent_head.encode(),
ingress: Vec::new(),
}.encode();
let params_offset = alloc(&params)?;
Ok(
vec![
I32(arguments_offset as i32),
I64(arguments.len() as i64),
I32(params_offset as i32),
I32(params.len() as i32),
]
)
},
@@ -111,10 +116,8 @@ fn build_block_with_proof(
#[test]
fn validate_block_with_no_extrinsics() {
let (client, longest_chain) = create_test_client();
let witness_data_storage_root = *longest_chain
.best_chain()
.expect("Best block exists")
.state_root();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let witness_data_storage_root = *parent_head.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (header, extrinsics) = block.deconstruct();
@@ -124,16 +127,14 @@ fn validate_block_with_no_extrinsics() {
witness_data,
witness_data_storage_root
);
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
}
#[test]
fn validate_block_with_extrinsics() {
let (client, longest_chain) = create_test_client();
let witness_data_storage_root = *longest_chain
.best_chain()
.expect("Best block exists")
.state_root();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let witness_data_storage_root = *parent_head.state_root();
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
let (header, extrinsics) = block.deconstruct();
@@ -143,17 +144,15 @@ fn validate_block_with_extrinsics() {
witness_data,
witness_data_storage_root
);
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
}
#[test]
#[should_panic]
fn validate_block_invalid_parent_hash() {
let (client, longest_chain) = create_test_client();
let witness_data_storage_root = *longest_chain
.best_chain()
.expect("Best block exists")
.state_root();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let witness_data_storage_root = *parent_head.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (mut header, extrinsics) = block.deconstruct();
header.set_parent_hash(Hash::from_low_u64_be(1));
@@ -164,5 +163,5 @@ fn validate_block_invalid_parent_hash() {
witness_data,
witness_data_storage_root
);
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
}