Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-xcm: Deprecate execute and send in favor of execute_blob and send_blob #3749

Merged
merged 53 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d9d97cc
feat(pallet-xcm): deprecate execute and send in favor of execute_blob…
franciscoaguirre Mar 19, 2024
d2359c6
Update polkadot/xcm/pallet-xcm/src/lib.rs
franciscoaguirre Mar 20, 2024
571b16c
fix(pallet-xcm): remove base function from controller traits
franciscoaguirre Mar 20, 2024
43ac662
fix(pallet-xcm): fmt
franciscoaguirre Mar 20, 2024
3655ba3
chore(pallet-xcm): add tests
franciscoaguirre Mar 20, 2024
d433de4
fix: add todos for pallet-xcm weights on all runtimes
franciscoaguirre Mar 20, 2024
ba086c2
fix(pallet-xcm): move MAX_XCM_ENCODED_SIZE to xcm crate
franciscoaguirre Mar 20, 2024
9f117d3
chore(xcm): add more xcm decoding tests
franciscoaguirre Mar 21, 2024
8c507ac
fix(weights::pallet_xcm): change todo! to Weight::MAX
franciscoaguirre Mar 21, 2024
5541d4e
chore(pallet-xcm): change message to encoded_message in blob extrinsics
franciscoaguirre Mar 21, 2024
3974e72
fix: remove usage of deprecated function, change max encoded size
franciscoaguirre Mar 21, 2024
01c629c
doc: add prdoc
franciscoaguirre Mar 21, 2024
caa74e6
fmt
franciscoaguirre Mar 21, 2024
cdae8bd
Merge branch 'master' into xcm-execute-blob
franciscoaguirre Mar 21, 2024
3f5683f
fix: add benchmark for execute_blob and send_blob
franciscoaguirre Mar 21, 2024
c8aa519
Merge branch 'master' into xcm-execute-blob
franciscoaguirre Mar 21, 2024
62d073b
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
650094a
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
be77fa2
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
d6f9e1d
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
5a31357
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
bf05d62
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
39ed827
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
8e32e0b
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
50d6a87
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
0d8cc33
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 21, 2024
169432c
chore(pallet-xcm): remove unnecessary tests
franciscoaguirre Mar 21, 2024
2419c1d
Merge branch 'master' into xcm-execute-blob
franciscoaguirre Mar 22, 2024
f549578
chore: fmt
franciscoaguirre Mar 22, 2024
72b00cc
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Mar 22, 2024
9b151ff
Patches for #3749 (#3821)
pgherveou Mar 25, 2024
b8a9955
Update polkadot/xcm/xcm-builder/src/controller.rs
franciscoaguirre Mar 25, 2024
56c920f
Update polkadot/xcm/xcm-builder/src/controller.rs
franciscoaguirre Mar 25, 2024
5e4f00b
doc(pallet-xcm): add doc comments to execute_blob and send_blob
franciscoaguirre Mar 25, 2024
8039abf
doc: update prdoc to mention pallet-contracts API changes
franciscoaguirre Mar 25, 2024
eb90b51
Merge branch 'master' into xcm-execute-blob
franciscoaguirre Mar 25, 2024
616d088
Update polkadot/xcm/pallet-xcm/src/tests/mod.rs
franciscoaguirre Mar 25, 2024
9a62004
Update polkadot/xcm/pallet-xcm/src/tests/mod.rs
franciscoaguirre Mar 25, 2024
12744e1
Update polkadot/xcm/pallet-xcm/src/lib.rs
franciscoaguirre Mar 25, 2024
bcb37c5
Update cumulus/parachains/integration-tests/emulated/tests/bridges/br…
franciscoaguirre Mar 25, 2024
55fd326
Update cumulus/parachains/integration-tests/emulated/tests/bridges/br…
franciscoaguirre Mar 25, 2024
25c3de1
Update cumulus/parachains/integration-tests/emulated/tests/bridges/br…
franciscoaguirre Mar 25, 2024
9251a2b
Update cumulus/parachains/integration-tests/emulated/common/src/impls.rs
franciscoaguirre Mar 25, 2024
f849435
Update cumulus/parachains/integration-tests/emulated/tests/assets/ass…
franciscoaguirre Mar 25, 2024
5141e32
Update cumulus/parachains/integration-tests/emulated/tests/assets/ass…
franciscoaguirre Mar 25, 2024
089f7d5
Update cumulus/parachains/integration-tests/emulated/tests/assets/ass…
franciscoaguirre Mar 25, 2024
5b8a875
Update cumulus/parachains/integration-tests/emulated/tests/bridges/br…
franciscoaguirre Mar 25, 2024
0f3f976
Update cumulus/parachains/integration-tests/emulated/tests/bridges/br…
franciscoaguirre Mar 25, 2024
2f52ad1
fix: don't panic in the runtime
franciscoaguirre Mar 25, 2024
e68fb13
fix(pallet-xcm): remove more instances of pallet-xcm execute
franciscoaguirre Mar 25, 2024
07dd350
fix(pallet-xcm): specify call in xcms in tests
franciscoaguirre Mar 25, 2024
3ffe01b
fmt
franciscoaguirre Mar 25, 2024
2110990
Merge branch 'master' into xcm-execute-blob
franciscoaguirre Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 78 additions & 5 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub trait WeightInfo {
fn new_query() -> Weight;
fn take_response() -> Weight;
fn claim_assets() -> Weight;
fn execute_blob() -> Weight;
fn send_blob() -> Weight;
}

/// fallback implementation
Expand Down Expand Up @@ -288,18 +290,41 @@ pub mod pallet {
fn execute() -> Weight {
T::WeightInfo::execute()
}
fn execute_blob() -> Weight {
T::WeightInfo::execute_blob()
}
}

impl<T: Config> ExecuteController<OriginFor<T>, <T as Config>::RuntimeCall> for Pallet<T> {
impl<T: Config> ExecuteController<OriginFor<T>, <T as Config>::RuntimeCall, MaxXcmEncodedSize> for Pallet<T> {
type WeightInfo = Self;
fn execute(
origin: OriginFor<T>,
message: Box<VersionedXcm<<T as Config>::RuntimeCall>>,
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo> {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
Self::execute_base(origin_location, message, max_weight)
}
fn execute_blob(
origin: OriginFor<T>,
message: BoundedVec<u8, MaxXcmEncodedSize>,
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo> {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
let message = VersionedXcm::<<T as Config>::RuntimeCall>::decode(&mut &message[..])
.map_err(|error| {
log::error!(target: "xcm::execute_blob", "Unable to decode XCM, error: {:?}", error);
Error::<T>::UnableToDecode
})?;
Self::execute_base(origin_location, message, max_weight)
}
fn execute_base(
origin_location: Location,
message: Box<VersionedXcm<<T as Config>::RuntimeCall>>,
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo> {
log::trace!(target: "xcm::pallet_xcm::execute", "message {:?}, max_weight {:?}", message, max_weight);
let outcome = (|| {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
let mut hash = message.using_encoded(sp_io::hashing::blake2_256);
let message = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
let value = (origin_location, message);
Expand All @@ -312,8 +337,7 @@ pub mod pallet {
max_weight,
max_weight,
))
})()
.map_err(|e: DispatchError| {
})().map_err(|e: DispatchError| {
e.with_weight(<Self::WeightInfo as ExecuteControllerWeightInfo>::execute())
})?;

Expand All @@ -335,16 +359,39 @@ pub mod pallet {
fn send() -> Weight {
T::WeightInfo::send()
}
fn send_blob() -> Weight {
T::WeightInfo::send_blob()
}
}

impl<T: Config> SendController<OriginFor<T>> for Pallet<T> {
impl<T: Config> SendController<OriginFor<T>, MaxXcmEncodedSize> for Pallet<T> {
type WeightInfo = Self;
fn send(
origin: OriginFor<T>,
dest: Box<VersionedLocation>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError> {
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
Self::send_base(origin_location, dest, message)
}
fn send_blob(
origin: OriginFor<T>,
dest: Box<VersionedLocation>,
message: BoundedVec<u8, MaxXcmEncodedSize>,
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<XcmHash, DispatchError> {
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
let message = VersionedXcm::<<T as Config>::RuntimeCall>::decode(&mut &message[..])
.map_err(|error| {
log::error!(target: "xcm::execute_blob", "Unable to decode XCM, error: {:?}", error);
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
Error::<T>::UnableToDecode
})?;
Self::send_base(origin_location, dest, message)
}
fn send_base(
origin_location: Location,
dest: Box<VersionedLocation>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError> {
let interior: Junctions =
origin_location.clone().try_into().map_err(|_| Error::<T>::InvalidOrigin)?;
let dest = Location::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
Expand Down Expand Up @@ -900,6 +947,7 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
/// WARNING: This call is DEPRECATED! Use `send_blob` instead.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::send())]
pub fn send(
Expand Down Expand Up @@ -1030,6 +1078,8 @@ pub mod pallet {
/// No more than `max_weight` will be used in its attempted execution. If this is less than
/// the maximum amount of weight that the message could take to be executed, then no
/// execution attempt will be made.
///
/// WARNING: This call is DEPRECATED! Use `execute_blob` instead.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::call_index(3)]
#[pallet::weight(max_weight.saturating_add(T::WeightInfo::execute()))]
pub fn execute(
Expand Down Expand Up @@ -1449,6 +1499,29 @@ pub mod pallet {
})?;
Ok(())
}

franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::call_index(13)]
#[pallet::weight(T::WeightInfo::execute_blob())]
fn execute_blob(
origin: OriginFor<T>,
message: BoundedVec<u8, MaxXcmEncodedSize>,
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
max_weight: Weight,
) -> DispatchResultWithPostInfo {
let weight_used =
<Self as ExecuteController<_, _, MaxXcmEncodedSize>>::execute_blob(origin, message, max_weight)?;
Ok(Some(weight_used.saturating_add(T::WeightInfo::execute_blob())).into())
}

#[pallet::call_index(14)]
#[pallet::weight(T::WeightInfo::send_blob())]
fn send_blob(
origin: OriginFor<T>,
message: BoundedVec<u8, MaxXcmEncodedSize>,
max_weight: Weight,
) -> DispatchResultWithPostInfo {
<Self as SendController<_, MaxXcmEncodedSize>>::send_blob(origin, dest, message)?;
Ok(())
}
}
}

Expand Down
51 changes: 50 additions & 1 deletion polkadot/xcm/xcm-builder/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ impl<T, Origin, RuntimeCall, Timeout> Controller<Origin, RuntimeCall, Timeout> f
pub trait ExecuteControllerWeightInfo {
/// Weight for [`ExecuteController::execute`]
fn execute() -> Weight;
/// Weight for [`ExecuteController::execute_blob`]
fn execute_blob() -> Weight;
}

/// Execute an XCM locally, for a given origin.
Expand All @@ -51,13 +53,15 @@ pub trait ExecuteControllerWeightInfo {
/// - Validating and Converting the origin to a Location.
/// - Handling versioning.
/// - Calling the internal executor, which implements [`ExecuteXcm`].
pub trait ExecuteController<Origin, RuntimeCall> {
pub trait ExecuteController<Origin, RuntimeCall, MaxXcmEncodedSize> {
/// Weight information for ExecuteController functions.
type WeightInfo: ExecuteControllerWeightInfo;

/// Attempt to execute an XCM locally, returns Ok with the weight consumed if the execution
/// complete successfully, Err otherwise.
///
/// WARNING: This call is DEPRECATED! Use `execute_blob` instead.
///
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
/// # Parameters
///
/// - `origin`: the origin of the call.
Expand All @@ -68,12 +72,35 @@ pub trait ExecuteController<Origin, RuntimeCall> {
message: Box<VersionedXcm<RuntimeCall>>,
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo>;

/// Attempt to execute an XCM locally, returns Ok with the weight consumed if the execution
/// complete successfully, Err otherwise.
///
/// # Parameters
///
/// - `origin`: the origin of the call.
/// - `message`: the XCM program to be executed, encoded.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
/// - `max_weight`: the maximum weight that can be consumed by the execution.
fn execute_blob(
origin: Origin,
message: BoundedVec<u8, MaxXcmEncodedSize>,
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo>;

/// The underlying XCM execution logic, shared by both `execute` and `execute_blob`.
fn execute_base(
origin_location: Location,
message: Box<VersionedXcm<RuntimeCall>>,
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo>;
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
}

/// Weight functions needed for [`SendController`].
pub trait SendControllerWeightInfo {
/// Weight for [`SendController::send`]
fn send() -> Weight;
/// Weight for [`SendController::send_blob`]
fn send_blob() -> Weight;
}

/// Send an XCM from a given origin.
Expand All @@ -89,6 +116,8 @@ pub trait SendController<Origin> {

/// Send an XCM to be executed by a remote location.
///
/// WARNING: This call is DEPRECATED! Use `send_blob` instead.
///
/// # Parameters
///
/// - `origin`: the origin of the call.
Expand All @@ -99,6 +128,26 @@ pub trait SendController<Origin> {
dest: Box<VersionedLocation>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError>;

/// Send an XCM to be executed by a remote location.
///
/// # Parameters
///
/// - `origin`: the origin of the call.
/// - `dest`: the destination of the message.
/// - `msg`: the XCM to be sent, encoded.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
fn send_blob(
origin: Origin,
dest: BoundedVec<u8, MaxXcmEncodedSize>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError>;

/// The underlying XCM sending logic, shared by both `send` and `send_blob`.
fn send_base(
origin_location: Location,
dest: BoundedVec<u8, MaxXcmEncodedSize>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError>;
}

/// Weight functions needed for [`QueryController`].
Expand Down
Loading