Minimal parachain framework part 1 (#113)

* dynamic inclusion threshold calculator

* collators interface

* collation helpers

* initial proposal-creation future

* create proposer when asked to propose

* remove local_availability duty

* statement table tracks includable parachain count

* beginnings of timing future

* finish proposal logic

* remove stray println

* extract shared table to separate module

* change ordering

* includability tracking

* fix doc

* initial changes to parachains module

* initialise dummy block before API calls

* give polkadot control over round proposer based on random seed

* propose only after enough candidates

* flesh out parachains module a bit more

* set_heads

* actually introduce set_heads to runtime

* update block_builder to accept parachains

* split block validity errors from real errors in evaluation

* update WASM runtimes

* polkadot-api methods for parachains additions

* delay evaluation until candidates are ready

* comments

* fix dynamic inclusion with zero initial

* test for includability tracker

* wasm validation of parachain candidates

* move primitives to primitives crate

* remove runtime-std dependency from codec

* adjust doc

* polkadot-parachain-primitives

* kill legacy polkadot-validator crate

* basic-add test chain

* test for basic_add parachain

* move to test-chains dir

* use wasm-build

* new wasm directory layout

* reorganize a bit more

* Fix for rh-minimal-parachain (#141)

* Remove extern "C"

We already encountered such behavior (bug?) in pwasm-std, I believe.

* Fix `panic_fmt` signature by adding `_col`

Wrong `panic_fmt` signature can inhibit some optimizations in LTO mode.

* Add linker flags and use wasm-gc in build script

Pass --import-memory to LLD to emit wasm binary with imported memory.

Also use wasm-gc instead of wasm-build.

* Fix effective_max.

I'm not sure why it was the way it was actually.

* Recompile wasm.

* Fix indent

* more basic_add tests

* validate parachain WASM

* produce statements on receiving statements

* tests for reactive statement production

* fix build

* add OOM lang item to runtime-io

* use dynamic_inclusion when evaluating as well

* fix update_includable_count

* remove dead code

* grumbles

* actually defer round_proposer logic

* update wasm

* address a few more grumbles

* grumbles

* update WASM checkins

* remove dependency on tokio-timer
This commit is contained in:
Robert Habermeier
2018-05-25 16:16:01 +02:00
committed by GitHub
parent 24d7d38c62
commit 27aafb0a04
63 changed files with 2825 additions and 921 deletions
+1 -2
View File
@@ -5,8 +5,7 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
substrate-runtime-std = { path = "../runtime-std", default_features = false }
[features]
default = ["std"]
std = ["substrate-runtime-std/std"]
std = []
+1 -1
View File
@@ -16,7 +16,7 @@
//! Trait
use rstd::iter::Extend;
use core::iter::Extend;
use super::slicable::Slicable;
/// Trait to allow itself to be serialised into a value which can be extended
+2 -2
View File
@@ -17,8 +17,8 @@
//! Serialiser and prepender.
use slicable::Slicable;
use rstd::iter::Extend;
use rstd::vec::Vec;
use core::iter::Extend;
use alloc::vec::Vec;
/// Trait to allow itselg to be serialised and prepended by a given slice.
pub trait KeyedVec {
+13 -4
View File
@@ -14,14 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Implements the serialization and deserialization codec for polkadot runtime
//! values.
//! Implements a serialization and deserialization codec for simple marshalling.
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg_attr(not(feature = "std"), macro_use)]
extern crate substrate_runtime_std as rstd;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
#[cfg(feature = "std")]
extern crate core;
#[cfg(feature = "std")]
pub mod alloc {
pub use std::boxed;
pub use std::vec;
}
mod slicable;
mod joiner;
+6 -5
View File
@@ -16,8 +16,9 @@
//! Serialisation.
use rstd::prelude::*;
use rstd::{mem, slice};
use alloc::vec::Vec;
use alloc::boxed::Box;
use core::{mem, slice};
use super::joiner::Joiner;
/// Trait that allows reading of data into a slice.
@@ -38,7 +39,7 @@ pub trait Input {
impl<'a> Input for &'a [u8] {
fn read(&mut self, into: &mut [u8]) -> usize {
let len = ::rstd::cmp::min(into.len(), self.len());
let len = ::core::cmp::min(into.len(), self.len());
into[..len].copy_from_slice(&self[..len]);
*self = &self[len..];
len
@@ -155,7 +156,7 @@ impl<T: Slicable> Slicable for Vec<T> {
}
fn encode(&self) -> Vec<u8> {
use rstd::iter::Extend;
use core::iter::Extend;
let len = self.len();
assert!(len <= u32::max_value() as usize, "Attempted to serialize vec with too many elements.");
@@ -241,7 +242,7 @@ macro_rules! tuple_impl {
#[allow(non_snake_case)]
mod inner_tuple_impl {
use rstd::vec::Vec;
use alloc::vec::Vec;
use super::{Input, Slicable};
tuple_impl!(A, B, C, D, E, F, G, H, I, J, K,);
@@ -433,9 +433,6 @@ impl CodeExecutor for WasmExecutor {
method: &str,
data: &[u8],
) -> Result<Vec<u8>> {
// TODO: handle all expects as errors to be returned.
println!("Wasm-Calling {}({})", method, HexDisplay::from(&data));
let module = Module::from_buffer(code).expect("all modules compiled with rustc are valid wasm code; qed");
// start module instantiation. Don't run 'start' function yet.
@@ -481,7 +478,6 @@ impl CodeExecutor for WasmExecutor {
let length = (r >> 32) as u32 as usize;
memory.get(offset, length)
.map_err(|_| ErrorKind::Runtime.into())
.map(|v| { println!("Returned {}", HexDisplay::from(&v)); v })
} else {
Err(ErrorKind::InvalidReturn.into())
}
-3
View File
@@ -67,9 +67,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "substrate-codec"
version = "0.1.0"
dependencies = [
"substrate-runtime-std 0.1.0",
]
[[package]]
name = "substrate-primitives"
@@ -22,7 +22,8 @@
extern crate serde;
#[cfg(feature = "std")]
#[allow(unused_imports)] #[macro_use] // can be removed when fixed: https://github.com/rust-lang/rust/issues/43497
#[allow(unused_imports)] // can be removed when fixed: https://github.com/rust-lang/rust/issues/43497
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "std")]
@@ -38,8 +38,8 @@ use primitives::traits::RefInto;
use substrate_primitives::bft::MisbehaviorReport;
pub const AUTHORITY_AT: &'static[u8] = b":auth:";
pub const AUTHORITY_COUNT: &'static[u8] = b":auth:len";
pub const AUTHORITY_AT: &'static [u8] = b":auth:";
pub const AUTHORITY_COUNT: &'static [u8] = b":auth:len";
struct AuthorityStorageVec<S: codec::Slicable + Default>(rstd::marker::PhantomData<S>);
impl<S: codec::Slicable + Default> StorageVec for AuthorityStorageVec<S> {
@@ -160,8 +160,8 @@ impl<T: Trait> Module<T> {
/// Set the random seed to something in particular. Can be used as an alternative to
/// `initialise` for tests that don't need to bother with the other environment entries.
#[cfg(any(feature = "std", test))]
pub fn set_random_seed(n: T::Hash) {
<RandomSeed<T>>::put(n);
pub fn set_random_seed(seed: T::Hash) {
<RandomSeed<T>>::put(seed);
}
/// Increment a particular account's nonce by 1.
@@ -37,6 +37,9 @@ use runtime_support::{StorageValue, Parameter};
use runtime_primitives::traits::{HasPublicAux, Executable, MaybeEmpty};
pub trait Trait: HasPublicAux + system::Trait {
// the position of the required timestamp-set extrinsic.
const SET_POSITION: u32;
type Value: Parameter + Default;
}
@@ -64,7 +67,11 @@ impl<T: Trait> Module<T> {
fn set(aux: &T::PublicAux, now: T::Value) {
assert!(aux.is_empty());
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
assert!(<system::Module<T>>::extrinsic_index() == 0, "Timestamp must be first extrinsic in the block");
assert!(
<system::Module<T>>::extrinsic_index() == T::SET_POSITION,
"Timestamp extrinsic must be at position {} in the block",
T::SET_POSITION
);
<Self as Store>::Now::put(now);
<Self as Store>::DidUpdate::put(true);
}
@@ -119,6 +126,7 @@ mod tests {
type Header = Header;
}
impl Trait for Test {
const SET_POSITION: u32 = 0;
type Value = u64;
}
type Timestamp = Module<Test>;
-3
View File
@@ -423,9 +423,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "substrate-codec"
version = "0.1.0"
dependencies = [
"substrate-runtime-std 0.1.0",
]
[[package]]
name = "substrate-primitives"