Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce whitelist for Transact and limit UMP processing to 10 messages per block #6280

Merged
merged 7 commits into from
Dec 2, 2022
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
182 changes: 181 additions & 1 deletion runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
};
use frame_support::{
match_types, parameter_types,
traits::{Everything, Nothing},
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use runtime_common::{xcm_sender, ToAuthor};
Expand Down Expand Up @@ -135,6 +135,185 @@ pub type Barrier = (
AllowSubscriptionsFrom<OnlyParachains>,
);

/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
/// account for proof size weights.
///
/// Calls that are allowed through this filter must:
/// 1. Have a fixed weight;
/// 2. Cannot lead to another call being made;
/// 3. Have a defined proof size weight, e.g. no unbounded vecs in call parameters.
pub struct SafeCallFilter;
impl Contains<RuntimeCall> for SafeCallFilter {
fn contains(t: &RuntimeCall) -> bool {
match t {
RuntimeCall::System(
frame_system::Call::fill_block { .. } |
frame_system::Call::kill_prefix { .. } |
frame_system::Call::set_heap_pages { .. },
) |
RuntimeCall::Babe(..) |
RuntimeCall::Timestamp(..) |
RuntimeCall::Indices(..) |
RuntimeCall::Balances(..) |
RuntimeCall::Staking(
pallet_staking::Call::bond { .. } |
pallet_staking::Call::bond_extra { .. } |
pallet_staking::Call::unbond { .. } |
pallet_staking::Call::withdraw_unbonded { .. } |
pallet_staking::Call::validate { .. } |
pallet_staking::Call::chill { .. } |
pallet_staking::Call::set_payee { .. } |
pallet_staking::Call::set_controller { .. } |
pallet_staking::Call::set_validator_count { .. } |
pallet_staking::Call::increase_validator_count { .. } |
pallet_staking::Call::scale_validator_count { .. } |
pallet_staking::Call::force_no_eras { .. } |
pallet_staking::Call::force_new_era { .. } |
pallet_staking::Call::set_invulnerables { .. } |
pallet_staking::Call::force_unstake { .. } |
pallet_staking::Call::force_new_era_always { .. } |
pallet_staking::Call::payout_stakers { .. } |
pallet_staking::Call::unbond { .. } |
pallet_staking::Call::reap_stash { .. } |
pallet_staking::Call::set_staking_configs { .. } |
pallet_staking::Call::chill_other { .. } |
pallet_staking::Call::force_apply_min_commission { .. },
) |
RuntimeCall::Session(pallet_session::Call::purge_keys { .. }) |
RuntimeCall::Grandpa(..) |
RuntimeCall::ImOnline(..) |
RuntimeCall::Democracy(
pallet_democracy::Call::second { .. } |
pallet_democracy::Call::vote { .. } |
pallet_democracy::Call::emergency_cancel { .. } |
pallet_democracy::Call::fast_track { .. } |
pallet_democracy::Call::veto_external { .. } |
pallet_democracy::Call::cancel_referendum { .. } |
pallet_democracy::Call::delegate { .. } |
pallet_democracy::Call::undelegate { .. } |
pallet_democracy::Call::clear_public_proposals { .. } |
pallet_democracy::Call::unlock { .. } |
pallet_democracy::Call::remove_vote { .. } |
pallet_democracy::Call::remove_other_vote { .. } |
pallet_democracy::Call::blacklist { .. } |
pallet_democracy::Call::cancel_proposal { .. },
) |
RuntimeCall::Council(
pallet_collective::Call::vote { .. } |
pallet_collective::Call::close_old_weight { .. } |
pallet_collective::Call::disapprove_proposal { .. } |
pallet_collective::Call::close { .. },
) |
RuntimeCall::TechnicalCommittee(
pallet_collective::Call::vote { .. } |
pallet_collective::Call::close_old_weight { .. } |
pallet_collective::Call::disapprove_proposal { .. } |
pallet_collective::Call::close { .. },
) |
RuntimeCall::PhragmenElection(
pallet_elections_phragmen::Call::remove_voter { .. } |
pallet_elections_phragmen::Call::submit_candidacy { .. } |
pallet_elections_phragmen::Call::renounce_candidacy { .. } |
pallet_elections_phragmen::Call::remove_member { .. } |
pallet_elections_phragmen::Call::clean_defunct_voters { .. },
) |
RuntimeCall::TechnicalMembership(
pallet_membership::Call::add_member { .. } |
pallet_membership::Call::remove_member { .. } |
pallet_membership::Call::swap_member { .. } |
pallet_membership::Call::change_key { .. } |
pallet_membership::Call::set_prime { .. } |
pallet_membership::Call::clear_prime { .. },
) |
RuntimeCall::Treasury(..) |
RuntimeCall::ConvictionVoting(..) |
RuntimeCall::Referenda(
pallet_referenda::Call::place_decision_deposit { .. } |
pallet_referenda::Call::refund_decision_deposit { .. } |
pallet_referenda::Call::cancel { .. } |
pallet_referenda::Call::kill { .. } |
pallet_referenda::Call::nudge_referendum { .. } |
pallet_referenda::Call::one_fewer_deciding { .. },
) |
RuntimeCall::FellowshipCollective(..) |
RuntimeCall::FellowshipReferenda(
pallet_referenda::Call::place_decision_deposit { .. } |
pallet_referenda::Call::refund_decision_deposit { .. } |
pallet_referenda::Call::cancel { .. } |
pallet_referenda::Call::kill { .. } |
pallet_referenda::Call::nudge_referendum { .. } |
pallet_referenda::Call::one_fewer_deciding { .. },
) |
RuntimeCall::Claims(
super::claims::Call::claim { .. } |
super::claims::Call::mint_claim { .. } |
super::claims::Call::move_claim { .. },
) |
RuntimeCall::Utility(pallet_utility::Call::as_derivative { .. }) |
RuntimeCall::Identity(
pallet_identity::Call::add_registrar { .. } |
pallet_identity::Call::set_identity { .. } |
pallet_identity::Call::clear_identity { .. } |
pallet_identity::Call::request_judgement { .. } |
pallet_identity::Call::cancel_request { .. } |
pallet_identity::Call::set_fee { .. } |
pallet_identity::Call::set_account_id { .. } |
pallet_identity::Call::set_fields { .. } |
pallet_identity::Call::provide_judgement { .. } |
pallet_identity::Call::kill_identity { .. } |
pallet_identity::Call::add_sub { .. } |
pallet_identity::Call::rename_sub { .. } |
pallet_identity::Call::remove_sub { .. } |
pallet_identity::Call::quit_sub { .. },
) |
RuntimeCall::Society(
pallet_society::Call::bid { .. } |
pallet_society::Call::unbid { .. } |
pallet_society::Call::vouch { .. } |
pallet_society::Call::unvouch { .. } |
pallet_society::Call::vote { .. } |
pallet_society::Call::defender_vote { .. } |
pallet_society::Call::payout { .. } |
pallet_society::Call::unfound { .. } |
pallet_society::Call::judge_suspended_member { .. } |
pallet_society::Call::judge_suspended_candidate { .. } |
pallet_society::Call::set_max_members { .. },
) |
RuntimeCall::Recovery(..) |
RuntimeCall::Vesting(..) |
RuntimeCall::Bounties(
pallet_bounties::Call::propose_bounty { .. } |
pallet_bounties::Call::approve_bounty { .. } |
pallet_bounties::Call::propose_curator { .. } |
pallet_bounties::Call::unassign_curator { .. } |
pallet_bounties::Call::accept_curator { .. } |
pallet_bounties::Call::award_bounty { .. } |
pallet_bounties::Call::claim_bounty { .. } |
pallet_bounties::Call::close_bounty { .. },
) |
RuntimeCall::ChildBounties(..) |
RuntimeCall::ElectionProviderMultiPhase(..) |
RuntimeCall::Gilt(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(
pallet_nomination_pools::Call::join { .. } |
pallet_nomination_pools::Call::bond_extra { .. } |
pallet_nomination_pools::Call::claim_payout { .. } |
pallet_nomination_pools::Call::unbond { .. } |
pallet_nomination_pools::Call::pool_withdraw_unbonded { .. } |
pallet_nomination_pools::Call::withdraw_unbonded { .. } |
pallet_nomination_pools::Call::create { .. } |
pallet_nomination_pools::Call::create_with_pool_id { .. } |
pallet_nomination_pools::Call::set_state { .. } |
pallet_nomination_pools::Call::set_configs { .. } |
pallet_nomination_pools::Call::update_roles { .. } |
pallet_nomination_pools::Call::chill { .. },
) => true,
_ => false,
}
}
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -166,6 +345,7 @@ impl xcm_executor::Config for XcmConfig {
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = SafeCallFilter;
}

parameter_types! {
Expand Down
10 changes: 9 additions & 1 deletion runtime/parachains/src/ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,21 @@ impl<T: Config> Pallet<T> {

/// Devote some time into dispatching pending upward messages.
pub(crate) fn process_pending_upward_messages() -> Weight {
const MAX_MESSAGES_PER_BLOCK: u8 = 10;
let mut messages_processed = 0;
let mut weight_used = Weight::zero();

let config = <configuration::Pallet<T>>::config();
let mut cursor = NeedsDispatchCursor::new::<T>();
let mut queue_cache = QueueCache::new();

while let Some(dispatchee) = cursor.peek() {
if weight_used.any_gte(config.ump_service_total_weight) {
if weight_used.any_gte(config.ump_service_total_weight) ||
messages_processed >= MAX_MESSAGES_PER_BLOCK
{
// Temporarily allow for processing of a max of 10 messages per block, until we
// properly account for proof size weights.
//
// Then check whether we've reached or overshoot the
// preferred weight for the dispatching stage.
//
Expand All @@ -534,6 +541,7 @@ impl<T: Config> Pallet<T> {
// our remaining weight limit, then consume it.
let maybe_next = queue_cache.peek_front::<T>(dispatchee);
if let Some(upward_message) = maybe_next {
messages_processed += 1;
match T::UmpSink::process_upward_message(dispatchee, upward_message, max_weight) {
Ok(used) => {
weight_used += used;
Expand Down
Loading