Check the genesis hash in transactions regardless of era. (#3286)

* Check the genesis hash in transactions regardless of era.

* Fix check-fees, too.

* Undo.

* Subkey supports new signing.

* Remove unneeded type param.

* Bump tx version

* Build.

* Another build fix

* Build again

* Cleanup

* Another fix.

* Fix

* Fixes

* 6 second blocks.

* Fixes

* Build fix

* Fix

* Fix.
This commit is contained in:
Gavin Wood
2019-08-02 18:30:20 +02:00
committed by GitHub
parent ae6c2f7f8c
commit 7927e80bc6
16 changed files with 102 additions and 116 deletions
+1 -1
View File
@@ -450,7 +450,7 @@ mod tests {
(
system::CheckEra::from(Era::Immortal),
system::CheckNonce::from(nonce),
system::CheckWeight::from(),
system::CheckWeight::new(),
balances::TakeFees::from(fee)
)
}
+4 -4
View File
@@ -36,7 +36,7 @@ use srml_support::{
decl_event, decl_storage, decl_module, dispatch::Result, storage::StorageValue
};
use sr_primitives::{
generic::{DigestItem, OpaqueDigestItemId}, traits::{CurrentHeight, Zero},
generic::{DigestItem, OpaqueDigestItemId}, traits::Zero,
};
use fg_primitives::{ScheduledChange, ConsensusLog, GRANDPA_ENGINE_ID};
pub use fg_primitives::{AuthorityId, AuthorityWeight};
@@ -232,7 +232,7 @@ impl<T: Trait> Module<T> {
pub fn schedule_pause(in_blocks: T::BlockNumber) -> Result {
if let StoredState::Live = <State<T>>::get() {
let scheduled_at = system::ChainContext::<T>::default().current_height();
let scheduled_at = <system::Module<T>>::block_number();
<State<T>>::put(StoredState::PendingPause {
delay: in_blocks,
scheduled_at,
@@ -247,7 +247,7 @@ impl<T: Trait> Module<T> {
pub fn schedule_resume(in_blocks: T::BlockNumber) -> Result {
if let StoredState::Paused = <State<T>>::get() {
let scheduled_at = system::ChainContext::<T>::default().current_height();
let scheduled_at = <system::Module<T>>::block_number();
<State<T>>::put(StoredState::PendingResume {
delay: in_blocks,
scheduled_at,
@@ -280,7 +280,7 @@ impl<T: Trait> Module<T> {
forced: Option<T::BlockNumber>,
) -> Result {
if !<PendingChange<T>>::exists() {
let scheduled_at = system::ChainContext::<T>::default().current_height();
let scheduled_at = <system::Module<T>>::block_number();
if let Some(_) = forced {
if Self::next_forced().map_or(false, |next| next > scheduled_at) {
+2 -2
View File
@@ -365,8 +365,8 @@ fn rewards_should_work() {
<Module<Test>>::add_reward_points_to_validator(1001, 10_000);
// Compute total payout now for whole duration as other parameter won't change
let total_payout = current_total_payout_for_duration(9*5);
assert!(total_payout > 10); // Test is meaningfull if reward something
let total_payout = current_total_payout_for_duration(9 * 5);
assert!(total_payout > 10); // Test is meaningful if reward something
// No reward yet
assert_eq!(Balances::total_balance(&2), init_balance_2);
+35 -21
View File
@@ -79,12 +79,15 @@ use rstd::map;
use rstd::marker::PhantomData;
use sr_primitives::generic::{self, Era};
use sr_primitives::Perbill;
use sr_primitives::weights::{Weight, DispatchInfo, DispatchClass, WeightMultiplier, SimpleDispatchInfo};
use sr_primitives::transaction_validity::{ValidTransaction, TransactionPriority, TransactionLongevity};
use sr_primitives::weights::{
Weight, DispatchInfo, DispatchClass, WeightMultiplier, SimpleDispatchInfo
};
use sr_primitives::transaction_validity::{
ValidTransaction, TransactionPriority, TransactionLongevity
};
use sr_primitives::traits::{self, CheckEqual, SimpleArithmetic, Zero, SignedExtension, Convert,
SimpleBitOps, Hash, Member, MaybeDisplay, EnsureOrigin, CurrentHeight, BlockNumberToHash,
MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug, StaticLookup, One, Bounded,
Lookup, DispatchError, SaturatedConversion,
SimpleBitOps, Hash, Member, MaybeDisplay, EnsureOrigin, DispatchError, SaturatedConversion,
MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug, StaticLookup, One, Bounded, Lookup,
};
use primitives::storage::well_known_keys;
use srml_support::{
@@ -866,7 +869,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> {
/// Utility constructor for tests and client code.
#[cfg(feature = "std")]
pub fn from() -> Self {
pub fn new() -> Self {
Self(PhantomData)
}
}
@@ -1012,6 +1015,32 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
}
}
/// Nonce check and increment to give replay protection for transactions.
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
pub struct CheckGenesis<T: Trait + Send + Sync>(rstd::marker::PhantomData<T>);
#[cfg(feature = "std")]
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckGenesis<T> {
fn fmt(&self, _f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
Ok(())
}
}
#[cfg(feature = "std")]
impl<T: Trait + Send + Sync> CheckGenesis<T> {
pub fn new() -> Self {
Self(std::marker::PhantomData)
}
}
impl<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> {
type AccountId = T::AccountId;
type AdditionalSigned = T::Hash;
fn additional_signed(&self) -> Result<Self::AdditionalSigned, &'static str> {
Ok(<Module<T>>::block_hash(T::BlockNumber::zero()))
}
}
pub struct ChainContext<T>(::rstd::marker::PhantomData<T>);
impl<T> Default for ChainContext<T> {
fn default() -> Self {
@@ -1027,21 +1056,6 @@ impl<T: Trait> Lookup for ChainContext<T> {
}
}
impl<T: Trait> CurrentHeight for ChainContext<T> {
type BlockNumber = T::BlockNumber;
fn current_height(&self) -> Self::BlockNumber {
<Module<T>>::block_number()
}
}
impl<T: Trait> BlockNumberToHash for ChainContext<T> {
type BlockNumber = T::BlockNumber;
type Hash = T::Hash;
fn block_number_to_hash(&self, n: Self::BlockNumber) -> Option<Self::Hash> {
Some(<Module<T>>::block_hash(n))
}
}
#[cfg(test)]
mod tests {
use super::*;