Skip to content

Commit

Permalink
Connect maintenance mode to frame system (#747)
Browse files Browse the repository at this point in the history
* moonbeam

* moonriver

* add back pool filtering

Co-authored-by: nanocryk <6422796+nanocryk@users.noreply.github.com>
  • Loading branch information
JoshOrndorff and nanocryk authored Aug 27, 2021
1 parent c17b604 commit 9ede6fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 10 additions & 2 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use sp_core::{u32_trait::*, OpaqueMetadata, H160, H256, U256};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity},
transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity},
AccountId32, ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill,
};
use sp_std::{convert::TryFrom, prelude::*};
Expand Down Expand Up @@ -869,7 +869,15 @@ runtime_common::impl_runtime_apis_plus_common! {
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
// Filtered calls should not enter the tx pool as they'll fail if inserted.
let allowed = <Runtime as frame_system::Config>
::BaseCallFilter::filter(&tx.function);

if allowed {
Executive::validate_transaction(source, tx, block_hash)
} else {
InvalidTransaction::Call.into()
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = RocksDbWeight;
type BaseCallFilter = BaseFilter;
type BaseCallFilter = MaintenanceMode;
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
Expand Down Expand Up @@ -786,7 +786,7 @@ impl Filter<Call> for PhaseThreeFilter {

impl pallet_maintenance_mode::Config for Runtime {
type Event = Event;
type NormalCallFilter = ();
type NormalCallFilter = BaseFilter;
type MaintenanceCallFilter = PhaseThreeFilter;
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
Expand Down
14 changes: 11 additions & 3 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use sp_core::{u32_trait::*, OpaqueMetadata, H160, H256, U256};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity},
transaction_validity::{InvalidTransaction, TransactionSource, TransactionValidity},
AccountId32, ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill,
};
use sp_std::{convert::TryFrom, prelude::*};
Expand Down Expand Up @@ -197,7 +197,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = RocksDbWeight;
type BaseCallFilter = ();
type BaseCallFilter = MaintenanceMode;
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
Expand Down Expand Up @@ -881,7 +881,15 @@ runtime_common::impl_runtime_apis_plus_common! {
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
// Filtered calls should not enter the tx pool as they'll fail if inserted.
let allowed = <Runtime as frame_system::Config>
::BaseCallFilter::filter(&tx.function);

if allowed {
Executive::validate_transaction(source, tx, block_hash)
} else {
InvalidTransaction::Call.into()
}
}
}
}
Expand Down

0 comments on commit 9ede6fc

Please sign in to comment.