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

Minimal parachain framework part 1 #113

Merged
merged 75 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
36055db
dynamic inclusion threshold calculator
rphmeier Apr 4, 2018
8634fcd
collators interface
rphmeier Apr 4, 2018
28bf531
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 4, 2018
90ed3a1
collation helpers
rphmeier Apr 5, 2018
b3e654a
initial proposal-creation future
rphmeier Apr 5, 2018
2c17d00
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 5, 2018
83879eb
create proposer when asked to propose
rphmeier Apr 5, 2018
04bf517
remove local_availability duty
rphmeier Apr 6, 2018
6559366
statement table tracks includable parachain count
rphmeier Apr 6, 2018
9bf4b2a
beginnings of timing future
rphmeier Apr 6, 2018
79ea48a
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 7, 2018
f1d7634
finish proposal logic
rphmeier Apr 7, 2018
908bcab
remove stray println
rphmeier Apr 7, 2018
74b7ded
extract shared table to separate module
rphmeier Apr 7, 2018
81508cf
change ordering
rphmeier Apr 9, 2018
d7cb48a
includability tracking
rphmeier Apr 9, 2018
616503d
fix doc
rphmeier Apr 9, 2018
7e049b3
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 9, 2018
ca6fbcb
initial changes to parachains module
rphmeier Apr 10, 2018
a8b0fc1
initialise dummy block before API calls
rphmeier Apr 10, 2018
f2297b8
give polkadot control over round proposer based on random seed
rphmeier Apr 10, 2018
f6fa97f
propose only after enough candidates
rphmeier Apr 10, 2018
6380239
flesh out parachains module a bit more
rphmeier Apr 11, 2018
00624c8
set_heads
rphmeier Apr 11, 2018
7cff6b7
actually introduce set_heads to runtime
rphmeier Apr 11, 2018
7e5d5ce
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 11, 2018
47095e5
update block_builder to accept parachains
rphmeier Apr 11, 2018
08a040c
split block validity errors from real errors in evaluation
rphmeier Apr 11, 2018
57b523a
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 12, 2018
0653de9
update WASM runtimes
rphmeier Apr 12, 2018
3ba45d5
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 13, 2018
6e73e55
polkadot-api methods for parachains additions
rphmeier Apr 13, 2018
acfdc27
delay evaluation until candidates are ready
rphmeier Apr 13, 2018
7bcf8e5
comments
rphmeier Apr 13, 2018
e63431b
fix dynamic inclusion with zero initial
rphmeier Apr 13, 2018
787ffeb
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 16, 2018
1f5faa3
test for includability tracker
rphmeier Apr 16, 2018
213cfab
wasm validation of parachain candidates
rphmeier Apr 17, 2018
eeebde3
move primitives to primitives crate
rphmeier Apr 17, 2018
d01531f
remove runtime-std dependency from codec
rphmeier Apr 17, 2018
1a84478
adjust doc
rphmeier Apr 17, 2018
c18ed9a
polkadot-parachain-primitives
rphmeier Apr 17, 2018
51c6063
kill legacy polkadot-validator crate
rphmeier Apr 17, 2018
90fe0ff
basic-add test chain
rphmeier Apr 17, 2018
fc5ff45
test for basic_add parachain
rphmeier Apr 17, 2018
0cce813
move to test-chains dir
rphmeier Apr 17, 2018
fb6f12d
use wasm-build
rphmeier Apr 17, 2018
5ba8dd3
new wasm directory layout
rphmeier Apr 17, 2018
f404eb8
reorganize a bit more
rphmeier Apr 18, 2018
39aad59
Fix for rh-minimal-parachain (#141)
pepyakin Apr 18, 2018
b5b2629
more basic_add tests
rphmeier Apr 18, 2018
3cd7c2c
validate parachain WASM
rphmeier Apr 18, 2018
da5d1a9
Merge branch 'master' into rh-minimal-parachain
rphmeier Apr 18, 2018
716f104
produce statements on receiving statements
rphmeier Apr 30, 2018
516c0c1
tests for reactive statement production
rphmeier May 1, 2018
11a2e2b
fix build
rphmeier May 1, 2018
e0acc9c
add OOM lang item to runtime-io
rphmeier May 1, 2018
0857ffa
use dynamic_inclusion when evaluating as well
rphmeier May 1, 2018
12ea3b3
Merge branch 'master' into rh-minimal-parachain
rphmeier May 2, 2018
8e38484
Merge branch 'master' into rh-minimal-parachain
rphmeier May 2, 2018
3f35959
fix update_includable_count
rphmeier May 4, 2018
3e88415
remove dead code
rphmeier May 5, 2018
157b0ca
grumbles
rphmeier May 6, 2018
0d17f97
actually defer round_proposer logic
rphmeier May 7, 2018
a8581ac
Merge branch 'master' into rh-minimal-parachain
rphmeier May 8, 2018
c658d29
update wasm
rphmeier May 8, 2018
ed05e14
address a few more grumbles
rphmeier May 8, 2018
75004e1
Merge branch 'master' into rh-minimal-parachain
rphmeier May 15, 2018
77c6df7
Merge branch 'master' into rh-minimal-parachain
rphmeier May 17, 2018
5c0c13b
Merge branch 'master' into rh-minimal-parachain
rphmeier May 23, 2018
e6e6b5a
grumbles
rphmeier May 23, 2018
251a93c
update WASM checkins
rphmeier May 23, 2018
9a3301f
Merge branch 'master' into rh-minimal-parachain
rphmeier May 23, 2018
78f7428
remove dependency on tokio-timer
rphmeier May 24, 2018
c04aeef
Merge branch 'master' into rh-minimal-parachain
rphmeier May 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ members = [
"polkadot/consensus",
"polkadot/executor",
"polkadot/keystore",
"polkadot/parachain",
"polkadot/primitives",
"polkadot/runtime",
"polkadot/statement-table",
"polkadot/transaction-pool",
"polkadot/validator",
"polkadot/service",

"substrate/bft",
"substrate/client",
"substrate/client/db",
Expand Down Expand Up @@ -53,6 +54,7 @@ members = [
"substrate/serializer",
"substrate/state-machine",
"substrate/test-runtime",

"demo/runtime",
"demo/primitives",
"demo/executor",
Expand Down
2 changes: 2 additions & 0 deletions demo/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ impl consensus::Trait for Concrete {
pub type Consensus = consensus::Module<Concrete>;

impl timestamp::Trait for Concrete {
const SET_POSITION: u32 = 0;

type Value = u64;
}

Expand Down
3 changes: 0 additions & 3 deletions 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.
1 change: 0 additions & 1 deletion polkadot/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
error-chain = "0.11"
log = "0.3"
polkadot-executor = { path = "../executor" }
polkadot-runtime = { path = "../runtime" }
polkadot-primitives = { path = "../primitives" }
Expand Down
58 changes: 48 additions & 10 deletions polkadot/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use polkadot_executor::Executor as LocalDispatch;
use substrate_executor::{NativeExecutionDispatch, NativeExecutor};
use state_machine::OverlayedChanges;
use primitives::{AccountId, BlockId, Hash, Index, SessionKey, Timestamp};
use primitives::parachain::DutyRoster;
use runtime::{Block, Header, UncheckedExtrinsic, Extrinsic, Call, TimestampCall};
use primitives::parachain::{DutyRoster, CandidateReceipt, Id as ParaId};
use runtime::{Block, Header, UncheckedExtrinsic, Extrinsic, Call, TimestampCall, ParachainsCall};

error_chain! {
errors {
Expand Down Expand Up @@ -135,12 +135,21 @@ pub trait PolkadotApi {
/// Get the index of an account at a block.
fn index(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<Index>;

/// Get the active parachains at a block.
fn active_parachains(&self, at: &Self::CheckedBlockId) -> Result<Vec<ParaId>>;

/// Evaluate a block and see if it gives an error.
fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result<()>;
/// Get the validation code of a parachain at a block. If the parachain is active, this will always return `Some`.
fn parachain_code(&self, at: &Self::CheckedBlockId, parachain: ParaId) -> Result<Option<Vec<u8>>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to wrap Vec<u8> into something type safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO type-safety is only useful when we have guarded types (for example, that this type can only be instantiated with valid WASM that fulfills the parachain ABI). But since any arbitrary bytes can be registered as the parachain code, what do we actually gain from writing a wrapper?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the fact that the arbitrary bytes type hanging around in the code is actually a parachain code, not anything else.


/// Get the chain head of a parachain. If the parachain is active, this will always return `Some`.
fn parachain_head(&self, at: &Self::CheckedBlockId, parachain: ParaId) -> Result<Option<Vec<u8>>>;

/// Evaluate a block. Returns true if the block is good, false if it is known to be bad,
/// and an error if we can't evaluate for some reason.
fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result<bool>;

/// Create a block builder on top of the parent block.
fn build_block(&self, parent: &Self::CheckedBlockId, timestamp: u64) -> Result<Self::BlockBuilder>;
fn build_block(&self, parent: &Self::CheckedBlockId, timestamp: u64, parachains: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder>;
}

/// A checked block ID used for the substrate-client implementation of CheckedBlockId;
Expand Down Expand Up @@ -213,15 +222,36 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
with_runtime!(self, at, ::runtime::Timestamp::now)
}

fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<()> {
with_runtime!(self, at, || ::runtime::Executive::execute_block(block))
fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<bool> {
use substrate_executor::error::ErrorKind as ExecErrorKind;

let res = with_runtime!(self, at, || ::runtime::Executive::execute_block(block));
match res {
Ok(()) => Ok(true),
Err(err) => match err.kind() {
&ErrorKind::Executor(ExecErrorKind::Runtime) => Ok(false),
_ => Err(err)
}
}
}

fn index(&self, at: &CheckedId, account: AccountId) -> Result<Index> {
with_runtime!(self, at, || ::runtime::System::account_index(account))
}

fn build_block(&self, parent: &CheckedId, timestamp: Timestamp) -> Result<Self::BlockBuilder> {
fn active_parachains(&self, at: &CheckedId) -> Result<Vec<ParaId>> {
with_runtime!(self, at, ::runtime::Parachains::active_parachains)
}

fn parachain_code(&self, at: &CheckedId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
with_runtime!(self, at, || ::runtime::Parachains::parachain_code(parachain))
}

fn parachain_head(&self, at: &CheckedId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
with_runtime!(self, at, || ::runtime::Parachains::parachain_head(parachain))
}

fn build_block(&self, parent: &CheckedId, timestamp: Timestamp, parachains: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
let parent = parent.block_id();
let header = Header {
parent_hash: self.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?,
Expand All @@ -239,6 +269,14 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
function: Call::Timestamp(TimestampCall::set(timestamp)),
},
signature: Default::default(),
},
UncheckedExtrinsic {
extrinsic: Extrinsic {
signed: Default::default(),
index: Default::default(),
function: Call::Parachains(ParachainsCall::set_heads(parachains)),
},
signature: Default::default(),
}
];

Expand Down Expand Up @@ -275,7 +313,7 @@ pub struct ClientBlockBuilder<S> {
impl<S: state_machine::Backend> ClientBlockBuilder<S>
where S::Error: Into<client::error::Error>
{
// initialises a block ready to allow extrinsics to be applied.
// initialises a block, ready to allow extrinsics to be applied.
fn initialise_block(&mut self) -> Result<()> {
let result = {
let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
Expand Down Expand Up @@ -406,7 +444,7 @@ mod tests {
let client = client();

let id = client.check_id(BlockId::Number(0)).unwrap();
let block_builder = client.build_block(&id, 1_000_000).unwrap();
let block_builder = client.build_block(&id, 1_000_000, Vec::new()).unwrap();
let block = block_builder.bake();

assert_eq!(block.header.number, 1);
Expand Down
4 changes: 3 additions & 1 deletion polkadot/collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[package]
name = "polkadot-collator"
version = "0.1.0"
authors = ["Parity Technologies <rphmeier@gmail.com>"]
authors = ["Parity Technologies <admin@parity.io>"]
description = "Abstract collation logic"

[dependencies]
futures = "0.1.17"
substrate-codec = { path = "../../substrate/codec", version = "0.1" }
substrate-primitives = { path = "../../substrate/primitives", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-parachain = { path = "../parachain", version = "0.1" }
8 changes: 3 additions & 5 deletions polkadot/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
//! to be performed, as the collation logic itself.

extern crate futures;
extern crate substrate_codec as codec;
extern crate substrate_primitives as primitives;
extern crate polkadot_primitives;

Expand Down Expand Up @@ -82,7 +83,6 @@ pub trait RelayChainContext {
}

/// Collate the necessary ingress queue using the given context.
// TODO: impl trait
pub fn collate_ingress<'a, R>(relay_context: R)
-> Box<Future<Item=ConsolidatedIngress, Error=R::Error> + 'a>
where
Expand All @@ -105,7 +105,7 @@ pub fn collate_ingress<'a, R>(relay_context: R)
// and then by the parachain ID.
//
// then transform that into the consolidated egress queue.
let future = stream::futures_unordered(egress_fetch)
Box::new(stream::futures_unordered(egress_fetch)
.fold(BTreeMap::new(), |mut map, (routing_id, egresses)| {
for (depth, egress) in egresses.into_iter().rev().enumerate() {
let depth = -(depth as i64);
Expand All @@ -116,9 +116,7 @@ pub fn collate_ingress<'a, R>(relay_context: R)
})
.map(|ordered| ordered.into_iter().map(|((_, id), egress)| (id, egress)))
.map(|i| i.collect::<Vec<_>>())
.map(ConsolidatedIngress);

Box::new(future)
.map(ConsolidatedIngress))
}

/// Produce a candidate for the parachain.
Expand Down
2 changes: 2 additions & 0 deletions polkadot/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ authors = ["Parity Technologies <admin@parity.io>"]
futures = "0.1.17"
parking_lot = "0.4"
tokio-core = "0.1.12"
tokio-timer = "0.1"
ed25519 = { path = "../../substrate/ed25519" }
error-chain = "0.11"
log = "0.3"
exit-future = "0.1"
polkadot-api = { path = "../api" }
polkadot-collator = { path = "../collator" }
polkadot-parachain = { path = "../parachain" }
polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" }
polkadot-statement-table = { path = "../statement-table" }
Expand Down
Loading