diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4ffdbf34..34a86f11 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -39,14 +39,23 @@ jobs: target: wasm32-unknown-unknown components: rustfmt - - name: Check Build + - name: Check Build Trappist Runtime run: | - SKIP_WASM_BUILD=1 cargo check --release + SKIP_WASM_BUILD=1 cargo check --release --features with-trappist-runtime - - name: Check Build for Benchmarking + - name: Check Build Base Runtime + run: | + SKIP_WASM_BUILD=1 cargo check --release --features with-base-runtime + + - name: Check Build for Benchmarking Trappist Runtime + run: > + pushd node && + cargo check --features=runtime-benchmarks,with-trappist-runtime --release + + - name: Check Build for Benchmarking Base Runtime run: > pushd node && - cargo check --features=runtime-benchmarks --release + cargo check --features=runtime-benchmarks,with-base-runtime --release - name: Check formatting uses: actions-rs/cargo@v1 diff --git a/.gitignore b/.gitignore index 58513f67..b546950a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ # Log files *.log + +# Binaries +**/bin/ diff --git a/Cargo.lock b/Cargo.lock index 74eac548..49983d52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,11 +162,11 @@ checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" [[package]] name = "assert_cmd" -version = "2.0.5" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5c2ca00549910ec251e3bd15f87aeeb206c9456b9a77b43ff6c97c54042a472" +checksum = "ba45b8163c49ab5f972e59a8a5a03b6d2972619d486e19ec9fe744f7c2753d3c" dependencies = [ - "bstr", + "bstr 1.0.1", "doc-comment", "predicates", "predicates-core", @@ -196,30 +196,30 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" dependencies = [ - "concurrent-queue", + "concurrent-queue 1.2.4", "event-listener", "futures-core", ] [[package]] name = "async-executor" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" dependencies = [ + "async-lock", "async-task", - "concurrent-queue", + "concurrent-queue 2.0.0", "fastrand", "futures-lite", - "once_cell", "slab", ] [[package]] name = "async-global-executor" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0da5b41ee986eed3f524c380e6d64965aea573882a8907682ad100f7859305ca" +checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" dependencies = [ "async-channel", "async-executor", @@ -232,16 +232,16 @@ dependencies = [ [[package]] name = "async-io" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e21f3a490c72b3b0cf44962180e60045de2925d8dff97918f7ee43c8f637c7" +checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ + "async-lock", "autocfg", - "concurrent-queue", + "concurrent-queue 1.2.4", "futures-lite", "libc", "log", - "once_cell", "parking", "polling", "slab", @@ -252,11 +252,12 @@ dependencies = [ [[package]] name = "async-lock" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6" +checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685" dependencies = [ "event-listener", + "futures-lite", ] [[package]] @@ -339,9 +340,9 @@ dependencies = [ [[package]] name = "asynchronous-codec" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0de5164e5edbf51c45fb8c2d9664ae1c095cce1b265ecf7569093c0d66ef690" +checksum = "06a0daa378f5fd10634e44b0a29b2a87b890657658e072a30d6f26e57ddee182" dependencies = [ "bytes", "futures-sink", @@ -402,6 +403,86 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base-runtime" +version = "1.0.0" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-ping", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal", + "kusama-runtime-constants", + "log", + "pallet-asset-registry", + "pallet-asset-tx-payment", + "pallet-assets", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-collective", + "pallet-contracts", + "pallet-contracts-primitives", + "pallet-contracts-rpc-runtime-api", + "pallet-contracts-xcm", + "pallet-dex", + "pallet-dex-rpc-runtime-api", + "pallet-identity", + "pallet-multisig", + "pallet-preimage", + "pallet-randomness-collective-flip", + "pallet-scheduler", + "pallet-session", + "pallet-society", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-uniques", + "pallet-utility", + "pallet-xcm", + "parachain-info", + "parachains-common", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain", + "polkadot-runtime-common", + "scale-info", + "serde", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "substrate-wasm-builder", + "xcm", + "xcm-builder", + "xcm-executor", + "xcm-primitives", +] + [[package]] name = "base-x" version = "0.2.11" @@ -422,9 +503,9 @@ checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64ct" @@ -702,9 +783,19 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ - "lazy_static", "memchr", +] + +[[package]] +name = "bstr" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fca0852af221f458706eb0725c03e4ed6c46af9ac98e6a689d5e634215d594dd" +dependencies = [ + "memchr", + "once_cell", "regex-automata", + "serde", ] [[package]] @@ -724,9 +815,9 @@ checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-slice-cast" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "byte-tools" @@ -796,9 +887,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" dependencies = [ "jobserver", ] @@ -928,14 +1019,14 @@ checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", - "libloading 0.7.3", + "libloading 0.7.4", ] [[package]] name = "clap" -version = "3.2.22" +version = "3.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" dependencies = [ "atty", "bitflags", @@ -972,9 +1063,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.48" +version = "0.1.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" dependencies = [ "cc", ] @@ -1003,9 +1094,9 @@ dependencies = [ [[package]] name = "comfy-table" -version = "6.1.1" +version = "6.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b3d16bb3da60be2f7c7acfc438f2ae6f3496897ce68c291d0509bb67b4e248e" +checksum = "1090f39f45786ec6dc6286f8ea9c75d0a7ef0a0d3cda674cef0c3af7b307fbc2" dependencies = [ "strum", "strum_macros", @@ -1021,6 +1112,15 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "concurrent-queue" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-oid" version = "0.7.1" @@ -1860,9 +1960,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f83d0ebf42c6eafb8d7c52f7e5f2d3003b89c7aa4fd2b79229209459a849af8" +checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" dependencies = [ "cc", "cxxbridge-flags", @@ -1872,9 +1972,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07d050484b55975889284352b0ffc2ecbda25c0c55978017c132b29ba0818a86" +checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" dependencies = [ "cc", "codespan-reporting", @@ -1887,15 +1987,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d2199b00553eda8012dfec8d3b1c75fce747cf27c169a270b3b99e3448ab78" +checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" [[package]] name = "cxxbridge-macro" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb67a6de1f602736dd7eaead0080cf3435df806c61b24b13328db128c58868f" +checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" dependencies = [ "proc-macro2", "quote", @@ -2129,15 +2229,15 @@ dependencies = [ [[package]] name = "ed25519-zebra" -version = "3.0.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403ef3e961ab98f0ba902771d29f842058578bb1ce7e3c59dad5a6a93e784c69" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ "curve25519-dalek 3.2.0", + "hashbrown", "hex", "rand_core 0.6.4", "sha2 0.9.9", - "thiserror", "zeroize", ] @@ -2210,9 +2310,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ "atty", "humantime", @@ -2697,9 +2797,9 @@ dependencies = [ [[package]] name = "fs-err" -version = "2.8.1" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64db3e262960f0662f43a6366788d5f10f7f244b8f7d7d987f560baf5ded5c50" +checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" [[package]] name = "fs-swap" @@ -2960,7 +3060,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" dependencies = [ "aho-corasick", - "bstr", + "bstr 0.2.17", "fnv", "log", "regex", @@ -2991,9 +3091,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ "bytes", "fnv", @@ -3163,9 +3263,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.20" +version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ "bytes", "futures-channel", @@ -3202,9 +3302,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.51" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -3348,9 +3448,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "0.7.3" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" +checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" [[package]] name = "ip_network" @@ -3372,9 +3472,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" [[package]] name = "itertools" @@ -3739,9 +3839,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.135" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libloading" @@ -3755,9 +3855,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -3765,9 +3865,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "libp2p" @@ -4521,9 +4621,9 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95af15f345b17af2efc8ead6080fb8bc376f8cec1b35277b935637595fe77498" +checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc" dependencies = [ "libc", ] @@ -4603,14 +4703,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -4936,9 +5036,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", @@ -4959,7 +5059,6 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" dependencies = [ - "proc-macro-crate", "proc-macro2", "quote", "syn", @@ -4979,9 +5078,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "opaque-debug" @@ -5042,9 +5141,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.3.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" [[package]] name = "owning_ref" @@ -5432,7 +5531,6 @@ dependencies = [ "pallet-xcm", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-runtime", "sp-std", @@ -5459,7 +5557,7 @@ dependencies = [ [[package]] name = "pallet-dex" version = "0.0.1" -source = "git+https://github.com/paritytech/substrate-dex.git#fe793352c7b030fda6fb35406fcedaae55f4ab6e" +source = "git+https://github.com/paritytech/substrate-dex.git#1d165c651aa3aa0d026ad2cc34f5528cf083fc37" dependencies = [ "frame-benchmarking", "frame-support", @@ -5473,7 +5571,7 @@ dependencies = [ [[package]] name = "pallet-dex-rpc" version = "0.0.1" -source = "git+https://github.com/paritytech/substrate-dex.git#fe793352c7b030fda6fb35406fcedaae55f4ab6e" +source = "git+https://github.com/paritytech/substrate-dex.git#1d165c651aa3aa0d026ad2cc34f5528cf083fc37" dependencies = [ "jsonrpsee", "pallet-dex-rpc-runtime-api", @@ -5486,7 +5584,7 @@ dependencies = [ [[package]] name = "pallet-dex-rpc-runtime-api" version = "0.0.1" -source = "git+https://github.com/paritytech/substrate-dex.git#fe793352c7b030fda6fb35406fcedaae55f4ab6e" +source = "git+https://github.com/paritytech/substrate-dex.git#1d165c651aa3aa0d026ad2cc34f5528cf083fc37" dependencies = [ "pallet-dex", "parity-scale-codec", @@ -6402,9 +6500,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc7bc69c062e492337d74d59b120c274fd3d261b6bf6d3207d499b4b379c41a" +checksum = "a528564cc62c19a7acac4d81e01f39e53e25e17b934878f4c6d25cc2836e62f8" dependencies = [ "thiserror", "ucd-trie", @@ -6412,9 +6510,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b75706b9642ebcb34dab3bc7750f811609a0eb1dd8b88c2d15bf628c1c65b2" +checksum = "d5fd9bc6500181952d34bd0b2b0163a54d794227b498be0b7afa7698d0a7b18f" dependencies = [ "pest", "pest_generator", @@ -6422,9 +6520,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f9272122f5979a6511a749af9db9bfc810393f63119970d7085fed1c4ea0db" +checksum = "d2610d5ac5156217b4ff8e46ddcef7cdf44b273da2ac5bca2ecbfa86a330e7c4" dependencies = [ "pest", "pest_meta", @@ -6435,9 +6533,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8717927f9b79515e565a64fe46c38b8cd0427e64c40680b14a7365ab09ac8d" +checksum = "824749bf7e21dd66b36fbe26b3f45c713879cccd4a009a917ab8e045ca8246fe" dependencies = [ "once_cell", "pest", @@ -6505,9 +6603,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "platforms" @@ -7643,9 +7741,9 @@ dependencies = [ [[package]] name = "polling" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899b00b9c8ab553c743b3e11e87c5c7d423b2a2de229ba95b24a756344748011" +checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -7680,15 +7778,15 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "predicates" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" +checksum = "ab68289ded120dcbf9d571afcf70163233229052aec9b08ab09532f698d0e1e6" dependencies = [ "difflib", "itertools", @@ -7697,20 +7795,30 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" +checksum = "a6e7125585d872860e9955ca571650b27a4979c5823084168c5ed5bbfb016b56" [[package]] name = "predicates-tree" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" +checksum = "ad3f7fa8d61e139cbc7c3edfebf3b6678883a53f5ffac65d1259329a93ee43a5" dependencies = [ "predicates-core", "termtree", ] +[[package]] +name = "prettyplease" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c142c0e46b57171fe0c528bee8c5b7569e80f0c17e377cd0e30ea57dbc11bb51" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "primitive-types" version = "0.11.1" @@ -7832,12 +7940,12 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c3c31cdec40583bb68f0b18403400d01ec4289c383aa047560439952c4dd7" +checksum = "a0841812012b2d4a6145fae9a6af1534873c32aa67fff26bd09f8fa42c83f95a" dependencies = [ "bytes", - "prost-derive 0.11.0", + "prost-derive 0.11.2", ] [[package]] @@ -7864,9 +7972,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f835c582e6bd972ba8347313300219fed5bfa52caf175298d860b61ff6069bb" +checksum = "1d8b442418ea0822409d9e7d047cbf1e7e9e1760b172bf9982cf29d517c93511" dependencies = [ "bytes", "heck", @@ -7875,9 +7983,11 @@ dependencies = [ "log", "multimap", "petgraph", - "prost 0.11.0", - "prost-types 0.11.1", + "prettyplease", + "prost 0.11.2", + "prost-types 0.11.2", "regex", + "syn", "tempfile", "which", ] @@ -7910,9 +8020,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7345d5f0e08c0536d7ac7229952590239e77abf0a0100a1b1d890add6ea96364" +checksum = "164ae68b6587001ca506d3bf7f1000bfa248d0e1217b618108fba4ec1d0cc306" dependencies = [ "anyhow", "itertools", @@ -7933,12 +8043,12 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dfaa718ad76a44b3415e6c4d53b17c8f99160dcb3a99b10470fce8ad43f6e3e" +checksum = "747761bc3dc48f9a34553bf65605cf6cb6288ba219f3450b4275dbd81539551a" dependencies = [ "bytes", - "prost 0.11.0", + "prost 0.11.2", ] [[package]] @@ -8147,18 +8257,18 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12a733f1746c929b4913fe48f8697fcf9c55e3304ba251a79ffb41adfeaf49c2" +checksum = "53b15debb4f9d60d767cd8ca9ef7abb2452922f3214671ff052defc7f3502c44" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5887de4a01acafd221861463be6113e6e87275e79804e56779f4cdc131c60368" +checksum = "abfa8511e9e94fd3de6585a3d3cd00e01ed556dc9814829280af0e8dc72a8f36" dependencies = [ "proc-macro2", "quote", @@ -8179,9 +8289,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", @@ -8199,9 +8309,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "remote-externalities" @@ -8434,16 +8544,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.35.11" +version = "0.35.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbb2fda4666def1433b1b05431ab402e42a1084285477222b72d6c564c417cef" +checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -8857,6 +8967,40 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "sc-consensus-manual-seal" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" +dependencies = [ + "assert_matches", + "async-trait", + "futures 0.3.25", + "jsonrpsee", + "log", + "parity-scale-codec", + "sc-client-api", + "sc-consensus", + "sc-consensus-aura", + "sc-consensus-babe", + "sc-consensus-epochs", + "sc-transaction-pool", + "sc-transaction-pool-api", + "serde", + "sp-api", + "sp-blockchain", + "sp-consensus", + "sp-consensus-aura", + "sp-consensus-babe", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-keystore", + "sp-runtime", + "sp-timestamp", + "substrate-prometheus-endpoint", + "thiserror", +] + [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" @@ -9109,8 +9253,8 @@ dependencies = [ "futures 0.3.25", "libp2p", "log", - "prost 0.11.0", - "prost-build 0.11.1", + "prost 0.11.2", + "prost-build 0.11.2", "sc-client-api", "sc-network-common", "sp-blockchain", @@ -9586,9 +9730,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "333af15b02563b8182cd863f925bd31ef8fa86a0e095d30c091956057d436153" +checksum = "88d8a765117b237ef233705cc2cc4c6a27fccd46eea6ef0c8c6dae5f3ef407f8" dependencies = [ "bitvec", "cfg-if 1.0.0", @@ -9600,9 +9744,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53f56acbd0743d29ffa08f911ab5397def774ad01bab3786804cf6ee057fb5e1" +checksum = "cdcd47b380d8c4541044e341dcd9475f55ba37ddc50c908d945fc036a8642496" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9675,9 +9819,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff" +checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" dependencies = [ "secp256k1-sys", ] @@ -9758,18 +9902,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.146" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6df50b7a60a0ad48e1b42eb38373eac8ff785d619fb14db917b4e63d5439361f" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.146" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a714fd32ba1d66047ce7d53dabd809e9922d538f9047de13cc4cffca47b36205" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -10764,9 +10908,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.33.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab7554f8a8b6f8d71cd5a8e6536ef116e2ce0504cf97ebf16311d58065dc8a6" +checksum = "37a9821878e1f13aba383aa40a86fb1b33c7265774ec91e32563cb1dd1577496" dependencies = [ "Inflector", "num-format", @@ -11034,9 +11178,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" +checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" [[package]] name = "tempfile" @@ -11063,15 +11207,15 @@ dependencies = [ [[package]] name = "termtree" -version = "0.2.4" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" +checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8" [[package]] name = "textwrap" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" @@ -11386,6 +11530,24 @@ dependencies = [ "assert_cmd", "async-trait", "clap", + "derive_more", + "futures 0.3.25", + "log", + "nix 0.23.1", + "substrate-build-script-utils", + "tempfile", + "trappist-cli", + "trappist-service", +] + +[[package]] +name = "trappist-cli" +version = "1.0.0" +dependencies = [ + "assert_cmd", + "async-trait", + "base-runtime", + "clap", "cumulus-client-cli", "cumulus-client-consensus-aura", "cumulus-client-consensus-common", @@ -11398,60 +11560,55 @@ dependencies = [ "cumulus-relay-chain-interface", "cumulus-relay-chain-rpc-interface", "derive_more", - "frame-benchmarking", "frame-benchmarking-cli", "futures 0.3.25", "hex-literal", "jsonrpsee", "log", "nix 0.23.1", - "pallet-contracts-rpc", - "pallet-dex-rpc", - "pallet-transaction-payment-rpc", "parachains-common", "parity-scale-codec", "polkadot-cli", "polkadot-parachain", "polkadot-primitives", "polkadot-service", - "sc-basic-authorship", - "sc-chain-spec", "sc-cli", - "sc-client-api", - "sc-consensus", - "sc-executor", - "sc-keystore", - "sc-network", - "sc-rpc", - "sc-rpc-api", "sc-service", "sc-sysinfo", "sc-telemetry", "sc-tracing", - "sc-transaction-pool", - "sc-transaction-pool-api", "serde", - "sp-api", - "sp-block-builder", - "sp-blockchain", - "sp-consensus", - "sp-consensus-aura", "sp-core", - "sp-inherents", - "sp-io", - "sp-keystore", - "sp-offchain", "sp-runtime", - "sp-session", - "sp-timestamp", - "sp-transaction-pool", "substrate-build-script-utils", - "substrate-frame-rpc-system", - "substrate-prometheus-endpoint", "tempfile", "trappist-runtime", + "trappist-service", "try-runtime-cli", - "xcm", +] + +[[package]] +name = "trappist-rpc" +version = "1.0.0" +dependencies = [ + "futures 0.3.25", + "jsonrpsee", + "pallet-contracts-rpc", + "pallet-dex-rpc", + "pallet-transaction-payment-rpc", + "parachains-common", + "parity-scale-codec", + "sc-client-api", + "sc-consensus-manual-seal", + "sc-rpc", + "sc-rpc-api", + "sc-transaction-pool-api", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-runtime", + "substrate-frame-rpc-system", + "trappist-runtime", ] [[package]] @@ -11534,6 +11691,83 @@ dependencies = [ "xcm-primitives", ] +[[package]] +name = "trappist-service" +version = "1.0.0" +dependencies = [ + "assert_cmd", + "async-trait", + "base-runtime", + "clap", + "cumulus-client-cli", + "cumulus-client-consensus-aura", + "cumulus-client-consensus-common", + "cumulus-client-consensus-relay-chain", + "cumulus-client-network", + "cumulus-client-service", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "cumulus-relay-chain-inprocess-interface", + "cumulus-relay-chain-interface", + "cumulus-relay-chain-rpc-interface", + "derive_more", + "frame-benchmarking", + "frame-benchmarking-cli", + "futures 0.3.25", + "hex-literal", + "jsonrpsee", + "log", + "nix 0.23.1", + "pallet-contracts-rpc", + "pallet-dex-rpc", + "pallet-transaction-payment-rpc", + "parachains-common", + "parity-scale-codec", + "polkadot-cli", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-service", + "sc-basic-authorship", + "sc-chain-spec", + "sc-cli", + "sc-client-api", + "sc-consensus", + "sc-executor", + "sc-keystore", + "sc-network", + "sc-rpc", + "sc-rpc-api", + "sc-service", + "sc-sysinfo", + "sc-telemetry", + "sc-tracing", + "sc-transaction-pool", + "sc-transaction-pool-api", + "serde", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-aura", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-timestamp", + "sp-transaction-pool", + "substrate-build-script-utils", + "substrate-frame-rpc-system", + "substrate-prometheus-endpoint", + "tempfile", + "trappist-rpc", + "trappist-runtime", + "try-runtime-cli", + "xcm", +] + [[package]] name = "trie-db" version = "0.24.0" diff --git a/Cargo.toml b/Cargo.toml index 0ea10265..41b2ce5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,8 @@ [workspace] members = [ "node", - "runtime", + "runtime/base", + "runtime/trappist", "primitives/xcm", ] exclude = [ diff --git a/README.md b/README.md index 1dd8bb0c..1779cb3a 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,15 @@ First, complete the [basic Rust setup instructions](./docs/rust-setup.md). Use the following command to build the Trappist collector binary: -```sh -cargo build --release +When the base collator is built, rename the binary into `base-collator` and place it into the `./bin` folder. ``` +cargo b -r --features with-base-runtime +cargo b -r --features with-trappist-runtime +``` + +Alternatively, run +`bash build_runtimes.sh` . + ### XCM Playground via Zombienet @@ -62,6 +68,9 @@ Create a `bin` directory into the root of this repository and place the followin - `polkadot` (which you can download from [the releases](https://github.com/paritytech/polkadot/releases)) - `polkadot-parachain` (which you will build from [cumulus](https://github.com/paritytech/cumulus)) - `trappist-collator` (which you will build from this repository) +- `base-collator` (which you will build from this repository) + + Download the [latest release of zombienet](https://github.com/paritytech/zombienet/releases/) into the root of this repository and make it executable: ``` diff --git a/build_runtimes.sh b/build_runtimes.sh new file mode 100644 index 00000000..320aa23c --- /dev/null +++ b/build_runtimes.sh @@ -0,0 +1,3 @@ +cargo b -r --features with-base-runtime +cp target/release/trappist-collator target/release/base-collator +cargo b -r --features with-trappist-runtime diff --git a/node/Cargo.toml b/node/Cargo.toml index e9c5b9a2..c8eff107 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -7,7 +7,6 @@ license = "Unlicense" homepage = "https://trappist.io" repository = "https://github.com/TrappistNetwork/trappist" edition = "2021" -build = "build.rs" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -24,86 +23,9 @@ async-trait = "0.1.57" clap = { version = "3.2.17", features = ["derive"] } derive_more = "0.99.2" log = "0.4.17" -codec = { package = "parity-scale-codec", version = "3.0.0" } -serde = { version = "1.0.140", features = ["derive"] } -hex-literal = "0.3.4" futures = { version = "0.3.1", features = ["compat"] } - -# RPC related Dependencies -jsonrpsee = { version = "0.15.1", features = ["server"] } - -# Local Dependencies -trappist-runtime = { path = "../runtime" } - -# Substrate Dependencies -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } - -pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } - -substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } - -## Substrate Client Dependencies -sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-cli = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30" } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-executor = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30" } -sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-service = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30" } -sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } - -## Substrate Primitive Dependencies -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } - -# Cumulus dependencies -cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } -cumulus-relay-chain-rpc-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } - -parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } - -# Polkadot dependencies -polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } -polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } -polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } - -# External Dependencies -pallet-dex-rpc = { version = "0.0.1", git = "https://github.com/paritytech/substrate-dex.git", default-features = false} +trappist-cli = { path = "cli" } +trappist-service = { path = "service" } [dev-dependencies] assert_cmd = "2.0" @@ -113,9 +35,13 @@ tempfile = "3.2.0" [features] default = [] runtime-benchmarks = [ - "polkadot-cli/runtime-benchmarks", - "trappist-runtime/runtime-benchmarks" + "trappist-cli/runtime-benchmarks" ] -try-runtime = [ - "trappist-runtime/try-runtime" +with-trappist-runtime = [ + "trappist-service/with-trappist-runtime", + "trappist-cli/with-trappist-runtime", ] +with-base-runtime = [ + "trappist-service/with-base-runtime", + "trappist-cli/with-base-runtime", +] \ No newline at end of file diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml new file mode 100644 index 00000000..c0f72bcd --- /dev/null +++ b/node/cli/Cargo.toml @@ -0,0 +1,101 @@ +[package] +name = "trappist-cli" +version = "1.0.0" +authors = ["Trappist Network "] +description = "A versatile Proof-of-Authority (PoA) Blockchain network." +license = "Unlicense" +homepage = "https://trappist.io" +repository = "https://github.com/TrappistNetwork/trappist" +edition = "2021" +build = "build.rs" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[build-dependencies] +substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[dependencies] +async-trait = "0.1.57" +clap = { version = "3.2.17", features = ["derive"] } +derive_more = "0.99.2" +log = "0.4.17" +codec = { package = "parity-scale-codec", version = "3.0.0" } +serde = { version = "1.0.140", features = ["derive"] } +hex-literal = "0.3.4" +futures = { version = "0.3.1", features = ["compat"] } + +# RPC related Dependencies +jsonrpsee = { version = "0.15.1", features = ["server"] } + +# Local Dependencies +trappist-runtime = { path = "../../runtime/trappist" } +base-runtime = { path = "../../runtime/base" } + +# Substrate Dependencies +frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30", optional = true } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30", optional = true } + +## Substrate Client Dependencies +sc-cli = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30", optional = true} +sc-service = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30", optional = true } +sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +## Substrate Primitive Dependencies +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" , optional = true} +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +# Cumulus dependencies +cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-relay-chain-rpc-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } + +parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } + +# Polkadot dependencies +polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } + +service = { package = "trappist-service", path = "../service", default-features = false, optional = true } + +[dev-dependencies] +assert_cmd = "2.0" +nix = "0.23" +tempfile = "3.2.0" + +[features] +default = [ "cli" ] +cli = [ + "service", + "sp-core", + "sc-cli", + "sc-service", + "frame-benchmarking-cli", + "try-runtime-cli", +] +runtime-benchmarks = [ + "polkadot-cli/runtime-benchmarks", + "trappist-runtime/runtime-benchmarks", + "base-runtime/runtime-benchmarks" +] +try-runtime = [ + "service/try-runtime" +] +with-trappist-runtime = [ + "service/with-trappist-runtime", +] +with-base-runtime = [ + "service/with-base-runtime", +] \ No newline at end of file diff --git a/node/build.rs b/node/cli/build.rs similarity index 100% rename from node/build.rs rename to node/cli/build.rs diff --git a/node/src/cli.rs b/node/cli/src/cli.rs similarity index 92% rename from node/src/cli.rs rename to node/cli/src/cli.rs index 9e2dda99..86abcb4f 100644 --- a/node/src/cli.rs +++ b/node/cli/src/cli.rs @@ -14,6 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use service::chain_spec; +#[cfg(feature = "with-base-runtime")] +use service::chain_spec::base::Extensions; +#[cfg(feature = "with-trappist-runtime")] +use service::chain_spec::trappist::Extensions; use std::path::PathBuf; /// Sub-commands supported by the collator. @@ -101,7 +106,7 @@ impl RelayChainCli { para_config: &sc_service::Configuration, relay_chain_args: impl Iterator, ) -> Self { - let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); + let extension = Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot")); Self { base_path, chain_id, base: clap::Parser::parse_from(relay_chain_args) } diff --git a/node/src/command.rs b/node/cli/src/command.rs similarity index 89% rename from node/src/command.rs rename to node/cli/src/command.rs index bf35f499..566ab969 100644 --- a/node/src/command.rs +++ b/node/cli/src/command.rs @@ -15,24 +15,23 @@ use sc_service::{ }; use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; + +#[cfg(feature = "with-base-runtime")] +use base_runtime::{Block, RuntimeApi}; +#[cfg(feature = "with-trappist-runtime")] use trappist_runtime::{Block, RuntimeApi}; -use crate::{ - chain_spec, - cli::{Cli, RelayChainCli, Subcommand}, - service::{new_partial, TrappistRuntimeExecutor}, -}; +use crate::cli::{Cli, RelayChainCli, Subcommand}; +use service::{chain_spec, new_partial, RuntimeExecutor}; -fn load_spec(id: &str) -> std::result::Result, String> { - Ok(match id { - // -- Trappist - "dev" | "trappist_dev" => Box::new(chain_spec::development_config()), - "" | "local" | "trappist-local" | "trappist-rococo" => - Box::new(chain_spec::local_testnet_config()), - // -- Loading a specific spec from disk - path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), - }) -} +#[cfg(feature = "with-base-runtime")] +use service::chain_spec::base::{ + development_config, local_testnet_config, ChainSpec as ServiceChainSpec, Extensions, +}; +#[cfg(feature = "with-trappist-runtime")] +use service::chain_spec::trappist::{ + development_config, local_testnet_config, ChainSpec as ServiceChainSpec, Extensions, +}; impl SubstrateCli for Cli { fn impl_name() -> String { @@ -66,7 +65,13 @@ impl SubstrateCli for Cli { } fn load_spec(&self, id: &str) -> std::result::Result, String> { - load_spec(id) + Ok(match id { + // -- Trappist + "dev" | "trappist_dev" => Box::new(development_config()), + "" | "local" | "trappist-local" | "trappist-rococo" => Box::new(local_testnet_config()), + // -- Loading a specific spec from disk + path => Box::new(ServiceChainSpec::from_json_file(std::path::PathBuf::from(path))?), + }) } fn native_runtime_version(_: &Box) -> &'static RuntimeVersion { @@ -120,11 +125,11 @@ macro_rules! construct_async_run { runner.async_run(|$config| { let $components = new_partial::< RuntimeApi, - TrappistRuntimeExecutor, + RuntimeExecutor, _ >( &$config, - crate::service::parachain_build_import_queue, + service::parachain_build_import_queue, )?; let task_manager = $components.task_manager; { $( $code )* }.map(|v| (v, task_manager)) @@ -206,16 +211,16 @@ pub fn run() -> Result<()> { match cmd { BenchmarkCmd::Pallet(cmd) => if cfg!(feature = "runtime-benchmarks") { - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run::(config)) } else { Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." .into()) }, BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, - crate::service::parachain_build_import_queue, + service::parachain_build_import_queue, )?; cmd.run(partials.client) }), @@ -229,9 +234,9 @@ pub fn run() -> Result<()> { .into()), #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { - let partials = new_partial::( + let partials = new_partial::( &config, - crate::service::parachain_build_import_queue, + service::parachain_build_import_queue, )?; let db = partials.backend.expose_db(); let storage = partials.backend.expose_storage(); @@ -257,7 +262,7 @@ pub fn run() -> Result<()> { .map_err(|e| format!("Error: {:?}", e))?; runner.async_run(|config| { - Ok((cmd.run::(config), task_manager)) + Ok((cmd.run::(config), task_manager)) }) } else { Err("Try-runtime must be enabled by `--features try-runtime`.".into()) @@ -277,7 +282,7 @@ pub fn run() -> Result<()> { None }; - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) + let para_id = Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) .ok_or_else(|| "Could not find parachain ID in chain-spec.")?; @@ -306,7 +311,7 @@ pub fn run() -> Result<()> { info!("Parachain genesis state: {}", genesis_state); info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - crate::service::start_parachain_node( + service::start_parachain_node( config, polkadot_config, collator_options, diff --git a/node/cli/src/lib.rs b/node/cli/src/lib.rs new file mode 100644 index 00000000..59ec9bd6 --- /dev/null +++ b/node/cli/src/lib.rs @@ -0,0 +1,16 @@ +#![warn(missing_docs)] +#![warn(unused_extern_crates)] + +#[cfg(feature = "cli")] +mod cli; +#[cfg(feature = "cli")] +mod command; + +#[cfg(feature = "cli")] +pub use cli::*; + +#[cfg(feature = "cli")] +pub use command::*; + +#[cfg(feature = "cli")] +pub use sc_cli::{Error, Result}; diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml new file mode 100644 index 00000000..689f38a4 --- /dev/null +++ b/node/service/Cargo.toml @@ -0,0 +1,125 @@ +[package] +name = "trappist-service" +version = "1.0.0" +authors = ["Trappist Network "] +description = "A versatile Proof-of-Authority (PoA) Blockchain network." +license = "Unlicense" +homepage = "https://trappist.io" +repository = "https://github.com/TrappistNetwork/trappist" +edition = "2021" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[build-dependencies] +substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[dependencies] +async-trait = "0.1.57" +clap = { version = "3.2.17", features = ["derive"] } +derive_more = "0.99.2" +log = "0.4.17" +codec = { package = "parity-scale-codec", version = "3.0.0" } +serde = { version = "1.0.140", features = ["derive"] } +hex-literal = "0.3.4" +futures = { version = "0.3.1", features = ["compat"] } + +# RPC related Dependencies +jsonrpsee = { version = "0.15.1", features = ["server"] } + +# Local Dependencies +trappist-runtime = { path = "../../runtime/trappist", optional = true } +base-runtime = { path = "../../runtime/base", optional = true } +trappist-rpc = { path = "../../rpc" } + +# Substrate Dependencies +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +## Substrate Client Dependencies +sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-cli = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-executor = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30" } +sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-service = { git = "https://github.com/paritytech/substrate", features = ["wasmtime"], branch = "polkadot-v0.9.30" } +sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +## Substrate Primitive Dependencies +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +# Cumulus dependencies +cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } +cumulus-relay-chain-rpc-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } + +parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } + +# Polkadot dependencies +polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } + +# External Dependencies +pallet-dex-rpc = { version = "0.0.1", git = "https://github.com/paritytech/substrate-dex.git", default-features = false } + +[dev-dependencies] +assert_cmd = "2.0" +nix = "0.23" +tempfile = "3.2.0" + +[features] +default = [ "std" ] +std = [] +runtime-benchmarks = [ + "trappist-runtime/runtime-benchmarks", + "base-runtime/runtime-benchmarks" +] +try-runtime = [ + "trappist-runtime/try-runtime" +] +with-trappist-runtime = [ + "trappist-runtime", +] +with-base-runtime = [ + "base-runtime", +] \ No newline at end of file diff --git a/node/service/src/chain_spec/base.rs b/node/service/src/chain_spec/base.rs new file mode 100644 index 00000000..a14a364e --- /dev/null +++ b/node/service/src/chain_spec/base.rs @@ -0,0 +1,245 @@ +use base_runtime::{ + constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig, + CouncilConfig, GenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, +}; +use cumulus_primitives_core::ParaId; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; +use sc_service::ChainType; +use serde::{Deserialize, Serialize}; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::traits::{IdentifyAccount, Verify}; + +const DEFAULT_PROTOCOL_ID: &str = "base"; + +/// Specialized `ChainSpec` for the normal parachain runtime. +pub type ChainSpec = sc_service::GenericChainSpec; + +/// The default XCM version to set in genesis config. +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; + +/// Helper function to generate a crypto pair from seed +pub fn get_public_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// The extensions for the [`ChainSpec`]. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +#[serde(deny_unknown_fields)] +pub struct Extensions { + /// The relay chain of the Parachain. + pub relay_chain: String, + /// The id of the Parachain. + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + +type AccountPublic = ::Signer; + +/// Generate collator keys from seed. +/// +/// This function's return type must always match the session keys of the chain in tuple format. +pub fn get_collator_keys_from_seed(seed: &str) -> AuraId { + get_public_from_seed::(seed) +} + +/// Helper function to generate an account ID from seed +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_public_from_seed::(seed)).into_account() +} + +/// Generate the session keys from individual elements. +/// +/// The input must be a tuple of individual keys (a single arg for now since we have just one key). +fn session_keys(aura: AuraId) -> SessionKeys { + SessionKeys { aura } +} + +pub fn development_config() -> ChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "xUSD".into()); + properties.insert("tokenDecimals".into(), 12.into()); + properties.insert("ss58Format".into(), 42.into()); + + ChainSpec::from_genesis( + // Name + "Base Development", + // ID + "base_dev", + ChainType::Development, + move || { + testnet_genesis( + // Initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), + ], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + ], + 3000.into(), + ) + }, + // Bootnodes + vec![], + // Telemetry + None, + // Protocol ID + Some(DEFAULT_PROTOCOL_ID), + None, + // Properties + Some(properties), + // Extensions + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: 3000, + }, + ) +} + +pub fn local_testnet_config() -> ChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "xUSD".into()); + properties.insert("tokenDecimals".into(), 12.into()); + properties.insert("ss58Format".into(), 42.into()); + + ChainSpec::from_genesis( + // Name + "Base Local", + // ID + "base_local", + ChainType::Local, + move || { + testnet_genesis( + // Initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), + ], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + ], + 3000.into(), + ) + }, + // Bootnodes + vec![], + // Telemetry + None, + // Protocol ID + Some(DEFAULT_PROTOCOL_ID), + None, + // Properties + Some(properties), + // Extensions + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: 3000, + }, + ) +} + +pub const LOCAL_ASSET_ID: u32 = 20; + +/// Configure initial storage state for FRAME modules. +fn testnet_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + root_key: AccountId, + endowed_accounts: Vec, + id: ParaId, +) -> GenesisConfig { + GenesisConfig { + system: SystemConfig { + code: base_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!") + .to_vec(), + }, + balances: BalancesConfig { + // Configure endowed accounts with initial balance of 1 << 60. + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + parachain_info: base_runtime::ParachainInfoConfig { parachain_id: id }, + collator_selection: base_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: EXISTENTIAL_DEPOSIT * 16, + ..Default::default() + }, + session: SessionConfig { + keys: invulnerables + .iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc.clone(), // validator id + session_keys(aura.clone()), // session keys + ) + }) + .collect(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: base_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) }, + sudo: SudoConfig { + // Assign network admin rights. + key: Some(root_key), + }, + assets: AssetsConfig { + assets: vec![ + // id, owner, is_sufficient, min_balance + (LOCAL_ASSET_ID, get_account_id_from_seed::("Alice"), true, 1), + ], + metadata: vec![ + // id, name, symbol, decimals + (LOCAL_ASSET_ID, "BASE".into(), "xUSD".into(), 10), + ], + accounts: vec![ + // id, account_id, balance + (LOCAL_ASSET_ID, get_account_id_from_seed::("Alice"), 100), + ], + }, + council: CouncilConfig { + members: invulnerables.iter().map(|x| x.0.clone()).collect::>(), + phantom: Default::default(), + }, + } +} diff --git a/node/service/src/chain_spec/mod.rs b/node/service/src/chain_spec/mod.rs new file mode 100644 index 00000000..ac651893 --- /dev/null +++ b/node/service/src/chain_spec/mod.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "with-base-runtime")] +pub mod base; +#[cfg(feature = "with-trappist-runtime")] +pub mod trappist; diff --git a/node/src/chain_spec.rs b/node/service/src/chain_spec/trappist.rs similarity index 100% rename from node/src/chain_spec.rs rename to node/service/src/chain_spec/trappist.rs diff --git a/node/src/service.rs b/node/service/src/lib.rs similarity index 64% rename from node/src/service.rs rename to node/service/src/lib.rs index 1c73f99f..f3ced4a6 100644 --- a/node/src/service.rs +++ b/node/service/src/lib.rs @@ -7,7 +7,9 @@ use std::{sync::Arc, time::Duration}; use jsonrpsee::RpcModule; // Common Runtime Types -pub use parachains_common::{AccountId, Balance, Block, BlockNumber, Hash, Header, Index as Nonce}; +pub use parachains_common::{ + AccountId, AssetId, Balance, Block, BlockNumber, Hash, Header, Index as Nonce, +}; // Cumulus Imports use cumulus_client_cli::CollatorOptions; @@ -33,23 +35,59 @@ use substrate_prometheus_endpoint::Registry; use polkadot_service::CollatorPair; -use trappist_runtime::{AssetBalance, AssetId}; +#[cfg(feature = "with-base-runtime")] +use base_runtime::AssetBalance; +#[cfg(feature = "with-trappist-runtime")] +use trappist_runtime::AssetBalance; + +pub mod chain_spec; -/// Native executor instance. -pub struct TrappistRuntimeExecutor; +#[cfg(feature = "with-trappist-runtime")] +mod trappist_executor { + pub use trappist_runtime; -impl sc_executor::NativeExecutionDispatch for TrappistRuntimeExecutor { - type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; + pub struct RuntimeExecutor; + impl sc_executor::NativeExecutionDispatch for RuntimeExecutor { + type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; + + fn dispatch(method: &str, data: &[u8]) -> Option> { + trappist_runtime::api::dispatch(method, data) + } - fn dispatch(method: &str, data: &[u8]) -> Option> { - trappist_runtime::api::dispatch(method, data) + fn native_version() -> sc_executor::NativeVersion { + trappist_runtime::native_version() + } } +} + +#[cfg(feature = "with-base-runtime")] +mod base_executor { + pub use base_runtime; + + pub struct RuntimeExecutor; + impl sc_executor::NativeExecutionDispatch for RuntimeExecutor { + type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; - fn native_version() -> sc_executor::NativeVersion { - trappist_runtime::native_version() + fn dispatch(method: &str, data: &[u8]) -> Option> { + base_runtime::api::dispatch(method, data) + } + + fn native_version() -> sc_executor::NativeVersion { + base_runtime::native_version() + } } } +#[cfg(feature = "with-base-runtime")] +pub use base_executor::*; +#[cfg(feature = "with-trappist-runtime")] +pub use trappist_executor::*; + +#[cfg(feature = "with-trappist-runtime")] +pub type RuntimeApi = trappist_runtime::RuntimeApi; +#[cfg(feature = "with-base-runtime")] +pub type RuntimeApi = base_runtime::RuntimeApi; + /// Starts a `ServiceBuilder` for a full service. /// /// Use this macro if you don't actually need the full service, but just the builder in order to @@ -191,6 +229,7 @@ async fn build_relay_chain_interface( /// Start a node with the given parachain `Configuration` and relay chain `Configuration`. /// /// This is the actual implementation that is abstract over the executor and the runtime api. +#[cfg(feature = "with-trappist-runtime")] #[sc_tracing::logging::prefix_logs_with("Parachain")] async fn start_node_impl( parachain_config: Configuration, @@ -307,13 +346,227 @@ where let transaction_pool = transaction_pool.clone(); Box::new(move |deny_unsafe, _| { - let deps = crate::rpc::FullDeps { + let deps = trappist_rpc::FullDeps { client: client.clone(), pool: transaction_pool.clone(), deny_unsafe, }; - crate::rpc::create_full(deps).map_err(Into::into) + trappist_rpc::trappist_create_full(deps).map_err(Into::into) + }) + }; + + sc_service::spawn_tasks(sc_service::SpawnTasksParams { + rpc_builder, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + task_manager: &mut task_manager, + config: parachain_config, + keystore: params.keystore_container.sync_keystore(), + backend: backend.clone(), + network: network.clone(), + system_rpc_tx, + tx_handler_controller, + telemetry: telemetry.as_mut(), + })?; + + if let Some(hwbench) = hwbench { + sc_sysinfo::print_hwbench(&hwbench); + + if let Some(ref mut telemetry) = telemetry { + let telemetry_handle = telemetry.handle(); + task_manager.spawn_handle().spawn( + "telemetry_hwbench", + None, + sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench), + ); + } + } + + let announce_block = { + let network = network.clone(); + Arc::new(move |hash, data| network.announce_block(hash, data)) + }; + + let relay_chain_slot_duration = Duration::from_secs(6); + + if validator { + let parachain_consensus = build_consensus( + client.clone(), + prometheus_registry.as_ref(), + telemetry.as_ref().map(|t| t.handle()), + &task_manager, + relay_chain_interface.clone(), + transaction_pool, + network, + params.keystore_container.sync_keystore(), + force_authoring, + )?; + + let spawner = task_manager.spawn_handle(); + + let params = StartCollatorParams { + para_id: id, + block_status: client.clone(), + announce_block, + client: client.clone(), + task_manager: &mut task_manager, + relay_chain_interface: relay_chain_interface.clone(), + spawner, + parachain_consensus, + import_queue, + collator_key: collator_key.expect("Command line arguments do not allow this. qed"), + relay_chain_slot_duration, + }; + + start_collator(params).await?; + } else { + let params = StartFullNodeParams { + client: client.clone(), + announce_block, + task_manager: &mut task_manager, + para_id: id, + relay_chain_interface, + relay_chain_slot_duration, + import_queue, + collator_options, + }; + + start_full_node(params)?; + } + + start_network.start_network(); + + Ok((task_manager, client)) +} + +// TODO: how to avoid having two of these huge functions? +/// Start a node with the given parachain `Configuration` and relay chain `Configuration`. +/// +/// This is the actual implementation that is abstract over the executor and the runtime api. +#[cfg(feature = "with-base-runtime")] +#[sc_tracing::logging::prefix_logs_with("Parachain")] +async fn start_node_impl( + parachain_config: Configuration, + polkadot_config: Configuration, + collator_options: CollatorOptions, + id: ParaId, + _rpc_ext_builder: RB, + build_import_queue: BIQ, + build_consensus: BIC, + hwbench: Option, +) -> sc_service::error::Result<( + TaskManager, + Arc>>, +)> +where + RuntimeApi: ConstructRuntimeApi>> + + Send + + Sync + + 'static, + RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue + + sp_api::Metadata + + sp_session::SessionKeys + + sp_api::ApiExt< + Block, + StateBackend = sc_client_api::StateBackendFor, Block>, + > + sp_offchain::OffchainWorkerApi + + sp_block_builder::BlockBuilder + + cumulus_primitives_core::CollectCollationInfo + + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + + substrate_frame_rpc_system::AccountNonceApi + + pallet_contracts_rpc::ContractsRuntimeApi, + sc_client_api::StateBackendFor, Block>: sp_api::StateBackend, + Executor: sc_executor::NativeExecutionDispatch + 'static, + RB: Fn( + Arc>>, + ) -> Result, sc_service::Error> + + Send + + 'static, + BIQ: FnOnce( + Arc>>, + &Configuration, + Option, + &TaskManager, + ) -> Result< + sc_consensus::DefaultImportQueue< + Block, + TFullClient>, + >, + sc_service::Error, + > + 'static, + BIC: FnOnce( + Arc>>, + Option<&Registry>, + Option, + &TaskManager, + Arc, + Arc< + sc_transaction_pool::FullPool< + Block, + TFullClient>, + >, + >, + Arc>, + SyncCryptoStorePtr, + bool, + ) -> Result>, sc_service::Error>, +{ + let parachain_config = prepare_node_config(parachain_config); + + let params = new_partial::(¶chain_config, build_import_queue)?; + let (mut telemetry, telemetry_worker_handle) = params.other; + + let client = params.client.clone(); + let backend = params.backend.clone(); + + let mut task_manager = params.task_manager; + let (relay_chain_interface, collator_key) = build_relay_chain_interface( + polkadot_config, + ¶chain_config, + telemetry_worker_handle, + &mut task_manager, + collator_options.clone(), + hwbench.clone(), + ) + .await + .map_err(|e| match e { + RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x, + s => s.to_string().into(), + })?; + + let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id); + + let force_authoring = parachain_config.force_authoring; + let validator = parachain_config.role.is_authority(); + let prometheus_registry = parachain_config.prometheus_registry().cloned(); + let transaction_pool = params.transaction_pool.clone(); + let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue); + let (network, system_rpc_tx, tx_handler_controller, start_network) = + sc_service::build_network(sc_service::BuildNetworkParams { + config: ¶chain_config, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + spawn_handle: task_manager.spawn_handle(), + import_queue: import_queue.clone(), + block_announce_validator_builder: Some(Box::new(|_| { + Box::new(block_announce_validator) + })), + warp_sync: None, + })?; + + let rpc_builder = { + let client = client.clone(); + let transaction_pool = transaction_pool.clone(); + + Box::new(move |deny_unsafe, _| { + let deps = trappist_rpc::FullDeps { + client: client.clone(), + pool: transaction_pool.clone(), + deny_unsafe, + }; + + trappist_rpc::base_create_full(deps).map_err(Into::into) }) }; @@ -404,24 +657,14 @@ where /// Build the import queue for the rococo parachain runtime. #[allow(clippy::type_complexity)] pub fn parachain_build_import_queue( - client: Arc< - TFullClient< - Block, - trappist_runtime::RuntimeApi, - NativeElseWasmExecutor, - >, - >, + client: Arc>>, config: &Configuration, telemetry: Option, task_manager: &TaskManager, ) -> Result< sc_consensus::DefaultImportQueue< Block, - TFullClient< - Block, - trappist_runtime::RuntimeApi, - NativeElseWasmExecutor, - >, + TFullClient>, >, sc_service::Error, > { @@ -464,15 +707,9 @@ pub async fn start_parachain_node( hwbench: Option, ) -> sc_service::error::Result<( TaskManager, - Arc< - TFullClient< - Block, - trappist_runtime::RuntimeApi, - NativeElseWasmExecutor, - >, - >, + Arc>>, )> { - start_node_impl::( + start_node_impl::( parachain_config, polkadot_config, collator_options, diff --git a/node/src/main.rs b/node/src/main.rs index d114d2f5..c39414b3 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -19,13 +19,6 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] -mod chain_spec; -#[macro_use] -mod service; -mod cli; -mod command; -mod rpc; - -fn main() -> sc_cli::Result<()> { - command::run() +fn main() -> trappist_cli::Result<()> { + trappist_cli::run() } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml new file mode 100644 index 00000000..1a561e74 --- /dev/null +++ b/rpc/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "trappist-rpc" +version = "1.0.0" +authors = ["Trappist Network "] +description = "A versatile Proof-of-Authority (PoA) Blockchain network." +license = "Unlicense" +homepage = "https://trappist.io" +repository = "https://github.com/TrappistNetwork/trappist" +edition = "2021" + +[dependencies] +futures = "0.3.21" +jsonrpsee = { version = "0.15.1", features = ["server", "macros"] } +codec = { package = "parity-scale-codec", version = "3.0.0" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-contracts-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } + +parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } + +# External Dependencies +pallet-dex-rpc = { version = "0.0.1", git = "https://github.com/paritytech/substrate-dex.git", default-features = false } + +trappist-runtime = { path = "../runtime/trappist" } \ No newline at end of file diff --git a/node/src/rpc.rs b/rpc/src/lib.rs similarity index 66% rename from node/src/rpc.rs rename to rpc/src/lib.rs index e2cc46e5..dbcc5b9d 100644 --- a/node/src/rpc.rs +++ b/rpc/src/lib.rs @@ -42,7 +42,7 @@ pub struct FullDeps { } /// Instantiate all RPCs we want at the canvas-kusama chain. -pub fn create_full( +pub fn trappist_create_full( deps: FullDeps, ) -> Result> where @@ -88,3 +88,43 @@ where Ok(module) } + +/// Instantiate all RPCs we want at the canvas-kusama chain. +pub fn base_create_full( + deps: FullDeps, +) -> Result> +where + C: ProvideRuntimeApi + + sc_client_api::BlockBackend + + HeaderBackend + + AuxStore + + HeaderMetadata + + Send + + Sync + + 'static, + C::Api: substrate_frame_rpc_system::AccountNonceApi, + C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, + C::Api: pallet_contracts_rpc::ContractsRuntimeApi, + C::Api: BlockBuilder, + P: TransactionPool + Sync + Send + 'static, +{ + use pallet_contracts_rpc::{Contracts, ContractsApiServer}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use sc_rpc::dev::{Dev, DevApiServer}; + use substrate_frame_rpc_system::{System, SystemApiServer}; + + let mut module = RpcExtension::new(()); + let FullDeps { client, pool, deny_unsafe } = deps; + + module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?; + module.merge(TransactionPayment::new(client.clone()).into_rpc())?; + module.merge(Contracts::new(client.clone()).into_rpc())?; + module.merge(Dev::new(client.clone(), deny_unsafe).into_rpc())?; + + // Extend this RPC with a custom API by using the following syntax. + // `YourRpcStruct` should have a reference to a client, which is needed + // to call into the runtime. + // `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;` + + Ok(module) +} diff --git a/runtime/base/Cargo.toml b/runtime/base/Cargo.toml new file mode 100644 index 00000000..f31201ec --- /dev/null +++ b/runtime/base/Cargo.toml @@ -0,0 +1,199 @@ +[package] +name = "base-runtime" +version = "1.0.0" +authors = ["Trappist Network "] +license = "Unlicense" +homepage = "https://trappist.io" +repository = "https://github.com/TrappistNetwork/trappist" +edition = "2021" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[build-dependencies] +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[dependencies] +hex-literal = { version = "0.3.4", optional = true } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"]} +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +serde = { version = "1.0.140", optional = true, features = ["derive"] } +smallvec = "1.9.0" + +# Substrate Dependencies +## Substrate Primitive Dependencies +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } + +## Substrate FRAME Dependencies +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } +frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } + +## Substrate Pallet Dependencies +pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-asset-tx-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-contracts = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-contracts-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-contracts-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-identity = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-society = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } +pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } + +# Cumulus dependencies +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-ping = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false } +cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30", default-features = false, version = "3.0.0"} + +# Polkadot Dependencies +kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } +xcm-primitives = { path = "../../primitives/xcm/", default-features = false } + +# External Pallets +pallet-dex = { version = "0.0.1", git = "https://github.com/paritytech/substrate-dex.git", default-features = false } +pallet-dex-rpc-runtime-api = { version = "0.0.1", git = "https://github.com/paritytech/substrate-dex.git", default-features = false } +pallet-contracts-xcm = { version = "0.1.0", git = "https://github.com/paritytech/pallet-contracts-xcm", default-features = false, branch = "trappist/polkadot-v0.9.30" } + +# Trappist Pallets +pallet-asset-registry = { version = "0.0.1", default-features = false, path = "../../pallets/asset-registry" } + +[features] +default = ["std"] +std = [ + "codec/std", + "serde", + "scale-info/std", + "log/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "frame-executive/std", + "frame-support/std", + "frame-system/std", + "frame-system-rpc-runtime-api/std", + "pallet-assets/std", + "pallet-asset-tx-payment/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-collator-selection/std", + "pallet-collective/std", + "pallet-contracts/std", + "pallet-contracts-primitives/std", + "pallet-contracts-rpc-runtime-api/std", + "pallet-dex/std", + "pallet-dex-rpc-runtime-api/std", + "pallet-identity/std", + "pallet-multisig/std", + "pallet-randomness-collective-flip/std", + "pallet-scheduler/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-uniques/std", + "pallet-utility/std", + "pallet-xcm/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-ping/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "cumulus-pallet-dmp-queue/std", + "parachain-info/std", + "parachains-common/std", + "polkadot-parachain/std", + "polkadot-runtime-common/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std" +] +runtime-benchmarks = [ + "hex-literal", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-asset-registry/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-contracts/runtime-benchmarks", + "pallet-dex/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-society/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks" +] +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", +] diff --git a/runtime/build.rs b/runtime/base/build.rs similarity index 100% rename from runtime/build.rs rename to runtime/base/build.rs diff --git a/runtime/src/constants.rs b/runtime/base/src/constants.rs similarity index 100% rename from runtime/src/constants.rs rename to runtime/base/src/constants.rs diff --git a/runtime/src/contracts.rs b/runtime/base/src/contracts.rs similarity index 100% rename from runtime/src/contracts.rs rename to runtime/base/src/contracts.rs diff --git a/runtime/base/src/lib.rs b/runtime/base/src/lib.rs new file mode 100644 index 00000000..46583ef3 --- /dev/null +++ b/runtime/base/src/lib.rs @@ -0,0 +1,815 @@ +// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +// Make the WASM binary available. +#[cfg(feature = "std")] +include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +pub mod constants; +mod contracts; +mod xcm_config; + +use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use sp_api::impl_runtime_apis; +use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto}, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, +}; + +use sp_std::prelude::*; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; + +use constants::{currency::*, fee::WeightToFee}; +use frame_support::{ + construct_runtime, + dispatch::DispatchClass, + parameter_types, + traits::{ + AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64, EitherOfDiverse, + EqualPrivilegeOnly, Everything, + }, + weights::{ + constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, + ConstantMultiplier, Weight, + }, + PalletId, +}; +use frame_system::{ + limits::{BlockLength, BlockWeights}, + EnsureRoot, EnsureSigned, +}; +pub use parachains_common as common; +pub use parachains_common::{ + impls::{AssetsToBlockAuthor, DealWithFees}, + opaque, AccountId, AssetId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, + AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO, + SLOT_DURATION, +}; +use xcm_config::{CollatorSelectionUpdateOrigin, RelayLocation}; + +#[cfg(any(feature = "std", test))] +pub use sp_runtime::BuildStorage; + +// Polkadot imports +use pallet_xcm::{EnsureXcm, IsMajorityOfBody}; +use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; +use xcm::latest::prelude::BodyId; + +pub const MICROUNIT: Balance = 1_000_000; + +/// The address format for describing accounts. +pub type Address = sp_runtime::MultiAddress; +/// Block type as expected by this runtime. +pub type Block = generic::Block; +/// A Block signed with a Justification +pub type SignedBlock = generic::SignedBlock; +/// BlockId type as expected by this runtime. +pub type BlockId = generic::BlockId; +/// The SignedExtension to the basic transaction logic. +pub type SignedExtra = ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_asset_tx_payment::ChargeAssetTxPayment, +); +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; +/// Extrinsic type that has already been checked. +pub type CheckedExtrinsic = generic::CheckedExtrinsic; +/// Executive: handles dispatch to the various modules. +pub type Executive = frame_executive::Executive< + Runtime, + Block, + frame_system::ChainContext, + Runtime, + AllPalletsWithSystem, + pallet_contracts::Migration, +>; + +impl_opaque_keys! { + pub struct SessionKeys { + pub aura: Aura, + } +} + +#[sp_version::runtime_version] +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: create_runtime_str!("trappist-rococo"), + impl_name: create_runtime_str!("trappist-rococo"), + authoring_version: 1, + spec_version: 1, + impl_version: 0, + apis: RUNTIME_API_VERSIONS, + transaction_version: 1, + state_version: 1, +}; + +/// The version information used to identify this runtime when compiled natively. +#[cfg(feature = "std")] +pub fn native_version() -> NativeVersion { + NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } +} + +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + pub RuntimeBlockLength: BlockLength = + BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); + pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() + .base_block(BlockExecutionWeight::get()) + .for_class(DispatchClass::all(), |weights| { + weights.base_extrinsic = ExtrinsicBaseWeight::get(); + }) + .for_class(DispatchClass::Normal, |weights| { + weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); + // Operational transactions have some extra reserved space, so that they + // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. + weights.reserved = Some( + MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT + ); + }) + .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) + .build_or_panic(); +} + +// Configure FRAME pallets to include in runtime. +impl frame_system::Config for Runtime { + type BaseCallFilter = Everything; + type BlockWeights = RuntimeBlockWeights; + type BlockLength = RuntimeBlockLength; + type AccountId = AccountId; + type RuntimeCall = RuntimeCall; + type Lookup = AccountIdLookup; + type Index = Index; + type BlockNumber = BlockNumber; + type Hash = Hash; + type Hashing = BlakeTwo256; + type Header = Header; + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type BlockHashCount = BlockHashCount; + type DbWeight = RocksDbWeight; + type Version = Version; + type PalletInfo = PalletInfo; + type OnNewAccount = (); + type OnKilledAccount = (); + type AccountData = pallet_balances::AccountData; + type SystemWeightInfo = frame_system::weights::SubstrateWeight; + type SS58Prefix = ConstU16<42>; + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = ConstU32<16>; +} + +impl pallet_timestamp::Config for Runtime { + /// A timestamp: milliseconds since the unix epoch. + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>; + type WeightInfo = pallet_timestamp::weights::SubstrateWeight; +} + +impl pallet_authorship::Config for Runtime { + type FindAuthor = pallet_session::FindAccountFromAuthorIndex; + type UncleGenerations = ConstU32<0>; + type FilterUncle = (); + type EventHandler = (CollatorSelection,); +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = ConstU32<50>; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU128; + type AccountStore = System; + type WeightInfo = pallet_balances::weights::SubstrateWeight; + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 8]; +} + +parameter_types! { + /// Relay Chain `TransactionByteFee` / 10 + pub const TransactionByteFee: Balance = 1 * MILLICENTS; + pub const OperationalFeeMultiplier: u8 = 5; +} + +impl pallet_transaction_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnChargeTransaction = + pallet_transaction_payment::CurrencyAdapter>; + /// Relay Chain `TransactionByteFee` / 10 + type WeightToFee = WeightToFee; + type LengthToFee = ConstantMultiplier; + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; + type OperationalFeeMultiplier = OperationalFeeMultiplier; +} + +impl pallet_asset_tx_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Fungibles = Assets; + type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< + pallet_assets::BalanceToAssetBalance, + AssetsToBlockAuthor, + >; +} + +parameter_types! { + // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. + pub const DepositBase: Balance = deposit(1, 88); + // Additional storage item size of 32 bytes. + pub const DepositFactor: Balance = deposit(0, 32); +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = ConstU16<100>; + type WeightInfo = pallet_multisig::weights::SubstrateWeight; +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = pallet_utility::weights::SubstrateWeight; +} + +parameter_types! { + pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); +} + +impl cumulus_pallet_parachain_system::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnSystemEvent = (); + type SelfParaId = parachain_info::Pallet; + type DmpMessageHandler = DmpQueue; + type ReservedDmpWeight = ReservedDmpWeight; + type OutboundXcmpMessageSource = XcmpQueue; + type XcmpMessageHandler = XcmpQueue; + type ReservedXcmpWeight = ReservedXcmpWeight; + type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; +} + +impl pallet_randomness_collective_flip::Config for Runtime {} + +impl parachain_info::Config for Runtime {} + +impl cumulus_pallet_aura_ext::Config for Runtime {} + +parameter_types! { + pub const Period: u32 = 6 * HOURS; + pub const Offset: u32 = 0; +} + +impl pallet_session::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ValidatorId = ::AccountId; + // we don't have stash and controller, thus we don't need the convert as well. + type ValidatorIdOf = pallet_collator_selection::IdentityCollator; + type ShouldEndSession = pallet_session::PeriodicSessions; + type NextSessionRotation = pallet_session::PeriodicSessions; + type SessionManager = CollatorSelection; + // Essentially just Aura, but lets be pedantic. + type SessionHandler = ::KeyTypeIdProviders; + type Keys = SessionKeys; + type WeightInfo = pallet_session::weights::SubstrateWeight; +} + +impl pallet_aura::Config for Runtime { + type AuthorityId = AuraId; + type DisabledValidators = (); + type MaxAuthorities = ConstU32<100_000>; +} + +parameter_types! { + pub const PotId: PalletId = PalletId(*b"PotStake"); +} + +impl pallet_collator_selection::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type UpdateOrigin = CollatorSelectionUpdateOrigin; + type PotId = PotId; + type MaxCandidates = ConstU32<1000>; + type MinCandidates = ConstU32<5>; + type MaxInvulnerables = ConstU32<100>; + // should be a multiple of session or things will get inconsistent + type KickThreshold = Period; + type ValidatorId = ::AccountId; + type ValidatorIdOf = pallet_collator_selection::IdentityCollator; + type ValidatorRegistration = Session; + type WeightInfo = pallet_collator_selection::weights::SubstrateWeight; +} + +impl pallet_sudo::Config for Runtime { + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; +} + +parameter_types! { + pub const UnitBody: BodyId = BodyId::Unit; +} + +/// We allow local Root / Council or the Unit body from Rococo (over XCM) to execute privileged +/// asset operations. +pub type AssetsForceOrigin = + EitherOfDiverse>>; + +pub type AssetBalance = Balance; + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = AssetBalance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = AssetsForceOrigin; + type AssetDeposit = ConstU128<{ UNITS }>; + type MetadataDepositBase = ConstU128<{ UNITS }>; + type MetadataDepositPerByte = ConstU128<{ 10 * CENTS }>; + type ApprovalDeposit = ConstU128<{ 10 * CENTS }>; + type StringLimit = ConstU32<50>; + type Freezer = (); + type Extra = (); + type WeightInfo = pallet_assets::weights::SubstrateWeight; + type AssetAccountDeposit = ConstU128<{ UNITS }>; +} + +type CouncilCollective = pallet_collective::Instance1; +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type MotionDuration = ConstU32<{ 3 * MINUTES }>; + type MaxProposals = ConstU32<100>; + type MaxMembers = ConstU32<100>; + type DefaultVote = pallet_collective::PrimeDefaultVote; + type WeightInfo = pallet_collective::weights::SubstrateWeight; +} + +type EnsureRootOrHalfCouncil = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionAtLeast, +>; + +parameter_types! { + pub const BasicDeposit: Balance = deposit(1, 258); // 258 bytes on-chain + pub const FieldDeposit: Balance = deposit(0, 66); // 66 bytes on-chain + pub const SubAccountDeposit: Balance = deposit(1, 53); // 53 bytes on-chain +} + +impl pallet_identity::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; + type SubAccountDeposit = SubAccountDeposit; + type MaxSubAccounts = ConstU32<100>; + type MaxAdditionalFields = ConstU32<100>; + type MaxRegistrars = ConstU32<20>; + type Slashed = (); + type ForceOrigin = EnsureRootOrHalfCouncil; + type RegistrarOrigin = EnsureRootOrHalfCouncil; + type WeightInfo = (); +} + +parameter_types! { + pub const UniquesMetadataDepositBase: Balance = deposit(1, 129); + pub const AttributeDepositBase: Balance = deposit(1, 0); + pub const DepositPerByte: Balance = deposit(0, 1); + pub const CollectionDeposit: Balance = 100 * UNITS; + pub const ItemDeposit: Balance = 1 * UNITS; + pub const StringLimit: u32 = 50; + pub const KeyLimit: u32 = 32; + pub const ValueLimit: u32 = 256; +} + +impl pallet_uniques::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CollectionId = u32; + type ItemId = u32; + type Currency = Balances; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = CollectionDeposit; + type ItemDeposit = ItemDeposit; + type MetadataDepositBase = UniquesMetadataDepositBase; + type AttributeDepositBase = AttributeDepositBase; + type DepositPerByte = DepositPerByte; + type StringLimit = StringLimit; + type KeyLimit = KeyLimit; + type ValueLimit = ValueLimit; + type WeightInfo = pallet_uniques::weights::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); + type CreateOrigin = AsEnsureOriginWithArg>; + type Locker = (); +} + +impl pallet_asset_registry::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ReserveAssetModifierOrigin = frame_system::EnsureRoot; + type Assets = Assets; + type WeightInfo = pallet_asset_registry::weights::SubstrateWeight; +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = Weight::from_ref_time(10_000_000); + pub const NoPreimagePostponement: Option = Some(10); +} + +impl pallet_scheduler::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = frame_system::EnsureRoot; + type MaxScheduledPerBlock = ConstU32<50>; + type WeightInfo = pallet_scheduler::weights::SubstrateWeight; + type OriginPrivilegeCmp = EqualPrivilegeOnly; + type PreimageProvider = Preimage; + type NoPreimagePostponement = NoPreimagePostponement; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = deposit(2, 64); + pub const PreimageByteDeposit: Balance = deposit(0, 1); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = pallet_preimage::weights::SubstrateWeight; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type MaxSize = ConstU32<{ 4096 * 1024 }>; + type BaseDeposit = PreimageBaseDeposit; + type ByteDeposit = PreimageByteDeposit; +} + +// Create the runtime by composing the FRAME pallets that were previously configured. +construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = opaque::Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + // System support stuff. + System: frame_system::{Pallet, Call, Config, Storage, Event} = 0, + ParachainSystem: cumulus_pallet_parachain_system::{ + Pallet, Call, Config, Storage, Inherent, Event, ValidateUnsigned, + } = 1, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 2, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3, + ParachainInfo: parachain_info::{Pallet, Storage, Config} = 4, + + // Monetary stuff. + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, + AssetTxPayment: pallet_asset_tx_payment::{Pallet, Storage, Event} = 12, + + // Collator support. The order of these 5 are important and shall not change. + Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, + CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event, Config} = 21, + Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 22, + Aura: pallet_aura::{Pallet, Storage, Config} = 23, + AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config} = 24, + + // XCM helpers. + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 30, + PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 31, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 32, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, + + // Runtime features + Sudo: pallet_sudo = 40, + Contracts: pallet_contracts = 41, + Council: pallet_collective:: = 42, + Assets: pallet_assets = 43, + Identity: pallet_identity = 44, + Uniques: pallet_uniques = 45, + Scheduler: pallet_scheduler = 46, + Utility: pallet_utility = 47, + Preimage: pallet_preimage = 48, + Multisig: pallet_multisig = 49, + ContractsXCM: pallet_contracts_xcm = 50, + + Spambot: cumulus_ping::{Pallet, Call, Storage, Event} = 99, + + AssetRegistry: pallet_asset_registry::{Pallet, Call, Storage, Event} = 101, + } +); + +#[cfg(feature = "runtime-benchmarks")] +#[macro_use] +extern crate frame_benchmarking; + +#[cfg(feature = "runtime-benchmarks")] +mod benches { + define_benchmarks!( + [frame_system, SystemBench::] + [pallet_balances, Balances] + [pallet_session, SessionBench::] + [pallet_timestamp, Timestamp] + [pallet_collator_selection, CollatorSelection] + [pallet_contracts, Contracts] + [pallet_collective, Council] + [pallet_assets, Assets] + [pallet_identity, Identity] + [pallet_multisig, Multisig] + [pallet_uniques, Uniques] + [pallet_scheduler, Scheduler] + [pallet_utility, Utility] + [cumulus_pallet_xcmp_queue, XcmpQueue] + ); +} + +impl_runtime_apis! { + impl sp_consensus_aura::AuraApi for Runtime { + fn slot_duration() -> sp_consensus_aura::SlotDuration { + sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + } + + fn authorities() -> Vec { + Aura::authorities().into_inner() + } + } + + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + VERSION + } + + fn execute_block(block: Block) { + Executive::execute_block(block) + } + + fn initialize_block(header: &::Header) { + Executive::initialize_block(header) + } + } + + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + OpaqueMetadata::new(Runtime::metadata().into()) + } + } + + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { + Executive::apply_extrinsic(extrinsic) + } + + fn finalize_block() -> ::Header { + Executive::finalize_block() + } + + fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { + data.create_extrinsics() + } + + fn check_inherents( + block: Block, + data: sp_inherents::InherentData, + ) -> sp_inherents::CheckInherentsResult { + data.check_extrinsics(&block) + } + } + + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + tx: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + Executive::validate_transaction(source, tx, block_hash) + } + } + + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(header: &::Header) { + Executive::offchain_worker(header) + } + } + + impl sp_session::SessionKeys for Runtime { + fn generate_session_keys(seed: Option>) -> Vec { + SessionKeys::generate(seed) + } + + fn decode_session_keys( + encoded: Vec, + ) -> Option, KeyTypeId)>> { + SessionKeys::decode_into_raw_public_keys(&encoded) + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Index { + System::account_nonce(account) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { + fn query_info( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + } + + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } + + impl pallet_contracts_rpc_runtime_api::ContractsApi for Runtime { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: u64, + storage_deposit_limit: Option, + input_data: Vec, + ) -> pallet_contracts_primitives::ContractExecResult { + Contracts::bare_call( + origin, + dest, + value, + Weight::from_ref_time(gas_limit), + storage_deposit_limit, + input_data, + contracts::CONTRACTS_DEBUG_OUTPUT, + ) + } + + fn instantiate( + origin: AccountId, + value: Balance, + gas_limit: u64, + storage_deposit_limit: Option, + code: pallet_contracts_primitives::Code, + data: Vec, + salt: Vec, + ) -> pallet_contracts_primitives::ContractInstantiateResult { + Contracts::bare_instantiate( + origin, + value, + Weight::from_ref_time(gas_limit), + storage_deposit_limit, + code, + data, + salt, + contracts::CONTRACTS_DEBUG_OUTPUT, + ) + } + + fn upload_code( + origin: AccountId, + code: Vec, + storage_deposit_limit: Option, + ) -> pallet_contracts_primitives::CodeUploadResult { + Contracts::bare_upload_code(origin, code, storage_deposit_limit) + } + + fn get_storage( + address: AccountId, + key: Vec, + ) -> pallet_contracts_primitives::GetStorageResult { + Contracts::get_storage(address, key) + } + } + + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade trappist"); + let weight = Executive::try_runtime_upgrade().unwrap(); + (weight, RuntimeBlockWeights::get().max_block) + } + + fn execute_block_no_check(block: Block) -> Weight { + Executive::execute_block_no_check(block) + } + } + + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_benchmarking::{Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + use frame_system_benchmarking::Pallet as SystemBench; + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + return (list, storage_info) + } + + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig + ) -> Result, sp_runtime::RuntimeString> { + use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + + use frame_system_benchmarking::Pallet as SystemBench; + impl frame_system_benchmarking::Config for Runtime {} + + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + impl cumulus_pallet_session_benchmarking::Config for Runtime {} + + let whitelist: Vec = vec![ + // Block Number + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), + // Total Issuance + hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), + // Execution Phase + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), + // Event Count + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), + // System Events + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + ]; + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + add_benchmarks!(params, batches); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } +} + +struct CheckInherents; + +impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { + fn check_inherents( + block: &Block, + relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, + ) -> sp_inherents::CheckInherentsResult { + let relay_chain_slot = relay_state_proof + .read_slot() + .expect("Could not read the relay chain slot from the proof"); + + let inherent_data = + cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( + relay_chain_slot, + sp_std::time::Duration::from_secs(6), + ) + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); + + inherent_data.check_extrinsics(block) + } +} + +cumulus_pallet_parachain_system::register_validate_block! { + Runtime = Runtime, + BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, + CheckInherents = CheckInherents, +} diff --git a/runtime/src/xcm_config.rs b/runtime/base/src/xcm_config.rs similarity index 100% rename from runtime/src/xcm_config.rs rename to runtime/base/src/xcm_config.rs diff --git a/runtime/Cargo.toml b/runtime/trappist/Cargo.toml similarity index 98% rename from runtime/Cargo.toml rename to runtime/trappist/Cargo.toml index 03c22629..bd4b0b4d 100644 --- a/runtime/Cargo.toml +++ b/runtime/trappist/Cargo.toml @@ -93,7 +93,7 @@ polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", defa xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.30" } -xcm-primitives = { path = "../primitives/xcm/", default-features = false } +xcm-primitives = { path = "../../primitives/xcm/", default-features = false } # External Pallets pallet-dex = { version = "0.0.1", git = "https://github.com/paritytech/substrate-dex.git", default-features = false } @@ -101,14 +101,13 @@ pallet-dex-rpc-runtime-api = { version = "0.0.1", git = "https://github.com/pari pallet-contracts-xcm = { version = "0.1.0", git = "https://github.com/paritytech/pallet-contracts-xcm", default-features = false, branch = "trappist/polkadot-v0.9.30" } # Trappist Pallets -pallet-asset-registry = { version = "0.0.1", default-features = false, path = "../pallets/asset-registry" } +pallet-asset-registry = { version = "0.0.1", default-features = false, path = "../../pallets/asset-registry" } [features] default = ["std"] std = [ "codec/std", "serde", - "pallet-contracts-xcm/std", "scale-info/std", "log/std", "sp-api/std", @@ -198,4 +197,4 @@ runtime-benchmarks = [ try-runtime = [ "frame-try-runtime", "frame-executive/try-runtime", -] +] \ No newline at end of file diff --git a/runtime/trappist/build.rs b/runtime/trappist/build.rs new file mode 100644 index 00000000..9b53d245 --- /dev/null +++ b/runtime/trappist/build.rs @@ -0,0 +1,9 @@ +use substrate_wasm_builder::WasmBuilder; + +fn main() { + WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() +} diff --git a/runtime/trappist/src/constants.rs b/runtime/trappist/src/constants.rs new file mode 100644 index 00000000..21942362 --- /dev/null +++ b/runtime/trappist/src/constants.rs @@ -0,0 +1,84 @@ +// Copyright (C) 2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod currency { + use kusama_runtime_constants as constants; + use polkadot_core_primitives::Balance; + + /// The existential deposit. Set to 1/10 of its parent Relay Chain. + pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10; + + pub const UNITS: Balance = constants::currency::UNITS; + pub const CENTS: Balance = constants::currency::CENTS; + pub const GRAND: Balance = constants::currency::GRAND; + pub const MILLICENTS: Balance = constants::currency::MILLICENTS; + + pub const fn deposit(items: u32, bytes: u32) -> Balance { + // map to 1/10 of what the kusama relay chain charges (v9020) + constants::currency::deposit(items, bytes) / 10 + } +} + +/// Fee-related. +pub mod fee { + use super::currency::CENTS; + use frame_support::weights::{ + constants::{ExtrinsicBaseWeight, WEIGHT_PER_SECOND}, + WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, + }; + use polkadot_core_primitives::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + /// The block saturation level. Fees will be updates based on this value. + pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25); + + /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the + /// node's balance type. + /// + /// This should typically create a mapping between the following ranges: + /// - [0, MAXIMUM_BLOCK_WEIGHT] + /// - [Balance::min, Balance::max] + /// + /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: + /// - Setting it to `0` will essentially disable the weight fee. + /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. + pub struct WeightToFee; + impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in Statemine, we map to 1/10 of that, or 1/100 CENT + let p = super::currency::CENTS; + let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } + + pub fn base_tx_fee() -> Balance { + CENTS / 10 + } + + pub fn default_fee_per_second() -> u128 { + let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time()); + let base_tx_per_second = (WEIGHT_PER_SECOND.ref_time() as u128) / base_weight; + base_tx_per_second * base_tx_fee() + } +} diff --git a/runtime/trappist/src/contracts.rs b/runtime/trappist/src/contracts.rs new file mode 100644 index 00000000..8369dcc1 --- /dev/null +++ b/runtime/trappist/src/contracts.rs @@ -0,0 +1,64 @@ +use crate::{ + constants::currency::deposit, Balance, Balances, RandomnessCollectiveFlip, Runtime, + RuntimeBlockWeights, RuntimeCall, RuntimeEvent, Timestamp, +}; +use frame_support::{ + parameter_types, + traits::{ConstU32, Nothing}, + weights::Weight, +}; +use pallet_contracts::{ + weights::{SubstrateWeight, WeightInfo}, + Config, DefaultAddressGenerator, Frame, Schedule, +}; +use pallet_contracts_xcm::Extension as XCMContractExtension; +pub use parachains_common::AVERAGE_ON_INITIALIZE_RATIO; + +// Prints debug output of the `contracts` pallet to stdout if the node is +// started with `-lruntime::contracts=debug`. +pub const CONTRACTS_DEBUG_OUTPUT: bool = true; + +parameter_types! { + pub const DepositPerItem: Balance = deposit(1, 0); + pub const DepositPerByte: Balance = deposit(0, 1); + // The lazy deletion runs inside on_initialize. + pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * + RuntimeBlockWeights::get().max_block; + // The weight needed for decoding the queue should be less or equal than a fifth + // of the overall weight dedicated to the lazy deletion. + pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( + ::WeightInfo::on_initialize_per_queue_item(1) - + ::WeightInfo::on_initialize_per_queue_item(0) + ).ref_time()) / 5).ref_time() as u32; + pub MySchedule: Schedule = Default::default(); +} + +impl Config for Runtime { + type Time = Timestamp; + type Randomness = RandomnessCollectiveFlip; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + /// The safest default is to allow no calls at all. + /// + /// Runtimes should whitelist dispatchables that are allowed to be called from contracts + /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to + /// change because that would break already deployed contracts. The `Call` structure itself + /// is not allowed to change the indices of existing pallets, too. + type CallFilter = Nothing; + type DepositPerItem = DepositPerItem; + type DepositPerByte = DepositPerByte; + type WeightPrice = pallet_transaction_payment::Pallet; + type WeightInfo = SubstrateWeight; + type ChainExtension = XCMContractExtension; + type DeletionQueueDepth = DeletionQueueDepth; + type DeletionWeightLimit = DeletionWeightLimit; + type Schedule = MySchedule; + type CallStack = [Frame; 31]; + type AddressGenerator = DefaultAddressGenerator; + type ContractAccessWeight = pallet_contracts::DefaultContractAccessWeight; + type MaxCodeLen = ConstU32<{ 128 * 1024 }>; + type MaxStorageKeyLen = ConstU32<128>; +} + +impl pallet_contracts_xcm::Config for Runtime {} diff --git a/runtime/src/lib.rs b/runtime/trappist/src/lib.rs similarity index 100% rename from runtime/src/lib.rs rename to runtime/trappist/src/lib.rs diff --git a/runtime/trappist/src/xcm_config.rs b/runtime/trappist/src/xcm_config.rs new file mode 100644 index 00000000..32f3b651 --- /dev/null +++ b/runtime/trappist/src/xcm_config.rs @@ -0,0 +1,331 @@ +// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::constants::fee::default_fee_per_second; + +use super::{ + AccountId, AssetRegistry, Assets, Balance, Balances, ParachainInfo, ParachainSystem, + PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, +}; +use frame_support::{ + match_types, parameter_types, + traits::{EitherOfDiverse, Everything, Get, Nothing, PalletInfoAccess}, +}; +use frame_system::EnsureRoot; +use sp_std::marker::PhantomData; + +use parachains_common::{ + impls::DealWithFees, + xcm_config::{DenyReserveTransferToRelayChain, DenyThenTry}, + AssetId, +}; +use xcm_executor::traits::{FilterAssetLocation, JustTry}; +use xcm_primitives::{AsAssetMultiLocation, ConvertedRegisteredAssetId}; + +// use super::xcm_primitives::{AbsoluteReserveProvider, MultiNativeAsset}; +use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough}; +use polkadot_parachain::primitives::Sibling; +use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation}; + +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, + ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, +}; +use xcm_executor::XcmExecutor; + +parameter_types! { + pub const RelayLocation: MultiLocation = MultiLocation::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Polkadot; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub const Local: MultiLocation = Here.into(); + pub SelfReserve: MultiLocation = MultiLocation { parents:0, interior: Here }; + pub AssetsPalletLocation: MultiLocation = + PalletInstance(::index() as u8).into(); + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub const ExecutiveBody: BodyId = BodyId::Executive; +} + +/// We allow root and the Relay Chain council to execute privileged collator selection operations. +pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< + EnsureRoot, + EnsureXcm>, +>; + +/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the parent `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, +); + +/// Means for transacting the native currency on this chain. +pub type LocalAssetTransactor = CurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Convert an XCM MultiLocation into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports of `Balances`. + (), +>; + +/// Means for transacting assets besides the native currency on this chain. +pub type LocalFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ConvertedConcreteAssetId< + AssetId, + Balance, + AsPrefixedGeneralIndex, + JustTry, + >, + // Convert an XCM MultiLocation into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports of `Assets`. + Nothing, + // We don't track any teleports of `Assets`. + CheckingAccount, +>; + +/// Means for transacting reserved fungible assets. +/// AsAssetMultiLocation uses pallet_asset_registry to convert between AssetId and MultiLocation. +pub type ReservedFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a registered fungible asset matching the given location or name + // Assets not found in AssetRegistry will not be used + ConvertedRegisteredAssetId< + AssetId, + Balance, + AsAssetMultiLocation, + JustTry, + >, + // Convert an XCM MultiLocation into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports of `Assets`. + Nothing, + // We don't track any teleports of `Assets`. + CheckingAccount, +>; + +/// Means for transacting assets on this chain. +pub type AssetTransactors = + (LocalAssetTransactor, ReservedFungiblesTransactor, LocalFungiblesTransactor); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `Origin::Signed` origin of the same 32-byte value. + SignedAccountId32AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + XcmPassthrough, +); + +parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: u64 = 1_000_000_000; + pub const MaxInstructions: u32 = 100; +} + +match_types! { + pub type ParentOrParentsExecutivePlurality: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } + }; +} +match_types! { + pub type ParentOrSiblings: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(_) } + }; +} +match_types! { + pub type Statemine: impl Contains = { + MultiLocation { parents: 1, interior: X1(Parachain(1000)) } + }; +} + +pub type Barrier = DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), +>; + +parameter_types! { + pub StatemineLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(1000))); + // ALWAYS ensure that the index in PalletInstance stays up-to-date with + // Statemine's Assets pallet index + pub StatemineAssetsPalletLocation: MultiLocation = + MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); + + pub XUsdPerSecond: (xcm::v1::AssetId, u128) = ( + MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1))).into(), + default_fee_per_second() * 10 + ); +} + +//- From PR https://github.com/paritytech/cumulus/pull/936 +fn matches_prefix(prefix: &MultiLocation, loc: &MultiLocation) -> bool { + prefix.parent_count() == loc.parent_count() && + loc.len() >= prefix.len() && + prefix + .interior() + .iter() + .zip(loc.interior().iter()) + .all(|(prefix_junction, junction)| prefix_junction == junction) +} +pub struct ReserveAssetsFrom(PhantomData); +impl> FilterAssetLocation for ReserveAssetsFrom { + fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool { + let prefix = T::get(); + log::trace!(target: "xcm::AssetsFrom", "prefix: {:?}, origin: {:?}", prefix, origin); + &prefix == origin && + match asset { + MultiAsset { id: xcm::latest::AssetId::Concrete(asset_loc), fun: Fungible(_a) } => + matches_prefix(&prefix, asset_loc), + _ => false, + } + } +} + +//-- + +pub type Reserves = (NativeAsset, ReserveAssetsFrom); + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = Reserves; + type IsTeleporter = (); // Teleporting is disabled. + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = ( + FixedRateOfFungible, + UsingComponents>, + ); + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; +} + +/// Converts a local signed origin into an XCM multilocation. +/// Forms the basis for local origins sending/executing XCMs. +pub type LocalOriginToLocation = SignedToAccountId32; + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = ( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, +); + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type LocationInverter = LocationInverter; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; + type ChannelInfo = ParachainSystem; + type VersionWrapper = PolkadotXcm; + type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EitherOfDiverse< + EnsureRoot, + EnsureXcm>, + >; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; + type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight; +} + +impl cumulus_pallet_dmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; + type ExecuteOverweightOrigin = EnsureRoot; +} + +impl cumulus_ping::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; +} diff --git a/xcm-playground.toml b/xcm-playground.toml index 51d3289a..05810f72 100644 --- a/xcm-playground.toml +++ b/xcm-playground.toml @@ -62,14 +62,14 @@ add_to_genesis = true cumulus_based = true [[parachains.collators]] - name = "collator01" - command = "./bin/polkadot-parachain" + name = "base-collator01" + command = "./target/release/base-collator" ws_port = 9930 args = ["--log=xcm=trace,pallet-assets=trace"] [[parachains.collators]] - name = "collator02" - command = "./bin/polkadot-parachain" + name = "base-collator02" + command = "./target/release/base-collator" ws_port = 9931 args = ["--log=xcm=trace,pallet-assets=trace"]