Signed transactions now have affinity with runtime versions (#3430)

* Signed transactions now has affinity with runtime versions

* Bump runtime version
This commit is contained in:
Gavin Wood
2019-08-18 18:01:05 +02:00
committed by GitHub
parent 0e56b56a86
commit 6c5fbe64ca
33 changed files with 76 additions and 3 deletions
+1
View File
@@ -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",
]
+1 -1
View File
@@ -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 {
+1
View File
@@ -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 {
@@ -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 {
@@ -107,6 +107,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
impl Trait for Test {
type Event = ();
+3 -1
View File
@@ -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! {
+1
View File
@@ -277,6 +277,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
impl Trait for Test {
type Event = ();
+1
View File
@@ -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 {
+1
View File
@@ -476,6 +476,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
parameter_types! {
+1
View File
@@ -777,6 +777,7 @@ impl<T: Subtrait<I>, I: Instance> system::Trait for ElevatedTrait<T, I> {
type MaximumBlockWeight = T::MaximumBlockWeight;
type MaximumBlockLength = T::MaximumBlockLength;
type AvailableBlockRatio = T::AvailableBlockRatio;
type Version = T::Version;
}
impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
type Balance = T::Balance;
+1
View File
@@ -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;
+1
View File
@@ -419,6 +419,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
impl Trait<Instance1> for Test {
type Origin = Origin;
+1
View File
@@ -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;
+1
View File
@@ -119,6 +119,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
+1
View File
@@ -1029,6 +1029,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
+1
View File
@@ -1152,6 +1152,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
+1
View File
@@ -544,6 +544,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
+1
View File
@@ -402,6 +402,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
@@ -321,6 +321,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
parameter_types! {
pub const WindowSize: u64 = 11;
+1
View File
@@ -1063,6 +1063,7 @@ impl<T: Subtrait> system::Trait for ElevatedTrait<T> {
type AvailableBlockRatio = T::AvailableBlockRatio;
type WeightMultiplierUpdate = ();
type BlockHashCount = T::BlockHashCount;
type Version = T::Version;
}
impl<T: Subtrait> Trait for ElevatedTrait<T> {
type Balance = T::Balance;
+1
View File
@@ -61,6 +61,7 @@ impl system::Trait for Test {
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type BlockHashCount = BlockHashCount;
type Version = ();
}
impl Trait for Test {
+1
View File
@@ -63,6 +63,7 @@ impl system::Trait for Test {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
mod grandpa {
+1
View File
@@ -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;
+1
View File
@@ -238,6 +238,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
parameter_types! {
pub const One: u64 = 1;
+1
View File
@@ -84,6 +84,7 @@ impl system::Trait for Runtime {
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}
impl Trait for Runtime {
+1
View File
@@ -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 {
+1
View File
@@ -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;
+5 -1
View File
@@ -32,6 +32,10 @@ pub trait Get<T> {
fn get() -> T;
}
impl<T: Default> Get<T> 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<AccountId> {
impl<T> InitializeMembers<T> for () {
fn initialize_members(_: &[T]) {}
}
}
+2
View File
@@ -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]]
+1
View File
@@ -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 {
+36
View File
@@ -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<Perbill>;
/// Get the chain's current version.
type Version: Get<RuntimeVersion>;
}
pub type DigestOf<T> = generic::Digest<<T as Trait>::Hash>;
@@ -709,6 +712,9 @@ impl<T: Trait> Module<T> {
<ParentHash<T>>::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<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> {
}
}
/// Ensure the runtime version registered in the transaction is the same as at present.
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
pub struct CheckVersion<T: Trait + Send + Sync>(rstd::marker::PhantomData<T>);
#[cfg(feature = "std")]
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckVersion<T> {
fn fmt(&self, _f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
Ok(())
}
}
#[cfg(feature = "std")]
impl<T: Trait + Send + Sync> CheckVersion<T> {
pub fn new() -> Self {
Self(std::marker::PhantomData)
}
}
impl<T: Trait + Send + Sync> SignedExtension for CheckVersion<T> {
type AccountId = T::AccountId;
type Call = <T as Trait>::Call;
type AdditionalSigned = u32;
type Pre = ();
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
Ok(<Module<T>>::runtime_version().spec_version)
}
}
pub struct ChainContext<T>(::rstd::marker::PhantomData<T>);
impl<T> Default for ChainContext<T> {
fn default() -> Self {
@@ -1112,6 +1147,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
impl From<Event> for u16 {
+1
View File
@@ -371,6 +371,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
parameter_types! {
pub const MinimumPeriod: u64 = 5;
+1
View File
@@ -394,6 +394,7 @@ mod tests {
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;