Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect maintenance mode to frame system #747

Merged
merged 3 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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