From 2177b81ca6793279dea765b5c9935242819604eb Mon Sep 17 00:00:00 2001 From: wangjj9219 <183318287@qq.com> Date: Sun, 26 Nov 2023 00:38:00 +0800 Subject: [PATCH 1/2] add rate limit for xtokens transfer --- Cargo.lock | 66 ++++++++++++++++++--------- Cargo.toml | 2 + orml | 2 +- runtime/acala/Cargo.toml | 4 ++ runtime/acala/src/lib.rs | 17 +++++-- runtime/acala/src/xcm_config.rs | 9 ++-- runtime/common/Cargo.toml | 3 ++ runtime/common/src/lib.rs | 12 +++++ runtime/common/src/precompile/mock.rs | 2 + runtime/karura/Cargo.toml | 4 ++ runtime/karura/src/lib.rs | 17 +++++-- runtime/karura/src/xcm_config.rs | 9 ++-- runtime/mandala/Cargo.toml | 4 ++ runtime/mandala/src/lib.rs | 17 +++++-- runtime/mandala/src/xcm_config.rs | 9 ++-- 15 files changed, 136 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66ee61b879..d616477908 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,6 +175,7 @@ dependencies = [ "orml-oracle", "orml-oracle-runtime-api", "orml-parameters", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-tokens-runtime-api", @@ -5377,6 +5378,7 @@ dependencies = [ "orml-oracle", "orml-oracle-runtime-api", "orml-parameters", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-tokens-runtime-api", @@ -6289,6 +6291,7 @@ dependencies = [ "orml-oracle-runtime-api", "orml-parameters", "orml-payments", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-tokens-runtime-api", @@ -7842,7 +7845,7 @@ dependencies = [ [[package]] name = "orml-asset-registry" -version = "0.6.1" +version = "0.6.7" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -7879,7 +7882,7 @@ dependencies = [ [[package]] name = "orml-auction" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -7895,7 +7898,7 @@ dependencies = [ [[package]] name = "orml-authority" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -7913,7 +7916,7 @@ dependencies = [ [[package]] name = "orml-benchmarking" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-benchmarking", "frame-support", @@ -7934,14 +7937,14 @@ dependencies = [ [[package]] name = "orml-build-script-utils" -version = "0.6.1" +version = "0.6.7" dependencies = [ "walkdir", ] [[package]] name = "orml-currencies" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -7960,7 +7963,7 @@ dependencies = [ [[package]] name = "orml-gradually-update" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -7975,7 +7978,7 @@ dependencies = [ [[package]] name = "orml-nft" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -7990,7 +7993,7 @@ dependencies = [ [[package]] name = "orml-oracle" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8008,7 +8011,7 @@ dependencies = [ [[package]] name = "orml-oracle-runtime-api" -version = "0.6.1" +version = "0.6.7" dependencies = [ "parity-scale-codec", "sp-api", @@ -8017,7 +8020,7 @@ dependencies = [ [[package]] name = "orml-parameters" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8033,7 +8036,7 @@ dependencies = [ [[package]] name = "orml-payments" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8049,9 +8052,27 @@ dependencies = [ "sp-std", ] +[[package]] +name = "orml-rate-limit" +version = "0.6.7" +dependencies = [ + "frame-support", + "frame-system", + "orml-traits", + "orml-utilities", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "orml-rewards" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8067,7 +8088,7 @@ dependencies = [ [[package]] name = "orml-tokens" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8088,7 +8109,7 @@ dependencies = [ [[package]] name = "orml-tokens-runtime-api" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "parity-scale-codec", @@ -8098,7 +8119,7 @@ dependencies = [ [[package]] name = "orml-traits" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -8117,7 +8138,7 @@ dependencies = [ [[package]] name = "orml-unknown-tokens" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8135,7 +8156,7 @@ dependencies = [ [[package]] name = "orml-utilities" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8151,7 +8172,7 @@ dependencies = [ [[package]] name = "orml-vesting" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8167,7 +8188,7 @@ dependencies = [ [[package]] name = "orml-xcm" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "frame-system", @@ -8181,7 +8202,7 @@ dependencies = [ [[package]] name = "orml-xcm-support" -version = "0.6.1" +version = "0.6.7" dependencies = [ "frame-support", "orml-traits", @@ -8194,7 +8215,7 @@ dependencies = [ [[package]] name = "orml-xtokens" -version = "0.6.1" +version = "0.6.7" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -11750,6 +11771,7 @@ dependencies = [ "orml-currencies", "orml-nft", "orml-oracle", + "orml-rate-limit", "orml-rewards", "orml-tokens", "orml-traits", diff --git a/Cargo.toml b/Cargo.toml index e2995bb797..59d626bb09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ members = [ "orml/oracle", "orml/parameters", "orml/payments", + "orml/rate-limit", "orml/rewards", "orml/tokens", "orml/tokens/runtime-api", @@ -171,6 +172,7 @@ orml-oracle = { path = "orml/oracle", default-features = false } orml-oracle-runtime-api = { path = "orml/oracle/runtime-api", default-features = false } orml-parameters = { path = "orml/parameters", default-features = false } orml-payments = { path = "orml/payments", default-features = false } +orml-rate-limit = { path = "orml/rate-limit", default-features = false } orml-rewards = { path = "orml/rewards", default-features = false } orml-tokens = { path = "orml/tokens", default-features = false } orml-tokens-runtime-api = { path = "orml/tokens/runtime-api", default-features = false } diff --git a/orml b/orml index 8f59b50ab4..175792bd5e 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 8f59b50ab45d15572d18cee0425966e43567a954 +Subproject commit 175792bd5e06cf64e17762df037e15a4e6234d49 diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index 9b7cc667c0..40388e5fee 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -91,6 +91,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } +orml-rate-limit = { workspace = true, optional = true } # modules module-aggregated-dex = { workspace = true } @@ -227,6 +228,7 @@ std = [ "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -300,6 +302,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "orml-rate-limit/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", @@ -369,6 +372,7 @@ try-runtime = [ "orml-vesting/try-runtime", "orml-xcm/try-runtime", "orml-xtokens/try-runtime", + "orml-rate-limit/try-runtime", "module-aggregated-dex/try-runtime", "module-asset-registry/try-runtime", diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index ec31663aae..497a2cfb3b 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -110,9 +110,9 @@ use runtime_common::{ EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, ExistentialDepositsTimesOneHundred, FinancialCouncilInstance, FinancialCouncilMembershipInstance, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, MaxTipsOfPriority, - OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, RuntimeBlockLength, - RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, - TipPerWeightStep, ACA, AUSD, DOT, LCDOT, LDOT, TAP, + OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, RateLimiterId, Ratio, + RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, + TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, LCDOT, LDOT, TAP, }; use xcm::v3::prelude::*; @@ -1747,6 +1747,16 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +impl orml_rate_limit::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type GovernanceOrigin = EnsureRootOrOneThirdsTechnicalCommittee; + type RateLimiterId = RateLimiterId; + type MaxWhitelistFilterCount = ConstU32<3>; + type UnixTime = Timestamp; + type BlockNumberProvider = System; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { // Core & Utility @@ -1760,6 +1770,7 @@ construct_runtime!( // NOTE: IdleScheduler must be put before ParachainSystem in order to read relaychain blocknumber IdleScheduler: module_idle_scheduler = 7, Preimage: pallet_preimage = 8, + RateLimit: orml_rate_limit = 9, // Tokens & Related Balances: pallet_balances = 10, diff --git a/runtime/acala/src/xcm_config.rs b/runtime/acala/src/xcm_config.rs index e52a77d272..49c91c85f3 100644 --- a/runtime/acala/src/xcm_config.rs +++ b/runtime/acala/src/xcm_config.rs @@ -20,8 +20,8 @@ use super::{ constants::{fee::*, parachains}, AcalaTreasuryAccount, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, NativeTokenExistentialDeposit, - ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, UnknownTokens, - XcmInterface, XcmpQueue, ACA, AUSD, TAP, + ParachainInfo, ParachainSystem, PolkadotXcm, RateLimit, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + UnknownTokens, XcmInterface, XcmpQueue, ACA, AUSD, TAP, }; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -40,7 +40,7 @@ use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use primitives::evm::is_system_contract; use runtime_common::{ local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil, - EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, + EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RateLimiterId, }; use xcm::{prelude::*, v3::Weight as XcmWeight}; use xcm_builder::{EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, SignedToAccountId32}; @@ -324,6 +324,7 @@ parameter_types! { parameter_types! { pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; + pub const XtokensRateLimiterId: RateLimiterId = RateLimiterId::XTokens; } parameter_type_with_key! { @@ -351,4 +352,6 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = RateLimit; + type RateLimiterId = XtokensRateLimiterId; } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 023582429d..c8c4b0e320 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -79,6 +79,7 @@ wasm-bencher = { workspace = true, optional = true } orml-nft = { workspace = true, optional = true } orml-currencies = { workspace = true, optional = true } orml-rewards = { workspace = true, optional = true } +orml-rate-limit = { workspace = true, optional = true } [dev-dependencies] orml-utilities = { workspace = true, features = ["std"] } @@ -124,6 +125,7 @@ std = [ "orml-tokens/std", "orml-traits/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-asset-registry/std", "module-cdp-engine/std", @@ -168,6 +170,7 @@ wasm-bench = [ "orml-currencies", "orml-nft", "orml-rewards", + "orml-rate-limit", "orml-tokens/runtime-benchmarks", "xcm-builder/runtime-benchmarks", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index b62e6e866c..ebf2b8cb27 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -405,6 +405,18 @@ where } } +/// The type used to represent the kinds of rate limiter id. +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)] +pub enum RateLimiterId { + XTokens, +} + +impl Default for RateLimiterId { + fn default() -> Self { + Self::XTokens + } +} + #[cfg(feature = "std")] /// Returns `evm_genesis_accounts` pub fn evm_genesis(evm_accounts: Vec) -> BTreeMap> { diff --git a/runtime/common/src/precompile/mock.rs b/runtime/common/src/precompile/mock.rs index d710ee21c7..d40e1f56d7 100644 --- a/runtime/common/src/precompile/mock.rs +++ b/runtime/common/src/precompile/mock.rs @@ -909,6 +909,8 @@ impl orml_xtokens::Config for Test { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types!( diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index 355bf47f74..094831170c 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -91,6 +91,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } +orml-rate-limit = { workspace = true, optional = true } # modules module-aggregated-dex = { workspace = true } @@ -227,6 +228,7 @@ std = [ "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -300,6 +302,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "orml-rate-limit/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", @@ -369,6 +372,7 @@ try-runtime = [ "orml-vesting/try-runtime", "orml-xcm/try-runtime", "orml-xtokens/try-runtime", + "orml-rate-limit/try-runtime", "module-aggregated-dex/try-runtime", "module-asset-registry/try-runtime", diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 200a7fa837..5b46f689ab 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -110,9 +110,9 @@ use runtime_common::{ EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, ExistentialDepositsTimesOneHundred, FinancialCouncilInstance, FinancialCouncilMembershipInstance, FixedRateOfAsset, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, - MaxTipsOfPriority, OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, - RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, - TimeStampedPrice, TipPerWeightStep, KAR, KSM, KUSD, LKSM, TAI, + MaxTipsOfPriority, OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, + RateLimiterId, Ratio, RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, + TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, KAR, KSM, KUSD, LKSM, TAI, }; use xcm::v3::prelude::*; @@ -1739,6 +1739,16 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +impl orml_rate_limit::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type GovernanceOrigin = EnsureRootOrOneThirdsTechnicalCommittee; + type RateLimiterId = RateLimiterId; + type MaxWhitelistFilterCount = ConstU32<3>; + type UnixTime = Timestamp; + type BlockNumberProvider = System; + type WeightInfo = (); +} + construct_runtime!( pub enum Runtime { // Core & Utility @@ -1752,6 +1762,7 @@ construct_runtime!( // NOTE: IdleScheduler must be put before ParachainSystem in order to read relaychain blocknumber IdleScheduler: module_idle_scheduler = 7, Preimage: pallet_preimage = 8, + RateLimit: orml_rate_limit = 9, // Tokens & Related Balances: pallet_balances = 10, diff --git a/runtime/karura/src/xcm_config.rs b/runtime/karura/src/xcm_config.rs index 75d1b1ee96..dd6534b6bd 100644 --- a/runtime/karura/src/xcm_config.rs +++ b/runtime/karura/src/xcm_config.rs @@ -20,8 +20,8 @@ use super::{ constants::{fee::*, parachains}, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, FixedRateOfAsset, GetNativeCurrencyId, KaruraTreasuryAccount, - NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, UnknownTokens, XcmInterface, XcmpQueue, KAR, KUSD, LKSM, TAI, + NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, RateLimit, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, UnknownTokens, XcmInterface, XcmpQueue, KAR, KUSD, LKSM, TAI, }; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -38,7 +38,7 @@ use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use primitives::evm::is_system_contract; use runtime_common::{ local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil, - EnsureRootOrThreeFourthsGeneralCouncil, + EnsureRootOrThreeFourthsGeneralCouncil, RateLimiterId, }; use xcm::{prelude::*, v3::Weight as XcmWeight}; use xcm_builder::{EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, SignedToAccountId32}; @@ -269,6 +269,7 @@ parameter_types! { parameter_types! { pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; + pub const XtokensRateLimiterId: RateLimiterId = RateLimiterId::XTokens; } parameter_type_with_key! { @@ -296,6 +297,8 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = RateLimit; + type RateLimiterId = XtokensRateLimiterId; } pub type LocalAssetTransactor = MultiCurrencyAdapter< diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 6610427602..303c783cfe 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -96,6 +96,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } +orml-rate-limit = { workspace = true, optional = true } # modules module-transaction-pause = { workspace = true } @@ -245,6 +246,7 @@ std = [ "orml-xcm-support/std", "orml-xcm/std", "orml-xtokens/std", + "orml-rate-limit/std", "module-aggregated-dex/std", "module-asset-registry/std", @@ -323,6 +325,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-vesting/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", + "orml-rate-limit/runtime-benchmarks", "module-collator-selection/runtime-benchmarks", "module-evm-accounts/runtime-benchmarks", @@ -401,6 +404,7 @@ try-runtime = [ "orml-vesting/try-runtime", "orml-xcm/try-runtime", "orml-xtokens/try-runtime", + "orml-rate-limit/try-runtime", "module-aggregated-dex/try-runtime", "module-asset-registry/try-runtime", diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index a3a07d9010..12730a43e4 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -110,9 +110,9 @@ use runtime_common::{ EnsureRootOrTwoThirdsTechnicalCommittee, ExchangeRate, ExistentialDepositsTimesOneHundred, FinancialCouncilInstance, FinancialCouncilMembershipInstance, GasToWeight, GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, MaxTipsOfPriority, - OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, RuntimeBlockLength, - RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, - TipPerWeightStep, ACA, AUSD, DOT, KSM, LCDOT, LDOT, + OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, RateLimiterId, Ratio, + RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, + TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, KSM, LCDOT, LDOT, }; use xcm::prelude::*; @@ -1835,6 +1835,16 @@ impl orml_parameters::Config for Runtime { type WeightInfo = (); } +impl orml_rate_limit::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type GovernanceOrigin = EnsureRootOrOneThirdsTechnicalCommittee; + type RateLimiterId = RateLimiterId; + type MaxWhitelistFilterCount = ConstU32<3>; + type UnixTime = Timestamp; + type BlockNumberProvider = System; + type WeightInfo = (); +} + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] pub struct ConvertEthereumTx; @@ -1985,6 +1995,7 @@ construct_runtime!( Scheduler: pallet_scheduler = 2, TransactionPause: module_transaction_pause = 3, Preimage: pallet_preimage = 4, + RateLimit: orml_rate_limit = 9, // Tokens & Related Balances: pallet_balances = 10, diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 237b7a4454..f4fdced3ae 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -19,8 +19,8 @@ use super::{ constants::fee::*, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, NativeTokenExistentialDeposit, - ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TreasuryAccount, - UnknownTokens, XcmpQueue, ACA, + ParachainInfo, ParachainSystem, PolkadotXcm, RateLimit, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + TreasuryAccount, UnknownTokens, XcmpQueue, ACA, }; pub use cumulus_primitives_core::ParaId; pub use frame_support::{ @@ -39,7 +39,7 @@ use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use primitives::evm::is_system_contract; use runtime_common::{ local_currency_location, native_currency_location, xcm_impl::AccountKey20Aliases, AcalaDropAssets, - EnsureRootOrHalfGeneralCouncil, EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, + EnsureRootOrHalfGeneralCouncil, EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RateLimiterId, }; use xcm::{prelude::*, v3::Weight as XcmWeight}; pub use xcm_builder::{ @@ -373,6 +373,7 @@ impl Convert for AccountIdToMultiLocation { parameter_types! { pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; + pub const XtokensRateLimiterId: RateLimiterId = RateLimiterId::XTokens; } parameter_type_with_key! { @@ -396,4 +397,6 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type MultiLocationsFilter = Everything; type ReserveProvider = AbsoluteReserveProvider; + type RateLimiter = RateLimit; + type RateLimiterId = XtokensRateLimiterId; } From e826cf6612175eeaf3184070b5fc2a3c9b5bf303 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Wed, 13 Dec 2023 11:37:54 +0800 Subject: [PATCH 2/2] update Cargo.toml --- runtime/acala/Cargo.toml | 2 +- runtime/karura/Cargo.toml | 2 +- runtime/mandala/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index 44bd612ed3..ddaf4d2d67 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -91,7 +91,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } -orml-rate-limit = { workspace = true, optional = true } +orml-rate-limit = { workspace = true } # modules module-aggregated-dex = { workspace = true } diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index a5e4e73f12..b038666652 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -91,7 +91,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } -orml-rate-limit = { workspace = true, optional = true } +orml-rate-limit = { workspace = true } # modules module-aggregated-dex = { workspace = true } diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 2410a393fb..9d44b94016 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -96,7 +96,7 @@ orml-vesting = { workspace = true } orml-xcm = { workspace = true } orml-xcm-support = { workspace = true } orml-xtokens = { workspace = true } -orml-rate-limit = { workspace = true, optional = true } +orml-rate-limit = { workspace = true } # modules module-transaction-pause = { workspace = true }