Update to Substrate master (#176)

* Update to master

This introduces a new type `CollatorId`, currently just `SessionKey`
but which would forseeably change to its own thing. It seems to work
like this (despite there being a lot of the new-incompatible
`AccountId` replaced). No idea if it does anything sensible, though.

* Cleanups

* Fix tests

* Remove commented code

* Specify commit hash

* Remove commented code

* Correct version

* Update runtime/Cargo.toml

Co-Authored-By: gavofyork <github@gavwood.com>

* PairT instead of _Pair

* Update lock file

* Remove rev causing upset
This commit is contained in:
Gav Wood
2019-03-18 11:29:39 +01:00
committed by GitHub
parent 448c23dc52
commit 67275abe30
23 changed files with 1128 additions and 792 deletions
+11 -10
View File
@@ -77,10 +77,9 @@ use parking_lot::Mutex;
use polkadot_primitives::{Hash, Block, BlockId, BlockNumber, Header, SessionKey};
use polkadot_primitives::parachain::{
Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt,
CandidateSignature, ParachainHost, AttestedCandidate, Statement as PrimitiveStatement, Message,
OutgoingMessage,
ParachainHost, AttestedCandidate, Statement as PrimitiveStatement, Message, OutgoingMessage, CollatorSignature
};
use primitives::{Ed25519AuthorityId as AuthorityId, ed25519};
use primitives::{Pair, ed25519};
use runtime_primitives::{traits::{ProvideRuntimeApi, Header as HeaderT}, ApplyError};
use tokio::runtime::TaskExecutor;
use tokio::timer::{Delay, Interval};
@@ -95,6 +94,8 @@ use inherents::InherentData;
use runtime_aura::timestamp::TimestampInherentData;
use aura::SlotDuration;
use ed25519::Public as AuthorityId;
pub use self::collation::{validate_collation, message_queue_root, egress_roots, Collators};
pub use self::error::{ErrorKind, Error};
pub use self::shared_table::{
@@ -192,7 +193,7 @@ pub struct GroupInfo {
/// Sign a table statement against a parent hash.
/// The actual message signed is the encoded statement concatenated with the
/// parent hash.
pub fn sign_table_statement(statement: &Statement, key: &ed25519::Pair, parent_hash: &Hash) -> CandidateSignature {
pub fn sign_table_statement(statement: &Statement, key: &ed25519::Pair, parent_hash: &Hash) -> CollatorSignature {
// we sign using the primitive statement type because that's what the runtime
// expects. These types probably encode the same way so this clone could be optimized
// out in the future.
@@ -203,7 +204,7 @@ pub fn sign_table_statement(statement: &Statement, key: &ed25519::Pair, parent_h
}
/// Check signature on table statement.
pub fn check_statement(statement: &Statement, signature: &CandidateSignature, signer: SessionKey, parent_hash: &Hash) -> bool {
pub fn check_statement(statement: &Statement, signature: &CollatorSignature, signer: SessionKey, parent_hash: &Hash) -> bool {
use runtime_primitives::traits::Verify;
let mut encoded = PrimitiveStatement::from(statement.clone()).encode();
@@ -799,17 +800,17 @@ impl<C, TxApi> Future for CreateProposal<C, TxApi> where
#[cfg(test)]
mod tests {
use super::*;
use substrate_keyring::Keyring;
use substrate_keyring::AuthorityKeyring;
#[test]
fn sign_and_check_statement() {
let statement: Statement = GenericStatement::Valid([1; 32].into());
let parent_hash = [2; 32].into();
let sig = sign_table_statement(&statement, &Keyring::Alice.pair(), &parent_hash);
let sig = sign_table_statement(&statement, &AuthorityKeyring::Alice.pair(), &parent_hash);
assert!(check_statement(&statement, &sig, Keyring::Alice.to_raw_public().into(), &parent_hash));
assert!(!check_statement(&statement, &sig, Keyring::Alice.to_raw_public().into(), &[0xff; 32].into()));
assert!(!check_statement(&statement, &sig, Keyring::Bob.to_raw_public().into(), &parent_hash));
assert!(check_statement(&statement, &sig, AuthorityKeyring::Alice.into(), &parent_hash));
assert!(!check_statement(&statement, &sig, AuthorityKeyring::Alice.into(), &[0xff; 32].into()));
assert!(!check_statement(&statement, &sig, AuthorityKeyring::Bob.into(), &parent_hash));
}
}