XCM: Implement a blocking barrier (#7098)

* Move XCM matcher to xcm-builder

* Use ProcessMessageError as the error type in MatchXcm and ShouldExecute

* Implement a blocking barrier

* Fixes

* Add benchmarking for force_suspension

* ".git/.scripts/commands/bench/bench.sh" runtime westend pallet_xcm

* ".git/.scripts/commands/bench/bench.sh" runtime rococo pallet_xcm

* ".git/.scripts/commands/bench/bench.sh" runtime kusama pallet_xcm

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot pallet_xcm

* ".git/.scripts/commands/bench/bench.sh" runtime westend pallet_xcm

* ".git/.scripts/commands/bench/bench.sh" runtime rococo pallet_xcm

---------

Co-authored-by: command-bot <>
This commit is contained in:
Keith Yeung
2023-04-27 18:22:39 +08:00
committed by GitHub
parent 1125655024
commit d20e3c1145
18 changed files with 644 additions and 444 deletions
+27 -5
View File
@@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use crate::{barriers::AllowSubscriptionsFrom, test_utils::*};
use crate::{
barriers::{AllowSubscriptionsFrom, RespectSuspension},
test_utils::*,
};
pub use crate::{
AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowTopLevelPaidExecutionFrom,
AllowUnpaidExecutionFrom, FixedRateOfFungible, FixedWeightBounds, TakeWeightCredit,
@@ -32,7 +35,7 @@ pub use frame_support::{
pub use parity_scale_codec::{Decode, Encode};
pub use sp_io::hashing::blake2_256;
pub use sp_std::{
cell::RefCell,
cell::{Cell, RefCell},
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
fmt::Debug,
marker::PhantomData,
@@ -40,8 +43,8 @@ pub use sp_std::{
pub use xcm::latest::{prelude::*, Weight};
pub use xcm_executor::{
traits::{
AssetExchange, AssetLock, ConvertOrigin, Enact, ExportXcm, FeeManager, FeeReason,
LockError, OnResponse, TransactAsset,
AssetExchange, AssetLock, CheckSuspension, ConvertOrigin, Enact, ExportXcm, FeeManager,
FeeReason, LockError, OnResponse, TransactAsset,
},
Assets, Config,
};
@@ -128,6 +131,7 @@ thread_local! {
) -> Result<XcmHash, SendError>,
)>> = RefCell::new(None);
pub static SEND_PRICE: RefCell<MultiAssets> = RefCell::new(MultiAssets::new());
pub static SUSPENDED: Cell<bool> = Cell::new(false);
}
pub fn sent_xcm() -> Vec<(MultiLocation, opaque::Xcm, XcmHash)> {
SENT_XCM.with(|q| (*q.borrow()).clone())
@@ -419,6 +423,24 @@ parameter_types! {
pub static MaxInstructions: u32 = 100;
}
pub struct TestSuspender;
impl CheckSuspension for TestSuspender {
fn is_suspended<Call>(
_origin: &MultiLocation,
_instructions: &mut [Instruction<Call>],
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> bool {
SUSPENDED.with(|s| s.get())
}
}
impl TestSuspender {
pub fn set_suspended(suspended: bool) {
SUSPENDED.with(|s| s.set(suspended));
}
}
pub type TestBarrier = (
TakeWeightCredit,
AllowKnownQueryResponses<TestResponseHandler>,
@@ -629,7 +651,7 @@ impl Config for TestConfig {
type IsReserve = TestIsReserve;
type IsTeleporter = TestIsTeleporter;
type UniversalLocation = ExecutorUniversalLocation;
type Barrier = TestBarrier;
type Barrier = RespectSuspension<TestBarrier, TestSuspender>;
type Weigher = FixedWeightBounds<UnitWeightCost, TestCall, MaxInstructions>;
type Trader = FixedRateOfFungible<WeightPrice, ()>;
type ResponseHandler = TestResponseHandler;