diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 33dd6b84a47..22b2868359d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,7 +47,7 @@ default: when: - runner_system_failure - unknown_failure - - api_failure + - api_failure interruptible: true tags: - linux-docker @@ -145,7 +145,6 @@ test: # RUSTFLAGS: "-D warnings" script: &test-script - time cargo fetch - - time cargo fetch --manifest-path=`cargo metadata --format-version=1 | jq --compact-output --raw-output ".packages[] | select(.name == \"polkadot-test-runtime\").manifest_path"` - time cargo fetch --manifest-path=`cargo metadata --format-version=1 | jq --compact-output --raw-output ".packages[] | select(.name == \"polkadot-runtime\").manifest_path"` - time cargo fetch --manifest-path=`cargo metadata --format-version=1 | jq --compact-output --raw-output ".packages[] | select(.name == \"kusama-runtime\").manifest_path"` - CARGO_NET_OFFLINE=true SKIP_POLKADOT_RUNTIME_WASM_BUILD=1 SKIP_KUSAMA_RUNTIME_WASM_BUILD=1 SKIP_POLKADOT_TEST_RUNTIME_WASM_BUILD=1 time cargo test --verbose --workspace @@ -196,7 +195,6 @@ build: # master script: &build-script - time cargo fetch - - time cargo fetch --manifest-path=`cargo metadata --format-version=1 | jq --compact-output --raw-output ".packages[] | select(.name == \"polkadot-test-runtime\").manifest_path"` - time cargo fetch --manifest-path=`cargo metadata --format-version=1 | jq --compact-output --raw-output ".packages[] | select(.name == \"polkadot-runtime\").manifest_path"` - time cargo fetch --manifest-path=`cargo metadata --format-version=1 | jq --compact-output --raw-output ".packages[] | select(.name == \"kusama-runtime\").manifest_path"` - CARGO_NET_OFFLINE=true SKIP_POLKADOT_RUNTIME_WASM_BUILD=1 SKIP_KUSAMA_RUNTIME_WASM_BUILD=1 SKIP_POLKADOT_TEST_RUNTIME_WASM_BUILD=1 time cargo build --release --verbose --workspace diff --git a/.maintain/millau-weight-template.hbs b/.maintain/millau-weight-template.hbs index afa75f57c9b..aee13799339 100644 --- a/.maintain/millau-weight-template.hbs +++ b/.maintain/millau-weight-template.hbs @@ -46,9 +46,11 @@ pub trait WeightInfo { {{~/each}} } -/// Weights for `{{pallet}}` using the Millau node and recommended hardware. -pub struct MillauWeight(PhantomData); -impl WeightInfo for MillauWeight { +/// Weights for `{{pallet}}` that are generated using one of the Bridge testnets. +/// +/// Those weights are test only and must never be used in production. +pub struct BridgeWeight(PhantomData); +impl WeightInfo for BridgeWeight { {{~#each benchmarks as |benchmark|}} fn {{benchmark.name~}} ( diff --git a/Cargo.lock b/Cargo.lock index e8c61c91b47..322879c38b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -729,15 +729,9 @@ dependencies = [ name = "bp-kusama" version = "0.1.0" dependencies = [ - "bp-messages", "bp-polkadot-core", "bp-runtime", - "frame-support", - "smallvec", "sp-api", - "sp-runtime", - "sp-std", - "sp-version", ] [[package]] @@ -747,7 +741,6 @@ dependencies = [ "bitvec", "bp-runtime", "frame-support", - "frame-system", "hex", "hex-literal", "impl-trait-for-tuples", @@ -790,7 +783,6 @@ dependencies = [ "frame-support", "parity-scale-codec", "scale-info", - "serde", "sp-core", ] @@ -798,15 +790,10 @@ dependencies = [ name = "bp-polkadot" version = "0.1.0" dependencies = [ - "bp-messages", "bp-polkadot-core", "bp-runtime", - "frame-support", "smallvec", "sp-api", - "sp-runtime", - "sp-std", - "sp-version", ] [[package]] @@ -822,11 +809,9 @@ dependencies = [ "parity-util-mem", "scale-info", "serde", - "sp-api", "sp-core", "sp-runtime", "sp-std", - "sp-version", ] [[package]] @@ -872,16 +857,10 @@ dependencies = [ name = "bp-rococo" version = "0.1.0" dependencies = [ - "bp-messages", "bp-polkadot-core", "bp-runtime", "frame-support", - "parity-scale-codec", - "smallvec", "sp-api", - "sp-runtime", - "sp-std", - "sp-version", ] [[package]] @@ -923,31 +902,22 @@ dependencies = [ name = "bp-westend" version = "0.1.0" dependencies = [ - "bp-header-chain", "bp-polkadot-core", "bp-runtime", - "frame-support", "parity-scale-codec", "scale-info", - "smallvec", "sp-api", "sp-runtime", - "sp-std", - "sp-version", ] [[package]] name = "bp-wococo" version = "0.1.0" dependencies = [ - "bp-messages", "bp-polkadot-core", "bp-rococo", "bp-runtime", - "parity-scale-codec", "sp-api", - "sp-runtime", - "sp-std", ] [[package]] @@ -963,12 +933,10 @@ dependencies = [ "hash-db", "log", "millau-runtime", - "num-traits", "pallet-balances", "pallet-bridge-grandpa", "pallet-bridge-messages", "pallet-bridge-parachains", - "pallet-transaction-payment", "pallet-xcm", "parity-scale-codec", "scale-info", @@ -976,10 +944,8 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-state-machine", "sp-std", "sp-trie", - "sp-version", "static_assertions", "xcm", "xcm-builder", @@ -1936,28 +1902,6 @@ dependencies = [ "sp-timestamp", ] -[[package]] -name = "cumulus-primitives-utility" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=gav-xcm-v3#516669814078a308e8de659979aa0f97e8d67eff" -dependencies = [ - "cumulus-primitives-core", - "frame-support", - "log", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-runtime-common", - "sp-io", - "sp-runtime", - "sp-std", - "sp-trie", - "xcm", - "xcm-builder", - "xcm-executor", -] - [[package]] name = "cumulus-relay-chain-inprocess-interface" version = "0.1.0" @@ -3718,21 +3662,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "jsonrpc-core" -version = "18.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f7f76aef2d054868398427f6c54943cf3d1caa9a7ec7d0c38d69df97a965eb" -dependencies = [ - "futures", - "futures-executor", - "futures-util", - "log", - "serde", - "serde_derive", - "serde_json", -] - [[package]] name = "jsonrpsee" version = "0.15.1" @@ -4949,15 +4878,12 @@ dependencies = [ "beefy-gadget", "beefy-gadget-rpc", "beefy-primitives", - "bp-millau", - "bp-runtime", "clap 3.2.18", "frame-benchmarking", "frame-benchmarking-cli", "jsonrpsee", "millau-runtime", "node-inspect", - "pallet-bridge-messages", "pallet-mmr-rpc", "pallet-transaction-payment-rpc", "sc-basic-authorship", @@ -4989,7 +4915,6 @@ name = "millau-runtime" version = "0.1.0" dependencies = [ "beefy-primitives", - "bp-header-chain", "bp-messages", "bp-millau", "bp-polkadot-core", @@ -5006,7 +4931,6 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "hex-literal", - "libsecp256k1", "log", "pallet-aura", "pallet-balances", @@ -5028,12 +4952,10 @@ dependencies = [ "pallet-xcm", "parity-scale-codec", "scale-info", - "serde", "sp-api", "sp-block-builder", "sp-consensus-aura", "sp-core", - "sp-finality-grandpa", "sp-inherents", "sp-io", "sp-mmr-primitives", @@ -5042,7 +4964,6 @@ dependencies = [ "sp-session", "sp-std", "sp-transaction-pool", - "sp-trie", "sp-version", "static_assertions", "substrate-wasm-builder", @@ -5725,10 +5646,8 @@ dependencies = [ "frame-support", "frame-system", "log", - "num-traits", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-finality-grandpa", "sp-io", @@ -5753,7 +5672,6 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-io", "sp-runtime", @@ -5776,8 +5694,6 @@ dependencies = [ "pallet-bridge-grandpa", "parity-scale-codec", "scale-info", - "serde", - "sp-core", "sp-io", "sp-runtime", "sp-std", @@ -5795,12 +5711,10 @@ dependencies = [ "frame-support", "frame-system", "log", - "num-traits", "pallet-balances", "pallet-bridge-messages", "parity-scale-codec", "scale-info", - "serde", "sp-arithmetic", "sp-core", "sp-io", @@ -6437,15 +6351,11 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "backoff", "bp-parachains", "bp-polkadot-core", "futures", - "linked-hash-map", "log", - "num-traits", "parity-scale-codec", - "parking_lot 0.11.2", "relay-substrate-client", "relay-utils", "sp-core", @@ -7847,121 +7757,6 @@ dependencies = [ "sp-core", ] -[[package]] -name = "polkadot-test-runtime" -version = "0.9.27" -source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#dd02a13f43b4fabb5293027d6977b59fb0050eed" -dependencies = [ - "beefy-primitives", - "bitvec", - "frame-election-provider-support", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-rpc-runtime-api", - "log", - "pallet-authority-discovery", - "pallet-authorship", - "pallet-babe", - "pallet-balances", - "pallet-grandpa", - "pallet-indices", - "pallet-offences", - "pallet-session", - "pallet-staking", - "pallet-staking-reward-curve", - "pallet-sudo", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-vesting", - "pallet-xcm", - "parity-scale-codec", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-runtime-common", - "polkadot-runtime-parachains", - "rustc-hex", - "scale-info", - "serde", - "serde_derive", - "smallvec", - "sp-api", - "sp-authority-discovery", - "sp-block-builder", - "sp-consensus-babe", - "sp-core", - "sp-inherents", - "sp-io", - "sp-mmr-primitives", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-staking", - "sp-std", - "sp-transaction-pool", - "sp-version", - "substrate-wasm-builder", - "test-runtime-constants", - "xcm", - "xcm-builder", - "xcm-executor", -] - -[[package]] -name = "polkadot-test-service" -version = "0.9.27" -source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#dd02a13f43b4fabb5293027d6977b59fb0050eed" -dependencies = [ - "frame-benchmarking", - "frame-system", - "futures", - "hex", - "pallet-balances", - "pallet-staking", - "pallet-transaction-payment", - "polkadot-node-primitives", - "polkadot-node-subsystem", - "polkadot-overseer", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-rpc", - "polkadot-runtime-common", - "polkadot-runtime-parachains", - "polkadot-service", - "polkadot-test-runtime", - "rand 0.8.5", - "sc-authority-discovery", - "sc-chain-spec", - "sc-cli", - "sc-client-api", - "sc-consensus", - "sc-consensus-babe", - "sc-executor", - "sc-finality-grandpa", - "sc-network", - "sc-network-common", - "sc-service", - "sc-tracing", - "sc-transaction-pool", - "sp-arithmetic", - "sp-authority-discovery", - "sp-blockchain", - "sp-consensus", - "sp-consensus-babe", - "sp-core", - "sp-finality-grandpa", - "sp-inherents", - "sp-keyring", - "sp-runtime", - "sp-state-machine", - "substrate-test-client", - "tempfile", - "test-runtime-constants", - "tokio", - "tracing-gum", -] - [[package]] name = "polling" version = "2.2.0" @@ -8480,7 +8275,6 @@ dependencies = [ "sp-core", "sp-finality-grandpa", "sp-runtime", - "sp-version", ] [[package]] @@ -8496,7 +8290,6 @@ dependencies = [ "scale-info", "sp-core", "sp-runtime", - "sp-version", ] [[package]] @@ -8609,7 +8402,6 @@ dependencies = [ "sc-chain-spec", "sc-rpc-api", "sc-transaction-pool-api", - "serde", "sp-core", "sp-finality-grandpa", "sp-rpc", @@ -8654,7 +8446,6 @@ dependencies = [ "relay-substrate-client", "relay-utils", "sp-core", - "sp-runtime", ] [[package]] @@ -8719,78 +8510,34 @@ dependencies = [ name = "rialto-bridge-node" version = "0.1.0" dependencies = [ - "beefy-gadget", - "beefy-gadget-rpc", "beefy-primitives", - "bp-rialto", - "bp-runtime", "clap 3.2.18", "frame-benchmarking", "frame-benchmarking-cli", - "frame-system-rpc-runtime-api", - "futures", - "jsonrpc-core", - "kvdb", - "kvdb-rocksdb", - "lru 0.7.8", "node-inspect", - "pallet-bridge-messages", - "pallet-mmr-rpc", - "pallet-transaction-payment-rpc", - "pallet-transaction-payment-rpc-runtime-api", "polkadot-node-core-pvf", "polkadot-primitives", "polkadot-runtime-parachains", "polkadot-service", "rialto-runtime", - "sc-authority-discovery", - "sc-basic-authorship", "sc-cli", - "sc-client-api", - "sc-consensus", - "sc-consensus-babe", - "sc-consensus-slots", - "sc-consensus-uncles", "sc-executor", - "sc-finality-grandpa", - "sc-finality-grandpa-rpc", - "sc-keystore", - "sc-network", - "sc-rpc", "sc-service", - "sc-telemetry", - "sc-transaction-pool", "serde_json", - "sp-api", "sp-authority-discovery", - "sp-authorship", - "sp-block-builder", - "sp-blockchain", - "sp-consensus", "sp-consensus-babe", "sp-core", "sp-finality-grandpa", - "sp-inherents", - "sp-mmr-primitives", - "sp-offchain", "sp-runtime", - "sp-session", - "sp-timestamp", - "sp-transaction-pool", "substrate-build-script-utils", - "substrate-frame-rpc-system", - "substrate-prometheus-endpoint", - "thiserror", ] [[package]] name = "rialto-parachain-collator" version = "0.1.0" dependencies = [ - "bp-rialto-parachain", "clap 3.2.18", "cumulus-client-cli", - "cumulus-client-collator", "cumulus-client-consensus-aura", "cumulus-client-consensus-common", "cumulus-client-network", @@ -8799,20 +8546,15 @@ dependencies = [ "cumulus-primitives-parachain-inherent", "cumulus-relay-chain-inprocess-interface", "cumulus-relay-chain-interface", - "derive_more", "frame-benchmarking", "frame-benchmarking-cli", - "hex-literal", "jsonrpsee", "log", - "pallet-bridge-messages", "pallet-transaction-payment-rpc", "parity-scale-codec", "polkadot-cli", - "polkadot-parachain", "polkadot-primitives", "polkadot-service", - "polkadot-test-service", "rialto-parachain-runtime", "sc-basic-authorship", "sc-chain-spec", @@ -8820,7 +8562,6 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-executor", - "sc-keystore", "sc-network", "sc-rpc", "sc-rpc-api", @@ -8831,11 +8572,9 @@ dependencies = [ "serde", "sp-api", "sp-block-builder", - "sp-blockchain", "sp-consensus", "sp-consensus-aura", "sp-core", - "sp-inherents", "sp-keystore", "sp-offchain", "sp-runtime", @@ -8864,13 +8603,13 @@ dependencies = [ "cumulus-pallet-xcmp-queue", "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", + "hex-literal", "log", "pallet-aura", "pallet-balances", @@ -8887,7 +8626,6 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain", "scale-info", - "serde", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -8911,7 +8649,6 @@ name = "rialto-runtime" version = "0.1.0" dependencies = [ "beefy-primitives", - "bp-header-chain", "bp-messages", "bp-millau", "bp-relayers", @@ -8924,8 +8661,6 @@ dependencies = [ "frame-support", "frame-system", "frame-system-rpc-runtime-api", - "hex-literal", - "libsecp256k1", "log", "pallet-authority-discovery", "pallet-babe", @@ -8949,13 +8684,11 @@ dependencies = [ "polkadot-runtime-common", "polkadot-runtime-parachains", "scale-info", - "serde", "sp-api", "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", "sp-core", - "sp-finality-grandpa", "sp-inherents", "sp-io", "sp-mmr-primitives", @@ -8964,7 +8697,6 @@ dependencies = [ "sp-session", "sp-std", "sp-transaction-pool", - "sp-trie", "sp-version", "static_assertions", "substrate-wasm-builder", @@ -9531,17 +9263,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "sc-consensus-uncles" -version = "0.10.0-dev" -source = "git+https://github.com/paritytech//substrate?branch=sv-locked-for-gav-xcm-v3-and-bridges#57e3486d9c7bb4deaef33cf9ba2da083b4e40314" -dependencies = [ - "sc-client-api", - "sp-authorship", - "sp-runtime", - "thiserror", -] - [[package]] name = "sc-executor" version = "0.10.0-dev" @@ -11588,10 +11309,11 @@ dependencies = [ "anyhow", "async-std", "async-trait", + "bp-bridge-hub-rococo", + "bp-bridge-hub-wococo", "bp-header-chain", "bp-messages", "bp-millau", - "bp-parachains", "bp-polkadot-core", "bp-rialto", "bp-rialto-parachain", @@ -11602,7 +11324,6 @@ dependencies = [ "bp-wococo", "bridge-runtime-common", "finality-grandpa", - "finality-relay", "frame-support", "futures", "hex", @@ -11612,7 +11333,6 @@ dependencies = [ "millau-runtime", "num-format", "num-traits", - "pallet-balances", "pallet-bridge-messages", "pallet-bridge-parachains", "parachains-relay", @@ -11621,7 +11341,6 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "polkadot-runtime-parachains", - "rand 0.8.5", "relay-bridge-hub-rococo-client", "relay-bridge-hub-wococo-client", "relay-millau-client", @@ -11635,7 +11354,6 @@ dependencies = [ "rialto-parachain-runtime", "rialto-runtime", "sp-core", - "sp-io", "sp-keyring", "sp-runtime", "sp-version", @@ -11711,32 +11429,6 @@ dependencies = [ "trie-db", ] -[[package]] -name = "substrate-test-client" -version = "2.0.1" -source = "git+https://github.com/paritytech//substrate?branch=sv-locked-for-gav-xcm-v3-and-bridges#57e3486d9c7bb4deaef33cf9ba2da083b4e40314" -dependencies = [ - "async-trait", - "futures", - "hex", - "parity-scale-codec", - "sc-client-api", - "sc-client-db", - "sc-consensus", - "sc-executor", - "sc-offchain", - "sc-service", - "serde", - "serde_json", - "sp-blockchain", - "sp-consensus", - "sp-core", - "sp-keyring", - "sp-keystore", - "sp-runtime", - "sp-state-machine", -] - [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" @@ -11856,18 +11548,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "test-runtime-constants" -version = "0.9.27" -source = "git+https://github.com/paritytech//polkadot?branch=locked-for-gav-xcm-v3-and-bridges#dd02a13f43b4fabb5293027d6977b59fb0050eed" -dependencies = [ - "frame-support", - "polkadot-primitives", - "polkadot-runtime-common", - "smallvec", - "sp-runtime", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 0af32c9ca90..6a0eddb32a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,6 @@ pallet-membership = { git = "https://github.com/paritytech//substrate", branch = pallet-mmr = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } pallet-mmr-rpc = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } pallet-multisig = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } -#pallet-nicks = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } pallet-nomination-pools = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } pallet-offences = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } @@ -98,7 +97,6 @@ sc-consensus-babe = { git = "https://github.com/paritytech//substrate", branch = sc-consensus-babe-rpc = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sc-consensus-epochs = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sc-consensus-slots = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } -sc-consensus-uncles = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sc-executor = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sc-executor-common = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sc-executor-wasmi = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } @@ -159,7 +157,6 @@ sp-rpc = { git = "https://github.com/paritytech//substrate", branch = "sv-locked sp-runtime = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sp-runtime-interface = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sp-runtime-interface-proc-macro = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } -#sp-serializer = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sp-session = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sp-staking = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } sp-state-machine = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } @@ -178,14 +175,12 @@ substrate-build-script-utils = { git = "https://github.com/paritytech//substrate substrate-frame-rpc-system = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } -substrate-test-client = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } substrate-wasm-builder = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } try-runtime-cli = { git = "https://github.com/paritytech//substrate", branch = "sv-locked-for-gav-xcm-v3-and-bridges" } [patch."https://github.com/paritytech/polkadot"] kusama-runtime = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } kusama-runtime-constants = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } -#metered-channel = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } pallet-xcm = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-approval-distribution = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-availability-bitfield-distribution = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } @@ -221,8 +216,6 @@ polkadot-node-subsystem = { git = "https://github.com/paritytech//polkadot", bra polkadot-node-subsystem-types = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-node-subsystem-util = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-overseer = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } -#polkadot-overseer-gen = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } -#polkadot-overseer-gen-proc-macro = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-parachain = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-performance-test = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-primitives = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } @@ -235,10 +228,7 @@ polkadot-runtime-parachains = { git = "https://github.com/paritytech//polkadot", polkadot-service = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-statement-distribution = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } polkadot-statement-table = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } -polkadot-test-runtime = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } -polkadot-test-service = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } slot-range-helper = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } -test-runtime-constants = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } tracing-gum = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } tracing-gum-proc-macro = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } xcm = { git = "https://github.com/paritytech//polkadot", branch = "locked-for-gav-xcm-v3-and-bridges" } diff --git a/bin/millau/node/Cargo.toml b/bin/millau/node/Cargo.toml index e83f3c4f564..a7a2f86ea33 100644 --- a/bin/millau/node/Cargo.toml +++ b/bin/millau/node/Cargo.toml @@ -15,10 +15,7 @@ serde_json = "1.0.79" # Bridge dependencies -bp-millau = { path = "../../../primitives/chain-millau" } -bp-runtime = { path = "../../../primitives/runtime" } millau-runtime = { path = "../runtime" } -pallet-bridge-messages = { path = "../../../modules/messages" } # Substrate Dependencies diff --git a/bin/millau/runtime/Cargo.toml b/bin/millau/runtime/Cargo.toml index 05e79074b68..dfab9588d5d 100644 --- a/bin/millau/runtime/Cargo.toml +++ b/bin/millau/runtime/Cargo.toml @@ -9,14 +9,11 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] hex-literal = "0.3" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -libsecp256k1 = { version = "0.7", optional = true, default-features = false, features = ["hmac"] } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0", optional = true, features = ["derive"] } # Bridge dependencies -bp-header-chain = { path = "../../../primitives/header-chain", default-features = false } bp-messages = { path = "../../../primitives/messages", default-features = false } bp-millau = { path = "../../../primitives/chain-millau", default-features = false } bp-polkadot-core = { path = "../../../primitives/polkadot-core", default-features = false } @@ -56,7 +53,6 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -65,7 +61,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } # Polkadot Dependencies @@ -87,7 +82,6 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran default = ["std"] std = [ "beefy-primitives/std", - "bp-header-chain/std", "bp-messages/std", "bp-millau/std", "bp-polkadot-core/std", @@ -122,12 +116,10 @@ std = [ "pallet-transaction-payment/std", "pallet-xcm/std", "scale-info/std", - "serde", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", - "sp-finality-grandpa/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", @@ -135,7 +127,6 @@ std = [ "sp-session/std", "sp-std/std", "sp-transaction-pool/std", - "sp-trie/std", "sp-version/std", "xcm/std", "xcm-builder/std", @@ -146,7 +137,6 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", - "libsecp256k1", "pallet-bridge-messages/runtime-benchmarks", "pallet-bridge-parachains/runtime-benchmarks", "pallet-bridge-relayers/runtime-benchmarks", diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 2fea97cea8d..8470efa7e86 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -432,7 +432,7 @@ impl pallet_bridge_grandpa::Config for Runtime { type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type WeightInfo = pallet_bridge_grandpa::weights::MillauWeight; + type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } pub type WestendGrandpaInstance = pallet_bridge_grandpa::Instance1; @@ -441,7 +441,7 @@ impl pallet_bridge_grandpa::Config for Runtime { type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type WeightInfo = pallet_bridge_grandpa::weights::MillauWeight; + type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } impl pallet_shift_session_manager::Config for Runtime {} @@ -465,7 +465,7 @@ pub type WithRialtoMessagesInstance = (); impl pallet_bridge_messages::Config for Runtime { type Event = Event; - type WeightInfo = pallet_bridge_messages::weights::MillauWeight; + type WeightInfo = pallet_bridge_messages::weights::BridgeWeight; type Parameter = rialto_messages::MillauToRialtoMessagesParameter; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; @@ -500,7 +500,7 @@ pub type WithRialtoParachainMessagesInstance = pallet_bridge_messages::Instance1 impl pallet_bridge_messages::Config for Runtime { type Event = Event; - type WeightInfo = pallet_bridge_messages::weights::MillauWeight; + type WeightInfo = pallet_bridge_messages::weights::BridgeWeight; type Parameter = rialto_parachain_messages::MillauToRialtoParachainMessagesParameter; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; @@ -541,7 +541,7 @@ pub type WithRialtoParachainsInstance = (); impl pallet_bridge_parachains::Config for Runtime { type Event = Event; - type WeightInfo = pallet_bridge_parachains::weights::MillauWeight; + type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight; type BridgesGrandpaPalletInstance = RialtoGrandpaInstance; type ParasPalletName = RialtoParasPalletName; type TrackedParachains = frame_support::traits::Everything; @@ -553,7 +553,7 @@ pub type WithWestendParachainsInstance = pallet_bridge_parachains::Instance1; impl pallet_bridge_parachains::Config for Runtime { type Event = Event; - type WeightInfo = pallet_bridge_parachains::weights::MillauWeight; + type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight; type BridgesGrandpaPalletInstance = WestendGrandpaInstance; type ParasPalletName = WestendParasPalletName; type TrackedParachains = frame_support::traits::Everything; diff --git a/bin/millau/runtime/src/rialto_messages.rs b/bin/millau/runtime/src/rialto_messages.rs index ccca4222f61..f043f8b9d43 100644 --- a/bin/millau/runtime/src/rialto_messages.rs +++ b/bin/millau/runtime/src/rialto_messages.rs @@ -236,7 +236,7 @@ impl messages::BridgedChainWithMessages for Rialto { } } -impl TargetHeaderChain for Rialto { +impl TargetHeaderChain for Rialto { type Error = &'static str; // The proof is: // - hash of the header this proof has been created with; @@ -320,7 +320,7 @@ mod tests { #[test] fn ensure_millau_message_lane_weights_are_correct() { - type Weights = pallet_bridge_messages::weights::MillauWeight; + type Weights = pallet_bridge_messages::weights::BridgeWeight; pallet_bridge_messages::ensure_weights_are_correct::( bp_millau::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT, diff --git a/bin/millau/runtime/src/rialto_parachain_messages.rs b/bin/millau/runtime/src/rialto_parachain_messages.rs index 6840b703f4f..f26e0d1006a 100644 --- a/bin/millau/runtime/src/rialto_parachain_messages.rs +++ b/bin/millau/runtime/src/rialto_parachain_messages.rs @@ -229,9 +229,7 @@ impl messages::BridgedChainWithMessages for RialtoParachain { } } -impl TargetHeaderChain - for RialtoParachain -{ +impl TargetHeaderChain for RialtoParachain { type Error = &'static str; // The proof is: // - hash of the header this proof has been created with; diff --git a/bin/rialto-parachain/node/Cargo.toml b/bin/rialto-parachain/node/Cargo.toml index 109be667c4c..1b37cb3a3fe 100644 --- a/bin/rialto-parachain/node/Cargo.toml +++ b/bin/rialto-parachain/node/Cargo.toml @@ -18,16 +18,9 @@ runtime-benchmarks = ['rialto-parachain-runtime/runtime-benchmarks'] [dependencies] clap = { version = "3.1", features = ["derive"] } -derive_more = '0.99.2' log = '0.4.17' codec = { package = 'parity-scale-codec', version = '3.1.5' } serde = { version = '1.0', features = ['derive'] } -hex-literal = '0.3.1' - -# Bridge dependencies - -bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain" } -pallet-bridge-messages = { path = "../../../modules/messages" } # RPC related Dependencies jsonrpsee = { version = "0.15.1", features = ["server"] } @@ -52,7 +45,6 @@ sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "mas sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", features = ['wasmtime'] } @@ -63,11 +55,9 @@ sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master ## Substrate Primitive Dependencies sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -78,7 +68,6 @@ sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch # Cumulus dependencies cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3" } cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3" } -cumulus-client-collator = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3" } cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3" } cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3" } cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3" } @@ -89,7 +78,5 @@ cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech # Polkadot dependencies polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" } polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" } -polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "gav-xcm-v3" } diff --git a/bin/rialto-parachain/node/src/cli.rs b/bin/rialto-parachain/node/src/cli.rs index bd45db9758c..51fa1e9776c 100644 --- a/bin/rialto-parachain/node/src/cli.rs +++ b/bin/rialto-parachain/node/src/cli.rs @@ -50,7 +50,7 @@ pub enum Subcommand { /// Revert the chain to a previous state. Revert(sc_cli::RevertCmd), - /// The custom benchmark subcommmand benchmarking runtime pallets. + /// The custom benchmark subcommand benchmarking runtime pallets. #[clap(subcommand)] Benchmark(frame_benchmarking_cli::BenchmarkCmd), } @@ -116,7 +116,7 @@ pub struct Cli { #[derive(Debug)] pub struct RelayChainCli { - /// The actual relay chain cli object. + /// The actual relay chain CLI object. pub base: polkadot_cli::RunCmd, /// Optional chain id that should be passed to the relay chain. diff --git a/bin/rialto-parachain/runtime/Cargo.toml b/bin/rialto-parachain/runtime/Cargo.toml index d125931220f..de306716265 100644 --- a/bin/rialto-parachain/runtime/Cargo.toml +++ b/bin/rialto-parachain/runtime/Cargo.toml @@ -11,9 +11,9 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran [dependencies] codec = { package = 'parity-scale-codec', version = '3.1.5', default-features = false, features = ['derive']} +hex-literal = "0.3" log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = '1.0', optional = true, features = ['derive'] } # Bridge depedencies @@ -67,7 +67,6 @@ cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = " cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3", default-features = false } cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3", default-features = false } cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3", default-features = false } -cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3", default-features = false } parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "gav-xcm-v3", default-features = false } # Polkadot Dependencies @@ -98,7 +97,6 @@ std = [ "codec/std", "log/std", "scale-info/std", - "serde", "sp-api/std", "sp-std/std", "sp-io/std", @@ -130,7 +128,6 @@ 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", diff --git a/bin/rialto-parachain/runtime/src/lib.rs b/bin/rialto-parachain/runtime/src/lib.rs index 885688d683d..b714e6d6318 100644 --- a/bin/rialto-parachain/runtime/src/lib.rs +++ b/bin/rialto-parachain/runtime/src/lib.rs @@ -538,7 +538,7 @@ impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_millau::Millau; type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type WeightInfo = pallet_bridge_grandpa::weights::MillauWeight; + type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } parameter_types! { @@ -559,7 +559,7 @@ pub type WithMillauMessagesInstance = (); impl pallet_bridge_messages::Config for Runtime { type Event = Event; - type WeightInfo = pallet_bridge_messages::weights::MillauWeight; + type WeightInfo = pallet_bridge_messages::weights::BridgeWeight; type Parameter = millau_messages::RialtoParachainToMillauMessagesParameter; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; @@ -777,6 +777,13 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(_extra: bool) -> ( + Vec, + Vec, + ) { + todo!("TODO: fix or remove") + } + fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { diff --git a/bin/rialto-parachain/runtime/src/millau_messages.rs b/bin/rialto-parachain/runtime/src/millau_messages.rs index 136b4343c19..96ff18810bc 100644 --- a/bin/rialto-parachain/runtime/src/millau_messages.rs +++ b/bin/rialto-parachain/runtime/src/millau_messages.rs @@ -243,7 +243,7 @@ impl messages::BridgedChainWithMessages for Millau { } } -impl TargetHeaderChain for Millau { +impl TargetHeaderChain for Millau { type Error = &'static str; // The proof is: // - hash of the header this proof has been created with; diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index fe2186ea3f3..6a0a1e946c8 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -10,68 +10,26 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] clap = { version = "3.1", features = ["derive"] } -futures = "0.3" -jsonrpc-core = "18.0" -kvdb = "0.11" -kvdb-rocksdb = "0.15" -lru = "0.7" serde_json = "1.0.79" -thiserror = "1.0" # Bridge dependencies -bp-runtime = { path = "../../../primitives/runtime" } -bp-rialto = { path = "../../../primitives/chain-rialto" } -pallet-bridge-messages = { path = "../../../modules/messages" } rialto-runtime = { path = "../runtime" } # Substrate Dependencies -beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" } -beefy-gadget-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } -frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } node-inspect = { git = "https://github.com/paritytech/substrate", branch = "master" } -pallet-mmr-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } -pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } -pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-consensus-uncles = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" } -substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "master" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } # Polkadot Dependencies diff --git a/bin/rialto/runtime/Cargo.toml b/bin/rialto/runtime/Cargo.toml index 8d90f1f3296..fe2ab903b0a 100644 --- a/bin/rialto/runtime/Cargo.toml +++ b/bin/rialto/runtime/Cargo.toml @@ -8,15 +8,11 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -hex-literal = "0.3" -libsecp256k1 = { version = "0.7", optional = true, default-features = false, features = ["hmac"] } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0", optional = true, features = ["derive"] } # Bridge dependencies -bp-header-chain = { path = "../../../primitives/header-chain", default-features = false } bp-messages = { path = "../../../primitives/messages", default-features = false } bp-millau = { path = "../../../primitives/chain-millau", default-features = false } bp-relayers = { path = "../../../primitives/relayers", default-features = false } @@ -53,7 +49,6 @@ sp-authority-discovery = { git = "https://github.com/paritytech/substrate", bran sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -62,7 +57,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } # Polkadot (parachain) Dependencies @@ -78,7 +72,6 @@ xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "gav-x [dev-dependencies] bridge-runtime-common = { path = "../../runtime-common", features = ["integrity-test"] } env_logger = "0.8" -libsecp256k1 = { version = "0.7", features = ["hmac"] } static_assertions = "1.1" [build-dependencies] @@ -88,7 +81,6 @@ substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", bran default = ["std"] std = [ "beefy-primitives/std", - "bp-header-chain/std", "bp-messages/std", "bp-millau/std", "bp-relayers/std", @@ -123,13 +115,11 @@ std = [ "polkadot-runtime-common/std", "polkadot-runtime-parachains/std", "scale-info/std", - "serde", "sp-api/std", "sp-authority-discovery/std", "sp-block-builder/std", "sp-consensus-babe/std", "sp-core/std", - "sp-finality-grandpa/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", @@ -137,7 +127,6 @@ std = [ "sp-session/std", "sp-std/std", "sp-transaction-pool/std", - "sp-trie/std", "sp-version/std", "xcm/std", "xcm-builder/std", @@ -148,7 +137,6 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", - "libsecp256k1", "pallet-bridge-messages/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index 3729ab78630..09afe728fd2 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -424,7 +424,7 @@ impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_millau::Millau; type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type WeightInfo = pallet_bridge_grandpa::weights::MillauWeight; + type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } impl pallet_shift_session_manager::Config for Runtime {} @@ -447,7 +447,7 @@ pub type WithMillauMessagesInstance = (); impl pallet_bridge_messages::Config for Runtime { type Event = Event; - type WeightInfo = pallet_bridge_messages::weights::MillauWeight; + type WeightInfo = pallet_bridge_messages::weights::BridgeWeight; type Parameter = millau_messages::RialtoToMillauMessagesParameter; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; diff --git a/bin/rialto/runtime/src/millau_messages.rs b/bin/rialto/runtime/src/millau_messages.rs index 1267cbd06e2..e5869998fa8 100644 --- a/bin/rialto/runtime/src/millau_messages.rs +++ b/bin/rialto/runtime/src/millau_messages.rs @@ -233,7 +233,7 @@ impl messages::BridgedChainWithMessages for Millau { } } -impl TargetHeaderChain for Millau { +impl TargetHeaderChain for Millau { type Error = &'static str; // The proof is: // - hash of the header this proof has been created with; @@ -315,7 +315,7 @@ mod tests { #[test] fn ensure_rialto_message_lane_weights_are_correct() { - type Weights = pallet_bridge_messages::weights::MillauWeight; + type Weights = pallet_bridge_messages::weights::BridgeWeight; pallet_bridge_messages::ensure_weights_are_correct::( bp_rialto::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT, diff --git a/bin/runtime-common/Cargo.toml b/bin/runtime-common/Cargo.toml index bb75d828d28..3f717b05c6e 100644 --- a/bin/runtime-common/Cargo.toml +++ b/bin/runtime-common/Cargo.toml @@ -10,7 +10,6 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } hash-db = { version = "0.15.2", default-features = false } log = { version = "0.4.17", default-features = false } -num-traits = { version = "0.2", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } static_assertions = { version = "1.1", optional = true } @@ -29,15 +28,12 @@ pallet-bridge-parachains = { path = "../../modules/parachains", default-features frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } -pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } # Polkadot dependencies @@ -61,18 +57,15 @@ std = [ "frame-system/std", "hash-db/std", "log/std", - "num-traits/std", "pallet-bridge-grandpa/std", "pallet-bridge-messages/std", "pallet-bridge-parachains/std", - "pallet-transaction-payment/std", "pallet-xcm/std", "scale-info/std", "sp-api/std", "sp-core/std", "sp-io/std", "sp-runtime/std", - "sp-state-machine/std", "sp-std/std", "sp-trie/std", "xcm/std", @@ -83,8 +76,6 @@ runtime-benchmarks = [ "pallet-balances", "pallet-bridge-grandpa/runtime-benchmarks", "pallet-bridge-messages/runtime-benchmarks", - "sp-state-machine", - "sp-version", "xcm-builder/runtime-benchmarks", ] integrity-test = [ diff --git a/bin/runtime-common/src/messages.rs b/bin/runtime-common/src/messages.rs index a7ad19dc1f1..50944826dde 100644 --- a/bin/runtime-common/src/messages.rs +++ b/bin/runtime-common/src/messages.rs @@ -315,7 +315,6 @@ pub mod source { impl LaneMessageVerifier< OriginOf>, - AccountIdOf>, FromThisChainMessagePayload, BalanceOf>, > for FromThisChainMessageVerifier diff --git a/deployments/bridges/rialto-parachain-millau/entrypoints/relay-millau-rialto-parachain-entrypoint.sh b/deployments/bridges/rialto-parachain-millau/entrypoints/relay-millau-rialto-parachain-entrypoint.sh index f2732e82f49..7ef933eef49 100755 --- a/deployments/bridges/rialto-parachain-millau/entrypoints/relay-millau-rialto-parachain-entrypoint.sh +++ b/deployments/bridges/rialto-parachain-millau/entrypoints/relay-millau-rialto-parachain-entrypoint.sh @@ -38,5 +38,6 @@ sleep 6 --rialto-parachain-transactions-mortality=64 \ --rialto-host rialto-node-alice \ --rialto-port 9944 \ + --relayer-mode=altruistic \ --lane=00000000 \ --prometheus-host=0.0.0.0 diff --git a/modules/grandpa/Cargo.toml b/modules/grandpa/Cargo.toml index 55022d7e5c4..45f314a0bbd 100644 --- a/modules/grandpa/Cargo.toml +++ b/modules/grandpa/Cargo.toml @@ -11,9 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } finality-grandpa = { version = "0.16.0", default-features = false } log = { version = "0.4.17", default-features = false } -num-traits = { version = "0.2", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0", optional = true } # Bridge Dependencies @@ -47,10 +45,9 @@ std = [ "finality-grandpa/std", "frame-support/std", "frame-system/std", + "frame-benchmarking/std", "log/std", - "num-traits/std", "scale-info/std", - "serde", "sp-finality-grandpa/std", "sp-runtime/std", "sp-std/std", diff --git a/modules/grandpa/src/weights.rs b/modules/grandpa/src/weights.rs index f23a2ac1903..ece88ab55c5 100644 --- a/modules/grandpa/src/weights.rs +++ b/modules/grandpa/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for `pallet_bridge_grandpa` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-07-06, STEPS: 50, REPEAT: 20 +//! DATE: 2022-10-04, STEPS: 50, REPEAT: 20 //! LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled //! CHAIN: Some("dev"), DB CACHE: 1024 @@ -53,13 +53,15 @@ pub trait WeightInfo { fn submit_finality_proof(p: u32, v: u32) -> Weight; } -/// Weights for `pallet_bridge_grandpa` using the Millau node and recommended hardware. -pub struct MillauWeight(PhantomData); -impl WeightInfo for MillauWeight { +/// Weights for `pallet_bridge_grandpa` that are generated using one of the Bridge testnets. +/// +/// Those weights are test only and must never be used in production. +pub struct BridgeWeight(PhantomData); +impl WeightInfo for BridgeWeight { fn submit_finality_proof(p: u32, v: u32) -> Weight { - (55_070_000 as Weight) - .saturating_add((39_678_000 as Weight).saturating_mul(p as Weight)) - .saturating_add((1_540_000 as Weight).saturating_mul(v as Weight)) + (105_417_000 as Weight) + .saturating_add((40_923_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((1_691_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } @@ -68,9 +70,9 @@ impl WeightInfo for MillauWeight { // For backwards compatibility and tests impl WeightInfo for () { fn submit_finality_proof(p: u32, v: u32) -> Weight { - (55_070_000 as Weight) - .saturating_add((39_678_000 as Weight).saturating_mul(p as Weight)) - .saturating_add((1_540_000 as Weight).saturating_mul(v as Weight)) + (105_417_000 as Weight) + .saturating_add((40_923_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((1_691_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } diff --git a/modules/messages/Cargo.toml b/modules/messages/Cargo.toml index 78a70b9bd58..f8ff74cdd55 100644 --- a/modules/messages/Cargo.toml +++ b/modules/messages/Cargo.toml @@ -12,7 +12,6 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features = log = { version = "0.4.17", default-features = false } num-traits = { version = "0.2", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0.101", optional = true, features = ["derive"] } # Bridge dependencies @@ -41,10 +40,10 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "frame-benchmarking/std", "log/std", "num-traits/std", "scale-info/std", - "serde", "sp-core/std", "sp-runtime/std", "sp-std/std", diff --git a/modules/messages/src/lib.rs b/modules/messages/src/lib.rs index c2e4dce9b2d..0580a0ffdfa 100644 --- a/modules/messages/src/lib.rs +++ b/modules/messages/src/lib.rs @@ -175,7 +175,6 @@ pub mod pallet { /// Message payload verifier. type LaneMessageVerifier: LaneMessageVerifier< Self::Origin, - Self::AccountId, Self::OutboundPayload, Self::OutboundMessageFee, >; diff --git a/modules/messages/src/mock.rs b/modules/messages/src/mock.rs index 9584d17b836..41ae0352cfb 100644 --- a/modules/messages/src/mock.rs +++ b/modules/messages/src/mock.rs @@ -298,9 +298,7 @@ impl TargetHeaderChain for TestTargetHeaderChain { #[derive(Debug, Default)] pub struct TestLaneMessageVerifier; -impl LaneMessageVerifier - for TestLaneMessageVerifier -{ +impl LaneMessageVerifier for TestLaneMessageVerifier { type Error = &'static str; fn verify_message( diff --git a/modules/messages/src/weights.rs b/modules/messages/src/weights.rs index 3f9ea8bbb16..02b014120f1 100644 --- a/modules/messages/src/weights.rs +++ b/modules/messages/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for `pallet_bridge_messages` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-07-20, STEPS: 50, REPEAT: 20 +//! DATE: 2022-10-04, STEPS: 50, REPEAT: 20 //! LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled //! CHAIN: Some("dev"), DB CACHE: 1024 @@ -66,26 +66,28 @@ pub trait WeightInfo { fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight; } -/// Weights for `pallet_bridge_messages` using the Millau node and recommended hardware. -pub struct MillauWeight(PhantomData); -impl WeightInfo for MillauWeight { +/// Weights for `pallet_bridge_messages` that are generated using one of the Bridge testnets. +/// +/// Those weights are test only and must never be used in production. +pub struct BridgeWeight(PhantomData); +impl WeightInfo for BridgeWeight { fn send_minimal_message_worst_case() -> Weight { - (38_822_000 as Weight) + (62_300_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(10 as Weight)) } fn send_1_kb_message_worst_case() -> Weight { - (39_799_000 as Weight) + (63_176_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(10 as Weight)) } fn send_16_kb_message_worst_case() -> Weight { - (47_772_000 as Weight) + (73_472_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(10 as Weight)) } fn maximal_increase_message_fee() -> Weight { - (3_081_804_000 as Weight) + (2_539_209_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -96,47 +98,47 @@ impl WeightInfo for MillauWeight { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof() -> Weight { - (26_523_000 as Weight) + (49_205_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn receive_two_messages_proof() -> Weight { - (39_278_000 as Weight) + (62_182_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn receive_single_message_proof_with_outbound_lane_state() -> Weight { - (32_416_000 as Weight) + (55_928_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn receive_single_message_proof_1_kb() -> Weight { - (27_078_000 as Weight) + (47_298_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_16_kb() -> Weight { - (78_235_000 as Weight) + (105_016_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_single_prepaid_message_proof() -> Weight { - (27_635_000 as Weight) + (49_067_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn receive_delivery_proof_for_single_message() -> Weight { - (34_576_000 as Weight) + (58_520_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { - (37_318_000 as Weight) + (61_563_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { - (41_245_000 as Weight) + (63_197_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -145,22 +147,22 @@ impl WeightInfo for MillauWeight { // For backwards compatibility and tests impl WeightInfo for () { fn send_minimal_message_worst_case() -> Weight { - (38_822_000 as Weight) + (62_300_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } fn send_1_kb_message_worst_case() -> Weight { - (39_799_000 as Weight) + (63_176_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } fn send_16_kb_message_worst_case() -> Weight { - (47_772_000 as Weight) + (73_472_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(10 as Weight)) } fn maximal_increase_message_fee() -> Weight { - (3_081_804_000 as Weight) + (2_539_209_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -171,47 +173,47 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof() -> Weight { - (26_523_000 as Weight) + (49_205_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn receive_two_messages_proof() -> Weight { - (39_278_000 as Weight) + (62_182_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn receive_single_message_proof_with_outbound_lane_state() -> Weight { - (32_416_000 as Weight) + (55_928_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn receive_single_message_proof_1_kb() -> Weight { - (27_078_000 as Weight) + (47_298_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_16_kb() -> Weight { - (78_235_000 as Weight) + (105_016_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_single_prepaid_message_proof() -> Weight { - (27_635_000 as Weight) + (49_067_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn receive_delivery_proof_for_single_message() -> Weight { - (34_576_000 as Weight) + (58_520_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { - (37_318_000 as Weight) + (61_563_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { - (41_245_000 as Weight) + (63_197_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } diff --git a/modules/messages/src/weights_ext.rs b/modules/messages/src/weights_ext.rs index 3c5a24788ec..52eb4261905 100644 --- a/modules/messages/src/weights_ext.rs +++ b/modules/messages/src/weights_ext.rs @@ -392,7 +392,7 @@ impl WeightInfoExt for () { } } -impl WeightInfoExt for crate::weights::MillauWeight { +impl WeightInfoExt for crate::weights::BridgeWeight { fn expected_extra_storage_proof_size() -> u32 { EXTRA_STORAGE_PROOF_SIZE } diff --git a/modules/parachains/Cargo.toml b/modules/parachains/Cargo.toml index 99e91180b38..bccd16f3d59 100644 --- a/modules/parachains/Cargo.toml +++ b/modules/parachains/Cargo.toml @@ -9,7 +9,6 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0.101", optional = true } # Bridge Dependencies @@ -23,7 +22,6 @@ pallet-bridge-grandpa = { path = "../grandpa", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -42,11 +40,10 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", + "frame-benchmarking/std", "log/std", "pallet-bridge-grandpa/std", "scale-info/std", - "serde", - "sp-core/std", "sp-runtime/std", "sp-std/std", "sp-trie/std", diff --git a/modules/parachains/src/weights.rs b/modules/parachains/src/weights.rs index b96e24752d5..1ab2e6c5548 100644 --- a/modules/parachains/src/weights.rs +++ b/modules/parachains/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for `pallet_bridge_parachains` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-07-06, STEPS: 50, REPEAT: 20 +//! DATE: 2022-10-04, STEPS: 50, REPEAT: 20 //! LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled //! CHAIN: Some("dev"), DB CACHE: 1024 @@ -55,23 +55,25 @@ pub trait WeightInfo { fn submit_parachain_heads_with_16kb_proof() -> Weight; } -/// Weights for `pallet_bridge_parachains` using the Millau node and recommended hardware. -pub struct MillauWeight(PhantomData); -impl WeightInfo for MillauWeight { +/// Weights for `pallet_bridge_parachains` that are generated using one of the Bridge testnets. +/// +/// Those weights are test only and must never be used in production. +pub struct BridgeWeight(PhantomData); +impl WeightInfo for BridgeWeight { fn submit_parachain_heads_with_n_parachains(p: u32) -> Weight { (0 as Weight) - .saturating_add((18_706_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((24_869_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(p as Weight))) .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(p as Weight))) } fn submit_parachain_heads_with_1kb_proof() -> Weight { - (27_549_000 as Weight) + (56_262_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn submit_parachain_heads_with_16kb_proof() -> Weight { - (80_792_000 as Weight) + (105_189_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -81,18 +83,18 @@ impl WeightInfo for MillauWeight { impl WeightInfo for () { fn submit_parachain_heads_with_n_parachains(p: u32) -> Weight { (0 as Weight) - .saturating_add((18_706_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((24_869_000 as Weight).saturating_mul(p as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(p as Weight))) .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(p as Weight))) } fn submit_parachain_heads_with_1kb_proof() -> Weight { - (27_549_000 as Weight) + (56_262_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn submit_parachain_heads_with_16kb_proof() -> Weight { - (80_792_000 as Weight) + (105_189_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } diff --git a/modules/parachains/src/weights_ext.rs b/modules/parachains/src/weights_ext.rs index 98655a6ea47..63684ecc215 100644 --- a/modules/parachains/src/weights_ext.rs +++ b/modules/parachains/src/weights_ext.rs @@ -16,7 +16,7 @@ //! Weight-related utilities. -use crate::weights::{MillauWeight, WeightInfo}; +use crate::weights::{BridgeWeight, WeightInfo}; use bp_runtime::Size; use frame_support::weights::{RuntimeDbWeight, Weight}; @@ -101,7 +101,7 @@ impl WeightInfoExt for () { } } -impl WeightInfoExt for MillauWeight { +impl WeightInfoExt for BridgeWeight { fn expected_extra_storage_proof_size() -> u32 { EXTRA_STORAGE_PROOF_SIZE } diff --git a/modules/relayers/Cargo.toml b/modules/relayers/Cargo.toml index 70720a211ce..00d1bb59120 100644 --- a/modules/relayers/Cargo.toml +++ b/modules/relayers/Cargo.toml @@ -9,9 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } log = { version = "0.4.17", default-features = false } -num-traits = { version = "0.2", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0.101", optional = true, features = ["derive"] } # Bridge dependencies @@ -43,10 +41,8 @@ std = [ "frame-support/std", "frame-system/std", "log/std", - "num-traits/std", "pallet-bridge-messages/std", "scale-info/std", - "serde", "sp-arithmetic/std", "sp-std/std", ] diff --git a/modules/relayers/src/weights.rs b/modules/relayers/src/weights.rs index fd7efe940d4..afecbe9d6d7 100644 --- a/modules/relayers/src/weights.rs +++ b/modules/relayers/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for `pallet_bridge_relayers` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-07-20, STEPS: 50, REPEAT: 20 +//! DATE: 2022-10-04, STEPS: 50, REPEAT: 20 //! LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled //! CHAIN: Some("dev"), DB CACHE: 1024 @@ -53,11 +53,13 @@ pub trait WeightInfo { fn claim_rewards() -> Weight; } -/// Weights for `pallet_bridge_relayers` using the Millau node and recommended hardware. -pub struct MillauWeight(PhantomData); -impl WeightInfo for MillauWeight { +/// Weights for `pallet_bridge_relayers` that are generated using one of the Bridge testnets. +/// +/// Those weights are test only and must never be used in production. +pub struct BridgeWeight(PhantomData); +impl WeightInfo for BridgeWeight { fn claim_rewards() -> Weight { - (38_435_000 as Weight) + (55_856_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -66,7 +68,7 @@ impl WeightInfo for MillauWeight { // For backwards compatibility and tests impl WeightInfo for () { fn claim_rewards() -> Weight { - (38_435_000 as Weight) + (55_856_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } diff --git a/primitives/chain-bridge-hub-rococo/src/lib.rs b/primitives/chain-bridge-hub-rococo/src/lib.rs index b991404d2ea..8043c270d77 100644 --- a/primitives/chain-bridge-hub-rococo/src/lib.rs +++ b/primitives/chain-bridge-hub-rococo/src/lib.rs @@ -17,6 +17,8 @@ //! Module with configuration which reflects BridgeHubRococo runtime setup (AccountId, Headers, //! Hashes...) +#![cfg_attr(not(feature = "std"), no_std)] + pub use bp_polkadot_core::*; use bp_runtime::decl_bridge_finality_runtime_apis; use frame_support::{parameter_types, sp_runtime::MultiAddress}; @@ -27,6 +29,9 @@ pub type WeightToFee = frame_support::weights::IdentityFee; /// The address format for describing accounts. pub type Address = MultiAddress; +/// Identifier of BridgeHubRococo in the Rococo relay chain. +pub const BRIDGE_HUB_ROCOCO_PARACHAIN_ID: u32 = 1013; + parameter_types! { pub const SS58Prefix: u16 = 42; } diff --git a/primitives/chain-bridge-hub-wococo/Cargo.toml b/primitives/chain-bridge-hub-wococo/Cargo.toml index 01cb7e2af15..1cc1f0eebf5 100644 --- a/primitives/chain-bridge-hub-wococo/Cargo.toml +++ b/primitives/chain-bridge-hub-wococo/Cargo.toml @@ -10,7 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies -bp-bridge-hub-rococo = { path = "../chain-bridge-hub-rococo" } +bp-bridge-hub-rococo = { path = "../chain-bridge-hub-rococo", default-features = false } bp-runtime = { path = "../../primitives/runtime", default-features = false } # Substrate Based Dependencies @@ -20,5 +20,7 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d [features] default = ["std"] std = [ + "bp-runtime/std", + "sp-api/std", "bp-bridge-hub-rococo/std", ] diff --git a/primitives/chain-bridge-hub-wococo/src/lib.rs b/primitives/chain-bridge-hub-wococo/src/lib.rs index 044c2a93740..40c5b6cfc8d 100644 --- a/primitives/chain-bridge-hub-wococo/src/lib.rs +++ b/primitives/chain-bridge-hub-wococo/src/lib.rs @@ -20,14 +20,20 @@ //! but actually this is just reexported BridgeHubRococo stuff, because they are supposed to be //! identical, at least uses the same parachain runtime +#![cfg_attr(not(feature = "std"), no_std)] + // Re-export only what is really needed pub use bp_bridge_hub_rococo::{ account_info_storage_key, AccountId, AccountPublic, Address, Balance, BlockNumber, Hash, Hashing, Header, Nonce, SS58Prefix, Signature, SignedBlock, SignedExtensions, UncheckedExtrinsic, WeightToFee, EXTRA_STORAGE_PROOF_SIZE, + MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, }; use bp_runtime::decl_bridge_finality_runtime_apis; pub type BridgeHubWococo = bp_bridge_hub_rococo::BridgeHubRococo; +/// Identifier of BridgeHubWococo in the Wococo relay chain. +pub const BRIDGE_HUB_WOCOCO_PARACHAIN_ID: u32 = 1013; + decl_bridge_finality_runtime_apis!(wococo); diff --git a/primitives/chain-kusama/Cargo.toml b/primitives/chain-kusama/Cargo.toml index a676b565c33..3bca5f4c3f0 100644 --- a/primitives/chain-kusama/Cargo.toml +++ b/primitives/chain-kusama/Cargo.toml @@ -7,31 +7,20 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -smallvec = "1.7" # Bridge Dependencies -bp-messages = { path = "../messages", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ - "bp-messages/std", "bp-polkadot-core/std", "bp-runtime/std", - "frame-support/std", "sp-api/std", - "sp-runtime/std", - "sp-std/std", - "sp-version/std", ] diff --git a/primitives/chain-kusama/src/lib.rs b/primitives/chain-kusama/src/lib.rs index 0b218b22250..7837afe690e 100644 --- a/primitives/chain-kusama/src/lib.rs +++ b/primitives/chain-kusama/src/lib.rs @@ -18,58 +18,12 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{ - InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails, -}; -use frame_support::weights::{ - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; - pub use bp_polkadot_core::*; -use bp_runtime::decl_bridge_runtime_apis; +use bp_runtime::decl_bridge_finality_runtime_apis; /// Kusama Chain pub type Kusama = PolkadotLike; -// NOTE: This needs to be kept up to date with the Kusama runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("kusama"), - impl_name: sp_version::create_runtime_str!("parity-kusama"), - authoring_version: 2, - spec_version: 9180, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 11, - state_version: 0, -}; - -// NOTE: This needs to be kept up to date with the Kusama runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 1_000_000_000_000 / 30_000; - // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - -/// Per-byte fee for Kusama transactions. -pub const TRANSACTION_BYTE_FEE: Balance = 10 * 1_000_000_000_000 / 30_000 / 1_000; - -/// Existential deposit on Kusama. -pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 30_000; - /// The target length of a session (how often authorities change) on Kusama measured in of number of /// blocks. /// @@ -79,16 +33,5 @@ pub const SESSION_LENGTH: BlockNumber = time_units::HOURS; /// Name of the With-Kusama GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_KUSAMA_GRANDPA_PALLET_NAME: &str = "BridgeKusamaGrandpa"; -/// Name of the With-Kusama messages pallet instance that is deployed at bridged chains. -pub const WITH_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessages"; - -/// Name of the transaction payment pallet at the Kusama runtime. -pub const TRANSACTION_PAYMENT_PALLET_NAME: &str = "TransactionPayment"; - -/// Name of the DOT->KSM conversion rate stored in the Kusama runtime. -pub const POLKADOT_TO_KUSAMA_CONVERSION_RATE_PARAMETER_NAME: &str = - "PolkadotToKusamaConversionRate"; -/// Name of the Polkadot fee multiplier parameter, stored in the Polkadot runtime. -pub const POLKADOT_FEE_MULTIPLIER_PARAMETER_NAME: &str = "PolkadotFeeMultiplier"; -decl_bridge_runtime_apis!(kusama); +decl_bridge_finality_runtime_apis!(kusama); diff --git a/primitives/chain-polkadot/Cargo.toml b/primitives/chain-polkadot/Cargo.toml index 738899b658c..8be9b25c77f 100644 --- a/primitives/chain-polkadot/Cargo.toml +++ b/primitives/chain-polkadot/Cargo.toml @@ -11,27 +11,17 @@ smallvec = "1.7" # Bridge Dependencies -bp-messages = { path = "../messages", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ - "bp-messages/std", "bp-polkadot-core/std", "bp-runtime/std", - "frame-support/std", "sp-api/std", - "sp-runtime/std", - "sp-std/std", - "sp-version/std", ] diff --git a/primitives/chain-polkadot/src/lib.rs b/primitives/chain-polkadot/src/lib.rs index 6f584f5526a..cfcbacb0d1a 100644 --- a/primitives/chain-polkadot/src/lib.rs +++ b/primitives/chain-polkadot/src/lib.rs @@ -18,58 +18,12 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{ - InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails, -}; -use frame_support::weights::{ - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; - pub use bp_polkadot_core::*; -use bp_runtime::decl_bridge_runtime_apis; +use bp_runtime::decl_bridge_finality_runtime_apis; /// Polkadot Chain pub type Polkadot = PolkadotLike; -// NOTE: This needs to be kept up to date with the Polkadot runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("polkadot"), - impl_name: sp_version::create_runtime_str!("parity-polkadot"), - authoring_version: 0, - spec_version: 9180, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 12, - state_version: 0, -}; - -// NOTE: This needs to be kept up to date with the Polkadot runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 10_000_000_000 / 100; - // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - -/// Per-byte fee for Polkadot transactions. -pub const TRANSACTION_BYTE_FEE: Balance = 10 * 10_000_000_000 / 100 / 1_000; - -/// Existential deposit on Polkadot. -pub const EXISTENTIAL_DEPOSIT: Balance = 10_000_000_000; - /// The target length of a session (how often authorities change) on Polkadot measured in of number /// of blocks. /// @@ -79,16 +33,5 @@ pub const SESSION_LENGTH: BlockNumber = 4 * time_units::HOURS; /// Name of the With-Polkadot GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_POLKADOT_GRANDPA_PALLET_NAME: &str = "BridgePolkadotGrandpa"; -/// Name of the With-Polkadot messages pallet instance that is deployed at bridged chains. -pub const WITH_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotMessages"; - -/// Name of the transaction payment pallet at the Polkadot runtime. -pub const TRANSACTION_PAYMENT_PALLET_NAME: &str = "TransactionPayment"; - -/// Name of the KSM->DOT conversion rate parameter, stored in the Polkadot runtime. -pub const KUSAMA_TO_POLKADOT_CONVERSION_RATE_PARAMETER_NAME: &str = - "KusamaToPolkadotConversionRate"; -/// Name of the Kusama fee multiplier parameter, stored in the Polkadot runtime. -pub const KUSAMA_FEE_MULTIPLIER_PARAMETER_NAME: &str = "KusamaFeeMultiplier"; -decl_bridge_runtime_apis!(polkadot); +decl_bridge_finality_runtime_apis!(polkadot); diff --git a/primitives/chain-rococo/Cargo.toml b/primitives/chain-rococo/Cargo.toml index fe6b07eeb76..73a2450cd17 100644 --- a/primitives/chain-rococo/Cargo.toml +++ b/primitives/chain-rococo/Cargo.toml @@ -7,31 +7,20 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -smallvec = "1.7" # Bridge Dependencies -bp-messages = { path = "../messages", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ - "bp-messages/std", "bp-polkadot-core/std", "bp-runtime/std", - "frame-support/std", - "codec/std", "sp-api/std", - "sp-runtime/std", - "sp-std/std", - "sp-version/std", + "frame-support/std", ] diff --git a/primitives/chain-rococo/src/lib.rs b/primitives/chain-rococo/src/lib.rs index f9bd0323891..3738a3ba269 100644 --- a/primitives/chain-rococo/src/lib.rs +++ b/primitives/chain-rococo/src/lib.rs @@ -18,82 +18,28 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{ - InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails, -}; -use frame_support::{ - parameter_types, - weights::{Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial}, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; - pub use bp_polkadot_core::*; -use bp_runtime::decl_bridge_runtime_apis; +use bp_runtime::decl_bridge_finality_runtime_apis; +use frame_support::parameter_types; /// Rococo Chain pub type Rococo = PolkadotLike; +parameter_types! { + pub const SS58Prefix: u8 = 42; +} + /// The target length of a session (how often authorities change) on Rococo measured in of number /// of blocks. /// /// Note that since this is a target sessions may change before/after this time depending on network /// conditions. -pub const SESSION_LENGTH: BlockNumber = time_units::HOURS; - -parameter_types! { - pub const SS58Prefix: u8 = 42; -} - -// TODO:check-parameter - update? -// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("rococo"), - impl_name: sp_version::create_runtime_str!("parity-rococo-v2.0"), - authoring_version: 0, - spec_version: 9200, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 0, - state_version: 0, -}; +pub const SESSION_LENGTH: BlockNumber = HOURS; -// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 1_000_000_000_000 / 100; - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} +/// Name of the parachains pallet in the Rococo runtime. +pub const PARAS_PALLET_NAME: &str = "Paras"; /// Name of the With-Rococo GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_ROCOCO_GRANDPA_PALLET_NAME: &str = "BridgeRococoGrandpa"; -/// Name of the With-Rococo messages pallet instance that is deployed at bridged chains. -pub const WITH_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages"; - -/// Existential deposit on Rococo. -pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100; - -/// Weight of pay-dispatch-fee operation for inbound messages at Rococo chain. -/// -/// This value corresponds to the result of -/// `pallet_bridge_messages::WeightInfoExt::pay_inbound_dispatch_fee_overhead()` call for your -/// chain. Don't put too much reserve there, because it is used to **decrease** -/// `DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT` cost. So putting large reserve would make delivery -/// transactions cheaper. -pub const PAY_INBOUND_DISPATCH_FEE_WEIGHT: Weight = 600_000_000; - -/// Name of the parachains pallet in the Rococo runtime. -pub const PARAS_PALLET_NAME: &str = "Paras"; -decl_bridge_runtime_apis!(rococo); +decl_bridge_finality_runtime_apis!(rococo); diff --git a/primitives/chain-westend/Cargo.toml b/primitives/chain-westend/Cargo.toml index f37aa3b0e39..e5f7bf89565 100644 --- a/primitives/chain-westend/Cargo.toml +++ b/primitives/chain-westend/Cargo.toml @@ -9,33 +9,24 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -smallvec = "1.7" # Bridge Dependencies -bp-header-chain = { path = "../header-chain", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ - "bp-header-chain/std", "bp-polkadot-core/std", "bp-runtime/std", - "frame-support/std", "codec/std", "scale-info/std", "sp-api/std", "sp-runtime/std", - "sp-std/std", - "sp-version/std", ] diff --git a/primitives/chain-westend/src/lib.rs b/primitives/chain-westend/src/lib.rs index 1e023295a8a..08803b7a3dd 100644 --- a/primitives/chain-westend/src/lib.rs +++ b/primitives/chain-westend/src/lib.rs @@ -18,12 +18,7 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use frame_support::weights::{ - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, -}; use scale_info::TypeInfo; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; pub use bp_polkadot_core::*; use bp_runtime::decl_bridge_finality_runtime_apis; @@ -31,36 +26,6 @@ use bp_runtime::decl_bridge_finality_runtime_apis; /// Westend Chain pub type Westend = PolkadotLike; -// NOTE: This needs to be kept up to date with the Westend runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 1_000_000_000_000 / 1_000; - // in Westend, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - -// NOTE: This needs to be kept up to date with the Westend runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("westend"), - impl_name: sp_version::create_runtime_str!("parity-westend"), - authoring_version: 2, - spec_version: 9140, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 8, - state_version: 0, -}; - /// Westend Runtime `Call` enum. /// /// We are not currently submitting any Westend transactions => it is empty. diff --git a/primitives/chain-wococo/Cargo.toml b/primitives/chain-wococo/Cargo.toml index 92e7c9e80e2..6b741cd4b73 100644 --- a/primitives/chain-wococo/Cargo.toml +++ b/primitives/chain-wococo/Cargo.toml @@ -7,28 +7,20 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } # Bridge Dependencies -bp-messages = { path = "../messages", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } -bp-rococo = { path = "../chain-rococo", default-features = false } bp-runtime = { path = "../runtime", default-features = false } +bp-rococo = { path = "../chain-rococo", default-features = false } # Substrate Based Dependencies sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ - "bp-messages/std", "bp-polkadot-core/std", "bp-runtime/std", "bp-rococo/std", - "codec/std", "sp-api/std", - "sp-runtime/std", - "sp-std/std", ] diff --git a/primitives/chain-wococo/src/lib.rs b/primitives/chain-wococo/src/lib.rs index a33c30115c0..4a39d732cd5 100644 --- a/primitives/chain-wococo/src/lib.rs +++ b/primitives/chain-wococo/src/lib.rs @@ -18,19 +18,9 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{ - InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; - pub use bp_polkadot_core::*; -// Rococo runtime = Wococo runtime -pub use bp_rococo::{ - SS58Prefix, WeightToFee, EXISTENTIAL_DEPOSIT, PARAS_PALLET_NAME, - PAY_INBOUND_DISPATCH_FEE_WEIGHT, VERSION, -}; -use bp_runtime::decl_bridge_runtime_apis; +pub use bp_rococo::{SS58Prefix, PARAS_PALLET_NAME}; +use bp_runtime::decl_bridge_finality_runtime_apis; /// Wococo Chain pub type Wococo = PolkadotLike; @@ -40,11 +30,9 @@ pub type Wococo = PolkadotLike; /// /// Note that since this is a target sessions may change before/after this time depending on network /// conditions. -pub const SESSION_LENGTH: BlockNumber = time_units::MINUTES; +pub const SESSION_LENGTH: BlockNumber = MINUTES; /// Name of the With-Wococo GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_WOCOCO_GRANDPA_PALLET_NAME: &str = "BridgeWococoGrandpa"; -/// Name of the With-Wococo messages pallet instance that is deployed at bridged chains. -pub const WITH_WOCOCO_MESSAGES_PALLET_NAME: &str = "BridgeWococoMessages"; -decl_bridge_runtime_apis!(wococo); +decl_bridge_finality_runtime_apis!(wococo); diff --git a/primitives/messages/Cargo.toml b/primitives/messages/Cargo.toml index 6690a1bfbb0..736764ef20f 100644 --- a/primitives/messages/Cargo.toml +++ b/primitives/messages/Cargo.toml @@ -20,7 +20,6 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Dependencies frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -35,7 +34,6 @@ std = [ "bp-runtime/std", "codec/std", "frame-support/std", - "frame-system/std", "scale-info/std", "serde", "sp-core/std", diff --git a/primitives/messages/src/source_chain.rs b/primitives/messages/src/source_chain.rs index be56ffe87fb..5c6283a8036 100644 --- a/primitives/messages/src/source_chain.rs +++ b/primitives/messages/src/source_chain.rs @@ -61,6 +61,10 @@ pub struct RelayerRewards { /// All implementations of this trait should only work with finalized data that /// can't change. Wrong implementation may lead to invalid lane states (i.e. lane /// that's stuck) and/or processing messages without paying fees. +/// +/// The `Payload` type here means the payload of the message that is sent from the +/// source chain to the target chain. The `AccountId` type here means the account +/// type used by the source chain. pub trait TargetHeaderChain { /// Error type. type Error: Debug + Into<&'static str>; @@ -96,7 +100,7 @@ pub trait TargetHeaderChain { /// Lane3 until some block, ...), then it may be built using this verifier. /// /// Any fee requirements should also be enforced here. -pub trait LaneMessageVerifier { +pub trait LaneMessageVerifier { /// Error type. type Error: Debug + Into<&'static str>; @@ -278,8 +282,8 @@ impl TargetHeaderChain for ForbidOutboun } } -impl - LaneMessageVerifier for ForbidOutboundMessages +impl LaneMessageVerifier + for ForbidOutboundMessages { type Error = &'static str; diff --git a/primitives/parachains/Cargo.toml b/primitives/parachains/Cargo.toml index f6327c772c0..0aa2adfead1 100644 --- a/primitives/parachains/Cargo.toml +++ b/primitives/parachains/Cargo.toml @@ -9,7 +9,6 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0", optional = true, features = ["derive"] } # Bridge dependencies @@ -29,6 +28,5 @@ std = [ "codec/std", "frame-support/std", "scale-info/std", - "serde", "sp-core/std", ] diff --git a/primitives/polkadot-core/Cargo.toml b/primitives/polkadot-core/Cargo.toml index 4448e75f11a..9a68e8ccc2d 100644 --- a/primitives/polkadot-core/Cargo.toml +++ b/primitives/polkadot-core/Cargo.toml @@ -21,11 +21,9 @@ bp-runtime = { path = "../runtime", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [dev-dependencies] hex = "0.4" @@ -41,9 +39,7 @@ std = [ "parity-util-mem", "scale-info/std", "serde", - "sp-api/std", "sp-core/std", "sp-runtime/std", "sp-std/std", - "sp-version/std", ] diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index d775e09c47a..fdbadd94a8d 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -76,6 +76,12 @@ pub const ROCOCO_CHAIN_ID: ChainId = *b"roco"; /// Bridge-with-Wococo instance id. pub const WOCOCO_CHAIN_ID: ChainId = *b"woco"; +/// Bridge-with-BridgeHubRococo instance id. +pub const BRIDGE_HUB_ROCOCO_CHAIN_ID: ChainId = *b"bhro"; + +/// Bridge-with-BridgeHubWococo instance id. +pub const BRIDGE_HUB_WOCOCO_CHAIN_ID: ChainId = *b"bhwo"; + /// Call-dispatch module prefix. pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/dispatch"; diff --git a/relays/bin-substrate/Cargo.toml b/relays/bin-substrate/Cargo.toml index 7c8351060ab..38d3a7ad3fb 100644 --- a/relays/bin-substrate/Cargo.toml +++ b/relays/bin-substrate/Cargo.toml @@ -15,16 +15,16 @@ hex = "0.4" log = "0.4.17" num-format = "0.4" num-traits = "0.2" -rand = "0.8" structopt = "0.3" strum = { version = "0.21.0", features = ["derive"] } # Bridge dependencies +bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" } +bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" } bp-header-chain = { path = "../../primitives/header-chain" } bp-messages = { path = "../../primitives/messages" } bp-millau = { path = "../../primitives/chain-millau" } -bp-parachains = { path = "../../primitives/parachains" } bp-polkadot-core = { path = "../../primitives/polkadot-core" } bp-rialto = { path = "../../primitives/chain-rialto" } bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" } @@ -33,7 +33,6 @@ bp-runtime = { path = "../../primitives/runtime" } bp-westend = { path = "../../primitives/chain-westend" } bp-wococo = { path = "../../primitives/chain-wococo" } bridge-runtime-common = { path = "../../bin/runtime-common" } -finality-relay = { path = "../finality" } messages-relay = { path = "../messages" } millau-runtime = { path = "../../bin/millau/runtime" } pallet-bridge-messages = { path = "../../modules/messages" } @@ -56,9 +55,7 @@ substrate-relay-helper = { path = "../lib-substrate-relay" } # Substrate Dependencies frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/relays/bin-substrate/src/chains/millau.rs b/relays/bin-substrate/src/chains/millau.rs index b71ecb288e9..59d53edf997 100644 --- a/relays/bin-substrate/src/chains/millau.rs +++ b/relays/bin-substrate/src/chains/millau.rs @@ -90,7 +90,7 @@ impl CliEncodeMessage for Millau { } impl CliChain for Millau { - const RUNTIME_VERSION: RuntimeVersion = millau_runtime::VERSION; + const RUNTIME_VERSION: Option = Some(millau_runtime::VERSION); type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; diff --git a/relays/bin-substrate/src/chains/rialto.rs b/relays/bin-substrate/src/chains/rialto.rs index 9dd86c9d953..285476a3312 100644 --- a/relays/bin-substrate/src/chains/rialto.rs +++ b/relays/bin-substrate/src/chains/rialto.rs @@ -73,7 +73,7 @@ impl CliEncodeMessage for Rialto { } impl CliChain for Rialto { - const RUNTIME_VERSION: RuntimeVersion = rialto_runtime::VERSION; + const RUNTIME_VERSION: Option = Some(rialto_runtime::VERSION); type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; diff --git a/relays/bin-substrate/src/chains/rialto_parachain.rs b/relays/bin-substrate/src/chains/rialto_parachain.rs index 8cd7135c27a..c359c42087d 100644 --- a/relays/bin-substrate/src/chains/rialto_parachain.rs +++ b/relays/bin-substrate/src/chains/rialto_parachain.rs @@ -74,7 +74,7 @@ impl CliEncodeMessage for RialtoParachain { } impl CliChain for RialtoParachain { - const RUNTIME_VERSION: RuntimeVersion = rialto_parachain_runtime::VERSION; + const RUNTIME_VERSION: Option = Some(rialto_parachain_runtime::VERSION); type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; diff --git a/relays/bin-substrate/src/chains/rococo.rs b/relays/bin-substrate/src/chains/rococo.rs index fb4336de8af..b5d77c1e9ae 100644 --- a/relays/bin-substrate/src/chains/rococo.rs +++ b/relays/bin-substrate/src/chains/rococo.rs @@ -22,7 +22,7 @@ use relay_rococo_client::Rococo; use sp_version::RuntimeVersion; impl CliChain for Rococo { - const RUNTIME_VERSION: RuntimeVersion = bp_rococo::VERSION; + const RUNTIME_VERSION: Option = None; type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; @@ -33,7 +33,7 @@ impl CliChain for Rococo { } impl CliChain for BridgeHubRococo { - const RUNTIME_VERSION: RuntimeVersion = relay_bridge_hub_rococo_client::runtime::VERSION; + const RUNTIME_VERSION: Option = None; type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; diff --git a/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs b/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs index 9990aaf8aa7..54f27522670 100644 --- a/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs +++ b/relays/bin-substrate/src/chains/rococo_parachains_to_bridge_hub_wococo.rs @@ -41,7 +41,7 @@ impl SubstrateParachainsPipeline for BridgeHubRococoToBridgeHubWococo { type SubmitParachainHeadsCallBuilder = BridgeHubRococoToBridgeHubWococoCallBuilder; type TransactionSignScheme = relay_bridge_hub_wococo_client::BridgeHubWococo; - const SOURCE_PARACHAIN_PARA_ID: u32 = 1013; + const SOURCE_PARACHAIN_PARA_ID: u32 = bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID; } pub struct BridgeHubRococoToBridgeHubWococoCallBuilder; diff --git a/relays/bin-substrate/src/chains/westend.rs b/relays/bin-substrate/src/chains/westend.rs index 973288e5d96..8d43d6a5ab7 100644 --- a/relays/bin-substrate/src/chains/westend.rs +++ b/relays/bin-substrate/src/chains/westend.rs @@ -21,7 +21,7 @@ use relay_westend_client::{Westend, Westmint}; use sp_version::RuntimeVersion; impl CliChain for Westend { - const RUNTIME_VERSION: RuntimeVersion = bp_westend::VERSION; + const RUNTIME_VERSION: Option = None; type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; @@ -35,8 +35,7 @@ impl CliChain for Westend { } impl CliChain for Westmint { - // TODO:check-parameter - wrong VERSION, should be bp_westmint::VERSION - const RUNTIME_VERSION: RuntimeVersion = bp_westend::VERSION; + const RUNTIME_VERSION: Option = None; type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; diff --git a/relays/bin-substrate/src/chains/wococo.rs b/relays/bin-substrate/src/chains/wococo.rs index e9c198fb254..f0f37c37a6c 100644 --- a/relays/bin-substrate/src/chains/wococo.rs +++ b/relays/bin-substrate/src/chains/wococo.rs @@ -22,7 +22,7 @@ use relay_wococo_client::Wococo; use sp_version::RuntimeVersion; impl CliChain for Wococo { - const RUNTIME_VERSION: RuntimeVersion = bp_wococo::VERSION; + const RUNTIME_VERSION: Option = None; type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; @@ -33,7 +33,7 @@ impl CliChain for Wococo { } impl CliChain for BridgeHubWococo { - const RUNTIME_VERSION: RuntimeVersion = relay_bridge_hub_wococo_client::runtime::VERSION; + const RUNTIME_VERSION: Option = None; type KeyPair = sp_core::sr25519::Pair; type MessagePayload = Vec; diff --git a/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs b/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs index aa311ef2015..5874674e59f 100644 --- a/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs +++ b/relays/bin-substrate/src/chains/wococo_parachains_to_bridge_hub_rococo.rs @@ -41,7 +41,7 @@ impl SubstrateParachainsPipeline for BridgeHubWococoToBridgeHubRococo { type SubmitParachainHeadsCallBuilder = BridgeHubWococoToBridgeHubRococoCallBuilder; type TransactionSignScheme = relay_bridge_hub_rococo_client::BridgeHubRococo; - const SOURCE_PARACHAIN_PARA_ID: u32 = 1013; + const SOURCE_PARACHAIN_PARA_ID: u32 = bp_bridge_hub_wococo::BRIDGE_HUB_WOCOCO_PARACHAIN_ID; } pub struct BridgeHubWococoToBridgeHubRococoCallBuilder; diff --git a/relays/bin-substrate/src/cli/chain_schema.rs b/relays/bin-substrate/src/cli/chain_schema.rs index 0f108aed6de..8023fd9b0f7 100644 --- a/relays/bin-substrate/src/cli/chain_schema.rs +++ b/relays/bin-substrate/src/cli/chain_schema.rs @@ -115,7 +115,7 @@ macro_rules! declare_chain_connection_params_cli_schema { ) -> anyhow::Result> { let chain_runtime_version = self .[<$chain_prefix _runtime_version>] - .into_runtime_version(Some(Chain::RUNTIME_VERSION))?; + .into_runtime_version(Chain::RUNTIME_VERSION)?; Ok(relay_substrate_client::Client::new(relay_substrate_client::ConnectionParams { host: self.[<$chain_prefix _host>], port: self.[<$chain_prefix _port>], diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 44bfce9f384..42a073bd4f6 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -163,7 +163,9 @@ impl Balance { /// Used to abstract away CLI commands. pub trait CliChain: relay_substrate_client::Chain { /// Current version of the chain runtime, known to relay. - const RUNTIME_VERSION: sp_version::RuntimeVersion; + /// + /// can be `None` if relay is not going to submit transactions to that chain. + const RUNTIME_VERSION: Option; /// Crypto KeyPair type used to send messages. /// diff --git a/relays/client-bridge-hub-rococo/Cargo.toml b/relays/client-bridge-hub-rococo/Cargo.toml index 642b512d788..7210f784ef9 100644 --- a/relays/client-bridge-hub-rococo/Cargo.toml +++ b/relays/client-bridge-hub-rococo/Cargo.toml @@ -25,7 +25,6 @@ bp-runtime = { path = "../../primitives/runtime" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" } [dev-dependencies] sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/relays/client-bridge-hub-rococo/src/lib.rs b/relays/client-bridge-hub-rococo/src/lib.rs index c90e56d3aa1..ebee7714735 100644 --- a/relays/client-bridge-hub-rococo/src/lib.rs +++ b/relays/client-bridge-hub-rococo/src/lib.rs @@ -74,7 +74,6 @@ impl Chain for BridgeHubRococo { type SignedBlock = bp_bridge_hub_rococo::SignedBlock; type Call = runtime::Call; - type WeightToFee = bp_bridge_hub_rococo::WeightToFee; } impl TransactionSignScheme for BridgeHubRococo { diff --git a/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs b/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs index 6f2123432e5..6153b9b61ca 100644 --- a/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs +++ b/relays/client-bridge-hub-rococo/src/runtime_wrapper.rs @@ -21,28 +21,11 @@ use bp_polkadot_core::PolkadotLike; use codec::{Decode, Encode}; use scale_info::TypeInfo; -use sp_runtime::create_runtime_str; -use sp_version::RuntimeVersion; pub use bp_bridge_hub_rococo::SS58Prefix; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; use bp_runtime::Chain; -// TODO: we meed to keep this up-to-date with -// [github.com/paritytech/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/lib.rs::VERSION] -/// This runtime version. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: create_runtime_str!("bridge-hub-rococo"), - impl_name: create_runtime_str!("bridge-hub-rococo"), - authoring_version: 1, - spec_version: 1, - impl_version: 0, - // TODO:check-parameter - apis: /*RUNTIME_API_VERSIONS*/ sp_version::create_apis_vec![[]], - transaction_version: 1, - state_version: 1, -}; - // TODO:check-parameter - check SignedExtension /// Unchecked BridgeHubRococo extrinsic. pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic; diff --git a/relays/client-bridge-hub-wococo/Cargo.toml b/relays/client-bridge-hub-wococo/Cargo.toml index fa989ea9059..6971ecf951d 100644 --- a/relays/client-bridge-hub-wococo/Cargo.toml +++ b/relays/client-bridge-hub-wococo/Cargo.toml @@ -21,4 +21,3 @@ relay-bridge-hub-rococo-client = { path = "../client-bridge-hub-rococo" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/relays/client-bridge-hub-wococo/src/lib.rs b/relays/client-bridge-hub-wococo/src/lib.rs index e6d90f93a36..d3d4cb88b55 100644 --- a/relays/client-bridge-hub-wococo/src/lib.rs +++ b/relays/client-bridge-hub-wococo/src/lib.rs @@ -74,7 +74,6 @@ impl Chain for BridgeHubWococo { type SignedBlock = bp_bridge_hub_wococo::SignedBlock; type Call = runtime::Call; - type WeightToFee = bp_bridge_hub_wococo::WeightToFee; } impl TransactionSignScheme for BridgeHubWococo { diff --git a/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs b/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs index 85201c90db2..153ac03a25f 100644 --- a/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs +++ b/relays/client-bridge-hub-wococo/src/runtime_wrapper.rs @@ -14,14 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . -// TODO: join with primitives do we need this here or move to the primitives? +// TODO:check-parameter - join with primitives do we need this here or move to the primitives? //! Types that are specific to the BridgeHubWococo runtime. pub use bp_bridge_hub_wococo::SS58Prefix; // We reuse everything from rococo runtime wrapper -pub const VERSION: sp_version::RuntimeVersion = relay_bridge_hub_rococo_client::runtime::VERSION; pub type Call = relay_bridge_hub_rococo_client::runtime::Call; pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic; pub type BridgeGrandpaRococoCall = relay_bridge_hub_rococo_client::runtime::BridgeGrandpaRococoCall; diff --git a/relays/client-kusama/src/lib.rs b/relays/client-kusama/src/lib.rs index b076da7ab75..cdf7213df9b 100644 --- a/relays/client-kusama/src/lib.rs +++ b/relays/client-kusama/src/lib.rs @@ -58,7 +58,6 @@ impl Chain for Kusama { type SignedBlock = bp_kusama::SignedBlock; type Call = (); - type WeightToFee = bp_kusama::WeightToFee; } impl ChainWithGrandpa for Kusama { diff --git a/relays/client-millau/src/lib.rs b/relays/client-millau/src/lib.rs index 7bab3669c4d..3c861214df4 100644 --- a/relays/client-millau/src/lib.rs +++ b/relays/client-millau/src/lib.rs @@ -71,6 +71,7 @@ impl ChainWithMessages for Millau { bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX; const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX; + type WeightToFee = bp_millau::WeightToFee; type WeightInfo = (); } @@ -85,7 +86,6 @@ impl Chain for Millau { type SignedBlock = millau_runtime::SignedBlock; type Call = millau_runtime::Call; - type WeightToFee = bp_millau::WeightToFee; } impl ChainWithBalances for Millau { diff --git a/relays/client-polkadot/src/lib.rs b/relays/client-polkadot/src/lib.rs index 9327c76c4ef..bb3867fda53 100644 --- a/relays/client-polkadot/src/lib.rs +++ b/relays/client-polkadot/src/lib.rs @@ -58,7 +58,6 @@ impl Chain for Polkadot { type SignedBlock = bp_polkadot::SignedBlock; type Call = (); - type WeightToFee = bp_polkadot::WeightToFee; } impl ChainWithGrandpa for Polkadot { diff --git a/relays/client-rialto-parachain/src/lib.rs b/relays/client-rialto-parachain/src/lib.rs index c678a21420f..489baa4be5a 100644 --- a/relays/client-rialto-parachain/src/lib.rs +++ b/relays/client-rialto-parachain/src/lib.rs @@ -66,7 +66,6 @@ impl Chain for RialtoParachain { type SignedBlock = rialto_parachain_runtime::SignedBlock; type Call = rialto_parachain_runtime::Call; - type WeightToFee = bp_rialto_parachain::WeightToFee; } impl ChainWithBalances for RialtoParachain { @@ -93,6 +92,7 @@ impl ChainWithMessages for RialtoParachain { bp_rialto_parachain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX; const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = bp_rialto_parachain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX; + type WeightToFee = bp_rialto_parachain::WeightToFee; type WeightInfo = (); } diff --git a/relays/client-rialto/src/lib.rs b/relays/client-rialto/src/lib.rs index b2984336cd2..816a21baf0c 100644 --- a/relays/client-rialto/src/lib.rs +++ b/relays/client-rialto/src/lib.rs @@ -66,7 +66,6 @@ impl Chain for Rialto { type SignedBlock = rialto_runtime::SignedBlock; type Call = rialto_runtime::Call; - type WeightToFee = bp_rialto::WeightToFee; } impl RelayChain for Rialto { @@ -92,6 +91,7 @@ impl ChainWithMessages for Rialto { bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX; const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX; + type WeightToFee = bp_rialto::WeightToFee; type WeightInfo = (); } diff --git a/relays/client-rococo/src/lib.rs b/relays/client-rococo/src/lib.rs index 56cb1ce50de..5f1ff033559 100644 --- a/relays/client-rococo/src/lib.rs +++ b/relays/client-rococo/src/lib.rs @@ -61,7 +61,6 @@ impl Chain for Rococo { type SignedBlock = bp_rococo::SignedBlock; type Call = (); - type WeightToFee = bp_rococo::WeightToFee; } impl ChainWithGrandpa for Rococo { diff --git a/relays/client-substrate/Cargo.toml b/relays/client-substrate/Cargo.toml index 721415fb2d9..60ef1c67a26 100644 --- a/relays/client-substrate/Cargo.toml +++ b/relays/client-substrate/Cargo.toml @@ -14,7 +14,6 @@ jsonrpsee = { version = "0.15", features = ["macros", "ws-client"] } log = "0.4.17" num-traits = "0.2" rand = "0.7" -serde = { version = "1.0" } tokio = { version = "1.8", features = ["rt-multi-thread"] } thiserror = "1.0.26" diff --git a/relays/client-substrate/src/chain.rs b/relays/client-substrate/src/chain.rs index 9562d68d461..3f483078cac 100644 --- a/relays/client-substrate/src/chain.rs +++ b/relays/client-substrate/src/chain.rs @@ -59,9 +59,6 @@ pub trait Chain: ChainBase + Clone { type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification; /// The aggregated `Call` type. type Call: Clone + Codec + Dispatchable + Debug + Send; - - /// Type that is used by the chain, to convert from weight to fee. - type WeightToFee: WeightToFee; } /// Substrate-based relay chain that supports parachains. @@ -120,6 +117,8 @@ pub trait ChainWithMessages: Chain { /// `ChainWithMessages`. const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce; + /// Type that is used by the chain, to convert from weight to fee. + type WeightToFee: WeightToFee; /// Weights of message pallet calls. type WeightInfo: pallet_bridge_messages::WeightInfoExt; } @@ -127,7 +126,7 @@ pub trait ChainWithMessages: Chain { /// Call type used by the chain. pub type CallOf = ::Call; /// Weight-to-Fee type used by the chain. -pub type WeightToFeeOf = ::WeightToFee; +pub type WeightToFeeOf = ::WeightToFee; /// Transaction status of the chain. pub type TransactionStatusOf = TransactionStatus, HashOf>; diff --git a/relays/client-substrate/src/client.rs b/relays/client-substrate/src/client.rs index ed327e167b0..067d3d89d24 100644 --- a/relays/client-substrate/src/client.rs +++ b/relays/client-substrate/src/client.rs @@ -467,7 +467,8 @@ impl Client { prepare_extrinsic: impl FnOnce(HeaderIdOf, C::Index) -> Result> + Send + 'static, - ) -> Result> { + ) -> Result> { + let self_clone = self.clone(); let _guard = self.submit_signed_extrinsic_lock.lock().await; let transaction_nonce = self.next_account_index(extrinsic_signer).await?; let best_header = self.best_header().await?; @@ -494,6 +495,7 @@ impl Client { })?; log::trace!(target: "bridge", "Sent transaction to {} node: {:?}", C::NAME, tx_hash); let tracker = TransactionTracker::new( + self_clone, stall_timeout, tx_hash, Subscription(Mutex::new(receiver)), diff --git a/relays/client-substrate/src/lib.rs b/relays/client-substrate/src/lib.rs index b9e489688d3..bd38f3a928f 100644 --- a/relays/client-substrate/src/lib.rs +++ b/relays/client-substrate/src/lib.rs @@ -88,30 +88,3 @@ pub fn transaction_stall_timeout( .map(|mortality_period| average_block_interval.saturating_mul(mortality_period + 1 + 1)) .unwrap_or(default_stall_timeout) } - -/// Returns stall timeout for relay loop that submit transactions to two chains. -/// -/// Bidirectional relay may have two active transactions. Even if one of them has been spoiled, we -/// can't just restart the loop - the other transaction may still be alive and we'll be submitting -/// duplicate transaction, which may result in funds loss. So we'll be selecting maximal mortality -/// for choosing loop stall timeout. -pub fn bidirectional_transaction_stall_timeout( - left_mortality_period: Option, - right_mortality_period: Option, - left_average_block_interval: Duration, - right_average_block_interval: Duration, - default_stall_timeout: Duration, -) -> Duration { - std::cmp::max( - transaction_stall_timeout( - left_mortality_period, - left_average_block_interval, - default_stall_timeout, - ), - transaction_stall_timeout( - right_mortality_period, - right_average_block_interval, - default_stall_timeout, - ), - ) -} diff --git a/relays/client-substrate/src/test_chain.rs b/relays/client-substrate/src/test_chain.rs index f9a9e2455ed..8e1832db084 100644 --- a/relays/client-substrate/src/test_chain.rs +++ b/relays/client-substrate/src/test_chain.rs @@ -22,7 +22,7 @@ #![cfg(any(feature = "test-helpers", test))] use crate::{Chain, ChainWithBalances}; -use frame_support::weights::{IdentityFee, Weight}; +use frame_support::weights::Weight; use std::time::Duration; /// Chain that may be used in tests. @@ -60,7 +60,6 @@ impl Chain for TestChain { sp_runtime::generic::Block, >; type Call = (); - type WeightToFee = IdentityFee; } impl ChainWithBalances for TestChain { diff --git a/relays/client-substrate/src/transaction_tracker.rs b/relays/client-substrate/src/transaction_tracker.rs index b85e859017f..44d8b72cb8d 100644 --- a/relays/client-substrate/src/transaction_tracker.rs +++ b/relays/client-substrate/src/transaction_tracker.rs @@ -16,13 +16,28 @@ //! Helper for tracking transaction invalidation events. -use crate::{Chain, HashOf, Subscription, TransactionStatusOf}; +use crate::{Chain, Client, Error, HashOf, HeaderIdOf, Subscription, TransactionStatusOf}; use async_trait::async_trait; -use futures::{Stream, StreamExt}; -use relay_utils::TrackedTransactionStatus; +use futures::{future::Either, Future, FutureExt, Stream, StreamExt}; +use relay_utils::{HeaderId, TrackedTransactionStatus}; +use sp_runtime::traits::Header as _; use std::time::Duration; +/// Transaction tracker environment. +#[async_trait] +pub trait Environment: Send + Sync { + /// Returns header id by its hash. + async fn header_id_by_hash(&self, hash: HashOf) -> Result, Error>; +} + +#[async_trait] +impl Environment for Client { + async fn header_id_by_hash(&self, hash: HashOf) -> Result, Error> { + self.header_by_hash(hash).await.map(|h| HeaderId(*h.number(), hash)) + } +} + /// Substrate transaction tracker implementation. /// /// Substrate node provides RPC API to submit and watch for transaction events. This way @@ -43,55 +58,84 @@ use std::time::Duration; /// it is lost. /// /// This struct implements third option as it seems to be the most optimal. -pub struct TransactionTracker { +pub struct TransactionTracker { + environment: E, transaction_hash: HashOf, stall_timeout: Duration, subscription: Subscription>, } -impl TransactionTracker { +impl> TransactionTracker { /// Create transaction tracker. pub fn new( + environment: E, stall_timeout: Duration, transaction_hash: HashOf, subscription: Subscription>, ) -> Self { - Self { stall_timeout, transaction_hash, subscription } + Self { environment, stall_timeout, transaction_hash, subscription } } /// Wait for final transaction status and return it along with last known internal invalidation /// status. - async fn do_wait(self) -> (TrackedTransactionStatus, InvalidationStatus) { - let invalidation_status = watch_transaction_status::( + async fn do_wait( + self, + wait_for_stall_timeout: impl Future, + wait_for_stall_timeout_rest: impl Future, + ) -> (TrackedTransactionStatus>, Option>>) { + // sometimes we want to wait for the rest of the stall timeout even if + // `wait_for_invalidation` has been "select"ed first => it is shared + let wait_for_invalidation = watch_transaction_status::<_, C, _>( + self.environment, self.transaction_hash, self.subscription.into_stream(), - ) - .await; - match invalidation_status { - InvalidationStatus::Finalized => - (TrackedTransactionStatus::Finalized, invalidation_status), - InvalidationStatus::Invalid => (TrackedTransactionStatus::Lost, invalidation_status), - InvalidationStatus::Lost => { - async_std::task::sleep(self.stall_timeout).await; - // if someone is still watching for our transaction, then we're reporting - // an error here (which is treated as "transaction lost") + ); + futures::pin_mut!(wait_for_stall_timeout, wait_for_invalidation); + + match futures::future::select(wait_for_stall_timeout, wait_for_invalidation).await { + Either::Left((_, _)) => { log::trace!( target: "bridge", - "{} transaction {:?} is considered lost after timeout", + "{} transaction {:?} is considered lost after timeout (no status response from the node)", C::NAME, self.transaction_hash, ); - (TrackedTransactionStatus::Lost, invalidation_status) + (TrackedTransactionStatus::Lost, None) + }, + Either::Right((invalidation_status, _)) => match invalidation_status { + InvalidationStatus::Finalized(at_block) => + (TrackedTransactionStatus::Finalized(at_block), Some(invalidation_status)), + InvalidationStatus::Invalid => + (TrackedTransactionStatus::Lost, Some(invalidation_status)), + InvalidationStatus::Lost => { + // wait for the rest of stall timeout - this way we'll be sure that the + // transaction is actually dead if it has been crafted properly + wait_for_stall_timeout_rest.await; + // if someone is still watching for our transaction, then we're reporting + // an error here (which is treated as "transaction lost") + log::trace!( + target: "bridge", + "{} transaction {:?} is considered lost after timeout", + C::NAME, + self.transaction_hash, + ); + + (TrackedTransactionStatus::Lost, Some(invalidation_status)) + }, }, } } } #[async_trait] -impl relay_utils::TransactionTracker for TransactionTracker { - async fn wait(self) -> TrackedTransactionStatus { - self.do_wait().await.0 +impl> relay_utils::TransactionTracker for TransactionTracker { + type HeaderId = HeaderIdOf; + + async fn wait(self) -> TrackedTransactionStatus> { + let wait_for_stall_timeout = async_std::task::sleep(self.stall_timeout).shared(); + let wait_for_stall_timeout_rest = wait_for_stall_timeout.clone(); + self.do_wait(wait_for_stall_timeout, wait_for_stall_timeout_rest).await.0 } } @@ -101,9 +145,9 @@ impl relay_utils::TransactionTracker for TransactionTracker { /// ignored - relay loops are detecting the mining/finalization using their own /// techniques. That's why we're using `InvalidationStatus` here. #[derive(Debug, PartialEq)] -enum InvalidationStatus { - /// Transaction has been included into block and finalized. - Finalized, +enum InvalidationStatus { + /// Transaction has been included into block and finalized at given block. + Finalized(BlockId), /// Transaction has been invalidated. Invalid, /// We have lost track of transaction status. @@ -111,10 +155,15 @@ enum InvalidationStatus { } /// Watch for transaction status until transaction is finalized or we lose track of its status. -async fn watch_transaction_status>>( +async fn watch_transaction_status< + E: Environment, + C: Chain, + S: Stream>, +>( + environment: E, transaction_hash: HashOf, subscription: S, -) -> InvalidationStatus { +) -> InvalidationStatus> { futures::pin_mut!(subscription); loop { @@ -129,7 +178,23 @@ async fn watch_transaction_status header_id, + Err(e) => { + log::error!( + target: "bridge", + "Failed to read header {:?} when watching for {} transaction {:?}: {:?}", + block_hash, + C::NAME, + transaction_hash, + e, + ); + // that's the best option we have here + return InvalidationStatus::Lost + }, + }; + return InvalidationStatus::Finalized(header_id) }, Some(TransactionStatusOf::::Invalid) => { // if node says that the transaction is invalid, there are still chances that @@ -223,25 +288,62 @@ mod tests { use futures::{FutureExt, SinkExt}; use sc_transaction_pool_api::TransactionStatus; + struct TestEnvironment(Result, Error>); + + #[async_trait] + impl Environment for TestEnvironment { + async fn header_id_by_hash( + &self, + _hash: HashOf, + ) -> Result, Error> { + self.0.as_ref().map_err(|_| Error::UninitializedBridgePallet).cloned() + } + } + async fn on_transaction_status( status: TransactionStatus, HashOf>, - ) -> Option<(TrackedTransactionStatus, InvalidationStatus)> { + ) -> Option<( + TrackedTransactionStatus>, + InvalidationStatus>, + )> { let (mut sender, receiver) = futures::channel::mpsc::channel(1); - let tx_tracker = TransactionTracker::::new( + let tx_tracker = TransactionTracker::::new( + TestEnvironment(Ok(HeaderId(0, Default::default()))), Duration::from_secs(0), Default::default(), Subscription(async_std::sync::Mutex::new(receiver)), ); + let wait_for_stall_timeout = futures::future::pending(); + let wait_for_stall_timeout_rest = futures::future::ready(()); sender.send(Some(status)).await.unwrap(); - tx_tracker.do_wait().now_or_never() + tx_tracker + .do_wait(wait_for_stall_timeout, wait_for_stall_timeout_rest) + .now_or_never() + .map(|(ts, is)| (ts, is.unwrap())) } #[async_std::test] async fn returns_finalized_on_finalized() { assert_eq!( on_transaction_status(TransactionStatus::Finalized(Default::default())).await, - Some((TrackedTransactionStatus::Finalized, InvalidationStatus::Finalized)), + Some(( + TrackedTransactionStatus::Finalized(Default::default()), + InvalidationStatus::Finalized(Default::default()) + )), + ); + } + + #[async_std::test] + async fn returns_lost_on_finalized_and_environment_error() { + assert_eq!( + watch_transaction_status::<_, TestChain, _>( + TestEnvironment(Err(Error::UninitializedBridgePallet)), + Default::default(), + futures::stream::iter([TransactionStatus::Finalized(Default::default())]) + ) + .now_or_never(), + Some(InvalidationStatus::Lost), ); } @@ -314,9 +416,32 @@ mod tests { #[async_std::test] async fn lost_on_subscription_error() { assert_eq!( - watch_transaction_status::(Default::default(), futures::stream::iter([])) - .now_or_never(), + watch_transaction_status::<_, TestChain, _>( + TestEnvironment(Ok(HeaderId(0, Default::default()))), + Default::default(), + futures::stream::iter([]) + ) + .now_or_never(), Some(InvalidationStatus::Lost), ); } + + #[async_std::test] + async fn lost_on_timeout_when_waiting_for_invalidation_status() { + let (_sender, receiver) = futures::channel::mpsc::channel(1); + let tx_tracker = TransactionTracker::::new( + TestEnvironment(Ok(HeaderId(0, Default::default()))), + Duration::from_secs(0), + Default::default(), + Subscription(async_std::sync::Mutex::new(receiver)), + ); + + let wait_for_stall_timeout = futures::future::ready(()).shared(); + let wait_for_stall_timeout_rest = wait_for_stall_timeout.clone(); + let wait_result = tx_tracker + .do_wait(wait_for_stall_timeout, wait_for_stall_timeout_rest) + .now_or_never(); + + assert_eq!(wait_result, Some((TrackedTransactionStatus::Lost, None))); + } } diff --git a/relays/client-westend/Cargo.toml b/relays/client-westend/Cargo.toml index 2ad99634067..57d2ca3b1e7 100644 --- a/relays/client-westend/Cargo.toml +++ b/relays/client-westend/Cargo.toml @@ -17,4 +17,3 @@ bp-westend = { path = "../../primitives/chain-westend" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/relays/client-westend/src/lib.rs b/relays/client-westend/src/lib.rs index 4b27bfeb82d..f6a4220c618 100644 --- a/relays/client-westend/src/lib.rs +++ b/relays/client-westend/src/lib.rs @@ -61,7 +61,6 @@ impl Chain for Westend { type SignedBlock = bp_westend::SignedBlock; type Call = bp_westend::Call; - type WeightToFee = bp_westend::WeightToFee; } impl RelayChain for Westend { @@ -119,5 +118,4 @@ impl Chain for Westmint { type SignedBlock = bp_westend::SignedBlock; type Call = bp_westend::Call; - type WeightToFee = bp_westend::WeightToFee; } diff --git a/relays/client-wococo/src/lib.rs b/relays/client-wococo/src/lib.rs index cd34e0c3ea2..b4e9dd74d19 100644 --- a/relays/client-wococo/src/lib.rs +++ b/relays/client-wococo/src/lib.rs @@ -61,7 +61,6 @@ impl Chain for Wococo { type SignedBlock = bp_wococo::SignedBlock; type Call = (); - type WeightToFee = bp_wococo::WeightToFee; } impl ChainWithGrandpa for Wococo { diff --git a/relays/finality/src/finality_loop.rs b/relays/finality/src/finality_loop.rs index 951edfdde94..a8906860470 100644 --- a/relays/finality/src/finality_loop.rs +++ b/relays/finality/src/finality_loop.rs @@ -290,15 +290,55 @@ pub(crate) async fn run_until_connection_lost( // wait till exit signal, or new source block select! { transaction_status = last_transaction_tracker => { - if transaction_status == TrackedTransactionStatus::Lost { - log::error!( - target: "bridge", - "Finality synchronization from {} to {} has stalled. Going to restart", - P::SOURCE_NAME, - P::TARGET_NAME, - ); - - return Err(FailedClient::Both); + match transaction_status { + TrackedTransactionStatus::Finalized(_) => { + // transaction has been finalized, but it may have been finalized in the "failed" state. So + // let's check if the block number has been actually updated. If it is not, then we are stalled. + // + // please also note that we're restarting the loop if we have failed to read required data + // from the target client - that's the best we can do here to avoid actual stall. + target_client + .best_finalized_source_block_id() + .await + .map_err(|e| format!("failed to read best block from target node: {:?}", e)) + .and_then(|best_id_at_target| { + let last_submitted_header_number = last_submitted_header_number + .expect("always Some when last_transaction_tracker is set;\ + last_transaction_tracker is set;\ + qed"); + if last_submitted_header_number > best_id_at_target.0 { + Err(format!( + "best block at target after tx is {:?} and we've submitted {:?}", + best_id_at_target, + last_submitted_header_number, + )) + } else { + Ok(()) + } + }) + .map_err(|e| { + log::error!( + target: "bridge", + "Failed Finality synchronization from {} to {} has stalled. Transaction failed: {}. \ + Going to restart", + P::SOURCE_NAME, + P::TARGET_NAME, + e, + ); + + FailedClient::Both + })?; + }, + TrackedTransactionStatus::Lost => { + log::error!( + target: "bridge", + "Finality synchronization from {} to {} has stalled. Going to restart", + P::SOURCE_NAME, + P::TARGET_NAME, + ); + + return Err(FailedClient::Both); + }, } }, _ = async_std::task::sleep(next_tick).fuse() => {}, diff --git a/relays/finality/src/finality_loop_tests.rs b/relays/finality/src/finality_loop_tests.rs index 7144ccb0c48..c8d5cefc227 100644 --- a/relays/finality/src/finality_loop_tests.rs +++ b/relays/finality/src/finality_loop_tests.rs @@ -48,17 +48,19 @@ type TestNumber = u64; type TestHash = u64; #[derive(Clone, Debug)] -struct TestTransactionTracker(TrackedTransactionStatus); +struct TestTransactionTracker(TrackedTransactionStatus>); impl Default for TestTransactionTracker { fn default() -> TestTransactionTracker { - TestTransactionTracker(TrackedTransactionStatus::Finalized) + TestTransactionTracker(TrackedTransactionStatus::Finalized(Default::default())) } } #[async_trait] impl TransactionTracker for TestTransactionTracker { - async fn wait(self) -> TrackedTransactionStatus { + type HeaderId = HeaderId; + + async fn wait(self) -> TrackedTransactionStatus> { self.0 } } @@ -224,7 +226,9 @@ fn prepare_test_clients( target_best_block_id: HeaderId(5, 5), target_headers: vec![], - target_transaction_tracker: TestTransactionTracker(TrackedTransactionStatus::Finalized), + target_transaction_tracker: TestTransactionTracker(TrackedTransactionStatus::Finalized( + Default::default(), + )), })); ( TestSourceClient { @@ -581,3 +585,13 @@ fn stalls_when_transaction_tracker_returns_error() { assert_eq!(result, Err(FailedClient::Both)); } + +#[test] +fn stalls_when_transaction_tracker_returns_finalized_but_transaction_fails() { + let (_, result) = run_sync_loop(|data| { + data.target_best_block_id = HeaderId(5, 5); + data.target_best_block_id.0 == 16 + }); + + assert_eq!(result, Err(FailedClient::Both)); +} diff --git a/relays/lib-substrate-relay/src/finality/target.rs b/relays/lib-substrate-relay/src/finality/target.rs index 7bdb77d4ee0..132c3325343 100644 --- a/relays/lib-substrate-relay/src/finality/target.rs +++ b/relays/lib-substrate-relay/src/finality/target.rs @@ -89,7 +89,7 @@ where AccountIdOf: From< as Pair>::Public>, P::TransactionSignScheme: TransactionSignScheme, { - type TransactionTracker = TransactionTracker; + type TransactionTracker = TransactionTracker>; async fn best_finalized_source_block_id(&self) -> Result, Error> { // we can't continue to relay finality if target node is out of sync, because diff --git a/relays/lib-substrate-relay/src/messages_lane.rs b/relays/lib-substrate-relay/src/messages_lane.rs index f69ebc347d7..14227f379d7 100644 --- a/relays/lib-substrate-relay/src/messages_lane.rs +++ b/relays/lib-substrate-relay/src/messages_lane.rs @@ -164,13 +164,6 @@ where { let source_client = params.source_client; let target_client = params.target_client; - let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout( - params.source_transaction_params.mortality, - params.target_transaction_params.mortality, - P::SourceChain::AVERAGE_BLOCK_INTERVAL, - P::TargetChain::AVERAGE_BLOCK_INTERVAL, - STALL_TIMEOUT, - ); let relayer_id_at_source: AccountIdOf = params.source_transaction_params.signer.public().into(); @@ -202,8 +195,7 @@ where Max messages in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\ - Tx mortality: {:?} (~{}m)/{:?} (~{}m)\n\t\ - Stall timeout: {:?}", + Tx mortality: {:?} (~{}m)/{:?} (~{}m)", P::SourceChain::NAME, P::TargetChain::NAME, P::SourceChain::NAME, @@ -223,7 +215,6 @@ where P::TargetChain::AVERAGE_BLOCK_INTERVAL, STALL_TIMEOUT, ).as_secs_f64() / 60.0f64, - stall_timeout, ); messages_relay::message_lane_loop::run( @@ -232,7 +223,6 @@ where source_tick: P::SourceChain::AVERAGE_BLOCK_INTERVAL, target_tick: P::TargetChain::AVERAGE_BLOCK_INTERVAL, reconnect_delay: relay_utils::relay_loop::RECONNECT_DELAY, - stall_timeout, delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams { max_unrewarded_relayer_entries_at_target: P::SourceChain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, @@ -494,7 +484,7 @@ mod tests { use bp_runtime::Chain; type RialtoToMillauMessagesWeights = - pallet_bridge_messages::weights::MillauWeight; + pallet_bridge_messages::weights::BridgeWeight; #[test] fn select_delivery_transaction_limits_works() { diff --git a/relays/lib-substrate-relay/src/messages_source.rs b/relays/lib-substrate-relay/src/messages_source.rs index 5de9e30dd0e..e34f477e5f0 100644 --- a/relays/lib-substrate-relay/src/messages_source.rs +++ b/relays/lib-substrate-relay/src/messages_source.rs @@ -51,7 +51,7 @@ use num_traits::{Bounded, Zero}; use relay_substrate_client::{ AccountIdOf, AccountKeyPairOf, BalanceOf, BlockNumberOf, Chain, ChainWithMessages, Client, Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, SignParam, TransactionEra, - TransactionSignScheme, UnsignedTransaction, + TransactionSignScheme, TransactionTracker, UnsignedTransaction, }; use relay_utils::{relay_loop::Client as RelayClient, HeaderId}; use sp_core::{Bytes, Pair}; @@ -144,6 +144,8 @@ where From< as Pair>::Public>, P::SourceTransactionSignScheme: TransactionSignScheme, { + type TransactionTracker = TransactionTracker>; + async fn state(&self) -> Result>, SubstrateError> { // we can't continue to deliver confirmations if source node is out of sync, because // it may have already received confirmations that we're going to deliver @@ -338,13 +340,13 @@ where &self, _generated_at_block: TargetHeaderIdOf>, proof: as MessageLane>::MessagesReceivingProof, - ) -> Result<(), SubstrateError> { + ) -> Result { let genesis_hash = *self.source_client.genesis_hash(); let transaction_params = self.transaction_params.clone(); let (spec_version, transaction_version) = self.source_client.simple_runtime_version().await?; self.source_client - .submit_signed_extrinsic( + .submit_and_watch_signed_extrinsic( self.transaction_params.signer.public().into(), SignParam:: { spec_version, @@ -362,8 +364,7 @@ where ) }, ) - .await?; - Ok(()) + .await } async fn require_target_header_on_source(&self, id: TargetHeaderIdOf>) { diff --git a/relays/lib-substrate-relay/src/messages_target.rs b/relays/lib-substrate-relay/src/messages_target.rs index 29d80bc2c5e..da41dba63a5 100644 --- a/relays/lib-substrate-relay/src/messages_target.rs +++ b/relays/lib-substrate-relay/src/messages_target.rs @@ -39,13 +39,13 @@ use codec::Encode; use frame_support::weights::{Weight, WeightToFee}; use messages_relay::{ message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf}, - message_lane_loop::{TargetClient, TargetClientState}, + message_lane_loop::{NoncesSubmitArtifacts, TargetClient, TargetClientState}, }; use num_traits::{Bounded, Zero}; use relay_substrate_client::{ AccountIdOf, AccountKeyPairOf, BalanceOf, BlockNumberOf, Chain, ChainWithMessages, Client, Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, SignParam, TransactionEra, - TransactionSignScheme, UnsignedTransaction, WeightToFeeOf, + TransactionSignScheme, TransactionTracker, UnsignedTransaction, WeightToFeeOf, }; use relay_utils::{relay_loop::Client as RelayClient, HeaderId}; use sp_core::{Bytes, Pair}; @@ -145,6 +145,8 @@ where P::TargetTransactionSignScheme: TransactionSignScheme, BalanceOf: TryFrom>, { + type TransactionTracker = TransactionTracker>; + async fn state(&self) -> Result>, SubstrateError> { // we can't continue to deliver confirmations if source node is out of sync, because // it may have already received confirmations that we're going to deliver @@ -245,15 +247,16 @@ where _generated_at_header: SourceHeaderIdOf>, nonces: RangeInclusive, proof: as MessageLane>::MessagesProof, - ) -> Result, SubstrateError> { + ) -> Result, SubstrateError> { let genesis_hash = *self.target_client.genesis_hash(); let transaction_params = self.transaction_params.clone(); let relayer_id_at_source = self.relayer_id_at_source.clone(); let nonces_clone = nonces.clone(); let (spec_version, transaction_version) = self.target_client.simple_runtime_version().await?; - self.target_client - .submit_signed_extrinsic( + let tx_tracker = self + .target_client + .submit_and_watch_signed_extrinsic( self.transaction_params.signer.public().into(), SignParam:: { spec_version, @@ -274,7 +277,7 @@ where }, ) .await?; - Ok(nonces) + Ok(NoncesSubmitArtifacts { nonces, tx_tracker }) } async fn require_source_header_on_target(&self, id: SourceHeaderIdOf>) { @@ -494,7 +497,7 @@ where /// **WARNING**: this functions will only be accurate if weight-to-fee conversion function /// is linear. For non-linear polynomials the error will grow with `weight_difference` growth. /// So better to use smaller differences. -fn compute_fee_multiplier( +fn compute_fee_multiplier( smaller_adjusted_weight_fee: BalanceOf, smaller_tx_weight: Weight, larger_adjusted_weight_fee: BalanceOf, @@ -560,17 +563,17 @@ mod tests { #[test] fn compute_fee_multiplier_returns_sane_results() { - let multiplier: FixedU128 = bp_rococo::WeightToFee::weight_to_fee(&1).into(); + let multiplier: FixedU128 = bp_rialto::WeightToFee::weight_to_fee(&1).into(); let smaller_weight = 1_000_000; let smaller_adjusted_weight_fee = - multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee(&smaller_weight)); + multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee(&smaller_weight)); let larger_weight = smaller_weight + 200_000; let larger_adjusted_weight_fee = - multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee(&larger_weight)); + multiplier.saturating_mul_int(WeightToFeeOf::::weight_to_fee(&larger_weight)); assert_eq!( - compute_fee_multiplier::( + compute_fee_multiplier::( smaller_adjusted_weight_fee, smaller_weight, larger_adjusted_weight_fee, diff --git a/relays/lib-substrate-relay/src/parachains/target.rs b/relays/lib-substrate-relay/src/parachains/target.rs index fa159cdeb7e..8d0d361984f 100644 --- a/relays/lib-substrate-relay/src/parachains/target.rs +++ b/relays/lib-substrate-relay/src/parachains/target.rs @@ -34,7 +34,7 @@ use parachains_relay::{ use relay_substrate_client::{ AccountIdOf, AccountKeyPairOf, BlockNumberOf, Chain, Client, Error as SubstrateError, HashOf, HeaderIdOf, HeaderOf, RelayChain, SignParam, TransactionEra, TransactionSignScheme, - UnsignedTransaction, + TransactionTracker, UnsignedTransaction, }; use relay_utils::{relay_loop::Client as RelayClient, HeaderId}; use sp_core::{Bytes, Pair}; @@ -86,6 +86,8 @@ where P::TransactionSignScheme: TransactionSignScheme, AccountIdOf: From< as Pair>::Public>, { + type TransactionTracker = TransactionTracker>; + async fn best_block(&self) -> Result, Self::Error> { let best_header = self.client.best_header().await?; let best_id = best_header.id(); @@ -172,7 +174,7 @@ where at_relay_block: HeaderIdOf, updated_parachains: Vec<(ParaId, ParaHash)>, proof: ParaHeadsProof, - ) -> Result<(), Self::Error> { + ) -> Result { let genesis_hash = *self.client.genesis_hash(); let transaction_params = self.transaction_params.clone(); let (spec_version, transaction_version) = self.client.simple_runtime_version().await?; @@ -182,7 +184,7 @@ where proof, ); self.client - .submit_signed_extrinsic( + .submit_and_watch_signed_extrinsic( self.transaction_params.signer.public().into(), SignParam:: { spec_version, @@ -196,6 +198,5 @@ where }, ) .await - .map(drop) } } diff --git a/relays/messages/src/message_lane_loop.rs b/relays/messages/src/message_lane_loop.rs index bd7a7de8290..05c157ee721 100644 --- a/relays/messages/src/message_lane_loop.rs +++ b/relays/messages/src/message_lane_loop.rs @@ -33,7 +33,7 @@ use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; use bp_runtime::messages::DispatchFeePayment; use relay_utils::{ interval, metrics::MetricsParams, process_future_result, relay_loop::Client as RelayClient, - retry_backoff, FailedClient, + retry_backoff, FailedClient, TransactionTracker, }; use crate::{ @@ -55,8 +55,6 @@ pub struct Params { pub target_tick: Duration, /// Delay between moments when connection error happens and our reconnect attempt. pub reconnect_delay: Duration, - /// The loop will auto-restart if there has been no updates during this period. - pub stall_timeout: Duration, /// Message delivery race parameters. pub delivery_params: MessageDeliveryParams, } @@ -119,9 +117,20 @@ pub struct MessageProofParameters { pub dispatch_weight: Weight, } +/// Artifacts of submitting nonces proof. +pub struct NoncesSubmitArtifacts { + /// Submitted nonces range. + pub nonces: RangeInclusive, + /// Submitted transaction tracker. + pub tx_tracker: T, +} + /// Source client trait. #[async_trait] pub trait SourceClient: RelayClient { + /// Transaction tracker to track submitted transactions. + type TransactionTracker: TransactionTracker>; + /// Returns state of the client. async fn state(&self) -> Result, Self::Error>; @@ -160,7 +169,7 @@ pub trait SourceClient: RelayClient { &self, generated_at_block: TargetHeaderIdOf

, proof: P::MessagesReceivingProof, - ) -> Result<(), Self::Error>; + ) -> Result; /// We need given finalized target header on source to continue synchronization. async fn require_target_header_on_source(&self, id: TargetHeaderIdOf

); @@ -172,6 +181,9 @@ pub trait SourceClient: RelayClient { /// Target client trait. #[async_trait] pub trait TargetClient: RelayClient { + /// Transaction tracker to track submitted transactions. + type TransactionTracker: TransactionTracker>; + /// Returns state of the client. async fn state(&self) -> Result, Self::Error>; @@ -205,7 +217,7 @@ pub trait TargetClient: RelayClient { generated_at_header: SourceHeaderIdOf

, nonces: RangeInclusive, proof: P::MessagesProof, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; /// We need given finalized source header on target to continue synchronization. async fn require_source_header_on_target(&self, id: SourceHeaderIdOf

); @@ -327,7 +339,6 @@ async fn run_until_connection_lost< delivery_source_state_receiver, target_client.clone(), delivery_target_state_receiver, - params.stall_timeout, metrics_msg.clone(), params.delivery_params, ) @@ -342,7 +353,6 @@ async fn run_until_connection_lost< receiving_source_state_receiver, target_client.clone(), receiving_target_state_receiver, - params.stall_timeout, metrics_msg.clone(), ) .fuse(); @@ -465,7 +475,7 @@ pub(crate) mod tests { use futures::stream::StreamExt; use parking_lot::Mutex; - use relay_utils::{HeaderId, MaybeConnectionError}; + use relay_utils::{HeaderId, MaybeConnectionError, TrackedTransactionStatus}; use crate::relay_strategy::AltruisticStrategy; @@ -518,19 +528,39 @@ pub(crate) mod tests { type TargetHeaderHash = TestTargetHeaderHash; } - #[derive(Debug, Default, Clone)] + #[derive(Clone, Debug)] + pub struct TestTransactionTracker(TrackedTransactionStatus); + + impl Default for TestTransactionTracker { + fn default() -> TestTransactionTracker { + TestTransactionTracker(TrackedTransactionStatus::Finalized(Default::default())) + } + } + + #[async_trait] + impl TransactionTracker for TestTransactionTracker { + type HeaderId = TestTargetHeaderId; + + async fn wait(self) -> TrackedTransactionStatus { + self.0 + } + } + + #[derive(Debug, Clone)] pub struct TestClientData { is_source_fails: bool, is_source_reconnected: bool, source_state: SourceClientState, source_latest_generated_nonce: MessageNonce, source_latest_confirmed_received_nonce: MessageNonce, + source_tracked_transaction_status: TrackedTransactionStatus, submitted_messages_receiving_proofs: Vec, is_target_fails: bool, is_target_reconnected: bool, target_state: SourceClientState, target_latest_received_nonce: MessageNonce, target_latest_confirmed_received_nonce: MessageNonce, + target_tracked_transaction_status: TrackedTransactionStatus, submitted_messages_proofs: Vec, target_to_source_header_required: Option, target_to_source_header_requirements: Vec, @@ -538,10 +568,42 @@ pub(crate) mod tests { source_to_target_header_requirements: Vec, } + impl Default for TestClientData { + fn default() -> TestClientData { + TestClientData { + is_source_fails: false, + is_source_reconnected: false, + source_state: Default::default(), + source_latest_generated_nonce: 0, + source_latest_confirmed_received_nonce: 0, + source_tracked_transaction_status: TrackedTransactionStatus::Finalized(HeaderId( + 0, + Default::default(), + )), + submitted_messages_receiving_proofs: Vec::new(), + is_target_fails: false, + is_target_reconnected: false, + target_state: Default::default(), + target_latest_received_nonce: 0, + target_latest_confirmed_received_nonce: 0, + target_tracked_transaction_status: TrackedTransactionStatus::Finalized(HeaderId( + 0, + Default::default(), + )), + submitted_messages_proofs: Vec::new(), + target_to_source_header_required: None, + target_to_source_header_requirements: Vec::new(), + source_to_target_header_required: None, + source_to_target_header_requirements: Vec::new(), + } + } + } + #[derive(Clone)] pub struct TestSourceClient { data: Arc>, tick: Arc, + post_tick: Arc, } impl Default for TestSourceClient { @@ -549,6 +611,7 @@ pub(crate) mod tests { TestSourceClient { data: Arc::new(Mutex::new(TestClientData::default())), tick: Arc::new(|_| {}), + post_tick: Arc::new(|_| {}), } } } @@ -562,6 +625,7 @@ pub(crate) mod tests { let mut data = self.data.lock(); (self.tick)(&mut data); data.is_source_reconnected = true; + (self.post_tick)(&mut data); } Ok(()) } @@ -569,12 +633,15 @@ pub(crate) mod tests { #[async_trait] impl SourceClient for TestSourceClient { + type TransactionTracker = TestTransactionTracker; + async fn state(&self) -> Result, TestError> { let mut data = self.data.lock(); (self.tick)(&mut data); if data.is_source_fails { return Err(TestError) } + (self.post_tick)(&mut data); Ok(data.source_state.clone()) } @@ -587,6 +654,7 @@ pub(crate) mod tests { if data.is_source_fails { return Err(TestError) } + (self.post_tick)(&mut data); Ok((id, data.source_latest_generated_nonce)) } @@ -596,6 +664,7 @@ pub(crate) mod tests { ) -> Result<(SourceHeaderIdOf, MessageNonce), TestError> { let mut data = self.data.lock(); (self.tick)(&mut data); + (self.post_tick)(&mut data); Ok((id, data.source_latest_confirmed_received_nonce)) } @@ -630,6 +699,7 @@ pub(crate) mod tests { > { let mut data = self.data.lock(); (self.tick)(&mut data); + (self.post_tick)(&mut data); Ok(( id, nonces.clone(), @@ -648,7 +718,7 @@ pub(crate) mod tests { &self, _generated_at_block: TargetHeaderIdOf, proof: TestMessagesReceivingProof, - ) -> Result<(), TestError> { + ) -> Result { let mut data = self.data.lock(); (self.tick)(&mut data); data.source_state.best_self = @@ -656,7 +726,8 @@ pub(crate) mod tests { data.source_state.best_finalized_self = data.source_state.best_self; data.submitted_messages_receiving_proofs.push(proof); data.source_latest_confirmed_received_nonce = proof; - Ok(()) + (self.post_tick)(&mut data); + Ok(TestTransactionTracker(data.source_tracked_transaction_status)) } async fn require_target_header_on_source(&self, id: TargetHeaderIdOf) { @@ -664,6 +735,7 @@ pub(crate) mod tests { data.target_to_source_header_required = Some(id); data.target_to_source_header_requirements.push(id); (self.tick)(&mut data); + (self.post_tick)(&mut data); } async fn estimate_confirmation_transaction(&self) -> TestSourceChainBalance { @@ -675,6 +747,7 @@ pub(crate) mod tests { pub struct TestTargetClient { data: Arc>, tick: Arc, + post_tick: Arc, } impl Default for TestTargetClient { @@ -682,6 +755,7 @@ pub(crate) mod tests { TestTargetClient { data: Arc::new(Mutex::new(TestClientData::default())), tick: Arc::new(|_| {}), + post_tick: Arc::new(|_| {}), } } } @@ -695,6 +769,7 @@ pub(crate) mod tests { let mut data = self.data.lock(); (self.tick)(&mut data); data.is_target_reconnected = true; + (self.post_tick)(&mut data); } Ok(()) } @@ -702,12 +777,15 @@ pub(crate) mod tests { #[async_trait] impl TargetClient for TestTargetClient { + type TransactionTracker = TestTransactionTracker; + async fn state(&self) -> Result, TestError> { let mut data = self.data.lock(); (self.tick)(&mut data); if data.is_target_fails { return Err(TestError) } + (self.post_tick)(&mut data); Ok(data.target_state.clone()) } @@ -720,6 +798,7 @@ pub(crate) mod tests { if data.is_target_fails { return Err(TestError) } + (self.post_tick)(&mut data); Ok((id, data.target_latest_received_nonce)) } @@ -747,6 +826,7 @@ pub(crate) mod tests { if data.is_target_fails { return Err(TestError) } + (self.post_tick)(&mut data); Ok((id, data.target_latest_confirmed_received_nonce)) } @@ -762,7 +842,7 @@ pub(crate) mod tests { _generated_at_header: SourceHeaderIdOf, nonces: RangeInclusive, proof: TestMessagesProof, - ) -> Result, TestError> { + ) -> Result, TestError> { let mut data = self.data.lock(); (self.tick)(&mut data); if data.is_target_fails { @@ -777,7 +857,11 @@ pub(crate) mod tests { target_latest_confirmed_received_nonce; } data.submitted_messages_proofs.push(proof); - Ok(nonces) + (self.post_tick)(&mut data); + Ok(NoncesSubmitArtifacts { + nonces, + tx_tracker: TestTransactionTracker(data.target_tracked_transaction_status), + }) } async fn require_source_header_on_target(&self, id: SourceHeaderIdOf) { @@ -785,6 +869,7 @@ pub(crate) mod tests { data.source_to_target_header_required = Some(id); data.source_to_target_header_requirements.push(id); (self.tick)(&mut data); + (self.post_tick)(&mut data); } async fn estimate_delivery_transaction_in_source_tokens( @@ -803,21 +888,30 @@ pub(crate) mod tests { fn run_loop_test( data: TestClientData, source_tick: Arc, + source_post_tick: Arc, target_tick: Arc, + target_post_tick: Arc, exit_signal: impl Future + 'static + Send, ) -> TestClientData { async_std::task::block_on(async { let data = Arc::new(Mutex::new(data)); - let source_client = TestSourceClient { data: data.clone(), tick: source_tick }; - let target_client = TestTargetClient { data: data.clone(), tick: target_tick }; + let source_client = TestSourceClient { + data: data.clone(), + tick: source_tick, + post_tick: source_post_tick, + }; + let target_client = TestTargetClient { + data: data.clone(), + tick: target_tick, + post_tick: target_post_tick, + }; let _ = run( Params { lane: [0, 0, 0, 0], source_tick: Duration::from_millis(100), target_tick: Duration::from_millis(100), reconnect_delay: Duration::from_millis(0), - stall_timeout: Duration::from_millis(60 * 1000), delivery_params: MessageDeliveryParams { max_unrewarded_relayer_entries_at_target: 4, max_unconfirmed_nonces_at_target: 4, @@ -869,6 +963,7 @@ pub(crate) mod tests { data.is_target_fails = true; } }), + Arc::new(|_| {}), Arc::new(move |data: &mut TestClientData| { if data.is_target_reconnected { data.is_target_fails = false; @@ -883,12 +978,141 @@ pub(crate) mod tests { exit_sender.unbounded_send(()).unwrap(); } }), + Arc::new(|_| {}), exit_receiver.into_future().map(|(_, _)| ()), ); assert_eq!(result.submitted_messages_proofs, vec![(1..=1, None)],); } + #[test] + fn message_lane_loop_is_able_to_recover_from_race_stall() { + // with this configuration, both source and target clients will lose their transactions => + // reconnect will happen + let (source_exit_sender, exit_receiver) = unbounded(); + let target_exit_sender = source_exit_sender.clone(); + let result = run_loop_test( + TestClientData { + source_state: ClientState { + best_self: HeaderId(0, 0), + best_finalized_self: HeaderId(0, 0), + best_finalized_peer_at_best_self: HeaderId(0, 0), + actual_best_finalized_peer_at_best_self: HeaderId(0, 0), + }, + source_latest_generated_nonce: 1, + source_tracked_transaction_status: TrackedTransactionStatus::Lost, + target_state: ClientState { + best_self: HeaderId(0, 0), + best_finalized_self: HeaderId(0, 0), + best_finalized_peer_at_best_self: HeaderId(0, 0), + actual_best_finalized_peer_at_best_self: HeaderId(0, 0), + }, + target_latest_received_nonce: 0, + target_tracked_transaction_status: TrackedTransactionStatus::Lost, + ..Default::default() + }, + Arc::new(move |data: &mut TestClientData| { + if data.is_source_reconnected { + data.source_tracked_transaction_status = + TrackedTransactionStatus::Finalized(Default::default()); + } + if data.is_source_reconnected && data.is_target_reconnected { + source_exit_sender.unbounded_send(()).unwrap(); + } + }), + Arc::new(|_| {}), + Arc::new(move |data: &mut TestClientData| { + if data.is_target_reconnected { + data.target_tracked_transaction_status = + TrackedTransactionStatus::Finalized(Default::default()); + } + if data.is_source_reconnected && data.is_target_reconnected { + target_exit_sender.unbounded_send(()).unwrap(); + } + }), + Arc::new(|_| {}), + exit_receiver.into_future().map(|(_, _)| ()), + ); + + assert!(result.is_source_reconnected); + } + + #[test] + fn message_lane_loop_is_able_to_recover_from_unsuccessful_transaction() { + // with this configuration, both source and target clients will mine their transactions, but + // their corresponding nonce won't be udpated => reconnect will happen + let (exit_sender, exit_receiver) = unbounded(); + let result = run_loop_test( + TestClientData { + source_state: ClientState { + best_self: HeaderId(0, 0), + best_finalized_self: HeaderId(0, 0), + best_finalized_peer_at_best_self: HeaderId(0, 0), + actual_best_finalized_peer_at_best_self: HeaderId(0, 0), + }, + source_latest_generated_nonce: 1, + target_state: ClientState { + best_self: HeaderId(0, 0), + best_finalized_self: HeaderId(0, 0), + best_finalized_peer_at_best_self: HeaderId(0, 0), + actual_best_finalized_peer_at_best_self: HeaderId(0, 0), + }, + target_latest_received_nonce: 0, + ..Default::default() + }, + Arc::new(move |data: &mut TestClientData| { + // blocks are produced on every tick + data.source_state.best_self = + HeaderId(data.source_state.best_self.0 + 1, data.source_state.best_self.1 + 1); + data.source_state.best_finalized_self = data.source_state.best_self; + // syncing target headers -> source chain + if let Some(last_requirement) = data.target_to_source_header_requirements.last() { + if *last_requirement != data.source_state.best_finalized_peer_at_best_self { + data.source_state.best_finalized_peer_at_best_self = *last_requirement; + } + } + }), + Arc::new(move |data: &mut TestClientData| { + // if it is the first time we're submitting delivery proof, let's revert changes + // to source status => then the delivery confirmation transaction is "finalized", + // but the state is not altered + if data.submitted_messages_receiving_proofs.len() == 1 { + data.source_latest_confirmed_received_nonce = 0; + } + }), + Arc::new(move |data: &mut TestClientData| { + // blocks are produced on every tick + data.target_state.best_self = + HeaderId(data.target_state.best_self.0 + 1, data.target_state.best_self.1 + 1); + data.target_state.best_finalized_self = data.target_state.best_self; + // syncing source headers -> target chain + if let Some(last_requirement) = data.source_to_target_header_requirements.last() { + if *last_requirement != data.target_state.best_finalized_peer_at_best_self { + data.target_state.best_finalized_peer_at_best_self = *last_requirement; + } + } + // if source has received all messages receiving confirmations => stop + if data.source_latest_confirmed_received_nonce == 1 { + exit_sender.unbounded_send(()).unwrap(); + } + }), + Arc::new(move |data: &mut TestClientData| { + // if it is the first time we're submitting messages proof, let's revert changes + // to target status => then the messages delivery transaction is "finalized", but + // the state is not altered + if data.submitted_messages_proofs.len() == 1 { + data.target_latest_received_nonce = 0; + data.target_latest_confirmed_received_nonce = 0; + } + }), + exit_receiver.into_future().map(|(_, _)| ()), + ); + + assert!(result.is_source_reconnected); + assert_eq!(result.submitted_messages_proofs.len(), 2); + assert_eq!(result.submitted_messages_receiving_proofs.len(), 2); + } + #[test] fn message_lane_loop_works() { let (exit_sender, exit_receiver) = unbounded(); @@ -930,6 +1154,7 @@ pub(crate) mod tests { } } }), + Arc::new(|_| {}), Arc::new(move |data: &mut TestClientData| { // blocks are produced on every tick data.target_state.best_self = @@ -954,6 +1179,7 @@ pub(crate) mod tests { exit_sender.unbounded_send(()).unwrap(); } }), + Arc::new(|_| {}), exit_receiver.into_future().map(|(_, _)| ()), ); diff --git a/relays/messages/src/message_race_delivery.rs b/relays/messages/src/message_race_delivery.rs index 85f6d955e7d..e15e08b0423 100644 --- a/relays/messages/src/message_race_delivery.rs +++ b/relays/messages/src/message_race_delivery.rs @@ -13,7 +13,7 @@ //! Message delivery race delivers proof-of-messages from "lane.source" to "lane.target". -use std::{collections::VecDeque, marker::PhantomData, ops::RangeInclusive, time::Duration}; +use std::{collections::VecDeque, marker::PhantomData, ops::RangeInclusive}; use async_trait::async_trait; use futures::stream::FusedStream; @@ -24,7 +24,7 @@ use relay_utils::FailedClient; use crate::{ message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf}, message_lane_loop::{ - MessageDeliveryParams, MessageDetailsMap, MessageProofParameters, + MessageDeliveryParams, MessageDetailsMap, MessageProofParameters, NoncesSubmitArtifacts, SourceClient as MessageLaneSourceClient, SourceClientState, TargetClient as MessageLaneTargetClient, TargetClientState, }, @@ -43,7 +43,6 @@ pub async fn run( source_state_updates: impl FusedStream>, target_client: impl MessageLaneTargetClient

, target_state_updates: impl FusedStream>, - stall_timeout: Duration, metrics_msg: Option, params: MessageDeliveryParams, ) -> Result<(), FailedClient> { @@ -60,7 +59,6 @@ pub async fn run( _phantom: Default::default(), }, target_state_updates, - stall_timeout, MessageDeliveryStrategy:: { lane_source_client: source_client, lane_target_client: target_client, @@ -174,6 +172,7 @@ where { type Error = C::Error; type TargetNoncesData = DeliveryRaceTargetNoncesData; + type TransactionTracker = C::TransactionTracker; async fn require_source_header(&self, id: SourceHeaderIdOf

) { self.client.require_source_header_on_target(id).await @@ -215,7 +214,7 @@ where generated_at_block: SourceHeaderIdOf

, nonces: RangeInclusive, proof: P::MessagesProof, - ) -> Result, Self::Error> { + ) -> Result, Self::Error> { self.client.submit_messages_proof(generated_at_block, nonces, proof).await } } diff --git a/relays/messages/src/message_race_loop.rs b/relays/messages/src/message_race_loop.rs index a7254f70ee4..15308f93032 100644 --- a/relays/messages/src/message_race_loop.rs +++ b/relays/messages/src/message_race_loop.rs @@ -20,7 +20,7 @@ //! associated data - like messages, lane state, etc) to the target node by //! generating and submitting proof. -use crate::message_lane_loop::ClientState; +use crate::message_lane_loop::{ClientState, NoncesSubmitArtifacts}; use async_trait::async_trait; use bp_messages::MessageNonce; @@ -28,7 +28,10 @@ use futures::{ future::FutureExt, stream::{FusedStream, StreamExt}, }; -use relay_utils::{process_future_result, retry_backoff, FailedClient, MaybeConnectionError}; +use relay_utils::{ + process_future_result, retry_backoff, FailedClient, MaybeConnectionError, + TrackedTransactionStatus, TransactionTracker, +}; use std::{ fmt::Debug, ops::RangeInclusive, @@ -124,6 +127,8 @@ pub trait TargetClient { type Error: std::fmt::Debug + MaybeConnectionError; /// Type of the additional data from the target client, used by the race. type TargetNoncesData: std::fmt::Debug; + /// Transaction tracker to track submitted transactions. + type TransactionTracker: TransactionTracker; /// Ask headers relay to relay finalized headers up to (and including) given header /// from race source to race target. @@ -141,7 +146,7 @@ pub trait TargetClient { generated_at_block: P::SourceHeaderId, nonces: RangeInclusive, proof: P::Proof, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; } /// Race strategy. @@ -222,7 +227,6 @@ pub async fn run, TC: TargetClient

>( race_source_updated: impl FusedStream>, race_target: TC, race_target_updated: impl FusedStream>, - stall_timeout: Duration, mut strategy: impl RaceStrategy< P::SourceHeaderId, P::TargetHeaderId, @@ -234,7 +238,6 @@ pub async fn run, TC: TargetClient

>( ) -> Result<(), FailedClient> { let mut progress_context = Instant::now(); let mut race_state = RaceState::default(); - let mut stall_countdown = Instant::now(); let mut source_retry_backoff = retry_backoff(); let mut source_client_is_online = true; @@ -250,6 +253,7 @@ pub async fn run, TC: TargetClient

>( let target_best_nonces = futures::future::Fuse::terminated(); let target_finalized_nonces = futures::future::Fuse::terminated(); let target_submit_proof = futures::future::Fuse::terminated(); + let target_tx_tracker = futures::future::Fuse::terminated(); let target_go_offline_future = futures::future::Fuse::terminated(); futures::pin_mut!( @@ -261,6 +265,7 @@ pub async fn run, TC: TargetClient

>( target_best_nonces, target_finalized_nonces, target_submit_proof, + target_tx_tracker, target_go_offline_future, ); @@ -343,11 +348,7 @@ pub async fn run, TC: TargetClient

>( nonces, ); - let prev_best_at_target = strategy.best_at_target(); strategy.best_target_nonces_updated(nonces, &mut race_state); - if strategy.best_at_target() != prev_best_at_target { - stall_countdown = Instant::now(); - } }, &mut target_go_offline_future, async_std::task::sleep, @@ -394,28 +395,74 @@ pub async fn run, TC: TargetClient

>( &mut source_go_offline_future, async_std::task::sleep, || format!("Error generating proof at {}", P::source_name()), - ).fail_if_connection_error(FailedClient::Source)?; + ).fail_if_error(FailedClient::Source).map(|_| true)?; }, proof_submit_result = target_submit_proof => { target_client_is_online = process_future_result( proof_submit_result, &mut target_retry_backoff, - |nonces_range| { + |artifacts: NoncesSubmitArtifacts| { log::debug!( target: "bridge", "Successfully submitted proof of nonces {:?} to {}", - nonces_range, + artifacts.nonces, P::target_name(), ); race_state.nonces_to_submit = None; - race_state.nonces_submitted = Some(nonces_range); - stall_countdown = Instant::now(); + race_state.nonces_submitted = Some(artifacts.nonces); + target_tx_tracker.set(artifacts.tx_tracker.wait().fuse()); }, &mut target_go_offline_future, async_std::task::sleep, || format!("Error submitting proof {}", P::target_name()), - ).fail_if_connection_error(FailedClient::Target)?; + ).fail_if_error(FailedClient::Target).map(|_| true)?; + }, + target_transaction_status = target_tx_tracker => { + match (target_transaction_status, race_state.nonces_submitted.as_ref()) { + (TrackedTransactionStatus::Finalized(at_block), Some(nonces_submitted)) => { + // our transaction has been mined, but was it successful or not? let's check the best + // nonce at the target node. + race_target.nonces(at_block, false) + .await + .map_err(|e| format!("failed to read nonces from target node: {:?}", e)) + .and_then(|(_, nonces_at_target)| { + if nonces_at_target.latest_nonce < *nonces_submitted.end() { + Err(format!( + "best nonce at target after tx is {:?} and we've submitted {:?}", + nonces_at_target.latest_nonce, + nonces_submitted.end(), + )) + } else { + Ok(()) + } + }) + .map_err(|e| { + log::error!( + target: "bridge", + "{} -> {} race has stalled. Transaction failed: {}. Going to restart", + P::source_name(), + P::target_name(), + e, + ); + + FailedClient::Both + })?; + }, + (TrackedTransactionStatus::Lost, _) => { + log::warn!( + target: "bridge", + "{} -> {} race has stalled. State: {:?}. Strategy: {:?}", + P::source_name(), + P::target_name(), + race_state, + strategy, + ); + + return Err(FailedClient::Both); + }, + _ => (), + } }, // when we're ready to retry request @@ -429,24 +476,6 @@ pub async fn run, TC: TargetClient

>( progress_context = print_race_progress::(progress_context, &strategy); - if stall_countdown.elapsed() > stall_timeout { - log::warn!( - target: "bridge", - "{} -> {} race has stalled. State: {:?}. Strategy: {:?}", - P::source_name(), - P::target_name(), - race_state, - strategy, - ); - - return Err(FailedClient::Both) - } else if race_state.nonces_to_submit.is_none() && - race_state.nonces_submitted.is_none() && - strategy.is_empty() - { - stall_countdown = Instant::now(); - } - if source_client_is_online { source_client_is_online = false; diff --git a/relays/messages/src/message_race_receiving.rs b/relays/messages/src/message_race_receiving.rs index 5aa36cbd9c6..c3d65d0e86a 100644 --- a/relays/messages/src/message_race_receiving.rs +++ b/relays/messages/src/message_race_receiving.rs @@ -16,7 +16,7 @@ use crate::{ message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf}, message_lane_loop::{ - SourceClient as MessageLaneSourceClient, SourceClientState, + NoncesSubmitArtifacts, SourceClient as MessageLaneSourceClient, SourceClientState, TargetClient as MessageLaneTargetClient, TargetClientState, }, message_race_loop::{ @@ -31,7 +31,7 @@ use async_trait::async_trait; use bp_messages::MessageNonce; use futures::stream::FusedStream; use relay_utils::FailedClient; -use std::{marker::PhantomData, ops::RangeInclusive, time::Duration}; +use std::{marker::PhantomData, ops::RangeInclusive}; /// Message receiving confirmations delivery strategy. type ReceivingConfirmationsBasicStrategy

= BasicStrategy< @@ -49,7 +49,6 @@ pub async fn run( source_state_updates: impl FusedStream>, target_client: impl MessageLaneTargetClient

, target_state_updates: impl FusedStream>, - stall_timeout: Duration, metrics_msg: Option, ) -> Result<(), FailedClient> { crate::message_race_loop::run( @@ -65,7 +64,6 @@ pub async fn run( _phantom: Default::default(), }, source_state_updates, - stall_timeout, ReceivingConfirmationsBasicStrategy::

::new(), ) .await @@ -157,6 +155,7 @@ where { type Error = C::Error; type TargetNoncesData = (); + type TransactionTracker = C::TransactionTracker; async fn require_source_header(&self, id: TargetHeaderIdOf

) { self.client.require_target_header_on_source(id).await @@ -182,9 +181,10 @@ where generated_at_block: TargetHeaderIdOf

, nonces: RangeInclusive, proof: P::MessagesReceivingProof, - ) -> Result, Self::Error> { - self.client.submit_messages_receiving_proof(generated_at_block, proof).await?; - Ok(nonces) + ) -> Result, Self::Error> { + let tx_tracker = + self.client.submit_messages_receiving_proof(generated_at_block, proof).await?; + Ok(NoncesSubmitArtifacts { nonces, tx_tracker }) } } diff --git a/relays/parachains/Cargo.toml b/relays/parachains/Cargo.toml index 60ac120d7bc..2af091c7ebb 100644 --- a/relays/parachains/Cargo.toml +++ b/relays/parachains/Cargo.toml @@ -8,12 +8,8 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] async-std = "1.6.5" async-trait = "0.1.40" -backoff = "0.2" futures = "0.3.5" -linked-hash-map = "0.5.3" log = "0.4.17" -num-traits = "0.2" -parking_lot = "0.11.0" relay-utils = { path = "../utils" } # Bridge dependencies diff --git a/relays/parachains/src/parachains_loop.rs b/relays/parachains/src/parachains_loop.rs index f44f986d632..6648f2efc72 100644 --- a/relays/parachains/src/parachains_loop.rs +++ b/relays/parachains/src/parachains_loop.rs @@ -22,13 +22,21 @@ use bp_polkadot_core::{ parachains::{ParaHash, ParaHeadsProof, ParaId}, BlockNumber as RelayBlockNumber, }; -use futures::{future::FutureExt, select}; +use futures::{ + future::{FutureExt, Shared}, + poll, select, +}; use relay_substrate_client::{BlockNumberOf, Chain, HeaderIdOf}; -use relay_utils::{metrics::MetricsParams, relay_loop::Client as RelayClient, FailedClient}; +use relay_utils::{ + metrics::MetricsParams, relay_loop::Client as RelayClient, FailedClient, + TrackedTransactionStatus, TransactionTracker, +}; use std::{ collections::{BTreeMap, BTreeSet}, future::Future, - time::{Duration, Instant}, + pin::Pin, + task::Poll, + time::Duration, }; /// Parachain heads synchronization params. @@ -115,6 +123,9 @@ pub trait SourceClient: RelayClient { /// Target client used in parachain heads synchronization loop. #[async_trait] pub trait TargetClient: RelayClient { + /// Transaction tracker to track submitted transactions. + type TransactionTracker: TransactionTracker>; + /// Get best block id. async fn best_block(&self) -> Result, Self::Error>; @@ -141,7 +152,7 @@ pub trait TargetClient: RelayClient { at_source_block: HeaderIdOf, updated_parachains: Vec<(ParaId, ParaHash)>, proof: ParaHeadsProof, - ) -> Result<(), Self::Error>; + ) -> Result; } /// Return prefix that will be used by default to expose Prometheus metrics of the parachains @@ -196,7 +207,7 @@ where P::TargetChain::AVERAGE_BLOCK_INTERVAL, ); - let mut tx_tracker: Option> = None; + let mut submitted_heads_tracker: Option> = None; futures::pin_mut!(exit_signal); @@ -246,9 +257,29 @@ where &sync_params.parachains, ) .await?; - tx_tracker = tx_tracker.take().and_then(|tx_tracker| tx_tracker.update(&heads_at_target)); - if tx_tracker.is_some() { - continue + + // check if our transaction has been mined + if let Some(tracker) = submitted_heads_tracker.take() { + match tracker.update(&best_target_block, &heads_at_target).await { + SubmittedHeadsStatus::Waiting(tracker) => { + // no news about our transaction and we shall keep waiting + submitted_heads_tracker = Some(tracker); + continue + }, + SubmittedHeadsStatus::Final(TrackedTransactionStatus::Finalized(_)) => { + // all heads have been updated, we don't need this tracker anymore + }, + SubmittedHeadsStatus::Final(TrackedTransactionStatus::Lost) => { + log::warn!( + target: "bridge", + "Parachains synchronization from {} to {} has stalled. Going to restart", + P::SourceChain::NAME, + P::TargetChain::NAME, + ); + + return Err(FailedClient::Both) + }, + } } // we have no active transaction and may need to update heads, but do we have something for @@ -317,7 +348,7 @@ where "Incorrect parachains SourceClient implementation" ); - target_client + let transaction_tracker = target_client .submit_parachain_heads_proof( best_finalized_relay_block, updated_ids.iter().cloned().zip(head_hashes).collect(), @@ -334,11 +365,10 @@ where ); FailedClient::Target })?; - - tx_tracker = Some(TransactionTracker::

::new( + submitted_heads_tracker = Some(SubmittedHeadsTracker::

::new( updated_ids, best_finalized_relay_block.0, - sync_params.stall_timeout, + transaction_tracker, )); } } @@ -494,19 +524,42 @@ async fn read_heads_at_target( Ok(para_best_head_hashes) } -/// Parachain heads transaction tracker. -struct TransactionTracker { +/// Submitted heads status. +enum SubmittedHeadsStatus { + /// Heads are not yet updated. + Waiting(SubmittedHeadsTracker

), + /// Heads transaction has either been finalized or lost (i.e. received its "final" status). + Final(TrackedTransactionStatus>), +} + +/// Type of the transaction tracker that the `SubmittedHeadsTracker` is using. +/// +/// It needs to be shared because of `poll` macro and our consuming `update` method. +type SharedTransactionTracker

= Shared< + Pin< + Box< + dyn Future< + Output = TrackedTransactionStatus< + HeaderIdOf<

::TargetChain>, + >, + > + Send, + >, + >, +>; + +/// Submitted parachain heads transaction. +struct SubmittedHeadsTracker { /// Ids of parachains which heads were updated in the tracked transaction. awaiting_update: BTreeSet, /// Number of relay chain block that has been used to craft parachain heads proof. relay_block_number: BlockNumberOf, - /// Transaction submit time. - submitted_at: Instant, - /// Transaction death time. - death_time: Instant, + /// Future that waits for submitted transaction finality or loss. + /// + /// It needs to be shared because of `poll` macro and our consuming `update` method. + transaction_tracker: SharedTransactionTracker

, } -impl TransactionTracker

+impl SubmittedHeadsTracker

where P::SourceChain: Chain, { @@ -514,22 +567,21 @@ where pub fn new( awaiting_update: impl IntoIterator, relay_block_number: BlockNumberOf, - stall_timeout: Duration, + transaction_tracker: impl TransactionTracker> + 'static, ) -> Self { - let now = Instant::now(); - TransactionTracker { + SubmittedHeadsTracker { awaiting_update: awaiting_update.into_iter().collect(), relay_block_number, - submitted_at: now, - death_time: now + stall_timeout, + transaction_tracker: transaction_tracker.wait().fuse().boxed().shared(), } } - /// Returns `None` if all parachain heads have been updated or we consider our transaction dead. - pub fn update( + /// Returns `None` if all submitted parachain heads have been updated. + pub async fn update( mut self, + at_target_block: &HeaderIdOf, heads_at_target: &BTreeMap>, - ) -> Option { + ) -> SubmittedHeadsStatus

{ // remove all pending heads that were synced for (para, best_para_head) in heads_at_target { if best_para_head @@ -554,23 +606,26 @@ where // if we have synced all required heads, we are done if self.awaiting_update.is_empty() { - return None + return SubmittedHeadsStatus::Final(TrackedTransactionStatus::Finalized( + *at_target_block, + )) } - // if our transaction is dead now, we may start over again - let now = Instant::now(); - if now >= self.death_time { - log::warn!( - target: "bridge", - "Parachain heads update transaction {} has been lost: no updates for {}s", - P::TargetChain::NAME, - (now - self.submitted_at).as_secs(), - ); - - return None + // if underlying transaction tracker has reported that the transaction is lost, we may + // then restart our sync + let transaction_tracker = self.transaction_tracker.clone(); + match poll!(transaction_tracker) { + Poll::Ready(TrackedTransactionStatus::Lost) => + return SubmittedHeadsStatus::Final(TrackedTransactionStatus::Lost), + Poll::Ready(TrackedTransactionStatus::Finalized(_)) => { + // so we are here and our transaction is mined+finalized, but some of heads were not + // updated => we're considering our loop as stalled + return SubmittedHeadsStatus::Final(TrackedTransactionStatus::Lost) + }, + _ => (), } - Some(self) + SubmittedHeadsStatus::Waiting(self) } } @@ -613,6 +668,21 @@ mod tests { data: Arc>, } + #[derive(Clone, Debug)] + struct TestTransactionTracker(Option>>); + + #[async_trait] + impl TransactionTracker for TestTransactionTracker { + type HeaderId = HeaderIdOf; + + async fn wait(self) -> TrackedTransactionStatus> { + match self.0 { + Some(status) => status, + None => futures::future::pending().await, + } + } + } + #[derive(Clone, Debug)] struct TestClientData { source_sync_status: Result, @@ -711,6 +781,8 @@ mod tests { #[async_trait] impl TargetClient for TestClient { + type TransactionTracker = TestTransactionTracker; + async fn best_block(&self) -> Result, TestError> { self.data.lock().await.target_best_block.clone() } @@ -736,13 +808,16 @@ mod tests { _at_source_block: HeaderIdOf, _updated_parachains: Vec<(ParaId, ParaHash)>, _proof: ParaHeadsProof, - ) -> Result<(), Self::Error> { - self.data.lock().await.target_submit_result.clone()?; + ) -> Result { + let mut data = self.data.lock().await; + data.target_submit_result.clone()?; - if let Some(mut exit_signal_sender) = self.data.lock().await.exit_signal_sender.take() { + if let Some(mut exit_signal_sender) = data.exit_signal_sender.take() { exit_signal_sender.send(()).await.unwrap(); } - Ok(()) + Ok(TestTransactionTracker(Some( + TrackedTransactionStatus::Finalized(Default::default()), + ))) } } @@ -891,29 +966,62 @@ mod tests { const PARA_1_ID: u32 = PARA_ID + 1; const SOURCE_BLOCK_NUMBER: u32 = 100; - fn test_tx_tracker() -> TransactionTracker { - TransactionTracker::new( + fn test_tx_tracker() -> SubmittedHeadsTracker { + SubmittedHeadsTracker::new( vec![ParaId(PARA_ID), ParaId(PARA_1_ID)], SOURCE_BLOCK_NUMBER, - Duration::from_secs(1), + TestTransactionTracker(None), ) } - #[test] - fn tx_tracker_update_when_nothing_is_updated() { + fn all_expected_tracker_heads() -> BTreeMap> { + vec![ + ( + ParaId(PARA_ID), + Some(BestParaHeadHash { + at_relay_block_number: SOURCE_BLOCK_NUMBER, + head_hash: PARA_0_HASH, + }), + ), + ( + ParaId(PARA_1_ID), + Some(BestParaHeadHash { + at_relay_block_number: SOURCE_BLOCK_NUMBER, + head_hash: PARA_0_HASH, + }), + ), + ] + .into_iter() + .collect() + } + + impl From> for Option> { + fn from(status: SubmittedHeadsStatus) -> Option> { + match status { + SubmittedHeadsStatus::Waiting(tracker) => Some(tracker.awaiting_update), + _ => None, + } + } + } + + #[async_std::test] + async fn tx_tracker_update_when_nothing_is_updated() { assert_eq!( - test_tx_tracker() - .update(&vec![].into_iter().collect()) - .map(|t| t.awaiting_update), Some(test_tx_tracker().awaiting_update), + test_tx_tracker() + .update(&HeaderId(0, Default::default()), &vec![].into_iter().collect()) + .await + .into(), ); } - #[test] - fn tx_tracker_update_when_one_of_heads_is_updated_to_previous_value() { + #[async_std::test] + async fn tx_tracker_update_when_one_of_heads_is_updated_to_previous_value() { assert_eq!( + Some(test_tx_tracker().awaiting_update), test_tx_tracker() .update( + &HeaderId(0, Default::default()), &vec![( ParaId(PARA_ID), Some(BestParaHeadHash { @@ -924,16 +1032,18 @@ mod tests { .into_iter() .collect() ) - .map(|t| t.awaiting_update), - Some(test_tx_tracker().awaiting_update), + .await + .into(), ); } - #[test] - fn tx_tracker_update_when_one_of_heads_is_updated() { + #[async_std::test] + async fn tx_tracker_update_when_one_of_heads_is_updated() { assert_eq!( + Some(vec![ParaId(PARA_1_ID)].into_iter().collect::>()), test_tx_tracker() .update( + &HeaderId(0, Default::default()), &vec![( ParaId(PARA_ID), Some(BestParaHeadHash { @@ -944,48 +1054,63 @@ mod tests { .into_iter() .collect() ) - .map(|t| t.awaiting_update), - Some(vec![ParaId(PARA_1_ID)].into_iter().collect()), + .await + .into(), ); } - #[test] - fn tx_tracker_update_when_all_heads_are_updated() { + #[async_std::test] + async fn tx_tracker_update_when_all_heads_are_updated() { assert_eq!( + Option::>::None, test_tx_tracker() - .update( - &vec![ - ( - ParaId(PARA_ID), - Some(BestParaHeadHash { - at_relay_block_number: SOURCE_BLOCK_NUMBER, - head_hash: PARA_0_HASH, - }) - ), - ( - ParaId(PARA_1_ID), - Some(BestParaHeadHash { - at_relay_block_number: SOURCE_BLOCK_NUMBER, - head_hash: PARA_0_HASH, - }) - ), - ] - .into_iter() - .collect() - ) - .map(|t| t.awaiting_update), - None, + .update(&HeaderId(0, Default::default()), &all_expected_tracker_heads()) + .await + .into(), ); } - #[test] - fn tx_tracker_update_when_tx_is_stalled() { + #[async_std::test] + async fn tx_tracker_update_when_tx_is_lost() { let mut tx_tracker = test_tx_tracker(); - tx_tracker.death_time = Instant::now(); - assert_eq!( - tx_tracker.update(&vec![].into_iter().collect()).map(|t| t.awaiting_update), - None, - ); + tx_tracker.transaction_tracker = + futures::future::ready(TrackedTransactionStatus::Lost).boxed().shared(); + assert!(matches!( + tx_tracker + .update(&HeaderId(0, Default::default()), &vec![].into_iter().collect()) + .await, + SubmittedHeadsStatus::Final(TrackedTransactionStatus::Lost), + )); + } + + #[async_std::test] + async fn tx_tracker_update_when_tx_is_finalized_but_heads_are_not_updated() { + let mut tx_tracker = test_tx_tracker(); + tx_tracker.transaction_tracker = + futures::future::ready(TrackedTransactionStatus::Finalized(Default::default())) + .boxed() + .shared(); + assert!(matches!( + tx_tracker + .update(&HeaderId(0, Default::default()), &vec![].into_iter().collect()) + .await, + SubmittedHeadsStatus::Final(TrackedTransactionStatus::Lost), + )); + } + + #[async_std::test] + async fn tx_tracker_update_when_tx_is_finalized_and_heads_are_updated() { + let mut tx_tracker = test_tx_tracker(); + tx_tracker.transaction_tracker = + futures::future::ready(TrackedTransactionStatus::Finalized(Default::default())) + .boxed() + .shared(); + assert!(matches!( + tx_tracker + .update(&HeaderId(0, Default::default()), &all_expected_tracker_heads()) + .await, + SubmittedHeadsStatus::Final(TrackedTransactionStatus::Finalized(_)), + )); } #[test] diff --git a/relays/utils/src/lib.rs b/relays/utils/src/lib.rs index dbc8e5df821..eb3d8ec7525 100644 --- a/relays/utils/src/lib.rs +++ b/relays/utils/src/lib.rs @@ -122,18 +122,21 @@ pub trait MaybeConnectionError { /// Final status of the tracked transaction. #[derive(Debug, Clone, Copy, PartialEq)] -pub enum TrackedTransactionStatus { +pub enum TrackedTransactionStatus { /// Transaction has been lost. Lost, - /// Transaction has been mined and finalized. - Finalized, + /// Transaction has been mined and finalized at given block. + Finalized(BlockId), } /// Transaction tracker. #[async_trait] pub trait TransactionTracker: Send { + /// Header id, used by the chain. + type HeaderId: Clone + Send; + /// Wait until transaction is either finalized or invalidated/lost. - async fn wait(self) -> TrackedTransactionStatus; + async fn wait(self) -> TrackedTransactionStatus; } /// Stringified error that may be either connection-related or not. @@ -236,6 +239,16 @@ impl ProcessFutureResult { } } + /// Returns `Ok(())` if future has succeeded. + /// Returns `Err(failed_client)` otherwise. + pub fn fail_if_error(self, failed_client: FailedClient) -> Result<(), FailedClient> { + if self.is_ok() { + Ok(()) + } else { + Err(failed_client) + } + } + /// Returns Ok(true) if future has succeeded. /// Returns Ok(false) if future has failed with non-connection error. /// Returns Err if future is `ConnectionFailed`.