mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Contracts: xcm host fn fixes (#3086)
## Xcm changes: - Fix `pallet_xcm::execute`, move the logic into The `ExecuteController` so it can be shared with anything that implement that trait. - Make `ExecuteController::execute` retursn `DispatchErrorWithPostInfo` instead of `DispatchError`, so that we don't charge the full `max_weight` provided if the execution is incomplete (useful for force_batch or contracts calls) - Fix docstring for `pallet_xcm::execute`, to reflect the changes from #2405 - Update the signature for `ExecuteController::execute`, we don't need to return the `Outcome` anymore since we only care about `Outcome::Complete` ## Contracts changes: - Update host fn `xcm_exexute`, we don't need to write the `Outcome` to the sandbox memory anymore. This was also not charged as well before so it if fixes this too. - One of the issue was that the dry_run of a contract that call `xcm_execute` would exhaust the `gas_limit`. This is because `XcmExecuteController::execute` takes a `max_weight` argument, and since we don't want the user to specify it manually we were passing everything left by pre-charghing `ctx.ext.gas_meter().gas_left()` - To fix it I added a `fn influence_lowest_limit` on the `Token` trait and make it return false for `RuntimeCost::XcmExecute`. - Got rid of the `RuntimeToken` indirection, we can just use `RuntimeCost` directly. --------- Co-authored-by: command-bot <>
This commit is contained in:
@@ -792,7 +792,7 @@ pub trait HostFn {
|
||||
#[deprecated(
|
||||
note = "Unstable function. Behaviour can change without further notice. Use only for testing."
|
||||
)]
|
||||
fn xcm_execute(msg: &[u8], output: &mut &mut [u8]) -> Result;
|
||||
fn xcm_execute(msg: &[u8]) -> Result;
|
||||
|
||||
/// Send an XCM program from the contract to the specified destination.
|
||||
/// This is equivalent to dispatching `pallet_xcm::send` through `call_runtime`, except that
|
||||
@@ -804,7 +804,6 @@ pub trait HostFn {
|
||||
/// traps otherwise.
|
||||
/// - `msg`: The message, should be decodable as a [VersionedXcm](https://paritytech.github.io/polkadot-sdk/master/staging_xcm/enum.VersionedXcm.html),
|
||||
/// traps otherwise.
|
||||
/// - `output`: A reference to the output data buffer to write the [XcmHash](https://paritytech.github.io/polkadot-sdk/master/staging_xcm/v3/type.XcmHash.html)
|
||||
///
|
||||
/// # Return
|
||||
///
|
||||
|
||||
@@ -297,7 +297,7 @@ impl HostFn for HostFnImpl {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn xcm_execute(msg: &[u8], output: &mut &mut [u8]) -> Result {
|
||||
fn xcm_execute(msg: &[u8]) -> Result {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ mod sys {
|
||||
|
||||
pub fn weight_to_fee(gas: u64, output_ptr: *mut u8, output_len_ptr: *mut u32);
|
||||
|
||||
pub fn xcm_execute(msg_ptr: *const u8, msg_len: u32, output_ptr: *mut u8) -> ReturnCode;
|
||||
pub fn xcm_execute(msg_ptr: *const u8, msg_len: u32) -> ReturnCode;
|
||||
|
||||
pub fn xcm_send(
|
||||
dest_ptr: *const u8,
|
||||
@@ -819,9 +819,8 @@ impl HostFn for HostFnImpl {
|
||||
unsafe { sys::reentrance_count() }
|
||||
}
|
||||
|
||||
fn xcm_execute(msg: &[u8], output: &mut &mut [u8]) -> Result {
|
||||
let ret_code =
|
||||
unsafe { sys::xcm_execute(msg.as_ptr(), msg.len() as _, output.as_mut_ptr()) };
|
||||
fn xcm_execute(msg: &[u8]) -> Result {
|
||||
let ret_code = unsafe { sys::xcm_execute(msg.as_ptr(), msg.len() as _) };
|
||||
ret_code.into()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user