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
Introduce basic skeleton for Polkadot runtime. #32
Merged
Merged
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
36c171c
Introduce basic skeleton for Polkador runtime.
gavofyork f79b7bb
Clean up the runtime skeleton.
gavofyork b48e053
Make initial runtime skeleton compile.
gavofyork 4e25b24
Compile polkadot-runtime both for Wasm ad native, allowing for testin…
gavofyork b28402c
More fleshing out on runtime.
gavofyork bac50a4
Update native support.
gavofyork 9a4360f
Fix warning.
gavofyork 0890e72
Update gitignore
gavofyork 4cf5fd1
Update path.
gavofyork 12b15fd
Fix path.
gavofyork 47260c2
Remove accidentally committed files.
gavofyork 800eb20
Add wasm binaries.
gavofyork 10eaefe
Fix test.
gavofyork 24ba809
Native storage support API.
gavofyork 36a49ff
Add environmental module
gavofyork 50e7222
Add native environment to make native source-code compatible with wasm.
gavofyork 3e17caa
Finish up & polish environment stuff.
gavofyork e807c9a
Avoid using reentrancy issues.
gavofyork 402ae29
Add some docs and a test.
gavofyork 762826b
Remove unneeded function.
gavofyork 7e969c8
Documentation
gavofyork 64b0670
Tweak docs
gavofyork d34f62a
Remove TODOs.
gavofyork 89f35e3
Balance transfers + util methods.
gavofyork 5e42240
Rejig tests and ensure authorities are addressed consistently.
gavofyork d97e2d6
Add marshaller for xfer function
gavofyork 26ccc14
Transaction dispatch test.
gavofyork 7258e1f
Minor fix.
gavofyork c02e335
Add test for ser/de transaction.
gavofyork 28fa761
Add ser/de for header.
gavofyork cd93a37
Add tests for header ser/de
gavofyork b55095a
Introduce basic block decoding/execution framework.
gavofyork 288f653
Introduce block decoding/execution framework (p2)
gavofyork c64976b
Big refactor.
gavofyork 40e28fc
Split out joiner.
gavofyork ab37f64
Hide away support modules.
gavofyork 4844086
Fix up wasm runtime.
gavofyork 28d775d
use externalities for chain_id
gavofyork 75cedd9
Clean up (Test)Externalities.
gavofyork 0feadc6
Repot and introduce keccak-256 external.
gavofyork 15ae775
Signing with crypto.
gavofyork 5650997
fix unsafety hole in environmental using function
rphmeier 7820149
Introduce Ed25519 crypto.
gavofyork 4ef4239
Repotting.
gavofyork 8fa858c
Merge branch 'signing-ring' into polkadot-runtime-skeleton
gavofyork 78a22d4
Add ed25519_verify external.
gavofyork 93f7aed
Introduce Ed25519 verify as an external.
gavofyork cdc1387
fix unsafety hole around unwinding
rphmeier 0477b7e
Compile fixes.
gavofyork 66c9384
use new environmental API
rphmeier 121aa0b
Merge branch 'polkadot-runtime-skeleton' into environmental-api
rphmeier eebc071
Tests for ed25519 verify.
gavofyork 5685173
Polish
gavofyork f3d415c
Introduce UncheckedTransaction & test.
gavofyork 2c9cb7b
Implement basic block and tx processing
gavofyork eda7d71
Introduce static hex and valid signature for block test.
gavofyork fd9d8dc
Merge pull request #35 from paritytech/environmental-api
gavofyork e8cd918
Repot session.
gavofyork 3d1ff94
comments.
gavofyork 92a12f0
Refactor and timestamp test
gavofyork 5523277
Remove fluff
gavofyork 39128b7
Merge branch 'polkadot-runtime-skeleton' of github.com:paritytech/pol…
gavofyork 9a8f61d
Remove fluff.
gavofyork 90f965a
Staking eras and tests.
gavofyork 58670fc
Implement sessions.
gavofyork 999025f
Polish
gavofyork 4fde6f0
Test sessions.
gavofyork 9c8cafd
Introduce better hashing.
gavofyork ae5a9c9
Fix tests.
gavofyork 639554c
Introduce staking.
gavofyork 0e88dad
Tests for simple staking system.
gavofyork 80aa38c
Build fix for wasm.
gavofyork ef5d78a
Fix tests.
gavofyork e068f44
Repotting and docs.
gavofyork 2499910
Docs and licence.
gavofyork 0c53f71
Documentation.
gavofyork 850f7ee
Remove superfluous code.
gavofyork dde319c
Remove dummy key.
gavofyork 17ef2d0
Remove other superfluous file.
gavofyork 8adb7c6
Optimise with swap_remove
gavofyork cbd65cb
Merge remote-tracking branch 'origin/master' into polkadot-runtime-sk…
gavofyork 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
Big refactor.
- Loading branch information
commit c64976b22db3e08f3ccf45fb8259fb2c2f9d69ca
There are no files selected for viewing
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,72 @@ | ||
| use keyedvec::KeyedVec; | ||
| use storage::Storage; | ||
| use primitives::{AccountID, SessionKey, BlockNumber}; | ||
| use storage::storage_into; | ||
|
|
||
| pub fn set_authority(index: u32, authority: AccountID) { | ||
| authority.store(&index.to_keyed_vec(b"con\0aut\0")); | ||
| } | ||
|
|
||
| fn authority(index: u32) -> AccountID { | ||
| storage_into(&index.to_keyed_vec(b"con\0aut\0")) | ||
| } | ||
|
|
||
| pub fn set_authority_count(count: u32) { | ||
| (count..authority_count()).for_each(|i| set_authority(i, SessionKey::default())); | ||
| count.store(b"con\0aut\0len"); | ||
| } | ||
|
|
||
| fn authority_count() -> u32 { | ||
| storage_into(b"con\0aut\0len") | ||
| } | ||
|
|
||
| /// Get the current set of authorities. These are the session keys. | ||
| pub fn authorities() -> Vec<AccountID> { | ||
| (0..authority_count()).into_iter().map(authority).collect() | ||
| } | ||
|
|
||
| /// Set the current set of authorities' session keys. | ||
| /// | ||
| /// Called by `next_session` only. | ||
| pub fn set_authorities(authorities: &[AccountID]) { | ||
| set_authority_count(authorities.len() as u32); | ||
| authorities.iter().enumerate().for_each(|(v, &i)| set_authority(v as u32, i)); | ||
| } | ||
|
|
||
| /// Get the current set of validators. These are the long-term identifiers for the validators | ||
| /// and will be mapped to a session key with the most recent `set_next_session_key`. | ||
| pub fn validators() -> Vec<AccountID> { | ||
| unimplemented!() | ||
| } | ||
|
|
||
| /// Set the current set of validators. | ||
| /// | ||
| /// Called by staking::next_era() only. | ||
| pub fn set_validators(_new: &[AccountID]) { | ||
| unimplemented!() | ||
| } | ||
|
|
||
| /// The number of blocks in each session. | ||
| pub fn session_length() -> BlockNumber { | ||
| storage_into(b"con\0bps") | ||
| } | ||
|
|
||
| /// Sets the session key of `_transactor` to `_session`. This doesn't take effect until the next | ||
| /// session. | ||
| pub fn set_session_key(_transactor: &AccountID, _session: &AccountID) { | ||
| unimplemented!() | ||
| } | ||
|
|
||
| /// Move onto next session: register the new authority set. | ||
| pub fn next_session() { | ||
| // TODO: Call set_authorities(). | ||
| unimplemented!() | ||
| } | ||
|
|
||
| /// Hook to be called prior to transaction processing. | ||
| pub fn pre_transactions() {} | ||
|
|
||
| /// Hook to be called after to transaction processing. | ||
| pub fn post_transactions() { | ||
| // TODO: check block number and call next_session if necessary. | ||
| } |
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,29 @@ | ||
| pub trait EndianSensitive: Sized { | ||
| fn to_le(self) -> Self { self } | ||
| fn to_be(self) -> Self { self } | ||
| fn from_le(self) -> Self { self } | ||
| fn from_be(self) -> Self { self } | ||
| fn as_be_then<T, F: FnOnce(&Self) -> T>(&self, f: F) -> T { f(&self) } | ||
| fn as_le_then<T, F: FnOnce(&Self) -> T>(&self, f: F) -> T { f(&self) } | ||
| } | ||
|
|
||
| macro_rules! impl_endians { | ||
| ( $( $t:ty ),* ) => { $( | ||
| impl EndianSensitive for $t { | ||
| fn to_le(self) -> Self { <$t>::to_le(self) } | ||
| fn to_be(self) -> Self { <$t>::to_be(self) } | ||
| fn from_le(self) -> Self { <$t>::from_le(self) } | ||
| fn from_be(self) -> Self { <$t>::from_be(self) } | ||
| fn as_be_then<T, F: FnOnce(&Self) -> T>(&self, f: F) -> T { let d = self.to_be(); f(&d) } | ||
| fn as_le_then<T, F: FnOnce(&Self) -> T>(&self, f: F) -> T { let d = self.to_le(); f(&d) } | ||
| } | ||
| )* } | ||
| } | ||
| macro_rules! impl_non_endians { | ||
| ( $( $t:ty ),* ) => { $( | ||
| impl EndianSensitive for $t {} | ||
| )* } | ||
| } | ||
|
|
||
| impl_endians!(u16, u32, u64, usize, i16, i32, i64, isize); | ||
| impl_non_endians!(u8, i8, [u8; 20], [u8; 32]); |
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,33 @@ | ||
| use runtime_support::{Rc, RefCell, transmute, Box}; | ||
| use primitives::{BlockNumber, Digest}; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct Environment { | ||
| pub block_number: BlockNumber, | ||
| pub digest: Digest, | ||
| pub next_log_index: usize, | ||
| } | ||
|
|
||
| pub fn with_env<T, F: FnOnce(&mut Environment) -> T>(f: F) -> T { | ||
| let e = env(); | ||
| let mut eb = e.borrow_mut(); | ||
| f(&mut *eb) | ||
| } | ||
|
|
||
| pub fn env() -> Rc<RefCell<Environment>> { | ||
| // Initialize it to a null value | ||
| static mut SINGLETON: *const Rc<RefCell<Environment>> = 0 as *const Rc<RefCell<Environment>>; | ||
|
|
||
| unsafe { | ||
| if SINGLETON == 0 as *const Rc<RefCell<Environment>> { | ||
| // Make it | ||
| let singleton: Rc<RefCell<Environment>> = Rc::new(RefCell::new(Default::default())); | ||
|
|
||
| // Put it in the heap so it can outlive this call | ||
| SINGLETON = transmute(Box::new(singleton)); | ||
| } | ||
|
|
||
| // Now we give out a copy of the data that is safe to use concurrently. | ||
| (*SINGLETON).clone() | ||
| } | ||
| } |
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,50 @@ | ||
| use staking; | ||
| use consensus; | ||
| use primitives::AccountID; | ||
| use streamreader::StreamReader; | ||
|
|
||
| /// The functions that a transaction can call (and be dispatched to). | ||
| #[cfg_attr(test, derive(PartialEq, Debug))] | ||
| #[derive(Clone, Copy)] | ||
| pub enum Function { | ||
| StakingStake, | ||
| StakingUnstake, | ||
| StakingTransferStake, | ||
| ConsensusSetSessionKey, | ||
| } | ||
|
|
||
| impl Function { | ||
| pub fn from_u8(value: u8) -> Option<Function> { | ||
| match value { | ||
| x if x == Function::StakingStake as u8 => Some(Function::StakingStake), | ||
| x if x == Function::StakingUnstake as u8 => Some(Function::StakingUnstake), | ||
| x if x == Function::StakingTransferStake as u8 => Some(Function::StakingTransferStake), | ||
| x if x == Function::ConsensusSetSessionKey as u8 => Some(Function::ConsensusSetSessionKey), | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Function { | ||
| /// Dispatch the function. | ||
| pub fn dispatch(&self, transactor: &AccountID, data: &[u8]) { | ||
| let mut params = StreamReader::new(data); | ||
| match *self { | ||
| Function::StakingStake => { | ||
| staking::stake(transactor); | ||
| } | ||
| Function::StakingUnstake => { | ||
| staking::unstake(transactor); | ||
| } | ||
| Function::StakingTransferStake => { | ||
| let dest = params.read().unwrap(); | ||
| let value = params.read().unwrap(); | ||
| staking::transfer_stake(transactor, &dest, value); | ||
| } | ||
| Function::ConsensusSetSessionKey => { | ||
| let session = params.read().unwrap(); | ||
| consensus::set_session_key(transactor, &session); | ||
| } | ||
| } | ||
| } | ||
| } |
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,30 @@ | ||
| use primitives::AccountID; | ||
| use slicable::Slicable; | ||
|
|
||
| pub trait KeyedVec { | ||
| fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8>; | ||
| } | ||
|
|
||
| impl KeyedVec for AccountID { | ||
| fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8> { | ||
| let mut r = prepend_key.to_vec(); | ||
| r.extend_from_slice(self); | ||
| r | ||
| } | ||
| } | ||
|
|
||
| macro_rules! impl_endians { | ||
| ( $( $t:ty ),* ) => { $( | ||
| impl KeyedVec for $t { | ||
| fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8> { | ||
| self.as_slice_then(|slice| { | ||
| let mut r = prepend_key.to_vec(); | ||
| r.extend_from_slice(slice); | ||
| r | ||
| }) | ||
| } | ||
| } | ||
| )* } | ||
| } | ||
|
|
||
| impl_endians!(u16, u32, u64, usize, i16, i32, i64, isize); |
Oops, something went wrong.
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 are we re-exporting this stuff?