Skip to content

Commit

Permalink
XCM V5 - Backport SetHints instruction (#6566) (#6809)
Browse files Browse the repository at this point in the history
Backporting #6566 to stable2412

Last feature we wanted for V5, changing `SetAssetClaimer` to be just one
of many possible "hints" that you can specify at the beginning of your
program to change its behaviour.

This makes it easier to add new hints in the future and have barriers
accept them.

---------

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
franciscoaguirre and actions-user authored Dec 11, 2024
1 parent 2f20a64 commit 3ba7dbf
Show file tree
Hide file tree
Showing 43 changed files with 585 additions and 274 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ impl<H: Hasher> CacheProvider<H> {
}

impl<H: Hasher> TrieCacheProvider<H> for CacheProvider<H> {
type Cache<'a> = TrieCache<'a, H> where H: 'a;
type Cache<'a>
= TrieCache<'a, H>
where
H: 'a;

fn as_trie_db_cache(&self, storage_root: <H as Hasher>::Out) -> Self::Cache<'_> {
TrieCache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ impl<H: Hasher> SizeOnlyRecorderProvider<H> {
}

impl<H: trie_db::Hasher> sp_trie::TrieRecorderProvider<H> for SizeOnlyRecorderProvider<H> {
type Recorder<'a> = SizeOnlyRecorder<'a, H> where H: 'a;
type Recorder<'a>
= SizeOnlyRecorder<'a, H>
where
H: 'a;

fn drain_storage_proof(self) -> Option<StorageProof> {
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_set_asset_claimer_within_a_chain() {

type RuntimeCall = <AssetHubWestend as Chain>::RuntimeCall;
let asset_trap_xcm = Xcm::<RuntimeCall>::builder_unsafe()
.set_asset_claimer(bob_location.clone())
.set_hints(vec![AssetClaimer { location: bob_location.clone() }])
.withdraw_asset(assets.clone())
.clear_origin()
.build();
Expand Down Expand Up @@ -116,7 +116,7 @@ fn test_set_asset_claimer_between_the_chains() {
let assets: Assets = (Parent, trap_amount).into();
type RuntimeCall = <BridgeHubWestend as Chain>::RuntimeCall;
let trap_xcm = Xcm::<RuntimeCall>::builder_unsafe()
.set_asset_claimer(alice_bh_sibling.clone())
.set_hints(vec![AssetClaimer { location: alice_bh_sibling.clone() }])
.withdraw_asset(assets.clone())
.clear_origin()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use alloc::vec::Vec;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -176,8 +177,16 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 5_803_000 picoseconds.
Weight::from_parts(5_983_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use alloc::vec::Vec;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -176,8 +177,16 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 5_580_000 picoseconds.
Weight::from_parts(5_950_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use codec::Encode;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -257,8 +258,16 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 1_085_000 picoseconds.
Weight::from_parts(1_161_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use codec::Encode;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -178,8 +179,16 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 995_000 picoseconds.
Weight::from_parts(1_060_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use alloc::vec::Vec;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -255,8 +256,16 @@ impl<Call> XcmWeightInfo<Call> for CoretimeRococoXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 650_000 picoseconds.
Weight::from_parts(673_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use alloc::vec::Vec;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -176,8 +177,16 @@ impl<Call> XcmWeightInfo<Call> for CoretimeWestendXcmWeight<Call> {
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 624_000 picoseconds.
Weight::from_parts(659_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use alloc::vec::Vec;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -254,8 +255,16 @@ impl<Call> XcmWeightInfo<Call> for PeopleRococoXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 685_000 picoseconds.
Weight::from_parts(757_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use alloc::vec::Vec;
use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::{
latest::{prelude::*, AssetTransferFilter},
DoubleEncoded,
Expand Down Expand Up @@ -254,8 +255,16 @@ impl<Call> XcmWeightInfo<Call> for PeopleWestendXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 598_000 picoseconds.
Weight::from_parts(655_000, 0)
}
pub fn set_asset_claimer() -> Weight {
pub fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
13 changes: 11 additions & 2 deletions polkadot/runtime/rococo/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use xcm::{latest::prelude::*, DoubleEncoded};

use pallet_xcm_benchmarks_fungible::WeightInfo as XcmBalancesWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use sp_runtime::BoundedVec;
use xcm::latest::AssetTransferFilter;

/// Types of asset supported by the Rococo runtime.
Expand Down Expand Up @@ -290,8 +291,16 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for RococoXcmWeight<RuntimeCall> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
fn set_hints(hints: &BoundedVec<Hint, HintNumVariants>) -> Weight {
let mut weight = Weight::zero();
for hint in hints {
match hint {
AssetClaimer { .. } => {
weight = weight.saturating_add(XcmGeneric::<Runtime>::asset_claimer());
},
}
}
weight
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<RuntimeCall>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 2_899_000 picoseconds.
Weight::from_parts(3_090_000, 0)
}
pub(crate) fn set_asset_claimer() -> Weight {
pub(crate) fn asset_claimer() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
Expand Down
Loading

0 comments on commit 3ba7dbf

Please sign in to comment.