1. Entry: https://sourcegraph.com/github.com/paritytech/[email protected]/-/blob/xcm/xcm-executor/src/lib.rs?L68&subtree=true

  2. XCM Barrier: https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-executor/src/lib.rs?L113&subtree=true

    1. If all barriers failed, print log and return error:

      log::debug!(
          target: "xcm::execute_xcm_in_credit",
          "Barrier blocked execution! Error: {:?}. (origin: {:?}, message: {:?}, weight_limit: {:?}, weight_credit: {:?})",
          e,
          origin,
          message,
          weight_limit,
          weight_credit,
      );
      
      such as:
      xcm::execute_xcm_in_credit: [Relaychain] Barrier blocked execution!Error: ().
      
      
  3. should_execute trait: https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-executor/src/traits/should_execute.rs?L34&subtree=true#tab=references

    1. Implement trait for Tuple (Rust built-in type) https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-executor/src/traits/should_execute.rs?L43

      1. With this external crate https://docs.rs/impl-trait-for-tuples/latest/impl_trait_for_tuples/
      2. for_tuples!() call each barrier should_execute in Tuple
      for_tuples!( #(
      			match Tuple::should_execute(origin, message, max_weight, weight_credit) {
      				Ok(()) => return Ok(()),
      				_ => (),
      			}
      		)* );
      
  4. should_execute implementations, also types of barrier: https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-builder/src/barriers.rs?L32:5-32:19

    1. TakeWeightCredit
      1. allow XCM execution by local chain users via extrinsics
      2. takes max_weight from weight_credit weight_credit -= max_weight
    2. AllowTopLevelPaidExecutionFrom
      1. Only allows for TeleportAsset, WithdrawAsset, ClaimAsset and ReserveAssetDeposit XCMs
      2. Match first XCM message to TeleportAsset , WithdrawAsset, ClaimAsset and ReserveAssetDeposit
      3. Match ClearOrigin
      4. Match BuyExecution
    3. AllowUnpaidExecutionFrom
      1. Use only for executions from trusted origin groups.
      2. ensure!(T::contains(origin), ());
      3. For example: rococo barrier config AllowUnpaidExecutionFrom<IsInVec<AllowUnpaidFrom>> Only allow call origin is IsInVec<AllowUnpaidFrom>>
      4. In fact, this check is already performed in the previous step AllowTopLevelPaidExecutionFrom
    4. IsChildSystemParachain
      1. Allows a message only if it is from a system-level child parachain.
    5. AllowKnownQueryResponses
      1. Match QueryResponse and this QueryResponse is expected by ResponseHandler::expecting_response
    6. AllowSubscriptionsFrom
      1. Allows execution from origin if it is just a straight SubscribeVerison or UnsubscribeVersion instruction.
      2. Match SubscribeVerison or UnsubscribeVersion
      3. Sync XCM version
  5. Rococo barrier config: https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/runtime/rococo/src/xcm_config.rs?L112&subtree=true

    use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit};
    pub type Barrier = (
        TakeWeightCredit,
        AllowTopLevelPaidExecutionFrom<Everything>,
        AllowUnpaidExecutionFrom<IsInVec<AllowUnpaidFrom>>, // <- Trusted parachains get free execution
        // Expected responses are OK.
        AllowKnownQueryResponses<XcmPallet>,
        // Subscriptions for version tracking are OK.
        AllowSubscriptionsFrom<Everything>,
    );
    
    
  6. Moonbeam barrier config: https://sourcegraph.com/github.com/PureStake/moonbeam@8369da6dd073e1dc757deda2a778648c15c8298e/-/blob/runtime/moonbase/src/xcm_config.rs?L223

    pub type XcmBarrier = (
        TakeWeightCredit,
        AllowTopLevelPaidExecutionFrom<Everything>,
        AllowKnownQueryResponses<PolkadotXcm>,
        // Subscriptions for version tracking are OK.
        AllowSubscriptionsFrom<Everything>,
    );
     
    
  7. If pass barrier, XcmExecutor.execute will execute XCM instructions https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-executor/src/lib.rs?L131&subtree=true

    1. execute will print log: https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-executor/src/lib.rs?L187:9&subtree=true
    xcm::execute: [🌗] origin: ...
    
  8. After execute, print log xcm::execute_xcm_in_credit https://sourcegraph.com/github.com/paritytech/polkadot@ef71ed8baef3007b039cdf040d24f5958edb390b/-/blob/xcm/xcm-executor/src/lib.rs?L131&subtree=true

xcm::execute_xcm_in_credit: [🌗] result: Ok(())