From 2d9b54b03d77f5ee391d6508b269e378b843df4d Mon Sep 17 00:00:00 2001 From: Gav Date: Mon, 28 Aug 2023 13:58:58 +0100 Subject: [PATCH 1/3] Put `GetWeight` where it belongs --- polkadot/xcm/src/lib.rs | 5 ----- polkadot/xcm/src/v3/mod.rs | 5 +++-- polkadot/xcm/src/v3/traits.rs | 5 +++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/polkadot/xcm/src/lib.rs b/polkadot/xcm/src/lib.rs index a012c5f53fbf..52f32f7310ba 100644 --- a/polkadot/xcm/src/lib.rs +++ b/polkadot/xcm/src/lib.rs @@ -447,11 +447,6 @@ pub mod opaque { pub type VersionedXcm = super::VersionedXcm<()>; } -// A simple trait to get the weight of some object. -pub trait GetWeight { - fn weight(&self) -> latest::Weight; -} - #[test] fn conversion_works() { use latest::prelude::*; diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index 360867957862..491552375cee 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -20,7 +20,7 @@ use super::v2::{ Instruction as OldInstruction, Response as OldResponse, WeightLimit as OldWeightLimit, Xcm as OldXcm, }; -use crate::{DoubleEncoded, GetWeight}; +use crate::DoubleEncoded; use alloc::{vec, vec::Vec}; use bounded_collections::{parameter_types, BoundedVec}; use core::{ @@ -49,7 +49,7 @@ pub use multilocation::{ }; pub use traits::{ send_xcm, validate_send, Error, ExecuteXcm, Outcome, PreparedMessage, Result, SendError, - SendResult, SendXcm, Weight, XcmHash, + SendResult, SendXcm, Weight, XcmHash, GetWeight, }; // These parts of XCM v2 are unchanged in XCM v3, and are re-imported here. pub use super::v2::OriginKind; @@ -185,6 +185,7 @@ pub mod prelude { OriginKind, Outcome, PalletInfo, Parent, ParentThen, PreparedMessage, QueryId, QueryResponseInfo, Response, Result as XcmResult, SendError, SendResult, SendXcm, Weight, + GetWeight, WeightLimit::{self, *}, WildFungibility::{self, Fungible as WildFungible, NonFungible as WildNonFungible}, WildMultiAsset::{self, *}, diff --git a/polkadot/xcm/src/v3/traits.rs b/polkadot/xcm/src/v3/traits.rs index 128be42c2a2b..997507717d42 100644 --- a/polkadot/xcm/src/v3/traits.rs +++ b/polkadot/xcm/src/v3/traits.rs @@ -25,6 +25,11 @@ pub use sp_weights::Weight; use super::*; +// A simple trait to get the weight of some object. +pub trait GetWeight { + fn weight(&self) -> Weight; +} + /// Error codes used in XCM. The first errors codes have explicit indices and are part of the XCM /// format. Those trailing are merely part of the XCM implementation; there is no expectation that /// they will retain the same index over time. From 3158c46b6e8a0df92aab5e3e50e5671867120cdd Mon Sep 17 00:00:00 2001 From: Just van Stam Date: Mon, 28 Aug 2023 16:20:10 +0200 Subject: [PATCH 2/3] add GetWeight to v2 --- polkadot/xcm/src/v2/mod.rs | 4 ++-- polkadot/xcm/src/v2/traits.rs | 5 +++++ polkadot/xcm/src/v3/mod.rs | 6 +++--- polkadot/xcm/xcm-builder/src/weight.rs | 5 ++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/polkadot/xcm/src/v2/mod.rs b/polkadot/xcm/src/v2/mod.rs index 8a67b771c9e9..a81468cd4812 100644 --- a/polkadot/xcm/src/v2/mod.rs +++ b/polkadot/xcm/src/v2/mod.rs @@ -55,7 +55,7 @@ use super::{ NetworkId as NewNetworkId, Response as NewResponse, WeightLimit as NewWeightLimit, Xcm as NewXcm, }, - DoubleEncoded, GetWeight, + DoubleEncoded, }; use alloc::{vec, vec::Vec}; use bounded_collections::{ConstU32, WeakBoundedVec}; @@ -77,7 +77,7 @@ pub use multiasset::{ pub use multilocation::{ Ancestor, AncestorThen, InteriorMultiLocation, Junctions, MultiLocation, Parent, ParentThen, }; -pub use traits::{Error, ExecuteXcm, Outcome, Result, SendError, SendResult, SendXcm}; +pub use traits::{Error, ExecuteXcm, GetWeight, Outcome, Result, SendError, SendResult, SendXcm}; /// Basically just the XCM (more general) version of `ParachainDispatchOrigin`. #[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] diff --git a/polkadot/xcm/src/v2/traits.rs b/polkadot/xcm/src/v2/traits.rs index ae03cf5547ba..80603b4100db 100644 --- a/polkadot/xcm/src/v2/traits.rs +++ b/polkadot/xcm/src/v2/traits.rs @@ -23,6 +23,11 @@ use scale_info::TypeInfo; use super::*; +// A simple trait to get the weight of some object. +pub trait GetWeight { + fn weight(&self) -> sp_weights::Weight; +} + #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] pub enum Error { // Errors that happen due to instructions being executed. These alone are defined in the diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index 491552375cee..229df9c75303 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -48,8 +48,8 @@ pub use multilocation::{ Ancestor, AncestorThen, InteriorMultiLocation, MultiLocation, Parent, ParentThen, }; pub use traits::{ - send_xcm, validate_send, Error, ExecuteXcm, Outcome, PreparedMessage, Result, SendError, - SendResult, SendXcm, Weight, XcmHash, GetWeight, + send_xcm, validate_send, Error, ExecuteXcm, GetWeight, Outcome, PreparedMessage, Result, + SendError, SendResult, SendXcm, Weight, XcmHash, }; // These parts of XCM v2 are unchanged in XCM v3, and are re-imported here. pub use super::v2::OriginKind; @@ -174,6 +174,7 @@ pub mod prelude { AssetInstance::{self, *}, BodyId, BodyPart, Error as XcmError, ExecuteXcm, Fungibility::{self, *}, + GetWeight, Instruction::*, InteriorMultiLocation, Junction::{self, *}, @@ -185,7 +186,6 @@ pub mod prelude { OriginKind, Outcome, PalletInfo, Parent, ParentThen, PreparedMessage, QueryId, QueryResponseInfo, Response, Result as XcmResult, SendError, SendResult, SendXcm, Weight, - GetWeight, WeightLimit::{self, *}, WildFungibility::{self, Fungible as WildFungible, NonFungible as WildNonFungible}, WildMultiAsset::{self, *}, diff --git a/polkadot/xcm/xcm-builder/src/weight.rs b/polkadot/xcm/xcm-builder/src/weight.rs index f1c14a4c6517..c16c52939a38 100644 --- a/polkadot/xcm/xcm-builder/src/weight.rs +++ b/polkadot/xcm/xcm-builder/src/weight.rs @@ -73,7 +73,7 @@ where W: XcmWeightInfo, C: Decode + GetDispatchInfo, M: Get, - Instruction: xcm::GetWeight, + Instruction: xcm::latest::GetWeight, { fn weight(message: &mut Xcm) -> Result { log::trace!(target: "xcm::weight", "WeightInfoBounds message: {:?}", message); @@ -90,7 +90,7 @@ where W: XcmWeightInfo, C: Decode + GetDispatchInfo, M: Get, - Instruction: xcm::GetWeight, + Instruction: xcm::latest::GetWeight, { fn weight_with_limit(message: &Xcm, instrs_limit: &mut u32) -> Result { let mut r: Weight = Weight::zero(); @@ -104,7 +104,6 @@ where instruction: &Instruction, instrs_limit: &mut u32, ) -> Result { - use xcm::GetWeight; let instr_weight = match instruction { Transact { require_weight_at_most, .. } => *require_weight_at_most, SetErrorHandler(xcm) | SetAppendix(xcm) => Self::weight_with_limit(xcm, instrs_limit)?, From a03acd02bf3830755b98e21c7c853d4a4a207faa Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 30 Aug 2023 20:56:52 -0700 Subject: [PATCH 3/3] Re-export unchanged trait --- polkadot/xcm/src/v3/mod.rs | 6 +++--- polkadot/xcm/src/v3/traits.rs | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/polkadot/xcm/src/v3/mod.rs b/polkadot/xcm/src/v3/mod.rs index c3af157e9e37..78ea7a58aba7 100644 --- a/polkadot/xcm/src/v3/mod.rs +++ b/polkadot/xcm/src/v3/mod.rs @@ -50,11 +50,11 @@ pub use multilocation::{ Ancestor, AncestorThen, InteriorMultiLocation, MultiLocation, Parent, ParentThen, }; pub use traits::{ - send_xcm, validate_send, Error, ExecuteXcm, GetWeight, Outcome, PreparedMessage, Result, - SendError, SendResult, SendXcm, Weight, XcmHash, + send_xcm, validate_send, Error, ExecuteXcm, Outcome, PreparedMessage, Result, SendError, + SendResult, SendXcm, Weight, XcmHash, }; // These parts of XCM v2 are unchanged in XCM v3, and are re-imported here. -pub use super::v2::OriginKind; +pub use super::v2::{GetWeight, OriginKind}; /// This module's XCM version. pub const VERSION: super::Version = 3; diff --git a/polkadot/xcm/src/v3/traits.rs b/polkadot/xcm/src/v3/traits.rs index 997507717d42..128be42c2a2b 100644 --- a/polkadot/xcm/src/v3/traits.rs +++ b/polkadot/xcm/src/v3/traits.rs @@ -25,11 +25,6 @@ pub use sp_weights::Weight; use super::*; -// A simple trait to get the weight of some object. -pub trait GetWeight { - fn weight(&self) -> Weight; -} - /// Error codes used in XCM. The first errors codes have explicit indices and are part of the XCM /// format. Those trailing are merely part of the XCM implementation; there is no expectation that /// they will retain the same index over time.