diff --git a/Cargo.lock b/Cargo.lock index ea1f645917..6579406345 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -897,6 +897,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain", "serde", + "smallvec 1.6.1", "sp-api", "sp-arithmetic", "sp-block-builder", @@ -4057,6 +4058,85 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "kusama-runtime" +version = "0.9.9-1" +source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.9#7a9f624777ad2d2adb3a1e6797a31f9d653c9587" +dependencies = [ + "beefy-primitives", + "bitvec 0.20.4", + "frame-election-provider-support", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "log", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-balances", + "pallet-bounties", + "pallet-collective", + "pallet-democracy", + "pallet-election-provider-multi-phase", + "pallet-elections-phragmen", + "pallet-gilt", + "pallet-grandpa", + "pallet-identity", + "pallet-im-online", + "pallet-indices", + "pallet-membership", + "pallet-mmr-primitives", + "pallet-multisig", + "pallet-nicks", + "pallet-offences", + "pallet-proxy", + "pallet-recovery", + "pallet-scheduler", + "pallet-session", + "pallet-society", + "pallet-staking", + "pallet-staking-reward-fn", + "pallet-timestamp", + "pallet-tips", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-vesting", + "pallet-xcm", + "parity-scale-codec", + "polkadot-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "rustc-hex", + "serde", + "serde_derive", + "smallvec 1.6.1", + "sp-api", + "sp-arithmetic", + "sp-authority-discovery", + "sp-block-builder", + "sp-consensus-babe", + "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", + "sp-inherents", + "sp-io", + "sp-npos-elections", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", + "sp-transaction-pool", + "sp-version", + "static_assertions", + "substrate-wasm-builder", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "kv-log-macro" version = "1.0.7" @@ -5210,6 +5290,7 @@ dependencies = [ "async-trait", "bifrost-flexible-fee-rpc-runtime-api", "bifrost-runtime", + "bifrost-runtime-common", "bifrost-salp-rpc-runtime-api", "bs58 0.3.1", "cumulus-client-consensus-aura", @@ -5826,6 +5907,20 @@ dependencies = [ "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", ] +[[package]] +name = "pallet-gilt" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9#91061a7d925b5bc597804293da283477512ba4ff" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "sp-arithmetic", + "sp-runtime", + "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", +] + [[package]] name = "pallet-grandpa" version = "4.0.0-dev" @@ -6033,6 +6128,20 @@ dependencies = [ "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", ] +[[package]] +name = "pallet-recovery" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9#91061a7d925b5bc597804293da283477512ba4ff" +dependencies = [ + "enumflags2", + "frame-support", + "frame-system", + "parity-scale-codec", + "sp-io", + "sp-runtime", + "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", +] + [[package]] name = "pallet-scheduler" version = "4.0.0-dev" @@ -6068,6 +6177,19 @@ dependencies = [ "sp-trie", ] +[[package]] +name = "pallet-society" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9#91061a7d925b5bc597804293da283477512ba4ff" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "rand_chacha 0.2.2", + "sp-runtime", + "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", +] + [[package]] name = "pallet-staking" version = "4.0.0-dev" @@ -6101,6 +6223,15 @@ dependencies = [ "syn", ] +[[package]] +name = "pallet-staking-reward-fn" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9#91061a7d925b5bc597804293da283477512ba4ff" +dependencies = [ + "log", + "sp-arithmetic", +] + [[package]] name = "pallet-sudo" version = "4.0.0-dev" @@ -8358,6 +8489,107 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "runtime-integration-tests" +version = "0.8.0" +dependencies = [ + "asgard-runtime", + "bifrost-bancor", + "bifrost-bancor-runtime-api", + "bifrost-flexible-fee", + "bifrost-flexible-fee-rpc-runtime-api", + "bifrost-liquidity-mining", + "bifrost-minter-reward", + "bifrost-runtime", + "bifrost-runtime-common", + "bifrost-salp", + "bifrost-salp-rpc-runtime-api", + "bifrost-vesting", + "bifrost-vsbond-auction", + "bifrost-vtoken-mint", + "cumulus-pallet-aura-ext", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "cumulus-test-relay-sproof-builder", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex", + "hex-literal 0.3.3", + "kusama-runtime", + "libsecp256k1 0.3.5", + "log", + "node-primitives", + "node-service", + "orml-currencies", + "orml-tokens 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library?rev=8d5432c3458702a7df14b374bddde43a2a20aa43)", + "orml-traits 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library?rev=8d5432c3458702a7df14b374bddde43a2a20aa43)", + "orml-unknown-tokens", + "orml-xcm-support", + "orml-xtokens", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-bounties", + "pallet-collator-selection", + "pallet-collective", + "pallet-democracy", + "pallet-elections-phragmen", + "pallet-indices", + "pallet-membership", + "pallet-multisig", + "pallet-proxy", + "pallet-randomness-collective-flip", + "pallet-scheduler", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-tips", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-xcm", + "parachain-info", + "parity-scale-codec", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime-parachains", + "serde", + "smallvec 1.6.1", + "sp-api", + "sp-arithmetic", + "sp-block-builder", + "sp-consensus-aura", + "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", + "sp-transaction-pool", + "sp-trie", + "sp-version", + "static_assertions", + "xcm", + "xcm-builder", + "xcm-emulator", + "xcm-executor", + "xcm-support", + "zenlink-protocol", + "zenlink-protocol-runtime-api", +] + [[package]] name = "rustc-demangle" version = "0.1.20" @@ -12412,6 +12644,30 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "xcm-emulator" +version = "0.1.0" +source = "git+https://github.com/shaunxw/xcm-simulator?branch=polkadot-v0.9.9#b6cf9973c8a81fb1a68036d1d8ef0c922f0e7551" +dependencies = [ + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "cumulus-test-relay-sproof-builder", + "frame-support", + "frame-system", + "parachain-info", + "parity-scale-codec", + "paste", + "polkadot-primitives", + "polkadot-runtime-parachains", + "sp-io", + "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.9)", + "xcm", + "xcm-executor", +] + [[package]] name = "xcm-executor" version = "0.9.9-1" diff --git a/Cargo.toml b/Cargo.toml index bd776cadee..30a9923bbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "runtime/bifrost", "utils/subkey", "xcm-support", + "integration-tests", ] # The list of dependencies below (which can be both direct and indirect dependencies) are crates diff --git a/Makefile b/Makefile index 1198ef9b02..960ba9a0a8 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,10 @@ test-asgard: test-all: cargo test --features "with-all-runtime" +.PHONY: integration-test +integration-test: + SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features=with-asgard-runtime + .PHONY: clean clean: cargo clean diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml new file mode 100644 index 0000000000..3efaf9aaa1 --- /dev/null +++ b/integration-tests/Cargo.toml @@ -0,0 +1,215 @@ +[package] +name = "runtime-integration-tests" +version = "0.8.0" +authors = ["Ron Yang "] +edition = "2018" + +[dependencies] +# third-party dependencies +codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "max-encoded-len"] } +log = { version = "0.4.14", default-features = false } +serde = { version = "1.0.124", optional = true } +static_assertions = "1.1.0" +hex = { version = "0.4", default-features = false, optional = true } +hex-literal = { version = "0.3.1"} +smallvec = "1.6.1" + +# primitives +node-primitives = { default-features = false, path = "../node/primitives" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false} +sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } + +# frame dependencies +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false, optional = true } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false, optional = true } +frame-executive = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-bounties = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-democracy = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-indices = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-membership = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-proxy = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-tips = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } +pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false } + +# Cumulus dependencies +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +parachain-info = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } +pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.9" } + +# Polkadot dependencies +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } +xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9", default-features = false } + +# bifrost pallets +bifrost-bancor= { path = "../pallets/bancor",default-features = false } +bifrost-bancor-runtime-api = { path = "../pallets/bancor/rpc/runtime-api", default-features = false } +bifrost-flexible-fee = { path = "../pallets/flexible-fee", default-features = false } +bifrost-flexible-fee-rpc-runtime-api = { path = "../pallets/flexible-fee/rpc/runtime-api", default-features = false } +bifrost-liquidity-mining = { path = "../pallets/liquidity-mining", default-features = false } +bifrost-minter-reward = { path = "../pallets/minter-reward", default-features = false } +bifrost-runtime-common = { path = "../runtime/common", default-features = false } +bifrost-salp = { path = "../pallets/salp", default-features = false } +bifrost-salp-rpc-runtime-api = { path = "../pallets/salp/rpc/runtime-api", default-features = false } +bifrost-vsbond-auction = { path = "../pallets/vsbond-auction", default-features = false } +bifrost-vtoken-mint = { path = "../pallets/vtoken-mint", default-features = false } +pallet-vesting = { package = "bifrost-vesting", path = "../pallets/vesting", default-features = false } +xcm-support = { path = "../xcm-support", default-features = false } +asgard-runtime = { path = "../runtime/asgard", default-features = false } +bifrost-runtime = { path = "../runtime/bifrost", default-features = false } + +# orml +orml-currencies = { version = "0.4.1-dev", default-features = false } +orml-tokens = { version = "0.4.1-dev", default-features = false } +orml-traits = { version = "0.4.1-dev", default-features = false } +orml-xtokens = { version = "0.4.1-dev", default-features = false } +orml-unknown-tokens = { version = "0.4.1-dev", default-features = false } +orml-xcm-support = { version = "0.4.1-dev", default-features = false } + +zenlink-protocol = { version = "*", default-features = false } +zenlink-protocol-runtime-api = { version = "*", default-features = false } + +[dev-dependencies] +libsecp256k1 = "0.3.4" +hex = "0.4.0" + +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" } + +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" } +cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9" } + +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9" } +kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.9" } + +xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", branch = "polkadot-v0.9.9" } + +node-service = { path = "../node/service", features = ["with-all-runtime"] } + +[features] +default = ["std"] +no_std = [] +with-asgard-runtime=[ + "node-service/with-asgard-runtime" +] +with-bifrost-runtime=[ + "node-service/with-bifrost-runtime" +] +std = [ + "codec/std", + "log/std", + "frame-benchmarking/std", + "frame-try-runtime/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "node-primitives/std", + "pallet-aura/std", + "pallet-balances/std", + "pallet-bounties/std", + "pallet-collator-selection/std", + "pallet-collective/std", + "pallet-democracy/std", + "pallet-elections-phragmen/std", + "pallet-indices/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-proxy/std", + "pallet-randomness-collective-flip/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-tips/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "pallet-session/std", + "pallet-vesting/std", + "pallet-utility/std", + "sp-arithmetic/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-inherents/std", + "sp-runtime/std", + "sp-offchain/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "parachain-info/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-pallet-xcm/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "xcm/std", + "xcm-builder/std", + "xcm-executor/std", + "polkadot-primitives/std", + "polkadot-runtime-parachains/std", + "bifrost-bancor/std", + "bifrost-bancor-runtime-api/std", + "bifrost-flexible-fee/std", + "bifrost-flexible-fee-rpc-runtime-api/std", + "bifrost-minter-reward/std", + "bifrost-runtime-common/std", + "bifrost-salp/std", + "bifrost-salp-rpc-runtime-api/std", + "bifrost-vsbond-auction/std", + "bifrost-vtoken-mint/std", + "xcm-support/std", + "orml-currencies/std", + "orml-traits/std", + "orml-tokens/std", + "orml-xtokens/std", + "orml-unknown-tokens/std", + "orml-xcm-support/std", + "zenlink-protocol/std", + "zenlink-protocol-runtime-api/std", + "asgard-runtime/std", + "bifrost-runtime/std" +] diff --git a/integration-tests/src/integration_tests.rs b/integration-tests/src/integration_tests.rs new file mode 100644 index 0000000000..fce6bb0878 --- /dev/null +++ b/integration-tests/src/integration_tests.rs @@ -0,0 +1,220 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi 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 . + +pub use codec::Encode; +use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; +use frame_support::{ + assert_noop, assert_ok, + sp_runtime::app_crypto::sp_core::keccak_256, + traits::{ + schedule::DispatchTime, Currency, GenesisBuild, OnFinalize, OnInitialize, OriginTrait, + ValidatorSet, + }, + weights::constants::*, +}; +use frame_system::RawOrigin; +pub use node_primitives::*; +pub use orml_traits::{Change, GetByKey, MultiCurrency}; +pub use sp_runtime::{ + traits::{AccountIdConversion, BadOrigin, Convert, Zero}, + DispatchError, DispatchResult, FixedPointNumber, MultiAddress, +}; +use xcm::{ + opaque::v0::prelude::{BuyExecution, DepositAsset}, + v0::{ + ExecuteXcm, + Junction::{self, *}, + MultiAsset, + MultiLocation::*, + NetworkId, Outcome, Xcm, + }, +}; +pub const ALICE: [u8; 32] = [0u8; 32]; +pub const BOB: [u8; 32] = [1u8; 32]; + +#[cfg(feature = "with-asgard-runtime")] +pub use asgard_imports::*; +use xcm::v0::MultiLocation; + +#[cfg(feature = "with-asgard-runtime")] +mod asgard_imports { + pub use asgard_runtime::{ + create_x2_parachain_multilocation, AccountId, Balance, Balances, BifrostCrowdloanId, + BlockNumber, Call, Currencies, CurrencyId, Event, ExistentialDeposit, ExistentialDeposits, + NativeCurrencyId, Origin, OriginCaller, ParachainInfo, ParachainSystem, Perbill, Proxy, + RelayCurrencyId, RelaychainSovereignSubAccount, Runtime, Salp, Scheduler, Session, + SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig, + }; + pub use bifrost_runtime_common::constants::{currency::*, time::*}; + pub use frame_support::parameter_types; + pub use sp_runtime::traits::AccountIdConversion; +} + +fn run_to_block(n: u32) { + while System::block_number() < n { + Scheduler::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + Scheduler::on_initialize(System::block_number()); + Scheduler::on_initialize(System::block_number()); + Session::on_initialize(System::block_number()); + } +} + +fn set_relaychain_block_number(number: BlockNumber) { + ParachainSystem::on_initialize(number); + + let (relay_storage_root, proof) = + RelayStateSproofBuilder::default().into_state_root_and_proof(); + + assert_ok!(ParachainSystem::set_validation_data( + Origin::none(), + cumulus_primitives_parachain_inherent::ParachainInherentData { + validation_data: cumulus_primitives_core::PersistedValidationData { + parent_head: Default::default(), + relay_parent_number: number, + relay_parent_storage_root: relay_storage_root, + max_pov_size: Default::default(), + }, + relay_chain_state: proof, + downward_messages: Default::default(), + horizontal_messages: Default::default(), + } + )); +} + +pub fn get_all_module_accounts() -> Vec { + vec![BifrostCrowdloanId::get().into_account()] +} + +pub struct ExtBuilder { + balances: Vec<(AccountId, CurrencyId, Balance)>, +} + +impl Default for ExtBuilder { + fn default() -> Self { + Self { balances: vec![] } + } +} + +impl ExtBuilder { + pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + let native_currency_id = NativeCurrencyId::get(); + let existential_deposit = ExistentialDeposit::get(); + + pallet_balances::GenesisConfig:: { + balances: self + .balances + .clone() + .into_iter() + .filter(|(_, currency_id, _)| *currency_id == native_currency_id) + .map(|(account_id, _, initial_balance)| (account_id, initial_balance)) + .chain(get_all_module_accounts().iter().map(|x| (x.clone(), existential_deposit))) + .collect::>(), + } + .assimilate_storage(&mut t) + .unwrap(); + + orml_tokens::GenesisConfig:: { + balances: self + .balances + .into_iter() + .filter(|(_, currency_id, _)| *currency_id != native_currency_id) + .collect::>(), + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_membership::GenesisConfig:: { + members: vec![], + phantom: Default::default(), + } + .assimilate_storage(&mut t) + .unwrap(); + + >::assimilate_storage( + ¶chain_info::GenesisConfig { parachain_id: 2001.into() }, + &mut t, + ) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} + +#[test] +fn sanity_check_weight_per_time_constants_are_as_expected() { + assert_eq!(WEIGHT_PER_SECOND, 1_000_000_000_000); + assert_eq!(WEIGHT_PER_MILLIS, WEIGHT_PER_SECOND / 1000); + assert_eq!(WEIGHT_PER_MICROS, WEIGHT_PER_MILLIS / 1000); + assert_eq!(WEIGHT_PER_NANOS, WEIGHT_PER_MICROS / 1000); +} + +#[test] +fn parachain_subaccounts_are_unique() { + ExtBuilder::default().build().execute_with(|| { + let parachain: AccountId = ParachainInfo::parachain_id().into_account(); + assert_eq!( + parachain, + hex_literal::hex!["70617261d1070000000000000000000000000000000000000000000000000000"] + .into() + ); + + assert_eq!(RelaychainSovereignSubAccount::get(), create_x2_parachain_multilocation(0)); + + assert_eq!( + create_x2_parachain_multilocation(0), + MultiLocation::X2( + Junction::Parent, + Junction::AccountId32 { + network: NetworkId::Any, + id: [ + 90, 83, 115, 109, 142, 150, 241, 192, 7, 207, 13, 99, 10, 207, 82, 9, 178, + 6, 17, 97, 122, 242, 60, 233, 36, 200, 226, 83, 40, 235, 93, 40 + ] + } + ) + ); + }); +} + +#[test] +fn salp() { + ExtBuilder::default() + .balances(vec![ + (AccountId::from(ALICE), RelayCurrencyId::get(), 100 * DOLLARS), + (AccountId::from(BOB), RelayCurrencyId::get(), 100 * DOLLARS), + ]) + .build() + .execute_with(|| { + assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 1_000, 1, SlotLength::get())); + assert_ok!(Salp::funds(3_000).ok_or(())); + assert_eq!(Salp::current_trie_index(), 1); + }); +} + +#[test] +fn bancor() {} diff --git a/integration-tests/src/kusama_cross_chain_transfer.rs b/integration-tests/src/kusama_cross_chain_transfer.rs new file mode 100644 index 0000000000..eb7ad7f6a1 --- /dev/null +++ b/integration-tests/src/kusama_cross_chain_transfer.rs @@ -0,0 +1,69 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi 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 . + +//! Cross-chain transfer tests within Kusama network. + +use bifrost_runtime_common::*; +use frame_support::assert_ok; +use orml_traits::MultiCurrency; +use xcm::v0::{ + Junction::{self, Parachain, Parent}, + MultiAsset::*, + MultiLocation::*, + NetworkId, +}; +use xcm_emulator::TestExt; + +use crate::{integration_tests::*, kusama_test_net::*}; + +#[test] +fn transfer_from_relay_chain() { + Kusama::execute_with(|| { + assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( + kusama_runtime::Origin::signed(ALICE.into()), + X1(Parachain(2001)), + X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }), + vec![ConcreteFungible { id: Null, amount: DOLLARS }], + 600_000_000 + )); + }); + + Bifrost::execute_with(|| { + assert_eq!( + Tokens::free_balance(RelayCurrencyId::get(), &AccountId::from(BOB)), + 999_952_000_000 + ); + }); +} + +#[test] +fn transfer_to_relay_chain() { + Bifrost::execute_with(|| { + assert_ok!(XTokens::transfer( + Origin::signed(ALICE.into()), + RelayCurrencyId::get(), + DOLLARS, + X2(Parent, Junction::AccountId32 { id: BOB, network: NetworkId::Any }), + 3_000_000_000 + )); + }); + + Kusama::execute_with(|| { + assert_eq!(kusama_runtime::Balances::free_balance(&AccountId::from(BOB)), 999_920_000_005); + }); +} diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs new file mode 100644 index 0000000000..9174958e72 --- /dev/null +++ b/integration-tests/src/kusama_test_net.rs @@ -0,0 +1,122 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi 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 . + +//! Relay chain and parachains emulation. + +use cumulus_primitives_core::ParaId; +use frame_support::traits::GenesisBuild; +use polkadot_primitives::v1::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE}; +use polkadot_runtime_parachains::configuration::HostConfiguration; +use sp_runtime::traits::AccountIdConversion; +use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; + +use crate::integration_tests::*; + +decl_test_relay_chain! { + pub struct Kusama { + Runtime = kusama_runtime::Runtime, + XcmConfig = kusama_runtime::XcmConfig, + new_ext = kusama_ext(), + } +} + +decl_test_parachain! { + pub struct Bifrost { + Runtime = Runtime, + Origin = Origin, + new_ext = bifrost_ext(), + } +} + +decl_test_network! { + pub struct TestNet { + relay_chain = Kusama, + parachains = vec![ + (2001, Bifrost), + ], + } +} + +fn default_parachains_host_configuration() -> HostConfiguration { + HostConfiguration { + validation_upgrade_frequency: 1u32, + validation_upgrade_delay: 1, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + group_rotation_frequency: 20, + chain_availability_period: 4, + thread_availability_period: 4, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024, + ump_service_total_weight: 4 * 1_000_000_000, + max_upward_message_size: 1024 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_open_request_ttl: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_max_parathread_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_parathread_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + ..Default::default() + } +} + +pub fn kusama_ext() -> sp_io::TestExternalities { + use kusama_runtime::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (AccountId::from(ALICE), 1000 * DOLLARS), + (ParaId::from(2001).into_account(), 1000 * DOLLARS), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + polkadot_runtime_parachains::configuration::GenesisConfig:: { + config: default_parachains_host_configuration(), + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +pub fn bifrost_ext() -> sp_io::TestExternalities { + ExtBuilder::default() + .balances(vec![(AccountId::from(ALICE), RelayCurrencyId::get(), 10 * DOLLARS)]) + .build() +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs new file mode 100644 index 0000000000..8bb8327c5a --- /dev/null +++ b/integration-tests/src/lib.rs @@ -0,0 +1,25 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi 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(test)] +#[cfg(feature = "with-asgard-runtime")] +mod integration_tests; +#[cfg(feature = "with-asgard-runtime")] +mod kusama_cross_chain_transfer; +#[cfg(feature = "with-asgard-runtime")] +mod kusama_test_net; diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index ec3084f155..a4ad7c1381 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -215,9 +215,9 @@ fn extract_genesis_wasm(chain_spec: &Box) -> Result {{ @@ -305,11 +305,7 @@ pub fn run() -> Result<()> { if config.chain_spec.is_asgard_dev() { #[cfg(feature = "with-dev-runtime")] { - return if cli.sealing.is_some() { - service::manual::new_full(config).map_err(Into::into) - } else { - service::dev::new_full(config).map_err(Into::into) - }; + return service::dev::new_full(config).map_err(Into::into); } } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 9049570bdf..fe41b84230 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -74,6 +74,7 @@ async-trait = { version = "0.1.48" } log = '0.4' # Runtimes +bifrost-runtime-common = { path = "../../runtime/common"} asgard-runtime = { path = "../../runtime/asgard", optional = true } bifrost-runtime = { path = "../../runtime/bifrost", optional = true } dev-runtime = { path = "../../runtime/dev", optional = true } diff --git a/node/service/src/collator.rs b/node/service/src/collator.rs index 7a34b40ace..098e21df8f 100644 --- a/node/service/src/collator.rs +++ b/node/service/src/collator.rs @@ -18,7 +18,11 @@ use std::sync::Arc; +#[cfg(feature = "with-asgard-runtime")] +pub use asgard_runtime; use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi; +#[cfg(feature = "with-bifrost-runtime")] +pub use bifrost_runtime; use bifrost_salp_rpc_runtime_api::SalpRuntimeApi; use cumulus_client_consensus_aura::{ build_aura_consensus, BuildAuraConsensusParams, SlotProportion, @@ -29,10 +33,11 @@ use cumulus_client_service::{ prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams, }; use cumulus_primitives_core::ParaId; -use node_primitives::{AccountId, ParaId as BifrostParaId}; +pub use node_primitives::{AccountId, Block, BlockNumber, Hash, Header, ParaId as BifrostParaId}; use sc_client_api::ExecutorProvider; +use sc_consensus::LongestChain; +use sc_executor::NativeExecutionDispatch; pub use sc_executor::NativeExecutor; -use sc_executor::{native_executor_instance, NativeExecutionDispatch}; use sc_network::NetworkService; use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; @@ -41,23 +46,12 @@ use sp_api::ConstructRuntimeApi; use sp_consensus::SlotData; use sp_consensus_aura::sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair}; use sp_keystore::SyncCryptoStorePtr; +use sp_runtime::traits::BlakeTwo256; +use sp_trie::PrefixedMemoryDB; use substrate_prometheus_endpoint::Registry; use crate::RuntimeApiCollection; -type BlockNumber = u32; -type Header = sp_runtime::generic::Header; -pub type Block = sp_runtime::generic::Block; -type Hash = sp_core::H256; - -#[cfg(feature = "with-asgard-runtime")] -pub use asgard_runtime; -#[cfg(feature = "with-bifrost-runtime")] -pub use bifrost_runtime; -use sc_consensus::LongestChain; -use sp_runtime::traits::BlakeTwo256; -use sp_trie::PrefixedMemoryDB; - /// Full backend. type FullBackend = TFullBackend; @@ -67,22 +61,6 @@ type FullClient = TFullClient /// Maybe full select chain. type MaybeFullSelectChain = Option>; -#[cfg(feature = "with-asgard-runtime")] -native_executor_instance!( - pub AsgardExecutor, - asgard_runtime::api::dispatch, - asgard_runtime::native_version, - frame_benchmarking::benchmarking::HostFunctions, -); - -#[cfg(feature = "with-bifrost-runtime")] -native_executor_instance!( - pub BifrostExecutor, - bifrost_runtime::api::dispatch, - bifrost_runtime::native_version, - frame_benchmarking::benchmarking::HostFunctions, -); - /// 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 diff --git a/node/service/src/dev.rs b/node/service/src/dev.rs index 40b5933e0d..cffbde6e4b 100644 --- a/node/service/src/dev.rs +++ b/node/service/src/dev.rs @@ -16,21 +16,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::{sync::Arc, time::Duration}; +use std::sync::Arc; use cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider; -#[cfg(feature = "with-dev-runtime")] pub use dev_runtime; -use sc_client_api::ExecutorProvider; -use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; +use futures::StreamExt; +use jsonrpc_core::IoHandler; +use node_rpc::{self, RpcExtension}; +use sc_consensus::LongestChain; use sc_executor::native_executor_instance; pub use sc_executor::NativeExecutor; -use sc_finality_grandpa::SharedVoterState; -use sc_keystore::LocalKeystore; -use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; -use sc_telemetry::{Telemetry, TelemetryWorker}; -use sp_consensus::SlotData; -use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; +use sc_rpc::Metadata; +use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, TaskManager}; +use sc_telemetry::TelemetryWorker; #[cfg(feature = "with-dev-runtime")] native_executor_instance!( @@ -41,7 +39,7 @@ native_executor_instance!( ); pub type Block = dev_runtime::Block; -pub type Executor = crate::DevExecutor; +pub type Executor = DevExecutor; pub type RuntimeApi = dev_runtime::RuntimeApi; pub type FullClient = sc_service::TFullClient; pub type FullBackend = sc_service::TFullBackend; @@ -55,32 +53,24 @@ pub fn default_mock_parachain_inherent_data_provider() -> MockValidationDataInhe } } +/// Builds the PartialComponents for a parachain or development service +/// +/// Use this function if you don't actually need the full service, but just the partial in order to +/// be able to perform chain operations. +#[allow(clippy::type_complexity)] pub fn new_partial( config: &Configuration, ) -> Result< - sc_service::PartialComponents< + PartialComponents< FullClient, FullBackend, FullSelectChain, sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, - ( - sc_finality_grandpa::GrandpaBlockImport< - FullBackend, - Block, - FullClient, - FullSelectChain, - >, - sc_finality_grandpa::LinkHalf, - Option, - ), + (), >, ServiceError, > { - if config.keystore_remote.is_some() { - return Err(ServiceError::Other(format!("Remote Keystores are not supported."))); - } - let telemetry = config .telemetry_endpoints .clone() @@ -97,14 +87,8 @@ pub fn new_partial( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), )?; - let client = Arc::new(client); - let telemetry = telemetry.map(|(worker, telemetry)| { - task_manager.spawn_handle().spawn("telemetry", worker.run()); - telemetry - }); - - let select_chain = sc_consensus::LongestChain::new(backend.clone()); + let client = Arc::new(client); let transaction_pool = sc_transaction_pool::BasicPool::new_full( config.transaction_pool.clone(), @@ -114,85 +98,41 @@ pub fn new_partial( client.clone(), ); - let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import( - client.clone(), - &(client.clone() as Arc<_>), - select_chain.clone(), - telemetry.as_ref().map(|x| x.handle()), - )?; - - let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration(); + let select_chain = LongestChain::new(backend.clone()); - let import_queue = - sc_consensus_aura::import_queue::(ImportQueueParams { - block_import: grandpa_block_import.clone(), - justification_import: Some(Box::new(grandpa_block_import.clone())), - client: client.clone(), - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *timestamp, - slot_duration, - ); - - Ok((timestamp, slot, default_mock_parachain_inherent_data_provider())) - }, - spawner: &task_manager.spawn_essential_handle(), - can_author_with: sp_consensus::CanAuthorWithNativeVersion::new( - client.executor().clone(), - ), - registry: config.prometheus_registry(), - check_for_equivocation: Default::default(), - telemetry: telemetry.as_ref().map(|x| x.handle()), - })?; + // Depending whether we are + let import_queue = sc_consensus_manual_seal::import_queue( + Box::new(client.clone()), + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + ); - Ok(sc_service::PartialComponents { - client, + Ok(PartialComponents { backend, - task_manager, + client, import_queue, keystore_container, - select_chain, + task_manager, transaction_pool, - other: (grandpa_block_import, grandpa_link, telemetry), + select_chain, + other: (), }) } -fn remote_keystore(_url: &String) -> Result, &'static str> { - // FIXME: here would the concrete keystore be built, - // must return a concrete type (NOT `LocalKeystore`) that - // implements `CryptoStore` and `SyncCryptoStore` - Err("Remote Keystore not supported.") -} - -/// Builds a new service for a full client. -pub fn new_full(mut config: Configuration) -> Result { +/// Builds a new development service. This service uses manual seal, and mocks +/// the parachain inherent. +pub fn new_full(config: Configuration) -> Result { let sc_service::PartialComponents { client, backend, mut task_manager, import_queue, - mut keystore_container, + keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, mut telemetry), + other: (), } = new_partial(&config)?; - if let Some(url) = &config.keystore_remote { - match remote_keystore(url) { - Ok(k) => keystore_container.set_remote_keystore(k), - Err(e) => - return Err(ServiceError::Other(format!( - "Error hooking up remote keystore for {}: {}", - url, e - ))), - }; - } - - config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config()); - let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, @@ -214,118 +154,72 @@ pub fn new_full(mut config: Configuration) -> Result ); } - let role = config.role.clone(); - let force_authoring = config.force_authoring; - let backoff_authoring_blocks: Option<()> = None; - let name = config.network.node_name.clone(); - let enable_grandpa = !config.disable_grandpa; let prometheus_registry = config.prometheus_registry().cloned(); - - let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { - network: network.clone(), - client: client.clone(), - keystore: keystore_container.sync_keystore(), - task_manager: &mut task_manager, - transaction_pool: transaction_pool.clone(), - rpc_extensions_builder: Box::new(|_, _| Ok(())), - on_demand: None, - remote_blockchain: None, - backend, - system_rpc_tx, - config, - telemetry: telemetry.as_mut(), - })?; + let role = config.role.clone(); if role.is_authority() { let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), - transaction_pool, + transaction_pool.clone(), prometheus_registry.as_ref(), - telemetry.as_ref().map(|x| x.handle()), + None, ); - let can_author_with = - sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()); - - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - let raw_slot_duration = slot_duration.slot_duration(); - - let aura = sc_consensus_aura::start_aura::( - StartAuraParams { - slot_duration, + let pool = transaction_pool.pool().clone(); + let commands_stream = pool.validated_pool().import_notification_stream().map(|_| { + sc_consensus_manual_seal::rpc::EngineCommand::SealNewBlock { + create_empty: false, + finalize: true, + parent_hash: None, + sender: None, + } + }); + + let authorship_future = + sc_consensus_manual_seal::run_manual_seal(sc_consensus_manual_seal::ManualSealParams { + block_import: client.clone(), + env: proposer_factory, client: client.clone(), + pool: transaction_pool.clone(), + commands_stream, select_chain, - block_import, - proposer_factory, - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration( - *timestamp, - raw_slot_duration, - ); - - Ok((timestamp, slot, default_mock_parachain_inherent_data_provider())) + consensus_data_provider: None, + create_inherent_data_providers: |_, _| async { + Ok(( + sp_timestamp::InherentDataProvider::from_system_time(), + default_mock_parachain_inherent_data_provider(), + )) }, - force_authoring, - backoff_authoring_blocks, - keystore: keystore_container.sync_keystore(), - can_author_with, - sync_oracle: network.clone(), - justification_sync_link: network.clone(), - block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32), - max_block_proposal_slot_portion: None, - telemetry: telemetry.as_ref().map(|x| x.handle()), - }, - )?; - - // the AURA authoring task is considered essential, i.e. if it - // fails we take down the service with it. - task_manager.spawn_essential_handle().spawn_blocking("aura", aura); + }); + // we spawn the future on a background thread managed by service. + task_manager + .spawn_essential_handle() + .spawn_blocking("instant-seal", authorship_future); } - // if the node isn't actively participating in consensus then it doesn't - // need a keystore, regardless of which protocol we use below. - let keystore = - if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; - - let grandpa_config = sc_finality_grandpa::Config { - // FIXME #1578 make this available through chainspec - gossip_duration: Duration::from_millis(333), - justification_period: 512, - name: Some(name), - observer_enabled: false, - keystore, - local_role: role, - telemetry: telemetry.as_ref().map(|x| x.handle()), + let rpc_extensions_builder = { + Box::new(move |_deny_unsafe, _| -> Result, _> { + return Ok(RpcExtension::default()); + }) }; - if enable_grandpa { - // start the full GRANDPA voter - // NOTE: non-authorities could run the GRANDPA observer protocol, but at - // this point the full voter should provide better guarantees of block - // and vote data availability than the observer. The observer has not - // been tested extensively yet and having most nodes in a network run it - // could lead to finality stalls. - let grandpa_config = sc_finality_grandpa::GrandpaParams { - config: grandpa_config, - link: grandpa_link, - network, - voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(), - prometheus_registry, - shared_voter_state: SharedVoterState::empty(), - telemetry: telemetry.as_ref().map(|x| x.handle()), - }; + let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { + network, + client, + keystore: keystore_container.sync_keystore(), + task_manager: &mut task_manager, + transaction_pool, + rpc_extensions_builder, + on_demand: None, + remote_blockchain: None, + backend, + system_rpc_tx, + config, + telemetry: None, + })?; - // the GRANDPA voter task is considered infallible, i.e. - // if it fails we take down the service with it. - task_manager.spawn_essential_handle().spawn_blocking( - "grandpa-voter", - sc_finality_grandpa::run_grandpa_voter(grandpa_config)?, - ); - } + log::info!("Development Service Ready"); network_starter.start_network(); Ok(task_manager) diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 7423eabba0..7bddf08411 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -19,22 +19,35 @@ #![warn(unused_extern_crates)] //! Service implementation. Specialized wrapper over substrate service. - -// use sc_service::{TFullBackend, TFullClient}; - pub use client::*; pub use collator::*; +use sc_executor::native_executor_instance; pub mod chain_spec; mod client; pub mod collator; +#[cfg(feature = "with-asgard-runtime")] +pub use asgard_runtime; +#[cfg(feature = "with-bifrost-runtime")] +pub use bifrost_runtime; + +#[cfg(feature = "with-asgard-runtime")] +native_executor_instance!( + pub AsgardExecutor, + asgard_runtime::api::dispatch, + asgard_runtime::native_version, + frame_benchmarking::benchmarking::HostFunctions, +); + +#[cfg(feature = "with-bifrost-runtime")] +native_executor_instance!( + pub BifrostExecutor, + bifrost_runtime::api::dispatch, + bifrost_runtime::native_version, + frame_benchmarking::benchmarking::HostFunctions, +); + #[cfg(feature = "with-dev-runtime")] pub mod dev; -#[cfg(feature = "with-dev-runtime")] -pub mod manual; -#[cfg(feature = "with-dev-runtime")] -pub use dev::*; -#[cfg(feature = "with-dev-runtime")] -pub use manual::*; /// Can be called for a `Configuration` to check if it is a configuration for the `Bifrost` network. pub trait IdentifyVariant { diff --git a/node/service/src/manual.rs b/node/service/src/manual.rs deleted file mode 100644 index c89dc9d808..0000000000 --- a/node/service/src/manual.rs +++ /dev/null @@ -1,206 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) 2019-2021 Liebi 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 . - -use std::sync::Arc; - -pub use dev_runtime; -use futures::StreamExt; -use jsonrpc_core::IoHandler; -use node_rpc::{self, RpcExtension}; -use sc_consensus::LongestChain; -pub use sc_executor::NativeExecutor; -use sc_rpc::Metadata; -use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, TaskManager}; -use sc_telemetry::TelemetryWorker; - -use crate::{ - default_mock_parachain_inherent_data_provider, - dev::{Block, Executor, FullBackend, FullClient, FullSelectChain, RuntimeApi}, -}; - -/// Builds the PartialComponents for a parachain or development service -/// -/// Use this function if you don't actually need the full service, but just the partial in order to -/// be able to perform chain operations. -#[allow(clippy::type_complexity)] -pub fn new_partial( - config: &Configuration, -) -> Result< - PartialComponents< - FullClient, - FullBackend, - FullSelectChain, - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool, - (), - >, - ServiceError, -> { - let telemetry = config - .telemetry_endpoints - .clone() - .filter(|x| !x.is_empty()) - .map(|endpoints| -> Result<_, sc_telemetry::Error> { - let worker = TelemetryWorker::new(16)?; - let telemetry = worker.handle().new_telemetry(endpoints); - Ok((worker, telemetry)) - }) - .transpose()?; - - let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( - &config, - telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), - )?; - - let client = Arc::new(client); - - let transaction_pool = sc_transaction_pool::BasicPool::new_full( - config.transaction_pool.clone(), - config.role.is_authority().into(), - config.prometheus_registry(), - task_manager.spawn_essential_handle(), - client.clone(), - ); - - let select_chain = LongestChain::new(backend.clone()); - - // Depending whether we are - let import_queue = sc_consensus_manual_seal::import_queue( - Box::new(client.clone()), - &task_manager.spawn_essential_handle(), - config.prometheus_registry(), - ); - - Ok(PartialComponents { - backend, - client, - import_queue, - keystore_container, - task_manager, - transaction_pool, - select_chain, - other: (), - }) -} - -/// Builds a new development service. This service uses manual seal, and mocks -/// the parachain inherent. -pub fn new_full(config: Configuration) -> Result { - let sc_service::PartialComponents { - client, - backend, - mut task_manager, - import_queue, - keystore_container, - select_chain, - transaction_pool, - other: (), - } = new_partial(&config)?; - - let (network, system_rpc_tx, network_starter) = - sc_service::build_network(sc_service::BuildNetworkParams { - config: &config, - client: client.clone(), - transaction_pool: transaction_pool.clone(), - spawn_handle: task_manager.spawn_handle(), - import_queue, - on_demand: None, - block_announce_validator_builder: None, - warp_sync: None, - })?; - - if config.offchain_worker.enabled { - sc_service::build_offchain_workers( - &config, - task_manager.spawn_handle(), - client.clone(), - network.clone(), - ); - } - - let prometheus_registry = config.prometheus_registry().cloned(); - let role = config.role.clone(); - - if role.is_authority() { - let proposer_factory = sc_basic_authorship::ProposerFactory::new( - task_manager.spawn_handle(), - client.clone(), - transaction_pool.clone(), - prometheus_registry.as_ref(), - None, - ); - - let pool = transaction_pool.pool().clone(); - let commands_stream = pool.validated_pool().import_notification_stream().map(|_| { - sc_consensus_manual_seal::rpc::EngineCommand::SealNewBlock { - create_empty: false, - finalize: true, - parent_hash: None, - sender: None, - } - }); - - let authorship_future = - sc_consensus_manual_seal::run_manual_seal(sc_consensus_manual_seal::ManualSealParams { - block_import: client.clone(), - env: proposer_factory, - client: client.clone(), - pool: transaction_pool.clone(), - commands_stream, - select_chain, - consensus_data_provider: None, - create_inherent_data_providers: |_, _| async { - Ok(( - sp_timestamp::InherentDataProvider::from_system_time(), - default_mock_parachain_inherent_data_provider(), - )) - }, - }); - // we spawn the future on a background thread managed by service. - task_manager - .spawn_essential_handle() - .spawn_blocking("instant-seal", authorship_future); - } - - let rpc_extensions_builder = { - Box::new(move |_deny_unsafe, _| -> Result, _> { - return Ok(RpcExtension::default()); - }) - }; - - let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { - network, - client, - keystore: keystore_container.sync_keystore(), - task_manager: &mut task_manager, - transaction_pool, - rpc_extensions_builder, - on_demand: None, - remote_blockchain: None, - backend, - system_rpc_tx, - config, - telemetry: None, - })?; - - log::info!("Development Service Ready"); - - network_starter.start_network(); - Ok(task_manager) -} diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index c441882cf2..a7d2a78872 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -91,10 +91,10 @@ use frame_support::{ sp_runtime::traits::Convert, traits::{EnsureOrigin, OnRuntimeUpgrade}, }; -use node_primitives::{ - Amount, CurrencyId, ExtraFeeName, Moment, Nonce, ParaId, ParachainDerivedProxyAccountType, - ParachainTransactProxyType, ParachainTransactType, RpcContributionStatus, TokenSymbol, - TransferOriginType, XcmBaseWeight, +pub use node_primitives::{ + AccountId, Amount, Balance, BlockNumber, CurrencyId, ExtraFeeName, Moment, Nonce, ParaId, + ParachainDerivedProxyAccountType, ParachainTransactProxyType, ParachainTransactType, + RpcContributionStatus, TokenSymbol, TransferOriginType, XcmBaseWeight, }; // orml imports use orml_currencies::BasicCurrencyAdapter; @@ -1396,17 +1396,10 @@ construct_runtime! { pub type AccountIndex = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = sp_runtime::MultiSignature; -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; -/// Balance of an account. -pub type Balance = u128; /// Index of a transaction in the chain. pub type Index = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; -/// An index to a block. -pub type BlockNumber = u32; /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block header type as expected by this runtime. diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index cfef66fa00..6c50f5b869 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -85,10 +85,10 @@ use frame_support::{ }; use frame_system::{EnsureOneOf, EnsureRoot, RawOrigin}; use hex_literal::hex; -use node_primitives::{ - Amount, CurrencyId, ExtraFeeName, Moment, Nonce, ParaId, ParachainDerivedProxyAccountType, - ParachainTransactProxyType, ParachainTransactType, RpcContributionStatus, TokenSymbol, - TransferOriginType, XcmBaseWeight, +pub use node_primitives::{ + AccountId, Amount, Balance, BlockNumber, CurrencyId, ExtraFeeName, Moment, Nonce, ParaId, + ParachainDerivedProxyAccountType, ParachainTransactProxyType, ParachainTransactType, + RpcContributionStatus, TokenSymbol, TransferOriginType, XcmBaseWeight, }; // orml imports use orml_currencies::BasicCurrencyAdapter; @@ -1139,17 +1139,10 @@ construct_runtime! { pub type AccountIndex = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = sp_runtime::MultiSignature; -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; -/// Balance of an account. -pub type Balance = u128; /// Index of a transaction in the chain. pub type Index = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; -/// An index to a block. -pub type BlockNumber = u32; /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block header type as expected by this runtime. diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 34d4b9abaf..c760387538 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,6 +11,7 @@ log = { version = "0.4.14", default-features = false } serde = { version = "1.0.124", optional = true } static_assertions = "1.1.0" hex-literal = { version = "0.3.1", optional = true } +smallvec = "1.6.1" # primitives node-primitives = { default-features = false, path = "../../node/primitives" } diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index a6bd7c18c1..21c39e2bfe 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -101,9 +101,9 @@ use frame_support::{ traits::{EnsureOrigin, KeyOwnerProofSystem}, }; use node_primitives::{ - Amount, CurrencyId, ExtraFeeName, Moment, Nonce, ParaId, ParachainDerivedProxyAccountType, - ParachainTransactProxyType, ParachainTransactType, RpcContributionStatus, TokenSymbol, - TransferOriginType, XcmBaseWeight, + AccountId, Amount, Balance, BlockNumber, CurrencyId, ExtraFeeName, Moment, Nonce, ParaId, + ParachainDerivedProxyAccountType, ParachainTransactProxyType, ParachainTransactType, + RpcContributionStatus, TokenSymbol, TransferOriginType, XcmBaseWeight, }; // orml imports use orml_currencies::BasicCurrencyAdapter; @@ -1363,17 +1363,10 @@ construct_runtime! { pub type AccountIndex = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = sp_runtime::MultiSignature; -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; -/// Balance of an account. -pub type Balance = u128; /// Index of a transaction in the chain. pub type Index = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; -/// An index to a block. -pub type BlockNumber = u32; /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block header type as expected by this runtime. diff --git a/xcm-support/src/mock.rs b/xcm-support/src/mock.rs index a89c5b0b51..9defe617b1 100644 --- a/xcm-support/src/mock.rs +++ b/xcm-support/src/mock.rs @@ -19,8 +19,8 @@ pub use codec::Encode; pub use cumulus_pallet_dmp_queue; pub use cumulus_pallet_xcmp_queue; -pub use cumulus_primitives_core::{self, ParaId}; -use frame_support::{sp_io, traits::GenesisBuild}; +pub use cumulus_primitives_core::{self, ParaId as cumulusParaId}; +use frame_support::{sp_io, sp_runtime::traits::AccountIdConversion, traits::GenesisBuild}; pub use frame_support::{traits::Get, weights::Weight}; pub use paste; pub use polkadot_runtime_parachains::{dmp, ump}; @@ -289,9 +289,15 @@ pub fn relay_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } - .assimilate_storage(&mut t) - .unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![ + (ALICE, INITIAL_BALANCE), + (cumulusParaId::from(1).into_account(), 1000 * INITIAL_BALANCE), + (cumulusParaId::from(2).into_account(), 1000 * INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); diff --git a/xcm-support/src/tests.rs b/xcm-support/src/tests.rs index 017129a38f..37a7ae0b33 100644 --- a/xcm-support/src/tests.rs +++ b/xcm-support/src/tests.rs @@ -130,7 +130,7 @@ mod tests { Xcm::WithdrawAsset { assets: vec![MultiAsset::ConcreteFungible { id: MultiLocation::Null, - amount: 0 + amount: 200 * INITIAL_BALANCE, }], effects: vec![Order::BuyExecution { fees: MultiAsset::All,