Skip to content

Commit

Permalink
XCM V5 - SetHints instruction (paritytech#6566)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
franciscoaguirre and actions-user authored Dec 8, 2024
1 parent 526a440 commit 906fa9e
Show file tree
Hide file tree
Showing 40 changed files with 559 additions and 269 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.

4 changes: 2 additions & 2 deletions bridges/snowbridge/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn test_submit_happy_path() {
.into(),
nonce: 1,
message_id: [
97, 161, 116, 204, 182, 115, 192, 144, 130, 243, 240, 193, 122, 154, 108, 91, 247,
41, 226, 237, 202, 158, 238, 239, 210, 8, 147, 131, 84, 146, 171, 176,
86, 101, 80, 125, 84, 10, 227, 145, 230, 209, 152, 38, 206, 251, 206, 208, 244,
221, 22, 215, 1, 252, 79, 181, 99, 207, 166, 220, 98, 3, 81, 7,
],
fee_burned: 110000000000,
}
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
15 changes: 11 additions & 4 deletions polkadot/runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use xcm::{

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 westend runtime.
Expand Down Expand Up @@ -208,11 +209,17 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
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 @@ -82,7 +82,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 3_096_000 picoseconds.
Weight::from_parts(3_313_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 906fa9e

Please sign in to comment.