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 all 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
43 changes: 43 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ members = [
"substrate/frame/contracts/fixtures",
"substrate/frame/contracts/primitives",
"substrate/frame/contracts/proc-macro",
"substrate/frame/contracts/mock-network",
"substrate/frame/conviction-voting",
"substrate/frame/core-fellowship",
"substrate/frame/democracy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ impl Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type Debug = ();
type Environment = ();
type Xcm = pallet_xcm::Pallet<Self>;
}
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-builder/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use frame_support::pallet_prelude::DispatchError;
use sp_std::boxed::Box;
use xcm::prelude::*;
use xcm_executor::traits::QueryHandler;
pub use xcm_executor::traits::QueryHandler;

/// Umbrella trait for all Controller traits.
pub trait Controller<Origin, RuntimeCall, Timeout>:
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ pub use pay::{FixedLocation, LocatableAssetId, PayAccountId32OnChainOverXcm, Pay
mod controller;
pub use controller::{
Controller, ExecuteController, ExecuteControllerWeightInfo, QueryController,
QueryControllerWeightInfo, SendController, SendControllerWeightInfo,
QueryControllerWeightInfo, QueryHandler, SendController, SendControllerWeightInfo,
};
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 @@ -1353,6 +1353,7 @@ impl pallet_contracts::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Debug = ();
type Environment = ();
type Xcm = ();
}

impl pallet_sudo::Config for Runtime {
Expand Down
16 changes: 16 additions & 0 deletions substrate/frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ 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-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder", default-features = false}

[dev-dependencies]
array-bytes = "6.1"
assert_matches = "1"
Expand All @@ -56,13 +59,19 @@ pretty_assertions = "1"
wat = "1"
pallet-contracts-fixtures = { path = "./fixtures" }

# Polkadot Dependencies
xcm-builder = {package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder"}

# 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 Down Expand Up @@ -92,25 +101,32 @@ std = [
"sp-std/std",
"wasm-instrument/std",
"wasmi/std",
"xcm-builder/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",
"rand",
"rand_pcg",
"sp-runtime/runtime-benchmarks",
"wasm-instrument",
"xcm-builder/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",
Expand Down
52 changes: 52 additions & 0 deletions substrate/frame/contracts/fixtures/data/xcm_execute.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
;; 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 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 $assert (param i32)
(block $ok
(br_if $ok
(get_local 0)
)
(unreachable)
)
)

(func (export "call")
;; Receive the encoded call
(call $seal_input
(i32.const 4) ;; Pointer to the input buffer
(i32.const 0) ;; Pointer to the buffer length (before call) and to the copied data length (after call)
)
;; Input data layout.
;; [0..4) - size of the call
;; [4..) - message

;; Call xcm_execute with provided input.
(call $assert
(i32.eq
(call $xcm_execute
(i32.const 4) ;; Pointer where the message is stored
(i32.load (i32.const 0)) ;; Size of the message
(i32.const 100) ;; Pointer to the where the outcome is stored
)
(i32.const 0)
)
)

(call $seal_return
(i32.const 0) ;; flags
(i32.const 100) ;; Pointer to returned value
(i32.const 10) ;; length of returned value
)
)

(func (export "deploy"))
)

59 changes: 59 additions & 0 deletions substrate/frame/contracts/fixtures/data/xcm_send.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
;; 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 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 $assert (param i32)
(block $ok
(br_if $ok
(get_local 0)
)
(unreachable)
)
)

(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..) - message

;; Call xcm_send with provided input.
(call $assert
(i32.eq
(call $xcm_send
(i32.const 4) ;; Pointer where the dest is stored
(i32.const 7) ;; Pointer where the message is stored
(i32.sub
(i32.load (i32.const 0)) ;; length of the input buffer
(i32.const 3) ;; Size of the XCM dest
)
(i32.const 100) ;; Pointer to the where the message_id is stored
)
(i32.const 0)
)
)

;; Return the the message_id
(call $seal_return
(i32.const 0) ;; flags
(i32.const 100) ;; Pointer to returned value
(i32.const 32) ;; length of returned value
)
)

(func (export "deploy"))
)
2 changes: 2 additions & 0 deletions substrate/frame/contracts/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fn fixtures_root_dir() -> PathBuf {
// When `CARGO_MANIFEST_DIR` is not set, Rust resolves relative paths from the root folder
(Err(_), _) => "substrate/frame/contracts/fixtures/data".into(),
(Ok(path), Ok(s)) if s == "pallet-contracts" => PathBuf::from(path).join("fixtures/data"),
(Ok(path), Ok(s)) if s == "pallet-contracts-mock-network" =>
PathBuf::from(path).parent().unwrap().join("fixtures/data"),
(Ok(_), pkg_name) => panic!("Failed to resolve fixture dir for tests from {pkg_name:?}."),
}
}
Expand Down
91 changes: 91 additions & 0 deletions substrate/frame/contracts/mock-network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[package]
name = "pallet-contracts-mock-network"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage = "https://substrate.io"
repository.workspace = true
description = "A mock network for testing pallet-contracts"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ "derive", "max-encoded-len"] }

frame-support = { path = "../../support", default-features = false}
frame-system = { path = "../../system", default-features = false}
pallet-assets = { path = "../../assets" }
pallet-balances = { path = "../../balances" }
pallet-contracts = { path = ".." }
pallet-contracts-primitives = { path = "../primitives", default-features = false}
pallet-contracts-proc-macro = { path = "../proc-macro" }
pallet-insecure-randomness-collective-flip = { path = "../../insecure-randomness-collective-flip" }
pallet-message-queue = { path = "../../message-queue" }
pallet-proxy = { path = "../../proxy" }
pallet-timestamp = { path = "../../timestamp" }
pallet-utility = { path = "../../utility" }
pallet-xcm = { path = "../../../../polkadot/xcm/pallet-xcm", default-features = false}
polkadot-parachain-primitives = { path = "../../../../polkadot/parachain" }
polkadot-primitives = { path = "../../../../polkadot/primitives" }
polkadot-runtime-parachains = {path = "../../../../polkadot/runtime/parachains"}
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
sp-api = { path = "../../../primitives/api", default-features = false}
sp-core = { path = "../../../primitives/core", default-features = false}
sp-io = { path = "../../../primitives/io", default-features = false}
sp-keystore = { path = "../../../primitives/keystore" }
sp-runtime = { path = "../../../primitives/runtime", default-features = false}
sp-std = { path = "../../../primitives/std", default-features = false}
sp-tracing = { path = "../../../primitives/tracing" }
xcm = { package = "staging-xcm", path = "../../../../polkadot/xcm", default-features = false}
xcm-builder = {package = "staging-xcm-builder", path = "../../../../polkadot/xcm/xcm-builder"}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../polkadot/xcm/xcm-executor", default-features = false}
xcm-simulator = {path = "../../../../polkadot/xcm/xcm-simulator"}

[dev-dependencies]
assert_matches = "1"
pretty_assertions = "1"
pallet-contracts-fixtures = { path = "../fixtures" }

[features]
default = [ "std" ]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-contracts-primitives/std",
"pallet-contracts-proc-macro/full",
"pallet-contracts/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-proxy/std",
"pallet-timestamp/std",
"pallet-utility/std",
"pallet-xcm/std",
"scale-info/std",
"sp-api/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
"sp-runtime/std",
"sp-std/std",
"xcm-executor/std",
"xcm/std",
]

runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-contracts/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",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
Loading