diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 783881aac6..0360827e9a 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. spec_version: 154, - impl_version: 154, + impl_version: 155, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/srml/system/src/lib.rs b/substrate/srml/system/src/lib.rs index 2343af8bec..54aa3b282a 100644 --- a/substrate/srml/system/src/lib.rs +++ b/substrate/srml/system/src/lib.rs @@ -1020,7 +1020,7 @@ impl SignedExtension for CheckNonce { } } -/// Nonce check and increment to give replay protection for transactions. +/// Check for transaction mortality. #[derive(Encode, Decode, Clone, Eq, PartialEq)] pub struct CheckEra((Era, rstd::marker::PhantomData)); @@ -1045,6 +1045,21 @@ impl SignedExtension for CheckEra { type AdditionalSigned = T::Hash; type Pre = (); + fn validate( + &self, + _who: &Self::AccountId, + _call: &Self::Call, + _info: DispatchInfo, + _len: usize, + ) -> Result { + let current_u64 = >::block_number().saturated_into::(); + let valid_till = (self.0).0.death(current_u64); + Ok(ValidTransaction { + longevity: valid_till.saturating_sub(current_u64), + ..Default::default() + }) + } + fn additional_signed(&self) -> Result { let current_u64 = >::block_number().saturated_into::(); let n = (self.0).0.birth(current_u64).saturated_into::(); @@ -1478,4 +1493,23 @@ mod tests { assert!(CheckEra::::from(Era::mortal(4, 12)).additional_signed().is_ok()); }) } + + #[test] + fn signed_ext_check_era_should_change_longevity() { + with_externalities(&mut new_test_ext(), || { + let normal = DispatchInfo { weight: 100, class: DispatchClass::Normal }; + let len = 0_usize; + let ext = ( + CheckWeight::(PhantomData), + CheckEra::::from(Era::mortal(16, 256)), + ); + System::set_block_number(17); + >::insert(16, H256::repeat_byte(1)); + + assert_eq!( + ext.validate(&1, CALL, normal, len).unwrap().longevity, + 15, + ); + }) + } }