diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 37f8f30e28..cebf379d89 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -4125,6 +4125,7 @@ dependencies = [ "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", + "sr-version 2.0.0", "srml-support 2.0.0", "substrate-primitives 2.0.0", ] diff --git a/substrate/core/sr-version/src/lib.rs b/substrate/core/sr-version/src/lib.rs index cf96fe70e2..731c5b63c7 100644 --- a/substrate/core/sr-version/src/lib.rs +++ b/substrate/core/sr-version/src/lib.rs @@ -62,7 +62,7 @@ macro_rules! create_apis_vec { /// This triplet have different semantics and mis-interpretation could cause problems. /// In particular: bug fixes should result in an increment of `spec_version` and possibly `authoring_version`, /// absolutely not `impl_version` since they change the semantics of the runtime. -#[derive(Clone, PartialEq, Eq, Encode)] +#[derive(Clone, PartialEq, Eq, Encode, Default)] #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize, Decode))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] pub struct RuntimeVersion { diff --git a/substrate/core/test-runtime/src/lib.rs b/substrate/core/test-runtime/src/lib.rs index e9ee40af75..55b6ad9b5f 100644 --- a/substrate/core/test-runtime/src/lib.rs +++ b/substrate/core/test-runtime/src/lib.rs @@ -373,6 +373,7 @@ impl srml_system::Trait for Runtime { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl srml_timestamp::Trait for Runtime { diff --git a/substrate/node-template/runtime/src/lib.rs b/substrate/node-template/runtime/src/lib.rs index 27ae69bd56..3f298f1032 100644 --- a/substrate/node-template/runtime/src/lib.rs +++ b/substrate/node-template/runtime/src/lib.rs @@ -107,6 +107,7 @@ parameter_types! { pub const MaximumBlockWeight: Weight = 1_000_000; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const MaximumBlockLength: u32 = 5 * 1024 * 1024; + pub const Version: RuntimeVersion = VERSION; } impl system::Trait for Runtime { @@ -140,6 +141,7 @@ impl system::Trait for Runtime { type MaximumBlockLength = MaximumBlockLength; /// Portion of the block weight that is available to all normal transactions. type AvailableBlockRatio = AvailableBlockRatio; + type Version = Version; } impl aura::Trait for Runtime { diff --git a/substrate/node-template/runtime/src/template.rs b/substrate/node-template/runtime/src/template.rs index aa399a8edd..7f9d03fbb7 100644 --- a/substrate/node-template/runtime/src/template.rs +++ b/substrate/node-template/runtime/src/template.rs @@ -107,6 +107,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl Trait for Test { type Event = (); diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 7fa848a0d6..c2cbe74194 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 146, + spec_version: 147, impl_version: 147, apis: RUNTIME_API_VERSIONS, }; @@ -108,6 +108,7 @@ parameter_types! { pub const MaximumBlockWeight: Weight = 1_000_000_000; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const MaximumBlockLength: u32 = 5 * 1024 * 1024; + pub const Version: RuntimeVersion = VERSION; } impl system::Trait for Runtime { @@ -126,6 +127,7 @@ impl system::Trait for Runtime { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = Version; } parameter_types! { diff --git a/substrate/srml/assets/src/lib.rs b/substrate/srml/assets/src/lib.rs index d5ae95c559..c8b24662be 100644 --- a/substrate/srml/assets/src/lib.rs +++ b/substrate/srml/assets/src/lib.rs @@ -277,6 +277,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } impl Trait for Test { type Event = (); diff --git a/substrate/srml/aura/src/mock.rs b/substrate/srml/aura/src/mock.rs index 6fef48d3d7..5861b11e07 100644 --- a/substrate/srml/aura/src/mock.rs +++ b/substrate/srml/aura/src/mock.rs @@ -60,6 +60,7 @@ impl system::Trait for Test { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } impl timestamp::Trait for Test { diff --git a/substrate/srml/authorship/src/lib.rs b/substrate/srml/authorship/src/lib.rs index 32dd140e82..424223a2c9 100644 --- a/substrate/srml/authorship/src/lib.rs +++ b/substrate/srml/authorship/src/lib.rs @@ -476,6 +476,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } parameter_types! { diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index 66d0ee0284..1c9a2f7ec3 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -777,6 +777,7 @@ impl, I: Instance> system::Trait for ElevatedTrait { type MaximumBlockWeight = T::MaximumBlockWeight; type MaximumBlockLength = T::MaximumBlockLength; type AvailableBlockRatio = T::AvailableBlockRatio; + type Version = T::Version; } impl, I: Instance> Trait for ElevatedTrait { type Balance = T::Balance; diff --git a/substrate/srml/balances/src/mock.rs b/substrate/srml/balances/src/mock.rs index 954d500a10..a90c5d56b2 100644 --- a/substrate/srml/balances/src/mock.rs +++ b/substrate/srml/balances/src/mock.rs @@ -98,6 +98,7 @@ impl system::Trait for Runtime { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl Trait for Runtime { type Balance = u64; diff --git a/substrate/srml/collective/src/lib.rs b/substrate/srml/collective/src/lib.rs index 76320d1117..3828988015 100644 --- a/substrate/srml/collective/src/lib.rs +++ b/substrate/srml/collective/src/lib.rs @@ -419,6 +419,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl Trait for Test { type Origin = Origin; diff --git a/substrate/srml/contracts/src/tests.rs b/substrate/srml/contracts/src/tests.rs index 224d01d48a..5c5910c157 100644 --- a/substrate/srml/contracts/src/tests.rs +++ b/substrate/srml/contracts/src/tests.rs @@ -119,6 +119,7 @@ impl system::Trait for Test { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } impl balances::Trait for Test { type Balance = u64; diff --git a/substrate/srml/council/src/lib.rs b/substrate/srml/council/src/lib.rs index 787abdb078..635d62fd2c 100644 --- a/substrate/srml/council/src/lib.rs +++ b/substrate/srml/council/src/lib.rs @@ -119,6 +119,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } parameter_types! { pub const ExistentialDeposit: u64 = 0; diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index 5a1c61b8ae..cfac7fdfbc 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -1029,6 +1029,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } parameter_types! { pub const ExistentialDeposit: u64 = 0; diff --git a/substrate/srml/elections/src/lib.rs b/substrate/srml/elections/src/lib.rs index 58ad47a4ed..a82b3fab7e 100644 --- a/substrate/srml/elections/src/lib.rs +++ b/substrate/srml/elections/src/lib.rs @@ -1152,6 +1152,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } parameter_types! { pub const ExistentialDeposit: u64 = 0; diff --git a/substrate/srml/example/src/lib.rs b/substrate/srml/example/src/lib.rs index 0cfad989b1..1c0191b69d 100644 --- a/substrate/srml/example/src/lib.rs +++ b/substrate/srml/example/src/lib.rs @@ -544,6 +544,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } parameter_types! { pub const ExistentialDeposit: u64 = 0; diff --git a/substrate/srml/executive/src/lib.rs b/substrate/srml/executive/src/lib.rs index 9c29c95f10..d25cacf446 100644 --- a/substrate/srml/executive/src/lib.rs +++ b/substrate/srml/executive/src/lib.rs @@ -402,6 +402,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } parameter_types! { pub const ExistentialDeposit: u64 = 0; diff --git a/substrate/srml/finality-tracker/src/lib.rs b/substrate/srml/finality-tracker/src/lib.rs index 26a0e0d415..1ed9d07dbb 100644 --- a/substrate/srml/finality-tracker/src/lib.rs +++ b/substrate/srml/finality-tracker/src/lib.rs @@ -321,6 +321,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } parameter_types! { pub const WindowSize: u64 = 11; diff --git a/substrate/srml/generic-asset/src/lib.rs b/substrate/srml/generic-asset/src/lib.rs index 45dd534492..016e39127f 100644 --- a/substrate/srml/generic-asset/src/lib.rs +++ b/substrate/srml/generic-asset/src/lib.rs @@ -1063,6 +1063,7 @@ impl system::Trait for ElevatedTrait { type AvailableBlockRatio = T::AvailableBlockRatio; type WeightMultiplierUpdate = (); type BlockHashCount = T::BlockHashCount; + type Version = T::Version; } impl Trait for ElevatedTrait { type Balance = T::Balance; diff --git a/substrate/srml/generic-asset/src/mock.rs b/substrate/srml/generic-asset/src/mock.rs index 2c348a0175..7e47de0b36 100644 --- a/substrate/srml/generic-asset/src/mock.rs +++ b/substrate/srml/generic-asset/src/mock.rs @@ -61,6 +61,7 @@ impl system::Trait for Test { type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; type BlockHashCount = BlockHashCount; + type Version = (); } impl Trait for Test { diff --git a/substrate/srml/grandpa/src/mock.rs b/substrate/srml/grandpa/src/mock.rs index 0f2cc90c1f..dd6ed766ce 100644 --- a/substrate/srml/grandpa/src/mock.rs +++ b/substrate/srml/grandpa/src/mock.rs @@ -63,6 +63,7 @@ impl system::Trait for Test { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } mod grandpa { diff --git a/substrate/srml/indices/src/mock.rs b/substrate/srml/indices/src/mock.rs index 50b38eae28..e28416fd3a 100644 --- a/substrate/srml/indices/src/mock.rs +++ b/substrate/srml/indices/src/mock.rs @@ -87,6 +87,7 @@ impl system::Trait for Runtime { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl Trait for Runtime { type AccountIndex = u64; diff --git a/substrate/srml/membership/src/lib.rs b/substrate/srml/membership/src/lib.rs index 8e8feec4ee..e36351ddbe 100644 --- a/substrate/srml/membership/src/lib.rs +++ b/substrate/srml/membership/src/lib.rs @@ -238,6 +238,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } parameter_types! { pub const One: u64 = 1; diff --git a/substrate/srml/offences/src/mock.rs b/substrate/srml/offences/src/mock.rs index 78355f642e..e7280c34e9 100644 --- a/substrate/srml/offences/src/mock.rs +++ b/substrate/srml/offences/src/mock.rs @@ -84,6 +84,7 @@ impl system::Trait for Runtime { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl Trait for Runtime { diff --git a/substrate/srml/session/src/mock.rs b/substrate/srml/session/src/mock.rs index 82fefc3958..c5608e1a54 100644 --- a/substrate/srml/session/src/mock.rs +++ b/substrate/srml/session/src/mock.rs @@ -151,6 +151,7 @@ impl system::Trait for Test { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } impl timestamp::Trait for Test { diff --git a/substrate/srml/staking/src/mock.rs b/substrate/srml/staking/src/mock.rs index 730c8306cb..aafe065118 100644 --- a/substrate/srml/staking/src/mock.rs +++ b/substrate/srml/staking/src/mock.rs @@ -125,6 +125,7 @@ impl system::Trait for Test { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } parameter_types! { pub const TransferFee: Balance = 0; diff --git a/substrate/srml/support/src/traits.rs b/substrate/srml/support/src/traits.rs index ff667879af..cca9fd2b10 100644 --- a/substrate/srml/support/src/traits.rs +++ b/substrate/srml/support/src/traits.rs @@ -32,6 +32,10 @@ pub trait Get { fn get() -> T; } +impl Get for () { + fn get() -> T { T::default() } +} + /// A trait for querying whether a type can be said to statically "contain" a value. Similar /// in nature to `Get`, except it is designed to be lazy rather than active (you can't ask it to /// enumerate all values that it contains) and work for multiple values rather than just one. @@ -698,4 +702,4 @@ pub trait InitializeMembers { impl InitializeMembers for () { fn initialize_members(_: &[T]) {} -} \ No newline at end of file +} diff --git a/substrate/srml/system/Cargo.toml b/substrate/srml/system/Cargo.toml index 9816555621..fb2b5296c7 100644 --- a/substrate/srml/system/Cargo.toml +++ b/substrate/srml/system/Cargo.toml @@ -12,6 +12,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false } runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false } sr-primitives = { path = "../../core/sr-primitives", default-features = false } +sr-version = { path = "../../core/sr-version", default-features = false } srml-support = { path = "../support", default-features = false } [dev-dependencies] @@ -28,6 +29,7 @@ std = [ "runtime_io/std", "srml-support/std", "sr-primitives/std", + "sr-version/std", ] [[bench]] diff --git a/substrate/srml/system/benches/bench.rs b/substrate/srml/system/benches/bench.rs index 521123118d..3d10db557c 100644 --- a/substrate/srml/system/benches/bench.rs +++ b/substrate/srml/system/benches/bench.rs @@ -75,6 +75,7 @@ impl system::Trait for Runtime { type MaximumBlockWeight = MaximumBlockWeight; type MaximumBlockLength = MaximumBlockLength; type AvailableBlockRatio = AvailableBlockRatio; + type Version = (); } impl module::Trait for Runtime { diff --git a/substrate/srml/system/src/lib.rs b/substrate/srml/system/src/lib.rs index 1d17ef2b1c..56093f4f7e 100644 --- a/substrate/srml/system/src/lib.rs +++ b/substrate/srml/system/src/lib.rs @@ -77,6 +77,7 @@ use rstd::prelude::*; #[cfg(any(feature = "std", test))] use rstd::map; use rstd::marker::PhantomData; +use sr_version::RuntimeVersion; use sr_primitives::generic::{self, Era}; use sr_primitives::Perbill; use sr_primitives::weights::{ @@ -216,6 +217,8 @@ pub trait Trait: 'static + Eq + Clone { /// module, including weight and length. type AvailableBlockRatio: Get; + /// Get the chain's current version. + type Version: Get; } pub type DigestOf = generic::Digest<::Hash>; @@ -709,6 +712,9 @@ impl Module { >::put(n); } + /// Return the chain's current runtime version. + pub fn runtime_version() -> RuntimeVersion { T::Version::get() } + /// Get the basic random seed. /// /// In general you won't want to use this, but rather `Self::random` which @@ -1059,6 +1065,35 @@ impl SignedExtension for CheckGenesis { } } +/// Ensure the runtime version registered in the transaction is the same as at present. +#[derive(Encode, Decode, Clone, Eq, PartialEq)] +pub struct CheckVersion(rstd::marker::PhantomData); + +#[cfg(feature = "std")] +impl rstd::fmt::Debug for CheckVersion { + fn fmt(&self, _f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result { + Ok(()) + } +} + +#[cfg(feature = "std")] +impl CheckVersion { + pub fn new() -> Self { + Self(std::marker::PhantomData) + } +} + +impl SignedExtension for CheckVersion { + type AccountId = T::AccountId; + type Call = ::Call; + type AdditionalSigned = u32; + type Pre = (); + + fn additional_signed(&self) -> Result { + Ok(>::runtime_version().spec_version) + } +} + pub struct ChainContext(::rstd::marker::PhantomData); impl Default for ChainContext { fn default() -> Self { @@ -1112,6 +1147,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } impl From for u16 { diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index 502acadf61..78a741aff4 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -371,6 +371,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } parameter_types! { pub const MinimumPeriod: u64 = 5; diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 21c670e152..bef510e2f4 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -394,6 +394,7 @@ mod tests { type MaximumBlockWeight = MaximumBlockWeight; type AvailableBlockRatio = AvailableBlockRatio; type MaximumBlockLength = MaximumBlockLength; + type Version = (); } parameter_types! { pub const ExistentialDeposit: u64 = 0;