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

Contracts expose pallet-xcm #1248

Merged
merged 126 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
251e8cd
boilerplate type changes
pgherveou Aug 29, 2023
3b1cc37
Add pallet_xcm::execute
pgherveou Aug 29, 2023
22430a3
wip
pgherveou Aug 30, 2023
c6e1f49
add other xcm_methods
pgherveou Aug 30, 2023
bf66839
add benchmarks
pgherveou Aug 31, 2023
a348bd9
build fixes
pgherveou Aug 31, 2023
b2a9f4e
fix
pgherveou Aug 31, 2023
d20d6ca
fix post-rebase missing imports
pgherveou Sep 1, 2023
8388585
Revert "boilerplate type changes"
pgherveou Sep 1, 2023
4bae246
Use trait instead of tight coupling
pgherveou Sep 1, 2023
0675899
add mock_network setup
pgherveou Sep 1, 2023
2049b57
fixes
pgherveou Sep 4, 2023
be04741
fix clippy
pgherveou Sep 4, 2023
b7875ad
quick fixes
pgherveou Sep 4, 2023
c312b98
simplify
pgherveou Sep 4, 2023
5983dbd
move stuff to pallet_xcm_extension
pgherveou Sep 4, 2023
7484d32
fmt
pgherveou Sep 4, 2023
b40f92c
headr
pgherveou Sep 4, 2023
c3f7d40
missing headers
pgherveou Sep 4, 2023
a08e41b
fix missing comment
pgherveou Sep 4, 2023
376a6b3
fixes
pgherveou Sep 4, 2023
5b883d6
Merge branch 'master' into pg/xcm
pgherveou Sep 4, 2023
967616c
Merge branch 'master' into pg/xcm
pgherveou Sep 4, 2023
d2b5ba3
refactoring
pgherveou Sep 4, 2023
d7fe1bc
fix build
pgherveou Sep 4, 2023
c15adab
missing type in node/runtime
pgherveou Sep 5, 2023
e15c7eb
format cargo.toml
pgherveou Sep 5, 2023
971b167
more zepter fixes
pgherveou Sep 5, 2023
3dba8d1
fixes
pgherveou Sep 5, 2023
be1a46d
missing trait implementation
pgherveou Sep 5, 2023
a4d706c
fix tests
pgherveou Sep 5, 2023
b15ea88
fixes
pgherveou Sep 5, 2023
b938df4
fmt fix
pgherveou Sep 5, 2023
fcc37f5
zepter format
pgherveou Sep 5, 2023
9cc990f
fix doc links
pgherveou Sep 5, 2023
7ff220b
rm println!
pgherveou Sep 5, 2023
bdf0ae7
add tests comments
pgherveou Sep 5, 2023
14e1514
worst case
pgherveou Sep 5, 2023
e9d2cdf
simplify XCM
pgherveou Sep 14, 2023
c9f8f35
add docs
pgherveou Sep 14, 2023
151175b
Filter out transact calls
pgherveou Sep 21, 2023
43f38d2
fmt
pgherveou Sep 21, 2023
4583e03
move ensure to it's own function for benchmark
pgherveou Sep 21, 2023
ceb3fc8
fix error handling
pgherveou Sep 21, 2023
db7c479
doc fixes
pgherveou Sep 22, 2023
cd8281e
fix weight
pgherveou Sep 22, 2023
c004909
improve weight
pgherveou Sep 22, 2023
526abbd
XCMAdapter -> XcmAdapter
pgherveou Sep 25, 2023
0a98a89
XCM<T> -> Xcm<T>
pgherveou Sep 25, 2023
1d1f40a
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
e01cb2c
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
2c7735b
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
4e3de86
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
e52f85f
s/xcm message/message
pgherveou Sep 25, 2023
d78ec47
typo
pgherveou Sep 25, 2023
435de45
fix build issues
pgherveou Sep 27, 2023
c4d87ff
fix fmt
pgherveou Sep 27, 2023
4363e6d
More doc fix changes
pgherveou Sep 27, 2023
ac39a50
Apply suggestions from code review
pgherveou Sep 29, 2023
0bf6e1a
address PR comments
pgherveou Sep 29, 2023
ddf485a
Add reentrency test
pgherveou Oct 9, 2023
975ef56
Simplify tests
pgherveou Oct 9, 2023
448c9d4
Apply suggestions from code review
pgherveou Oct 24, 2023
132e203
PR review comment
pgherveou Oct 24, 2023
7bf716d
Fix lint
pgherveou Oct 24, 2023
6a7a8bd
return proper error code
pgherveou Oct 24, 2023
8c1c118
Merge branch 'master' into pg/xcm
pgherveou Oct 24, 2023
06a5c9a
fix compilation issues after rebase
pgherveou Oct 24, 2023
b47f660
lint
pgherveou Oct 24, 2023
06cf121
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Oct 24, 2023
0949455
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Oct 24, 2023
14fed0e
Update substrate/frame/contracts/src/tests/test_xcm.rs
pgherveou Oct 25, 2023
e694941
simplify mock_network
pgherveou Oct 25, 2023
72f15c1
fix return type in comment
pgherveou Oct 26, 2023
c8f39e7
Contracts expose pallet-xcm - tweaks (#2062)
pgherveou Oct 27, 2023
54e2803
Add copyright
pgherveou Oct 27, 2023
ce637dc
reuse QueryHandler
pgherveou Oct 29, 2023
582467d
Contracts: Add XCM traits to interface with contracts
pgherveou Oct 30, 2023
79535cb
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou Oct 30, 2023
0a02451
Update doc
pgherveou Oct 30, 2023
262e17c
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Oct 31, 2023
9413874
use Outcome return value for xcm_execute
pgherveou Oct 31, 2023
18c6bb4
Use outcome in controller
pgherveou Oct 31, 2023
b9b2ccc
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Oct 31, 2023
198d692
add docstring
pgherveou Oct 31, 2023
e3ce2e0
Event consistency
pgherveou Oct 31, 2023
6342962
Add more docs
pgherveou Oct 31, 2023
a2fde63
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou Oct 31, 2023
0ae8763
fix doc
pgherveou Oct 31, 2023
034150c
fix CI
pgherveou Oct 31, 2023
7848e2f
move to xcm-builder
pgherveou Nov 1, 2023
b7155b6
move to pallet-xcm
pgherveou Nov 1, 2023
34329e5
Update doc links
pgherveou Nov 1, 2023
07439dd
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 1, 2023
b37d169
wip
pgherveou Nov 1, 2023
de8f1a9
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Nov 1, 2023
7cd84a2
update xcm stuff
pgherveou Nov 1, 2023
8ac21da
Bench compile fix
pgherveou Nov 1, 2023
7ee5d08
add missing use
pgherveou Nov 2, 2023
e13b51b
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Nov 2, 2023
2359fa0
fix test
pgherveou Nov 2, 2023
41215d3
mock-network crate
pgherveou Nov 10, 2023
e515180
Merge branch 'master' into pg/xcm
pgherveou Nov 10, 2023
8b0f8ac
revert bad merge
pgherveou Nov 10, 2023
3526658
move fixtures files
pgherveou Nov 10, 2023
784f8df
rm pallet-xcm dep
pgherveou Nov 10, 2023
0b5517a
fix xcm deps
pgherveou Nov 10, 2023
7b3ad3d
fix tests
pgherveou Nov 10, 2023
0b4c840
fix lint
pgherveou Nov 10, 2023
80e0c53
fixes
pgherveou Nov 10, 2023
59d67a0
fix
pgherveou Nov 10, 2023
9a9d572
fix
pgherveou Nov 10, 2023
3adde14
fixed deps moved to pallet-contracts-mock-network
pgherveou Nov 14, 2023
c70aca5
Review https://github.com/paritytech/polkadot-sdk/pull/1248#discussio…
pgherveou Nov 14, 2023
5d63636
Review https://github.com/paritytech/polkadot-sdk/pull/1248#discussio…
pgherveou Nov 14, 2023
57b7ca5
PR review https://github.com/paritytech/polkadot-sdk/pull/1248#discus…
pgherveou Nov 14, 2023
10f22fb
PR review https://github.com/paritytech/polkadot-sdk/pull/1248#discus…
pgherveou Nov 14, 2023
162ad54
PR review https://github.com/paritytech/polkadot-sdk/pull/1248#discus…
pgherveou Nov 14, 2023
3a4a251
rm macro_export
pgherveou Nov 14, 2023
dab8314
Temporary remove xcm_query and xcm_take_response fns
pgherveou Nov 14, 2023
e3161c9
misc removed stuff from query
pgherveou Nov 14, 2023
4128aa6
fix doc
pgherveou Nov 14, 2023
f0df85b
rm more stuff from query & take_response
pgherveou Nov 14, 2023
b48a8f9
fmt
pgherveou Nov 14, 2023
7c72e24
Merge branch 'master' into pg/xcm
pgherveou Nov 14, 2023
b34e245
doc test
pgherveou Nov 14, 2023
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
11 changes: 11 additions & 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 @@ -24,6 +24,7 @@ use frame_support::{
use pallet_contracts::{
migration::{v12, v13, v14, v15},
weights::SubstrateWeight,
xcm::XCMAdapter,
Config, DebugInfo, DefaultAddressGenerator, Frame, Schedule,
};
use sp_runtime::Perbill;
Expand Down Expand Up @@ -79,4 +80,5 @@ impl Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type Debug = ();
type Environment = ();
type Xcm = XCMAdapter<Self>;
}
27 changes: 27 additions & 0 deletions polkadot/xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ benchmarks! {
Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
}

new_query {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
}: {
Pallet::<T>::new_query(responder, timeout, match_querier);
}

take_response {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
let query_id = Pallet::<T>::new_query(responder, timeout, match_querier);
let infos = (0 .. xcm::v3::MaxPalletsInfo::get()).map(|_| PalletInfo::new(
u32::MAX,
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
u32::MAX,
u32::MAX,
u32::MAX,
).unwrap()).collect::<Vec<_>>();
Pallet::<T>::expect_response(query_id, Response::PalletsInfo(infos.try_into().unwrap()));

}: {
Pallet::<T>::take_response(query_id);
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext_with_balances(Vec::new()),
Expand Down
15 changes: 15 additions & 0 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ pub trait WeightInfo {
fn notify_target_migration_fail() -> Weight;
fn migrate_version_notify_targets() -> Weight;
fn migrate_and_notify_old_targets() -> Weight;
// TODO remove after benchmark are regenerated
fn new_query() -> Weight {
Weight::zero()
}
fn take_response() -> Weight {
Weight::zero()
}
}

/// fallback implementation
Expand Down Expand Up @@ -141,6 +148,14 @@ impl WeightInfo for TestWeightInfo {
fn migrate_and_notify_old_targets() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn new_query() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn take_response() -> Weight {
Weight::from_parts(100_000_000, 0)
}
}

#[frame_support::pallet]
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-executor/src/traits/on_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use crate::Xcm;
use core::result;
use frame_support::pallet_prelude::{Get, TypeInfo};
use parity_scale_codec::{FullCodec, MaxEncodedLen};
use parity_scale_codec::{Decode, Encode, FullCodec, MaxEncodedLen};
use sp_arithmetic::traits::Zero;
use sp_std::fmt::Debug;
use xcm::latest::{
Expand Down Expand Up @@ -103,7 +103,7 @@ impl VersionChangeNotifier for () {
}

/// The possible state of an XCM query response.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
pub enum QueryResponseStatus<BlockNumber> {
/// The response has arrived, and includes the inner Response and the block number it arrived
/// at.
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,7 @@ impl pallet_contracts::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Debug = ();
type Environment = ();
type Xcm = ();
}

impl pallet_sudo::Config for Runtime {
Expand Down
29 changes: 29 additions & 0 deletions substrate/frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,34 @@ sp-io = { path = "../../primitives/io", default-features = false}
sp-runtime = { path = "../../primitives/runtime", default-features = false}
sp-std = { path = "../../primitives/std", default-features = false}

xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../polkadot/xcm/pallet-xcm", default-features = false}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these crates are going to move into their own repo (cc @KiChjang ), so that should partially address your concern.

I don't see how we could bring xcm features to SC without bringing in these dependencies though... 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense.

Not my call, but I would strive to have things in the dep graph be correct before landing this PR. Else the slippery slope to a janky cluster of deps crossing boundaries will likely happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree you don't necessarily want to use xcm when using pallet-contracts, you might not even have access to it
Ideally we want contracts, at the pallet level, to allow xcm but not enforce knowing about it

It's good that you can disable the capability, but still relying on this dependencies sounds too much when I don't want to deal with xcm as a solochain developer for example

The only way to take this out of the dependencies would be to have a different crate, something like "xcm-powered-contracts", which is ugly. The other thing we could do is feature gate this, so at least some things are not even compiled if you don't want XCM. However, dependencies can't be defined per feature 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning is that even solo chain might eventually want to use xcm, to communicate messages over bridges for example. That's why we want xcm to be part of the config, rather than using other type of indirection like dispatching runtime call or building ad-hoc SC chain extension, which has been how team have interfaced with XCM so far.

We could feature gate everything but I think this is not necessary as the compiler should just strip pallet_xcm code if you use the default () noop trait.

Copy link
Member

@athei athei Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes XCM is not specific to being a parachain. It is a language to express intent. It will also be used for contract <-> runtime communication. In an ideal world it would also be used inside a transaction instead of the unstable encoded Call.

Hence there is no reason to jump though all these hoops and add all the complexity just to make it optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I initially I used tight coupling , but I think having an Xcm configuration trait provide a few advantage:

  • I find it a bit more readable to do T::Xcm::some_xcm_foo(..) rather than <T as pallet_xcm::Config>::xcm_foo(..)
  • You will need to replace all T:: by <T as Config> to get the pallet to compile
  • We can document the set of xcm operation we want to bring in through this trait
  • Even if the vision is to use Xcm for all chains, the upgrade path is slightly easier this way as they don't have to implement pallet_xcm::Config straight away.

Happy to update if you feel strongly that we should use tight coupling on the pallet.

[dev-dependencies]
array-bytes = "6.1"
assert_matches = "1"
env_logger = "0.9"
pretty_assertions = "1"
wat = "1"

# Polkadot Dependencies
xcm-simulator = {path = "../../../polkadot/xcm/xcm-simulator"}
xcm-builder = {package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder"}
polkadot-runtime-parachains = {path = "../../../polkadot/runtime/parachains"}
polkadot-parachain-primitives = { path = "../../../polkadot/parachain" }
polkadot-primitives = { path = "../../../polkadot/primitives" }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong: see #1318

Is it possibly to remove any dependency outside Substrate here? If not, why?

Unless it is now allowed to commingle any dependency in the SDK, that would erode the notion of any separation of the three previously (intentionally) separate repos. I hope that isn't the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dependencies are used to test the pallet in a mocked network environment.
Not sure why this is an issue here since this is only used for testing purpose.

Copy link
Contributor

@nuke-web3 nuke-web3 Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not my call, but testing relying on things downstream for Substrate seems wrong to me. I don't see other libraries calling their consumers to test their features... maybe this is actually idiomatic and OK? 🤷

Also might make you build a lot more stuff to get the tests run, but that is just a hunch

Copy link
Member

@athei athei Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with the opinion that this graph should be enforced. Big point of the monorepo was that which crates are in polkadot vs. cumulus vs. substrate is an arbitrary and ultimately useless distinction. Fact of the matter is that we need those crates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nukemandan all these deps apart from xcm and xcm-builder are now moved out to the testing crate pallet-contracts-mock-network.

xcm and xcm-builder should eventually be moved out of polkadot and into it's own repo, and hopefully be adopted by other substrate pallets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note @pgherveou - that is good news that things are moving away from any ./substrate/..... paths depending on ../../../polkadot/..... ones. There are a lot remaining in here so my opinion stands the same: #1318 . But as already pointed out, it is just an opinion. Getting this in if the team thinks it should not wait for the "right" thing should not depend on a approval from me (if it does, please remove my review to allow this to merge)

# Substrate Dependencies
pallet-balances = { path = "../balances" }
pallet-timestamp = { path = "../timestamp" }
pallet-message-queue = { path = "../message-queue" }
pallet-insecure-randomness-collective-flip = { path = "../insecure-randomness-collective-flip" }
pallet-utility = { path = "../utility" }
pallet-assets = { path = "../assets" }
pallet-proxy = { path = "../proxy" }
sp-keystore = { path = "../../primitives/keystore" }
sp-tracing = { path = "../../primitives/tracing" }

[features]
default = [ "std" ]
Expand All @@ -79,6 +93,7 @@ std = [
"pallet-proxy/std",
"pallet-timestamp/std",
"pallet-utility/std",
"pallet-xcm/std",
"rand/std",
"scale-info/std",
"serde",
Expand All @@ -90,27 +105,41 @@ std = [
"sp-std/std",
"wasm-instrument/std",
"wasmi/std",
"xcm-executor/std",
"xcm/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"rand",
"rand_pcg",
"sp-runtime/runtime-benchmarks",
"wasm-instrument",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"pallet-insecure-randomness-collective-flip/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-proxy/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"polkadot-runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
]
38 changes: 38 additions & 0 deletions substrate/frame/contracts/fixtures/xcm_execute.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; This passes its input to `seal_xcm_execute` and returns the return value to its caller.
(module
(import "seal0" "xcm_execute" (func $xcm_execute (param i32 i32) (result i32)))
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; 0x1000 = 4k in little endian
;; Size of input buffer
(data (i32.const 0) "\00\10")

(func (export "call")
;; Receive the encoded call
(call $seal_input
(i32.const 4) ;; Pointer to the input buffer
(i32.const 0) ;; Size of the length buffer
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
)
;; Input data layout.
;; [0..4) - size of the call
;; [4..) - xcm message

;; Just use the call passed as input and store result to memory
(i32.store (i32.const 0)
(call $xcm_execute
(i32.const 4) ;; Pointer where the xcm msg is stored
(i32.load (i32.const 0)) ;; Size of the xcm msg
)
)
(call $seal_return
(i32.const 0) ;; flags
(i32.const 0) ;; returned value
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
(i32.const 4) ;; length of returned value
)
)

(func (export "deploy"))
)

42 changes: 42 additions & 0 deletions substrate/frame/contracts/fixtures/xcm_query.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; This passes its input to `seal_xcm_query` and returns the return value to its caller.
(module
(import "seal0" "xcm_query" (func $xcm_query (param i32 i32 i32) (result i32)))
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; 0x1000 = 4k in little endian
;; size of input buffer
(data (i32.const 0) "\00\10")

(func (export "call")
;; Receive the encoded call
(call $seal_input
(i32.const 4) ;; Pointer to the input buffer
(i32.const 0) ;; Size of the length buffer
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
)
;; Input data layout.
;; [0..4) - size of the call
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
;; [4..12) - timeout
;; [12..49) - match_querier

;; Just use the call passed as input and store result to memory
(i32.store (i32.const 0)
(call $xcm_query
(i32.const 4) ;; Pointer where the timeout is stored
(i32.const 12) ;; Pointer where the match_querier is stored
(i32.const 49) ;; Pointer to the where the query_id is stored
)
)
(call $seal_return
(i32.const 0) ;; flags
(i32.const 49) ;; returned value
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
(i32.const 8) ;; length of returned value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(i32.const 8) ;; length of returned value
(i32.const 4) ;; length of returned value

i32 accirding to the imported fn sig

Copy link
Contributor Author

@pgherveou pgherveou Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's `(result i32) so it's 8 to take into account the enum variant tag
it's actually an i64, the comment is wrong will amend we are returning the QueryId not the return value

)
)

(func (export "deploy"))
)



pgherveou marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 44 additions & 0 deletions substrate/frame/contracts/fixtures/xcm_send.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;; This passes its input to `seal_xcm_send` and returns the return value to its caller.
(module
(import "seal0" "xcm_send" (func $xcm_send (param i32 i32 i32) (result i32)))
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; 0x1000 = 4k in little endian
;; size of input buffer
(data (i32.const 0) "\00\10")

(func (export "call")
;; Receive the encoded call
(call $seal_input
(i32.const 4) ;; Pointer to the input buffer
(i32.const 0) ;; Size of the length buffer
)
;; Input data layout.
;; [0..4) - size of the call
;; [4..7) - dest
;; [7..) - xcm message

;; Just use the call passed as input and store result to memory
(i32.store (i32.const 0)
(call $xcm_send
(i32.const 4) ;; Pointer where the dest is stored
(i32.const 7) ;; Pointer where the xcm msg is stored
(i32.sub ;; Size of the xcm msg
(i32.load (i32.const 0))
(i32.const 3)
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
(call $seal_return
(i32.const 0) ;; flags
(i32.const 0) ;; returned value
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
(i32.const 4) ;; length of returned value
)
)

(func (export "deploy"))
)


pgherveou marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions substrate/frame/contracts/fixtures/xcm_take_response.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; This passes its input to `seal_xcm_take_response` and returns the return value to its caller.
(module
(import "seal0" "xcm_take_response" (func $xcm_take_response (param i32 i32) (result i32)))
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))

;; 0x1000 = 4k in little endian
;; size of input buffer
(data (i32.const 0) "\00\10")

(func (export "call")
;; Receive the encoded call
(call $seal_input
(i32.const 4) ;; Pointer to the input buffer
(i32.const 0) ;; Size of the length buffer
)
;; Input data layout.
;; [0..4) - size of the call
;; [4..12) - query_id

;; Just use the call passed as input and store result to memory
(i32.store (i32.const 0)
(call $xcm_take_response
(i32.const 4) ;; Pointer where the query_id is stored
(i32.const 12) ;; Pointer where the response is stored
)
)

(call $seal_return
(i32.const 0) ;; flags
(i32.const 12) ;; returned value
(i32.const 112) ;; length of returned value
)
)

(func (export "deploy"))
)




pgherveou marked this conversation as resolved.
Show resolved Hide resolved
Loading