This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Collator for the "adder" (formerly basic-add) parachain and various small fixes #438
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4f03019
update basic_add wasm
rphmeier 82def8c
Merge remote-tracking branch 'upstream/master' into basic-add-collator
rphmeier 6d7a112
wasm feature and collator feature
rphmeier 7a2b86a
move test parachains around a little
rphmeier 78c0226
fix wasm build for basic_add
rphmeier 18dfc62
move basic_add to adder, introduce README
rphmeier 2bdcaf9
minimal basic_add collator
rphmeier 9083847
ensure collator messages are sent in the right order
rphmeier c157c4c
more logging
rphmeier 6b5f5ff
route consensus statements to all peers
rphmeier 957f69e
minor bugfixes for parachains
rphmeier d9e1c77
genesis builder accounts for parachain heads
rphmeier 53889d7
Merge remote-tracking branch 'upstream/master' into rh-simple-parachain
rphmeier d628c3d
fix parachains tests
rphmeier 5653984
targets for txpool
rphmeier 6888a5b
tweak runtime + collator
rphmeier beded4c
Merge remote-tracking branch 'upstream/master' into rh-simple-parachain
rphmeier ec68919
fix version in adder-collator
rphmeier 5c633ea
Merge remote-tracking branch 'upstream/master' into rh-simple-parachain
rphmeier 5625a81
consistency for overflowing
rphmeier b8e9dfc
Merge branch 'master' into rh-simple-parachain
gavofyork 2e7d5c8
Merge remote-tracking branch 'upstream/master' into rh-simple-parachain
rphmeier 55cbde1
Merge branch 'rh-simple-parachain' of github.com:paritytech/polkadot …
rphmeier 1ebdd12
adjust comment
rphmeier 65112b3
fix stable test run
rphmeier 5e50c6a
remove dummy registration test
rphmeier b393ae9
final grumbles
rphmeier b1e3250
Merge remote-tracking branch 'upstream/master' into rh-simple-parachain
rphmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
minimal basic_add collator
- Loading branch information
commit 2bdcaf94a20d165ed6949bcad79756c2e8f5e6d4
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [package] | ||
| name = "adder-collator" | ||
| version = "0.1.0" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
|
|
||
| [dependencies] | ||
| adder = { path = ".." } | ||
| polkadot-parachain = { path = "../../../parachain" } | ||
| polkadot-collator = { path = "../../../collator" } | ||
| polkadot-primitives = { path = "../../../primitives" } | ||
| ed25519 = { path = "../../../../substrate/ed25519" } | ||
| parking_lot = "0.4" | ||
| ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } | ||
| futures = "0.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // Copyright 2018 Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot 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. | ||
|
|
||
| // Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Collator for polkadot | ||
|
|
||
| extern crate adder; | ||
| extern crate polkadot_parachain as parachain; | ||
| extern crate polkadot_primitives as primitives; | ||
| extern crate polkadot_collator as collator; | ||
| extern crate ed25519; | ||
| extern crate parking_lot; | ||
| extern crate ctrlc; | ||
| extern crate futures; | ||
|
|
||
| use std::cell::RefCell; | ||
| use std::collections::HashMap; | ||
| use std::sync::Arc; | ||
|
|
||
| use adder::{HeadData as AdderHead, BlockData as AdderBody}; | ||
| use ed25519::Pair; | ||
| use parachain::codec::{Encode, Decode}; | ||
| use primitives::parachain::{HeadData, BlockData, Id as ParaId, Message}; | ||
| use collator::{InvalidHead, ParachainContext}; | ||
| use futures::sync::oneshot; | ||
| use futures::Future; | ||
| use parking_lot::Mutex; | ||
|
|
||
| const GENESIS: AdderHead = AdderHead { | ||
| number: 0, | ||
| parent_hash: [0; 32], | ||
| post_state: [1, 27, 77, 3, 221, 140, 1, 241, 4, 145, 67, 207, 156, 76, 129, 126, 75, 22, 127, 29, 27, 131, 229, 198, 240, 241, 13, 137, 186, 30, 123, 206], | ||
| }; | ||
|
|
||
| const GENESIS_BODY: AdderBody = AdderBody { | ||
| state: 0, | ||
| add: 0, | ||
| }; | ||
|
|
||
| #[derive(Clone)] | ||
| struct AdderContext { | ||
| db: Arc<Mutex<HashMap<AdderHead, AdderBody>>>, | ||
| } | ||
|
|
||
| /// The parachain context. | ||
| impl ParachainContext for AdderContext { | ||
| fn produce_candidate<I: IntoIterator<Item=(ParaId, Message)>>( | ||
| &self, | ||
| last_head: HeadData, | ||
| _ingress: I, | ||
| ) -> Result<(BlockData, HeadData), InvalidHead> | ||
| { | ||
| let adder_head = AdderHead::decode(&mut &last_head.0[..]) | ||
| .ok_or(InvalidHead)?; | ||
|
|
||
| let mut db = self.db.lock(); | ||
|
|
||
| let last_body = if adder_head == GENESIS { | ||
| GENESIS_BODY | ||
| } else { | ||
| db.get(&adder_head) | ||
| .expect("All past bodies stored since this is the only collator") | ||
| .clone() | ||
| }; | ||
|
|
||
| let next_body = AdderBody { | ||
| state: last_body.state + last_body.add, | ||
|
||
| add: adder_head.number % 100, | ||
| }; | ||
|
|
||
| let next_head = ::adder::execute(adder_head.hash(), adder_head, &next_body) | ||
| .expect("good execution params; qed"); | ||
|
|
||
| let encoded_head = HeadData(next_head.encode()); | ||
| let encoded_body = BlockData(next_body.encode()); | ||
|
|
||
| db.insert(next_head.clone(), next_body); | ||
| Ok((encoded_body, encoded_head)) | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| let key = Arc::new(Pair::from_seed(&[1; 32])); | ||
| let id: ParaId = 100.into(); | ||
|
|
||
| // can't use signal directly here because CtrlC takes only `Fn`. | ||
| let (exit_send, exit) = oneshot::channel(); | ||
|
|
||
| let exit_send_cell = RefCell::new(Some(exit_send)); | ||
| ctrlc::CtrlC::set_handler(move || { | ||
| if let Some(exit_send) = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take() { | ||
| exit_send.send(()).expect("Error sending exit notification"); | ||
| } | ||
| }); | ||
|
|
||
| let on_exit = exit.map_err(drop); | ||
| let context = AdderContext { | ||
| db: Arc::new(Mutex::new(HashMap::new())), | ||
| }; | ||
|
|
||
| let args: Vec<_> = ::std::env::args().into_iter().map(Into::into).collect(); | ||
| let res = ::collator::run_collator( | ||
| context, | ||
| id, | ||
| on_exit, | ||
| key, | ||
| args, | ||
| ); | ||
|
|
||
| if let Err(e) = res { | ||
| println!("{}", e); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ extern crate tiny_keccak; | |
| use parachain::codec::{Decode, Encode, Input, Output}; | ||
|
|
||
| /// Head data for this parachain. | ||
| #[derive(Default, Clone)] | ||
| #[derive(Default, Clone, Hash, Eq, PartialEq)] | ||
| pub struct HeadData { | ||
| /// Block number | ||
| pub number: u64, | ||
|
|
@@ -34,6 +34,12 @@ pub struct HeadData { | |
| pub post_state: [u8; 32], | ||
| } | ||
|
|
||
| impl HeadData { | ||
| pub fn hash(&self) -> [u8; 32] { | ||
| ::tiny_keccak::keccak256(&self.encode()) | ||
| } | ||
| } | ||
|
|
||
| impl Encode for HeadData { | ||
| fn encode_to<T: Output>(&self, dest: &mut T) { | ||
| dest.push(&self.number); | ||
|
|
@@ -82,12 +88,13 @@ pub fn hash_state(state: u64) -> [u8; 32] { | |
| } | ||
|
|
||
| /// Start state | ||
|
||
| #[derive(Debug)] | ||
| pub struct StateMismatch; | ||
|
|
||
| /// Execute a block body on top of given parent head, producing new parent head | ||
| /// if valid. | ||
| pub fn execute(parent_hash: [u8; 32], parent_head: HeadData, block_data: &BlockData) -> Result<HeadData, StateMismatch> { | ||
| debug_assert_eq!(parent_hash, ::tiny_keccak::keccak256(&parent_head.encode())); | ||
| debug_assert_eq!(parent_hash, parent_head.hash()); | ||
|
|
||
| if hash_state(block_data.state) != parent_head.post_state { | ||
| return Err(StateMismatch); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this in
membersbut other wasm projects inexclude?