From d2660900de2854b865f0f82f40a761b9891413f0 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 6 Feb 2018 15:41:28 +0100 Subject: [PATCH] unclobber function changes --- substrate/Cargo.lock | 10 +-- substrate/ed25519/Cargo.toml | 2 +- substrate/primitives/Cargo.toml | 4 +- substrate/primitives/src/lib.rs | 2 + substrate/primitives/src/proposal.rs | 68 +++++++++++------- substrate/primitives/src/runtime_function.rs | 69 +++++++++---------- substrate/wasm-runtime/Cargo.lock | 10 +-- .../polkadot/src/runtime/governance.rs | 13 +++- 8 files changed, 94 insertions(+), 84 deletions(-) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 75a256c839..8d46cf6766 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -197,7 +197,7 @@ version = "0.1.0" dependencies = [ "polkadot-primitives 0.1.0", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1077,7 +1077,7 @@ dependencies = [ "polkadot-runtime-codec 0.1.0", "polkadot-serializer 0.1.0", "pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1332,11 +1332,6 @@ name = "rustc-hex" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc-hex" -version = "2.0.0" -source = "git+https://github.com/rphmeier/rustc-hex.git#ee2ec40b9062ac7769ccb9dc891d6dc2cc9009d7" - [[package]] name = "rustc-serialize" version = "0.3.24" @@ -1919,7 +1914,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" -"checksum rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)" = "" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9743a7670d88d5d52950408ecdb7c71d8986251ab604d4689dd2ca25c9bca69" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" diff --git a/substrate/ed25519/Cargo.toml b/substrate/ed25519/Cargo.toml index a918468dd2..e6ba80d9a5 100644 --- a/substrate/ed25519/Cargo.toml +++ b/substrate/ed25519/Cargo.toml @@ -7,4 +7,4 @@ authors = ["Parity Technologies "] ring = "0.12" untrusted = "0.5" polkadot-primitives = { version = "0.1", path = "../primitives" } -rustc-hex = { git = "https://github.com/rphmeier/rustc-hex.git", version = "2.0", default_features = false } +rustc-hex = "1.0" diff --git a/substrate/primitives/Cargo.toml b/substrate/primitives/Cargo.toml index 6e5a4bd0c4..27c2e70f0e 100644 --- a/substrate/primitives/Cargo.toml +++ b/substrate/primitives/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Parity Technologies "] [dependencies] crunchy = "0.1" fixed-hash = { git = "https://github.com/rphmeier/primitives.git", branch = "compile-for-wasm", default_features = false } -rustc-hex = { git = "https://github.com/rphmeier/rustc-hex.git", version = "2.0", default_features = false } +rustc-hex = { version = "1.0", optional = true } serde = { version = "1.0", default_features = false } serde_derive = { version = "1.0", optional = true } uint = { git = "https://github.com/rphmeier/primitives.git", branch = "compile-for-wasm" } @@ -26,7 +26,7 @@ std = [ "fixed-hash/std", "polkadot-runtime-codec/std", "serde/std", - "rustc-hex/std", + "rustc-hex", "twox-hash", "blake2-rfc", "serde_derive", diff --git a/substrate/primitives/src/lib.rs b/substrate/primitives/src/lib.rs index 95c54c64d2..7b7da0c924 100644 --- a/substrate/primitives/src/lib.rs +++ b/substrate/primitives/src/lib.rs @@ -21,7 +21,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] +#[cfg(feature = "std")] extern crate rustc_hex; + extern crate serde; extern crate byteorder; diff --git a/substrate/primitives/src/proposal.rs b/substrate/primitives/src/proposal.rs index 4957a3dee6..65e85fa641 100644 --- a/substrate/primitives/src/proposal.rs +++ b/substrate/primitives/src/proposal.rs @@ -28,36 +28,41 @@ use codec::Slicable; #[repr(u8)] enum InternalFunctionId { /// Set the system's code. - SystemSetCode = 0, - /// Set the number of sessions per era. - StakingSetSessionsPerEra = 1, - /// Set the minimum bonding duration for staking. - StakingSetBondingDuration = 2, - /// Set the validator count for staking. - StakingSetValidatorCount = 3, - /// Set the per-mille of validator approval required for governance changes. - GovernanceSetApprovalPpmRequired = 4, + SystemSetCode = 0x00, + /// Set the session length. - SessionSetLength = 5, + SessionSetLength = 0x10, + /// Force a new session. + SessionForceNewSession = 0x11, + + /// Set the number of sessions per era. + StakingSetSessionsPerEra = 0x20, + /// Set the minimum bonding duration for staking. + StakingSetBondingDuration = 0x21, + /// Set the validator count for staking. + StakingSetValidatorCount = 0x22, + /// Force a new staking era. + StakingForceNewEra = 0x23, + + /// Set the per-mille of validator approval required for governance changes. + GovernanceSetApprovalPpmRequired = 0x30, + } impl InternalFunctionId { /// Derive `Some` value from a `u8`, or `None` if it's invalid. fn from_u8(value: u8) -> Option { - use self::*; let functions = [ InternalFunctionId::SystemSetCode, + InternalFunctionId::SessionSetLength, + InternalFunctionId::SessionForceNewSession, InternalFunctionId::StakingSetSessionsPerEra, InternalFunctionId::StakingSetBondingDuration, InternalFunctionId::StakingSetValidatorCount, + InternalFunctionId::StakingForceNewEra, InternalFunctionId::GovernanceSetApprovalPpmRequired, - InternalFunctionId::SessionSetLength ]; - if (value as usize) < functions.len() { - Some(functions[value as usize]) - } else { - None - } + functions.iter().map(|&f| f).find(|&f| value == f as u8) } } @@ -67,16 +72,21 @@ impl InternalFunctionId { pub enum InternalFunction { /// Set the system's code. SystemSetCode(Vec), + /// Set the session length. + SessionSetLength(BlockNumber), + /// Force a new session. + SessionForceNewSession, /// Set the number of sessions per era. StakingSetSessionsPerEra(BlockNumber), /// Set the minimum bonding duration for staking. StakingSetBondingDuration(BlockNumber), /// Set the validator count for staking. StakingSetValidatorCount(u32), + /// Force a new staking era. + StakingForceNewEra, /// Set the per-mille of validator approval required for governance changes. GovernanceSetApprovalPpmRequired(u32), - /// Set the session length. - SessionSetLength(BlockNumber), + } /// An internal function. @@ -93,16 +103,18 @@ impl Slicable for Proposal { let function = match id { InternalFunctionId::SystemSetCode => InternalFunction::SystemSetCode(try_opt!(Slicable::from_slice(value))), + InternalFunctionId::SessionSetLength => + InternalFunction::SessionSetLength(try_opt!(Slicable::from_slice(value))), + InternalFunctionId::SessionForceNewSession => InternalFunction::SessionForceNewSession, InternalFunctionId::StakingSetSessionsPerEra => InternalFunction::StakingSetSessionsPerEra(try_opt!(Slicable::from_slice(value))), InternalFunctionId::StakingSetBondingDuration => InternalFunction::StakingSetBondingDuration(try_opt!(Slicable::from_slice(value))), InternalFunctionId::StakingSetValidatorCount => InternalFunction::StakingSetValidatorCount(try_opt!(Slicable::from_slice(value))), + InternalFunctionId::StakingForceNewEra => InternalFunction::StakingForceNewEra, InternalFunctionId::GovernanceSetApprovalPpmRequired => InternalFunction::GovernanceSetApprovalPpmRequired(try_opt!(Slicable::from_slice(value))), - InternalFunctionId::SessionSetLength => - InternalFunction::SessionSetLength(try_opt!(Slicable::from_slice(value))), }; Some(Proposal { function }) @@ -115,6 +127,13 @@ impl Slicable for Proposal { (InternalFunctionId::SystemSetCode as u8).as_slice_then(|s| v.extend(s)); data.as_slice_then(|s| v.extend(s)); } + InternalFunction::SessionSetLength(ref data) => { + (InternalFunctionId::SessionSetLength as u8).as_slice_then(|s| v.extend(s)); + data.as_slice_then(|s| v.extend(s)); + } + InternalFunction::SessionForceNewSession => { + (InternalFunctionId::SessionForceNewSession as u8).as_slice_then(|s| v.extend(s)); + } InternalFunction::StakingSetSessionsPerEra(ref data) => { (InternalFunctionId::StakingSetSessionsPerEra as u8).as_slice_then(|s| v.extend(s)); data.as_slice_then(|s| v.extend(s)); @@ -127,14 +146,13 @@ impl Slicable for Proposal { (InternalFunctionId::StakingSetValidatorCount as u8).as_slice_then(|s| v.extend(s)); data.as_slice_then(|s| v.extend(s)); } + InternalFunction::StakingForceNewEra => { + (InternalFunctionId::StakingForceNewEra as u8).as_slice_then(|s| v.extend(s)); + } InternalFunction::GovernanceSetApprovalPpmRequired(ref data) => { (InternalFunctionId::GovernanceSetApprovalPpmRequired as u8).as_slice_then(|s| v.extend(s)); data.as_slice_then(|s| v.extend(s)); } - InternalFunction::SessionSetLength(ref data) => { - (InternalFunctionId::SessionSetLength as u8).as_slice_then(|s| v.extend(s)); - data.as_slice_then(|s| v.extend(s)); - } } v diff --git a/substrate/primitives/src/runtime_function.rs b/substrate/primitives/src/runtime_function.rs index 4c51411f4a..9ec5da029c 100644 --- a/substrate/primitives/src/runtime_function.rs +++ b/substrate/primitives/src/runtime_function.rs @@ -25,35 +25,30 @@ use codec::Slicable; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[repr(u8)] enum FunctionId { - /// Staking subsystem: begin staking. - StakingStake = 0, - /// Staking subsystem: stop staking. - StakingUnstake = 1, - /// Staking subsystem: transfer stake. - StakingTransfer = 2, - /// Set temporary session key as a validator. - SessionSetKey = 3, /// Set the timestamp. - TimestampSet = 4, + TimestampSet = 0x00, + /// Set temporary session key as a validator. + SessionSetKey = 0x10, + /// Staking subsystem: begin staking. + StakingStake = 0x20, + /// Staking subsystem: stop staking. + StakingUnstake = 0x21, + /// Staking subsystem: transfer stake. + StakingTransfer = 0x22, /// Make a proposal for the governance system. - GovernancePropose = 5, + GovernancePropose = 0x30, /// Approve a proposal for the governance system. - GovernanceApprove = 6, + GovernanceApprove = 0x31, } impl FunctionId { /// Derive `Some` value from a `u8`, or `None` if it's invalid. fn from_u8(value: u8) -> Option { - match value { - 0 => Some(FunctionId::StakingStake), - 1 => Some(FunctionId::StakingUnstake), - 2 => Some(FunctionId::StakingTransfer), - 3 => Some(FunctionId::SessionSetKey), - 4 => Some(FunctionId::TimestampSet), - 5 => Some(FunctionId::GovernancePropose), - 6 => Some(FunctionId::GovernanceApprove), - _ => None, - } + use self::*; + let functions = [FunctionId::StakingStake, FunctionId::StakingUnstake, + FunctionId::StakingTransfer, FunctionId::SessionSetKey, FunctionId::TimestampSet, + FunctionId::GovernancePropose, FunctionId::GovernanceApprove]; + functions.iter().map(|&f| f).find(|&f| value == f as u8) } } @@ -61,16 +56,16 @@ impl FunctionId { #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum Function { + /// Set the timestamp. + TimestampSet(::Timestamp), + /// Set temporary session key as a validator. + SessionSetKey(::SessionKey), /// Staking subsystem: begin staking. StakingStake, /// Staking subsystem: stop staking. StakingUnstake, /// Staking subsystem: transfer stake. StakingTransfer(::AccountId, ::Balance), - /// Set temporary session key as a validator. - SessionSetKey(::SessionKey), - /// Set the timestamp. - TimestampSet(::Timestamp), /// Make a proposal for the governance system. GovernancePropose(::proposal::Proposal), /// Approve a proposal for the governance system. @@ -81,16 +76,16 @@ impl Slicable for Function { fn from_slice(value: &mut &[u8]) -> Option { let id = try_opt!(u8::from_slice(value).and_then(FunctionId::from_u8)); Some(match id { + FunctionId::TimestampSet => + Function::TimestampSet(try_opt!(Slicable::from_slice(value))), + FunctionId::SessionSetKey => + Function::SessionSetKey(try_opt!(Slicable::from_slice(value))), FunctionId::StakingStake => Function::StakingStake, FunctionId::StakingUnstake => Function::StakingUnstake, FunctionId::StakingTransfer => Function::StakingTransfer( try_opt!(Slicable::from_slice(value)), try_opt!(Slicable::from_slice(value)), ), - FunctionId::SessionSetKey => - Function::SessionSetKey(try_opt!(Slicable::from_slice(value))), - FunctionId::TimestampSet => - Function::TimestampSet(try_opt!(Slicable::from_slice(value))), FunctionId::GovernancePropose => Function::GovernancePropose(try_opt!(Slicable::from_slice(value))), FunctionId::GovernanceApprove => @@ -101,6 +96,14 @@ impl Slicable for Function { fn to_vec(&self) -> Vec { let mut v = Vec::new(); match *self { + Function::TimestampSet(ref data) => { + (FunctionId::TimestampSet as u8).as_slice_then(|s| v.extend(s)); + data.as_slice_then(|s| v.extend(s)); + } + Function::SessionSetKey(ref data) => { + (FunctionId::SessionSetKey as u8).as_slice_then(|s| v.extend(s)); + data.as_slice_then(|s| v.extend(s)); + } Function::StakingStake => { (FunctionId::StakingStake as u8).as_slice_then(|s| v.extend(s)); } @@ -112,14 +115,6 @@ impl Slicable for Function { to.as_slice_then(|s| v.extend(s)); amount.as_slice_then(|s| v.extend(s)); } - Function::SessionSetKey(ref data) => { - (FunctionId::SessionSetKey as u8).as_slice_then(|s| v.extend(s)); - data.as_slice_then(|s| v.extend(s)); - } - Function::TimestampSet(ref data) => { - (FunctionId::TimestampSet as u8).as_slice_then(|s| v.extend(s)); - data.as_slice_then(|s| v.extend(s)); - } Function::GovernancePropose(ref data) => { (FunctionId::GovernancePropose as u8).as_slice_then(|s| v.extend(s)); data.as_slice_then(|s| v.extend(s)); diff --git a/substrate/wasm-runtime/Cargo.lock b/substrate/wasm-runtime/Cargo.lock index 3373ebcc9b..71665b12ce 100644 --- a/substrate/wasm-runtime/Cargo.lock +++ b/substrate/wasm-runtime/Cargo.lock @@ -94,7 +94,7 @@ version = "0.1.0" dependencies = [ "polkadot-primitives 0.1.0", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -384,7 +384,7 @@ dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", "polkadot-runtime-codec 0.1.0", - "rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -568,11 +568,6 @@ name = "rustc-hex" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "rustc-hex" -version = "2.0.0" -source = "git+https://github.com/rphmeier/rustc-hex.git#ee2ec40b9062ac7769ccb9dc891d6dc2cc9009d7" - [[package]] name = "rustc_version" version = "0.2.1" @@ -830,7 +825,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6f7d28b30a72c01b458428e0ae988d4149c20d902346902be881e3edc4bb325c" "checksum rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "babe6fce20c0ca9b1582998734c4569082d0ad08e43772a1c6c40aef4f106ef9" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" -"checksum rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)" = "" "checksum rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9743a7670d88d5d52950408ecdb7c71d8986251ab604d4689dd2ca25c9bca69" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" diff --git a/substrate/wasm-runtime/polkadot/src/runtime/governance.rs b/substrate/wasm-runtime/polkadot/src/runtime/governance.rs index b009e3597a..ad71a7a236 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/governance.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/governance.rs @@ -117,6 +117,12 @@ pub mod internal { InternalFunction::SystemSetCode(code) => { system::privileged::set_code(&code); } + InternalFunction::SessionSetLength(value) => { + session::privileged::set_length(value); + } + InternalFunction::SessionForceNewSession => { + session::privileged::force_new_session(); + } InternalFunction::StakingSetSessionsPerEra(value) => { staking::privileged::set_sessions_per_era(value); } @@ -126,12 +132,13 @@ pub mod internal { InternalFunction::StakingSetValidatorCount(value) => { staking::privileged::set_validator_count(value); } + InternalFunction::StakingForceNewEra => { + staking::privileged::force_new_era() + } InternalFunction::GovernanceSetApprovalPpmRequired(value) => { self::privileged::set_approval_ppm_required(value); } - InternalFunction::SessionSetLength(value) => { - session::privileged::set_length(value); - } + } } }