Skip to content
Snippets Groups Projects
  1. Aug 24, 2024
  2. Aug 23, 2024
    • Branislav Kontur's avatar
      [bridges] Prune messages from confirmation tx body, not from the on_idle (#5006) · e4ffba6e
      Branislav Kontur authored
      
      (Please, do not merge until SA, reverted and restored of
      https://github.com/paritytech/polkadot-sdk/pull/4944)
      
      Original PR with more context:
      https://github.com/paritytech/parity-bridges-common/pull/2211
      Relates to:
      https://github.com/paritytech/parity-bridges-common/issues/2210
      
      ## TODO
      
      - [x] fresh weighs for `pallet_bridge_messages`
      - [x] add `try_state` for `pallet_bridge_messages` which checks for
      unpruned messages - relates to the
      [comment](https://github.com/paritytech/parity-bridges-common/pull/2211#issuecomment-1643224831)
      - [x] ~prepare migration, that prunes leftovers, which would be pruned
      eventually from `on_idle` the
      [comment](https://github.com/paritytech/parity-bridges-common/pull/2211#issuecomment-1643224831)~
      can be done also by `set_storage` / `kill_storage` or with
      `OnRuntimeUpgrade` implementatino when `do_try_state_for_outbound_lanes`
      detects problem.
      
      ## Open question
      
      - [ ] Do we really need `oldest_unpruned_nonce` afterwards?
      - after the runtime upgrade and when `do_try_state_for_outbound_lanes`
      pass, we won't need any migrations here
          - we won't even need `do_try_state_for_outbound_lanes`
      - please check comments bellow:
      https://github.com/paritytech/polkadot-sdk/pull/4944#discussion_r1666737961
      
      ---------
      
      Signed-off-by: default avatarBranislav Kontur <bkontur@gmail.com>
      Co-authored-by: default avatarSerban Iorga <serban@parity.io>
      Co-authored-by: default avatarSvyatoslav Nikolsky <svyatonik@gmail.com>
      Co-authored-by: command-bot <>
    • Nazar Mokrynskyi's avatar
      Remove the need to wait for target block header in warp sync implementation (#5431) · 6d819a61
      Nazar Mokrynskyi authored
      I'm not sure if this is exactly what
      https://github.com/paritytech/polkadot-sdk/issues/3537 meant, but I
      think it should be fine to wait for relay chain before initializing
      parachain node fully, which removed the need for background task and
      extra hacks throughout the stack just to know where warp sync should
      start.
      
      Previously there were both `WarpSyncParams` and `WarpSyncConfig`, but
      there was no longer any point in having two data structures, so I
      simplified it to just `WarpSyncConfig`.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/3537
  3. Aug 22, 2024
    • Dónal Murray's avatar
      Add the Polkadot Coretime chain-spec (#5436) · dce789dd
      Dónal Murray authored
      Add the Polkadot Coretime chain-spec to the directory with the other
      system chain-specs.
      
      This is the chain-spec used at genesis and for which the genesis head
      data was generated.
      
      It is also included in the assets for fellowship [release
      v1.3.0](https://github.com/polkadot-fellows/runtimes/releases/tag/v1.3.0)
  4. Aug 21, 2024
  5. Aug 18, 2024
  6. Aug 15, 2024
  7. Aug 14, 2024
    • Adrian Catangiu's avatar
      [tests] dedup test code, add more tests, improve naming and docs (#5338) · e4f8a6de
      Adrian Catangiu authored
      This is mostly tests cleanup:
      - uses helper macro for generating teleport tests,
      - adds missing treasury tests,
      - improves naming and docs for transfer tests.
      
      - [x] does not need a PRDOC
      
      ---------
      
      Co-authored-by: command-bot <>
    • Francisco Aguirre's avatar
      Migrate foreign assets v3::Location to v4::Location (#4129) · be74fe92
      Francisco Aguirre authored
      
      In the move from XCMv3 to XCMv4, the `AssetId` for `ForeignAssets` in
      `asset-hub-rococo` and `asset-hub-westend` was left as `v3::Location` to
      be later migrated to `v4::Location`.
      
      This is that migration PR.
      
      Because the encoding of `v3::Location` and `v4::Location` is the same,
      we don't need to do any data migration, the keys will still be
      decodable.
      The [original idea by
      Jan](https://github.com/paritytech/polkadot/pull/7236) was to make the
      v4 changes in v3 since the ABI (the encoding/decoding) didn't change.
      Corroborated the ABI is the same iterating over all storage, the code is
      on [another
      branch](https://github.com/paritytech/polkadot-sdk/blob/cisco-assert-v3-v4-encodings-equal/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs).
      
      We will need a data migration when we want to update from `v4::Location`
      to `v5::Location` because of [the accepted RFC changing the NetworkId
      enum](https://github.com/polkadot-fellows/RFCs/pull/108).
      I'll configure MBMs (Multi-Block Migrations) then and make the actual
      migration.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/4128
      
      ---------
      
      Signed-off-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
      Co-authored-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
      Co-authored-by: command-bot <>
  8. Aug 13, 2024
  9. Aug 12, 2024
  10. Aug 09, 2024
  11. Aug 07, 2024
  12. Aug 05, 2024
    • Alexandru Gheorghe's avatar
      make polkadot-parachain startup errors pretty (#5214) · 0cc3e170
      Alexandru Gheorghe authored
      
      The errors on polkadot-parachain are not printed with their full display
      context(what is marked with `#[error(`) because main returns plain
      Result and the error will be shown in its Debug format, that's not
      consistent with how the polkadot binary behave and is not user friendly
      since it does not tell them why they got the error.
      
      Fix it by using `color_eyre` as polkadot already does it. 
      
      Fixes: https://github.com/paritytech/polkadot-sdk/issues/5211
      
      ## Output before
      ```
      Error: NetworkKeyNotFound("/acala/data/Collator2/chains/mandala-tc9/network/secret_ed25519")
      ```
      
      ## Output after
      ```
      Error: 
         0: Starting an authorithy without network key in /home/alexggh/.local/share/polkadot-parachain/chains/asset-hub-kusama/network/secret_ed25519.
            
             This is not a safe operation because other authorities in the network may depend on your node having a stable identity.
            
             Otherwise these other authorities may not being able to reach you.
            
             If it is the first time running your node you could use one of the following methods:
            
             1. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --base-path <YOUR_BASE_PATH>
            
             2. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --file <YOUR_PATH_TO_NODE_KEY>
            
             3. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --default-base-path
            
             4. [Unsafe] Pass --unsafe-force-node-key-generation and make sure you remove it for subsequent node restarts
      
      ```
      
      ---------
      
      Signed-off-by: default avatarAlexandru Gheorghe <alexandru.gheorghe@parity.io>
    • Sergej Sakac's avatar
      Coretime auto-renew (#4424) · f170af61
      Sergej Sakac authored
      
      This PR adds functionality that allows tasks to enable auto-renewal.
      Each task eligible for renewal can enable auto-renewal.
      
      A new storage value is added to track all the cores with auto-renewal
      enabled and the associated task running on the core. The `BoundedVec` is
      sorted by `CoreIndex` to make disabling auto-renewal more efficient.
      
      Cores are renewed at the start of a new bulk sale. If auto-renewal
      fails(e.g. due to the sovereign account of the task not holding
      sufficient balance), an event will be emitted, and the renewal will
      continue for the other cores.
      
      The two added extrinsics are:
      - `enable_auto_renew`: Extrinsic for enabling auto renewal.
      - `disable_auto_renew`: Extrinsic for disabling auto renewal.
      
      TODOs:
      - [x] Write benchmarks for the newly added extrinsics.
      
      Closes: #4351
      
      ---------
      
      Co-authored-by: default avatarDónal Murray <donalm@seadanda.dev>
  13. Aug 02, 2024
    • Francisco Aguirre's avatar
      Add an adapter for configuring AssetExchanger (#5130) · 8ccb6b33
      Francisco Aguirre authored
      
      Added a new adapter to xcm-builder, the `SingleAssetExchangeAdapter`.
      This adapter makes it easy to use `pallet-asset-conversion` for
      configuring the `AssetExchanger` XCM config item.
      
      I also took the liberty of adding a new function to the `AssetExchange`
      trait, with the following signature:
      
      ```rust
      fn quote_exchange_price(give: &Assets, want: &Assets, maximal: bool) -> Option<Assets>;
      ```
      
      The signature is meant to be fairly symmetric to that of
      `exchange_asset`.
      The way they interact can be seen in the doc comment for it in the
      `AssetExchange` trait.
      
      This is a breaking change but is needed for
      https://github.com/paritytech/polkadot-sdk/pull/5131.
      Another idea is to create a new trait for this but that would require
      setting it in the XCM config which is also breaking.
      
      Old PR: https://github.com/paritytech/polkadot-sdk/pull/4375.
      
      ---------
      
      Co-authored-by: default avatarAdrian Catangiu <adrian@parity.io>
  14. Jul 30, 2024
  15. Jul 29, 2024
    • girazoki's avatar
      add possibility to inject non-authorities session-keys in genesis (#5078) · d6f59871
      girazoki authored
      
      Add the possibility of injecting session-keys in genesis for
      non-validators. Currently all keys injected in genesis were considered
      as part of the initial validators set, this PR allows to inject a new
      vector with non-authority keys
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
    • dependabot[bot]'s avatar
      Bump serde_json from 1.0.120 to 1.0.121 in the known_good_semver group (#5169) · 4def82e7
      dependabot[bot] authored
      
      Bumps the known_good_semver group with 1 update:
      [serde_json](https://github.com/serde-rs/json).
      
      Updates `serde_json` from 1.0.120 to 1.0.121
      <details>
      <summary>Release notes</summary>
      <p><em>Sourced from <a
      href="https://github.com/serde-rs/json/releases">serde_json's
      releases</a>.</em></p>
      <blockquote>
      <h2>v1.0.121</h2>
      <ul>
      <li>Optimize position search in error path (<a
      href="https://redirect.github.com/serde-rs/json/issues/1160">#1160</a>,
      thanks <a
      href="https://github.com/purplesyringa"><code>@​purplesyringa</code></a>)</li>
      </ul>
      </blockquote>
      </details>
      <details>
      <summary>Commits</summary>
      <ul>
      <li><a
      href="https://github.com/serde-rs/json/commit/eca2658a22cb39952783cb6914eb18242659f66a"><code>eca2658</code></a>
      Release 1.0.121</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/b0d678cfb473386830d559b6ab255d9e21ba39c5"><code>b0d678c</code></a>
      Merge pull request <a
      href="https://redirect.github.com/serde-rs/json/issues/1160">#1160</a>
      from iex-rs/efficient-position</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/b1edc7d13f72880fd0ac569403a409e5f7961d5f"><code>b1edc7d</code></a>
      Optimize position search in error path</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/40dd7f5e862436f02471fe076f3486c55e472bc2"><code>40dd7f5</code></a>
      Merge pull request <a
      href="https://redirect.github.com/serde-rs/json/issues/1159">#1159</a>
      from iex-rs/fix-recursion</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/6a306e6ee9f47f3b37088217ffe3ebe9bbb54e5a"><code>6a306e6</code></a>
      Move call to tri! out of check_recursion!</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/3f1c6de4af28b1f6c5100da323f2bffaf7c2083f"><code>3f1c6de</code></a>
      Ignore byte_char_slices clippy lint in test</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/3fd6f5f49dc1c732d9b1d7dfece4f02c0d440d39"><code>3fd6f5f</code></a>
      Merge pull request <a
      href="https://redirect.github.com/serde-rs/json/issues/1153">#1153</a>
      from dpathakj/master</li>
      <li><a
      href="https://github.com/serde-rs/json/commit/fcb5e83e44abe0f9c27c755a240a6ad56312c090"><code>fcb5e83</code></a>
      Correct documentation URL for Value's Index impl.</li>
      <li>See full diff in <a
      href="https://github.com/serde-rs/json/compare/v1.0.120...v1.0.121">compare
      view</a></li>
      </ul>
      </details>
      <br />
      
      
      [![Dependabot compatibility
      score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=serde_json&package-manager=cargo&previous-version=1.0.120&new-version=1.0.121)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
      
      Dependabot will resolve any conflicts with this PR as long as you don't
      alter it yourself. You can also trigger a rebase manually by commenting
      `@dependabot rebase`.
      
      [//]: # (dependabot-automerge-start)
      [//]: # (dependabot-automerge-end)
      
      ---
      
      <details>
      <summary>Dependabot commands and options</summary>
      <br />
      
      You can trigger Dependabot actions by commenting on this PR:
      - `@dependabot rebase` will rebase this PR
      - `@dependabot recreate` will recreate this PR, overwriting any edits
      that have been made to it
      - `@dependabot merge` will merge this PR after your CI passes on it
      - `@dependabot squash and merge` will squash and merge this PR after
      your CI passes on it
      - `@dependabot cancel merge` will cancel a previously requested merge
      and block automerging
      - `@dependabot reopen` will reopen this PR if it is closed
      - `@dependabot close` will close this PR and stop Dependabot recreating
      it. You can achieve the same result by closing it manually
      - `@dependabot show <dependency name> ignore conditions` will show all
      of the ignore conditions of the specified dependency
      - `@dependabot ignore <dependency name> major version` will close this
      group update PR and stop Dependabot creating any more for the specific
      dependency's major version (unless you unignore this specific
      dependency's major version or upgrade to it yourself)
      - `@dependabot ignore <dependency name> minor version` will close this
      group update PR and stop Dependabot creating any more for the specific
      dependency's minor version (unless you unignore this specific
      dependency's minor version or upgrade to it yourself)
      - `@dependabot ignore <dependency name>` will close this group update PR
      and stop Dependabot creating any more for the specific dependency
      (unless you unignore this specific dependency or upgrade to it yourself)
      - `@dependabot unignore <dependency name>` will remove all of the ignore
      conditions of the specified dependency
      - `@dependabot unignore <dependency name> <ignore condition>` will
      remove the ignore condition of the specified dependency and ignore
      conditions
      
      
      </details>
      
      ---------
      
      Signed-off-by: default avatardependabot[bot] <support@github.com>
      Co-authored-by: default avatardependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      Co-authored-by: default avatarBastian Köcher <info@kchr.de>
  16. Jul 26, 2024
  17. Jul 25, 2024
    • Dónal Murray's avatar
      Add people polkadot genesis chainspec (#5124) · d6f7f495
      Dónal Murray authored
      Published as part of the fellowship
      [v1.2.6](https://github.com/polkadot-fellows/runtimes/releases/tag/v1.2.6)
      release and originally intentionally left out of the repo as the
      hardcoded system chains will soon be removed from the
      `polkadot-parachain`.
      
      After a conversation in
      https://github.com/paritytech/polkadot-sdk/issues/5112 it was pointed
      out by @josepot that there should be a single authoritative source for
      these chainspecs. Since this is already the place for these it will
      serve until something more fitting can be worked out.
    • Branislav Kontur's avatar
      Bridges improved tests and nits (#5128) · de6733ba
      Branislav Kontur authored
      
      This PR adds `exporter_is_compatible_with_pallet_xcm_bridge_hub_router`,
      which ensures that our `pallet_xcm_bridge_hub` and
      `pallet_xcm_bridge_hub_router` are compatible when handling
      `ExportMessage`. Other changes are just small nits and cosmetics which
      makes others stuff easier.
      
      ---------
      
      Co-authored-by: default avatarSvyatoslav Nikolsky <svyatonik@gmail.com>
  18. Jul 24, 2024
    • Muharem Ismailov's avatar
      Tx Payment: drop ED requirements for tx payments with exchangeable asset (#4488) · 5878ea27
      Muharem Ismailov authored
      Drop the Existential Deposit (ED) requirement for the asset amount
      exchangeable for the fee asset (eg. DOT/KSM) during transaction
      payments.
      
      This achieved by using `SwapCredit` implementation of swap, which works
      with imbalances and does not require a temporary balance account within
      the transaction payment.
      
      ### Problem
      Currently, every swap during transaction payment, processed with asset
      `A` for native asset, must be for an amount greater than the ED of a
      native asset if the user lacks a native asset account. Since fees are
      typically smaller, the current implementation necessitates additional
      swaps to meet the ED during `pre_dispatch`, with refunds for excess ED
      swap occurring during `post_dispatch`. Further details can be found
      [here](https://github.com/paritytech/polkadot-sdk/blob/115c2477
      
      /substrate/frame/transaction-payment/asset-conversion-tx-payment/src/payment.rs#L115).
      
      This setup presents an issue where a user is unable to transfer their
      entire balance and close the account. Instead, the user must transfer
      slightly less of asset `A` to ensure there is enough not only for the
      fee payment but also some extra to meet the ED requirement for their
      native account during `pre_dispatch`. In some cases during
      `post_dispatch`, the user will have the excess ED swapped back to asset
      `A`, while in other cases, it may not be sufficient to meet the ED
      requirement for asset `A`, leading it being left in the user's
      'temporary' native asset account.
      
      ---------
      
      Co-authored-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  19. Jul 23, 2024
    • Alexandru Vasile's avatar
      network/metrics: Expose number of banned peers from peerstore and enable litep2p metrics (#4977) · 7f905e28
      Alexandru Vasile authored
      
      This PR extends the metrics exposed by the peerstore with the total
      number of banned peers.
      
      The new metric is exposed under
      `substrate_sub_libp2p_peerset_num_banned_peers`.
      
      To easily extend metrics in the future, the `fn num_known_peers` is
      removed in favor of `fn status`.
      
      While at it, enable the metrics for litep2p:
      - total number of peers from peerstore (needed to debug memory
      consumption)
      - total number of banned peers from peerstore (needed to debug
      reputation bans and disconnects)
      
      Have added a couple of tests to validate that the number of banned peers
      is exposed properly.
      
      Part of: https://github.com/paritytech/polkadot-sdk/issues/4681
      
      
      ### Testing Done
      Using [subp2p-explorer](https://github.com/lexnv/subp2p-explorer) have
      submitted random data on tx protocol.
      The peer gets banned, the num of banned peers is incremented then the
      peer is disconnected.
      
      cc @paritytech/networking
      
      ---------
      
      Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
      Co-authored-by: default avatarDmitry Markin <dmitry@markin.tech>
    • polka.dom's avatar
      Remove pallet::getter macro from pallet-identity (#4586) · 9974a68c
      polka.dom authored
      
      As per #3326, removes pallet::getter macro usage from the
      pallet-identity. The syntax `StorageItem::<T, I>::get()` should be used
      instead.
      
      Also makes all storage values public
      
      cc @muraca
      
      ---------
      
      Co-authored-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      Co-authored-by: command-bot <>
    • Jun Jiang's avatar
      Replace all ansi_term crates (#2923) · bbb86686
      Jun Jiang authored
      
      Now Polkadot-SDK is ansi_term free
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
    • Muharem Ismailov's avatar
      Make `on_unbalanceds` work with `fungibles` `imbalances` (#4564) · 6d0926e2
      Muharem Ismailov authored
      Make `on_unbalanceds` work with `fungibles` `imbalances`.
      
      The `fungibles` `imbalances` cannot be handled by the default
      implementation of `on_unbalanceds` from the `OnUnbalanced` trait. This
      is because the `fungibles` `imbalances` types do not implement the
      `Imbalance` trait (and cannot with its current semantics). The
      `on_unbalanceds` function requires only the `merge` function for the
      imbalance type. In this PR, we provide the `TryMerge` trait, which can
      be implemented by all imbalance types and make `OnUnbalanced` require it
      instead `Imbalance`.
      
      ### Migration for `OnUnbalanced` trait implementations:
      In case if you have a custom implementation of `on_unbalanceds` trait
      function, remove it's `<B>` type argument.
      
      ### Migration for custom imbalance types:
      If you have your own imbalance types implementations, implement the
      `TryMerge` trait for it introduced with this update.
              
      The applicability of the `on_unbalanceds` function to fungibles
      imbalances is useful in cases like -
      [link](https://github.com/paritytech/polkadot-sdk/blob/3a8e675e
      
      /substrate/frame/transaction-payment/asset-conversion-tx-payment/src/payment.rs#L267)
      from https://github.com/paritytech/polkadot-sdk/pull/4488.
      
      ---------
      
      Co-authored-by: default avatarOliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  20. Jul 19, 2024
    • Bastian Köcher's avatar
      Implements `PoV` export and local validation (#4640) · d649746e
      Bastian Köcher authored
      This pull requests adds a new CLI flag to `polkadot-parachains`
      `--export-pov-to-path`. This CLI flag will instruct the node to export
      any `PoV` that it build locally to export to the given folder. Then
      these `PoV` files can be validated using the introduced
      `cumulus-pov-validator`. The combination of export and validation can be
      used for debugging parachain validation issues that may happen on the
      relay chain.
    • Joseph Zhao's avatar
      Backport claim assets tests from polkadot-fellows repo (#4930) · d16af0b8
      Joseph Zhao authored
      
      # Issue
      [Backport integration tests for claim assets to the polkadot-sdk from
      polkadot-fellows repo
      #4892](https://github.com/paritytech/polkadot-sdk/issues/4892)
      # Description
      For the first time to contribute this project, I just finished part and
      make sure everything is ok.
      - [x] backport [claim_assets test
      case](https://github.com/polkadot-fellows/runtimes/blob/main/integration-tests/emulated/tests/assets/asset-hub-kusama/src/tests/claim_assets.rs)
      to the polkadot-sdk testnet integration tests
      - [x] backport macro
      [test_chain_can_claim_assets](https://github.com/polkadot-fellows/runtimes/blob/main/integration-tests/emulated/helpers/src/lib.rs#L218)
      from fellows repo
      - [ ] when merged to polkadot-sdk and released, make sure that it is
      propagated to the fellows repo:
      https://github.com/polkadot-fellows/runtimes/issues/363
      - [x] backport and align other macros/test-cases from
      https://github.com/polkadot-fellows/runtimes/blob/8ec28f96eeb30fbba30d29006d75e1a3fa1cea1c/integration-tests/emulated/helpers/src/lib.rs#L31-L33
      
      ---------
      
      Co-authored-by: default avatarZihan Zhao <josephzhao@Zihans-MacBook-Pro-3.local>
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarAdrian Catangiu <adrian@parity.io>
      Co-authored-by: default avatarFrancisco Aguirre <franciscoaguirreperez@gmail.com>
    • Özgün Özerk's avatar
      relax `XcmFeeToAccount` trait bound on `AccountId` (#4959) · f8f70b37
      Özgün Özerk authored
      Fixes #4960 
      
      Configuring `FeeManager` enforces the boundary `Into<[u8; 32]>` for the
      `AccountId` type.
      
      Here is how it works currently: 
      
      Configuration:
      ```rust
          type FeeManager = XcmFeeManagerFromComponents<
              IsChildSystemParachain<primitives::Id>,
              XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
          >;
      ```
      
      `XcmToFeeAccount` struct:
      ```rust
      /// A `HandleFee` implementation that simply deposits the fees into a specific on-chain
      /// `ReceiverAccount`.
      ///
      /// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If
      /// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be
      /// logged and the fee burned.
      pub struct XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>(
      	PhantomData<(AssetTransactor, AccountId, ReceiverAccount)>,
      );
      
      impl<
      		AssetTransactor: TransactAsset,
      		AccountId: Clone + Into<[u8; 32]>,
      		ReceiverAccount: Get<AccountId>,
      	> HandleFee for XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>
      {
      	fn handle_fee(fee: Assets, context: Option<&XcmContext>, _reason: FeeReason) -> Assets {
      		deposit_or_burn_fee::<AssetTransactor, _>(fee, context, ReceiverAccount::get());
      
      		Assets::new()
      	}
      }
      ```
      
      `deposit_or_burn_fee()` function:
      ```rust
      /// Try to deposit the given fee in the specified account.
      /// Burns the fee in case of a failure.
      pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 32]>>(
      	fee: Assets,
      	context: Option<&XcmContext>,
      	receiver: AccountId,
      ) {
      	let dest = AccountId32 { network: None, id: receiver.into() }.into();
      	for asset in fee.into_inner() {
      		if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) {
      			log::trace!(
      				target: "xcm::fees",
      				"`AssetTransactor::deposit_asset` returned error: {:?}. Burning fee: {:?}. \
      				They might be burned.",
      				e, asset,
      			);
      		}
      	}
      }
      ```
      
      ---
      
      In order to use **another** `AccountId` type (for example, 20 byte
      addresses for compatibility with Ethereum or Bitcoin), one has to
      duplicate the code as the following (roughly changing every `32` to
      `20`):
      ```rust
      /// A `HandleFee` implementation that simply deposits the fees into a specific on-chain
      /// `ReceiverAccount`.
      ///
      /// It reuses the `AssetTransactor` configured on the XCM executor to deposit fee assets. If
      /// the `AssetTransactor` returns an error while calling `deposit_asset`, then a warning will be
      /// logged and the fee burned.
      pub struct XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>(
          PhantomData<(AssetTransactor, AccountId, ReceiverAccount)>,
      );
      impl<
              AssetTransactor: TransactAsset,
              AccountId: Clone + Into<[u8; 20]>,
              ReceiverAccount: Get<AccountId>,
          > HandleFee for XcmFeeToAccount<AssetTransactor, AccountId, ReceiverAccount>
      {
          fn handle_fee(fee: XcmAssets, context: Option<&XcmContext>, _reason: FeeReason) -> XcmAssets {
              deposit_or_burn_fee::<AssetTransactor, _>(fee, context, ReceiverAccount::get());
      
              XcmAssets::new()
          }
      }
      
      pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + Into<[u8; 20]>>(
          fee: XcmAssets,
          context: Option<&XcmContext>,
          receiver: AccountId,
      ) {
          let dest = AccountKey20 { network: None, key: receiver.into() }.into();
          for asset in fee.into_inner() {
              if let Err(e) = AssetTransactor::deposit_asset(&asset, &dest, context) {
                  log::trace!(
                      target: "xcm::fees",
                      "`AssetTransactor::deposit_asset` returned error: {:?}. Burning fee: {:?}. \
                      They might be burned.",
                      e, asset,
                  );
              }
          }
      }
      ```
      
      ---
      
      This results in code duplication, which can be avoided simply by
      relaxing the trait enforced by `XcmFeeToAccount`.
      
      In this PR, I propose to introduce a new trait called `IntoLocation` to
      be able to express both `Into<[u8; 32]>` and `Into<[u8; 20]>` should be
      accepted (and every other `AccountId` type as long as they implement
      this trait).
      
      Currently, `deposit_or_burn_fee()` function converts the `receiver:
      AccountId` to a location. I think converting an account to `Location`
      should not be the responsibility of `deposit_or_burn_fee()` function.
      
      This trait also decouples the conversion of `AccountId` to `Location`,
      from `deposit_or_burn_fee()` function. And exposes `IntoLocation` trait.
      Thus, allowing everyone to come up with their `AccountId` type and make
      it compatible for configuring `FeeManager`.
      
      ---
      
      Note 1: if there is a better file/location to put `IntoLocation`, I'm
      all ears
      
      Note 2: making `deposit_or_burn_fee` or `XcmToFeeAccount` generic was
      not possible from what I understood, due to Rust currently do not
      support a way to express the generic should implement either `trait A`
      or `trait B` (since the compiler cannot guarantee they won't overlap).
      In this case, they are `Into<[u8; 32]>` and `Into<[u8; 20]>`.
      See [this](https://github.com/rust-lang/rust/issues/20400) and
      [this](https://github.com/rust-lang/rfcs/pull/1672#issuecomment-262152934).
      
      Note 3: I should also submit a PR to `frontier` that implements
      `IntoLocation` for `AccountId20` if this PR gets accepted.
      
      
      ### Summary 
      this new trait:
      - decouples the conversion of `AccountId` to `Location`, from
      `deposit_or_burn_fee()` function
      - makes `XcmFeeToAccount` accept every possible `AccountId` type as long
      as they they implement `IntoLocation`
      - backwards compatible
      - keeps the API simple and clean while making it less restrictive
      
      
      @franciscoaguirre and @gupnik
      
       are already aware of the issue, so tagging
      them here for visibility.
      
      ---------
      
      Co-authored-by: default avatarFrancisco Aguirre <franciscoaguirreperez@gmail.com>
      Co-authored-by: default avatarBranislav Kontur <bkontur@gmail.com>
      Co-authored-by: default avatarAdrian Catangiu <adrian@parity.io>
      Co-authored-by: command-bot <>
  21. Jul 17, 2024