diff --git a/Cargo.lock b/Cargo.lock index cda1aeb82..88d64b682 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,6 +634,7 @@ dependencies = [ "frame-support", "parity-scale-codec", "scale-info", + "sp-runtime", "sp-std", ] @@ -1580,7 +1581,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", ] @@ -1598,7 +1599,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "frame-support", "frame-system", @@ -1632,7 +1633,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "bitflags", "frame-metadata", @@ -1662,7 +1663,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "Inflector", "frame-support-procedural-tools", @@ -1674,7 +1675,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -1686,7 +1687,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "proc-macro2", "quote", @@ -1696,7 +1697,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "frame-support", "log", @@ -2668,7 +2669,7 @@ dependencies = [ "libp2p-request-response", "libp2p-swarm", "log", - "prost", + "prost 0.9.0", "prost-build", "rand 0.8.5", ] @@ -2695,7 +2696,7 @@ dependencies = [ "multistream-select", "parking_lot 0.12.1", "pin-project 1.0.10", - "prost", + "prost 0.9.0", "prost-build", "rand 0.8.5", "ring", @@ -2745,7 +2746,7 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "prost", + "prost 0.9.0", "prost-build", "rand 0.7.3", "smallvec", @@ -2769,7 +2770,7 @@ dependencies = [ "libp2p-swarm", "log", "prometheus-client", - "prost", + "prost 0.9.0", "prost-build", "rand 0.7.3", "regex", @@ -2791,7 +2792,7 @@ dependencies = [ "libp2p-swarm", "log", "lru", - "prost", + "prost 0.9.0", "prost-build", "smallvec", ] @@ -2813,7 +2814,7 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "prost", + "prost 0.9.0", "prost-build", "rand 0.7.3", "sha2 0.10.2", @@ -2891,7 +2892,7 @@ dependencies = [ "lazy_static", "libp2p-core", "log", - "prost", + "prost 0.9.0", "prost-build", "rand 0.8.5", "sha2 0.10.2", @@ -2928,7 +2929,7 @@ dependencies = [ "futures", "libp2p-core", "log", - "prost", + "prost 0.9.0", "prost-build", "unsigned-varint", "void", @@ -2964,7 +2965,7 @@ dependencies = [ "libp2p-swarm", "log", "pin-project 1.0.10", - "prost", + "prost 0.9.0", "prost-build", "rand 0.8.5", "smallvec", @@ -2988,7 +2989,7 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "prost", + "prost 0.9.0", "prost-build", "rand 0.8.5", "sha2 0.10.2", @@ -3727,7 +3728,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "frame-benchmarking", "frame-support", @@ -3846,46 +3847,10 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-session" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" -dependencies = [ - "frame-support", - "frame-system", - "impl-trait-for-tuples", - "log", - "pallet-timestamp", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-session", - "sp-staking", - "sp-std", - "sp-trie", -] - -[[package]] -name = "pallet-shift-session-manager" -version = "0.1.0" -dependencies = [ - "frame-support", - "frame-system", - "pallet-session", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-runtime", - "sp-staking", - "sp-std", -] - [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "frame-benchmarking", "frame-support", @@ -3902,14 +3867,13 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", "serde", - "smallvec", "sp-core", "sp-io", "sp-runtime", @@ -3919,7 +3883,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -4295,7 +4259,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.9.0", +] + +[[package]] +name = "prost" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71adf41db68aa0daaefc69bb30bcd68ded9b9abaad5d1fbb6304c4fb390e083e" +dependencies = [ + "bytes", + "prost-derive 0.10.1", ] [[package]] @@ -4311,7 +4285,7 @@ dependencies = [ "log", "multimap", "petgraph", - "prost", + "prost 0.9.0", "prost-types", "regex", "tempfile", @@ -4331,6 +4305,19 @@ dependencies = [ "syn", ] +[[package]] +name = "prost-derive" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b670f45da57fb8542ebdbb6105a925fe571b67f9e7ed9f47a06a84e72b4e7cc" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "prost-types" version = "0.9.0" @@ -4338,7 +4325,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534b7a0e836e3c482d2693070f982e39e7611da9695d4d1f5a4b186b51faef0a" dependencies = [ "bytes", - "prost", + "prost 0.9.0", ] [[package]] @@ -4837,7 +4824,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "log", "sp-core", @@ -4848,7 +4835,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -4864,7 +4851,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "impl-trait-for-tuples", "memmap2", @@ -4881,7 +4868,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -4892,7 +4879,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "fnv", "futures", @@ -4920,7 +4907,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "async-trait", "futures", @@ -4944,7 +4931,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "lazy_static", "lru", @@ -4970,7 +4957,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "environmental", "parity-scale-codec", @@ -4987,7 +4974,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "log", "parity-scale-codec", @@ -5002,7 +4989,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "async-trait", "asynchronous-codec", @@ -5024,13 +5011,14 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "pin-project 1.0.10", - "prost", + "prost 0.10.4", "prost-build", "rand 0.7.3", "sc-block-builder", "sc-client-api", "sc-consensus", "sc-network-common", + "sc-network-light", "sc-network-sync", "sc-peerset", "sc-utils", @@ -5053,7 +5041,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "libp2p", @@ -5063,10 +5051,30 @@ dependencies = [ "smallvec", ] +[[package]] +name = "sc-network-light" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" +dependencies = [ + "futures", + "libp2p", + "log", + "parity-scale-codec", + "prost 0.10.4", + "prost-build", + "sc-client-api", + "sc-network-common", + "sc-peerset", + "sp-blockchain", + "sp-core", + "sp-runtime", + "thiserror", +] + [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "bitflags", "either", @@ -5076,7 +5084,7 @@ dependencies = [ "log", "lru", "parity-scale-codec", - "prost", + "prost 0.10.4", "prost-build", "sc-client-api", "sc-consensus", @@ -5095,7 +5103,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "libp2p", @@ -5108,7 +5116,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "jsonrpsee 0.13.1", @@ -5131,7 +5139,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "chrono", "futures", @@ -5149,7 +5157,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "log", @@ -5162,7 +5170,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "futures-timer", @@ -5532,7 +5540,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "hash-db", "log", @@ -5549,7 +5557,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "blake2", "proc-macro-crate", @@ -5561,7 +5569,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", "scale-info", @@ -5574,7 +5582,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "integer-sqrt", "num-traits", @@ -5589,7 +5597,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", "sp-api", @@ -5601,7 +5609,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "log", @@ -5619,7 +5627,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "async-trait", "futures", @@ -5638,7 +5646,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "base58", "bitflags", @@ -5684,7 +5692,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "blake2", "byteorder", @@ -5698,7 +5706,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "proc-macro2", "quote", @@ -5709,7 +5717,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -5718,7 +5726,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "proc-macro2", "quote", @@ -5728,7 +5736,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "environmental", "parity-scale-codec", @@ -5739,7 +5747,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "finality-grandpa", "log", @@ -5757,7 +5765,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -5771,7 +5779,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures", "hash-db", @@ -5796,7 +5804,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "async-trait", "futures", @@ -5812,7 +5820,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "thiserror", "zstd", @@ -5821,7 +5829,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "backtrace", "lazy_static", @@ -5831,7 +5839,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "rustc-hash", "serde", @@ -5841,7 +5849,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "either", "hash256-std-hasher", @@ -5863,7 +5871,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -5880,7 +5888,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "Inflector", "proc-macro-crate", @@ -5892,7 +5900,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "log", "parity-scale-codec", @@ -5906,30 +5914,16 @@ dependencies = [ [[package]] name = "sp-serializer" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "serde", "serde_json", ] -[[package]] -name = "sp-session" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" -dependencies = [ - "parity-scale-codec", - "scale-info", - "sp-api", - "sp-core", - "sp-runtime", - "sp-staking", - "sp-std", -] - [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", "scale-info", @@ -5940,7 +5934,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "hash-db", "log", @@ -5962,12 +5956,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "impl-serde", "parity-scale-codec", @@ -5980,7 +5974,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "log", "sp-core", @@ -5993,7 +5987,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "async-trait", "futures-timer", @@ -6009,7 +6003,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", "sp-std", @@ -6021,7 +6015,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "hash-db", "memory-db", @@ -6037,7 +6031,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "impl-serde", "parity-scale-codec", @@ -6054,7 +6048,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -6065,7 +6059,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "impl-trait-for-tuples", "log", @@ -6136,7 +6130,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.22#616d33ea23bab86cafffaf116fc607b6790fb4eb" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.23#76522d7937ba94ff1becef4e4e3ca78e3e1de341" dependencies = [ "futures-util", "hyper", diff --git a/bin/runtime-common/Cargo.toml b/bin/runtime-common/Cargo.toml index c3cf5eec2..c0845c6dc 100644 --- a/bin/runtime-common/Cargo.toml +++ b/bin/runtime-common/Cargo.toml @@ -25,17 +25,17 @@ pallet-bridge-messages = { path = "../../modules/messages", default-features = f # Substrate dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false, optional = true } -pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false, optional = true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false, optional = true } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false, optional = true } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false, optional = true } [features] default = ["std"] diff --git a/bin/runtime-common/src/messages.rs b/bin/runtime-common/src/messages.rs index d53887192..ad1082bb2 100644 --- a/bin/runtime-common/src/messages.rs +++ b/bin/runtime-common/src/messages.rs @@ -33,7 +33,7 @@ use bp_runtime::{ use codec::{Decode, DecodeLimit, Encode}; use frame_support::{ traits::{Currency, ExistenceRequirement}, - weights::{Weight, WeightToFeePolynomial}, + weights::{Weight, WeightToFee}, RuntimeDebug, }; use hash_db::Hasher; @@ -523,7 +523,7 @@ pub mod target { /// /// Our Call is opaque (`Vec`) for Bridged chain. So it is encoded, prefixed with /// vector length. Custom decode implementation here is exactly to deal with this. - #[derive(Decode, Encode, RuntimeDebug, PartialEq)] + #[derive(Decode, Encode, Clone, RuntimeDebug, PartialEq)] pub struct FromBridgedChainEncodedMessageCall { encoded_call: Vec, _marker: PhantomData, @@ -536,18 +536,6 @@ pub mod target { } } - impl From> - for Result - { - fn from(encoded_call: FromBridgedChainEncodedMessageCall) -> Self { - DecodedCall::decode_with_depth_limit( - sp_api::MAX_EXTRINSIC_DEPTH, - &mut &encoded_call.encoded_call[..], - ) - .map_err(drop) - } - } - /// Dispatching Bridged -> This chain messages. #[derive(RuntimeDebug, Clone, Copy)] pub struct FromBridgedChainMessageDispatch { @@ -585,6 +573,16 @@ pub mod target { message.data.payload.as_ref().map(|payload| payload.weight).unwrap_or(0) } + fn pre_dispatch( + relayer_account: &AccountIdOf>, + message: &DispatchMessage>>, + ) -> Result<(), &'static str> { + pallet_bridge_dispatch::Pallet::::pre_dispatch( + relayer_account, + message.data.payload.as_ref().map_err(drop), + ) + } + fn dispatch( relayer_account: &AccountIdOf>, message: DispatchMessage>>, @@ -593,10 +591,11 @@ pub mod target { pallet_bridge_dispatch::Pallet::::dispatch( B::BRIDGED_CHAIN_ID, B::THIS_CHAIN_ID, + relayer_account, message_id, message.data.payload.map_err(drop), |dispatch_origin, dispatch_weight| { - let unadjusted_weight_fee = ThisRuntime::WeightToFee::calc(&dispatch_weight); + let unadjusted_weight_fee = ThisRuntime::WeightToFee::weight_to_fee(&dispatch_weight); let fee_multiplier = pallet_transaction_payment::Pallet::::next_fee_multiplier(); let adjusted_weight_fee = @@ -617,6 +616,18 @@ pub mod target { } } + impl From> + for Result + { + fn from(encoded_call: FromBridgedChainEncodedMessageCall) -> Self { + DecodedCall::decode_with_depth_limit( + sp_api::MAX_EXTRINSIC_DEPTH, + &mut &encoded_call.encoded_call[..], + ) + .map_err(drop) + } + } + /// Return maximal dispatch weight of the message we're able to receive. pub fn maximal_incoming_message_dispatch_weight(maximal_extrinsic_weight: Weight) -> Weight { maximal_extrinsic_weight / 2 diff --git a/modules/dispatch/Cargo.toml b/modules/dispatch/Cargo.toml index 6ddc7cc6e..31f93d459 100644 --- a/modules/dispatch/Cargo.toml +++ b/modules/dispatch/Cargo.toml @@ -18,14 +18,14 @@ bp-runtime = { path = "../../primitives/runtime", default-features = false } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 56b3c7a60..8c08e34f2 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -25,7 +25,9 @@ // Generated by `decl_event!` #![allow(clippy::unused_unit)] -use bp_message_dispatch::{CallOrigin, MessageDispatch, MessagePayload, SpecVersion}; +use bp_message_dispatch::{ + CallOrigin, CallValidate, IntoDispatchOrigin, MessageDispatch, MessagePayload, SpecVersion, +}; use bp_runtime::{ derive_account_id, messages::{DispatchFeePayment, MessageDispatchResult}, @@ -33,13 +35,14 @@ use bp_runtime::{ }; use codec::Encode; use frame_support::{ - dispatch::Dispatchable, + dispatch::{DispatchInfo, DispatchResultWithPostInfo, Dispatchable, Weight}, ensure, - traits::{Contains, Get}, - weights::{extract_actual_weight, GetDispatchInfo}, + pallet_prelude::Pays, + traits::Get, + weights::GetDispatchInfo, }; use frame_system::RawOrigin; -use sp_runtime::traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify}; +use sp_runtime::traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify, Zero}; use sp_std::{fmt::Debug, prelude::*}; pub use pallet::*; @@ -77,22 +80,28 @@ pub mod pallet { Origin = ::Origin, PostInfo = frame_support::dispatch::PostDispatchInfo, >; - /// Pre-dispatch filter for incoming calls. + /// Pre-dispatch validation for incoming calls. /// - /// The pallet will filter all incoming calls right before they're dispatched. If this - /// filter rejects the call, special event (`Event::MessageCallRejected`) is emitted. - type CallFilter: Contains<>::Call>; + /// The pallet will validate all incoming calls right before they're dispatched. If this + /// validator rejects the call, special event (`Event::MessageCallRejected`) is emitted. + type CallValidator: CallValidate>::Call>; /// The type that is used to wrap the `Self::Call` when it is moved over bridge. /// /// The idea behind this is to avoid `Call` conversion/decoding until we'll be sure /// that all other stuff (like `spec_version`) is ok. If we would try to decode /// `Call` which has been encoded using previous `spec_version`, then we might end /// up with decoding error, instead of `MessageVersionSpecMismatch`. - type EncodedCall: Decode + Encode + Into>::Call, ()>>; + type EncodedCall: Decode + Encode + Into>::Call, ()>> + Clone; /// A type which can be turned into an AccountId from a 256-bit hash. /// /// Used when deriving target chain AccountIds from source chain AccountIds. type AccountIdConverter: sp_runtime::traits::Convert; + /// The type is used to customize the dispatch call origin. + type IntoDispatchOrigin: IntoDispatchOrigin< + Self::AccountId, + >::Call, + Self::Origin, + >; } type BridgeMessageIdOf = >::BridgeMessageId; @@ -150,9 +159,30 @@ impl, I: 'static> MessageDispatch message.weight } + fn pre_dispatch( + relayer_account: &T::AccountId, + message: Result<&Self::Message, ()>, + ) -> Result<(), &'static str> { + match message { + Ok(raw_message) => + if let Ok(call) = raw_message.clone().call.into() { + return T::CallValidator::check_receiving_before_dispatch(relayer_account, &call) + }, + Err(_) => { + log::trace!( + target: "runtime::bridge-dispatch", + "Message will be rejected in dispatch, still Ok here", + ); + }, + } + + Ok(()) + } + fn dispatch Result<(), ()>>( source_chain: ChainId, target_chain: ChainId, + relayer_account: &T::AccountId, id: T::BridgeMessageId, message: Result, pay_dispatch_fee: P, @@ -217,7 +247,7 @@ impl, I: 'static> MessageDispatch }; // prepare dispatch origin - let origin_account = match message.origin { + let origin_derived_account = match message.origin { CallOrigin::SourceRoot => { let hex_id = derive_account_id::(source_chain, SourceAccount::Root); @@ -260,8 +290,12 @@ impl, I: 'static> MessageDispatch }, }; - // filter the call - if !T::CallFilter::contains(&call) { + // generate dispatch origin from origin account + let dispatch_origin = + T::IntoDispatchOrigin::into_dispatch_origin(&origin_derived_account, &call); + + // validate the call + if let Err(_e) = T::CallValidator::call_validate(relayer_account, &dispatch_origin, &call) { log::trace!( target: "runtime::bridge-dispatch", "Message {:?}/{:?}: the call ({:?}) is rejected by filter", @@ -269,6 +303,7 @@ impl, I: 'static> MessageDispatch id, call, ); + // TODO: https://github.com/paritytech/substrate/pull/11599 Self::deposit_event(Event::MessageCallRejected(source_chain, id)); return dispatch_result; } @@ -300,7 +335,7 @@ impl, I: 'static> MessageDispatch let pay_dispatch_fee_at_target_chain = message.dispatch_fee_payment == DispatchFeePayment::AtTargetChain; if pay_dispatch_fee_at_target_chain - && pay_dispatch_fee(&origin_account, message.weight).is_err() + && pay_dispatch_fee(&origin_derived_account, message.weight).is_err() { log::trace!( target: "runtime::bridge-dispatch", @@ -312,18 +347,15 @@ impl, I: 'static> MessageDispatch Self::deposit_event(Event::MessageDispatchPaymentFailed( source_chain, id, - origin_account, + origin_derived_account, message.weight, )); return dispatch_result; } dispatch_result.dispatch_fee_paid_during_dispatch = pay_dispatch_fee_at_target_chain; - // finally dispatch message - let origin = RawOrigin::Signed(origin_account).into(); - log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:.4096?}", &call); - let result = call.dispatch(origin); + let result = call.dispatch(dispatch_origin); let actual_call_weight = extract_actual_weight(&result, &dispatch_info); dispatch_result.dispatch_result = result.is_ok(); dispatch_result.unspent_weight = message.weight.saturating_sub(actual_call_weight); @@ -349,6 +381,17 @@ impl, I: 'static> MessageDispatch } } +fn extract_actual_weight(result: &DispatchResultWithPostInfo, info: &DispatchInfo) -> Weight { + let post_info = match result { + Ok(post_info) => &post_info, + Err(err) => &err.post_info, + }; + match post_info.pays_fee { + Pays::Yes => post_info.calc_actual_weight(info), + Pays::No => Weight::zero(), + } +} + /// Check if the message is allowed to be dispatched on the target chain given the sender's origin /// on the source chain. /// @@ -433,6 +476,7 @@ mod tests { use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, + transaction_validity::{InvalidTransaction, TransactionValidityError}, Perbill, }; @@ -526,15 +570,16 @@ mod tests { type AccountIdConverter = AccountIdConverter; type BridgeMessageId = BridgeMessageId; type Call = Call; - type CallFilter = TestCallFilter; + type CallValidator = CallValidator; type EncodedCall = EncodedCall; type Event = Event; + type IntoDispatchOrigin = TestIntoDispatchOrigin; type SourceChainAccountId = AccountId; type TargetChainAccountPublic = TestAccountPublic; type TargetChainSignature = TestSignature; } - #[derive(Decode, Encode)] + #[derive(Decode, Encode, Clone)] pub struct EncodedCall(Vec); impl From for Result { @@ -543,11 +588,33 @@ mod tests { } } - pub struct TestCallFilter; + pub struct CallValidator; + impl CallValidate for CallValidator { + fn check_receiving_before_dispatch( + _relayer_account: &AccountId, + _call: &Call, + ) -> Result<(), &'static str> { + Ok(()) + } + + fn call_validate( + _relayer_account: &AccountId, + _origin: &Origin, + call: &Call, + ) -> Result<(), TransactionValidityError> { + match call { + Call::System(frame_system::Call::fill_block { .. }) => + Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), + _ => Ok(()), + } + } + } + + pub struct TestIntoDispatchOrigin; - impl Contains for TestCallFilter { - fn contains(call: &Call) -> bool { - !matches!(*call, Call::System(frame_system::Call::fill_block { .. })) + impl IntoDispatchOrigin for TestIntoDispatchOrigin { + fn into_dispatch_origin(id: &AccountId, _call: &Call) -> Origin { + frame_system::RawOrigin::Signed(*id).into() } } @@ -608,6 +675,7 @@ mod tests { fn should_fail_on_spec_version_mismatch() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; const BAD_SPEC_VERSION: SpecVersion = 99; let mut message = prepare_root_message(Call::System(frame_system::Call::remark { @@ -620,6 +688,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -649,6 +718,7 @@ mod tests { fn should_fail_on_weight_mismatch() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let call = Call::System(frame_system::Call::set_heap_pages { pages: 42 }); let call_weight = call.get_dispatch_info().weight; let mut message = prepare_root_message(call); @@ -659,6 +729,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -688,6 +759,7 @@ mod tests { fn should_fail_on_signature_mismatch() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let call_origin = CallOrigin::TargetAccount(1, TestAccountPublic(1), TestSignature(99)); let message = prepare_message( @@ -700,6 +772,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -727,11 +800,13 @@ mod tests { fn should_emit_event_for_rejected_messages() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; System::set_block_number(1); Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Err(()), |_, _| unreachable!(), @@ -755,6 +830,7 @@ mod tests { fn should_fail_on_call_decode() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let mut message = prepare_root_message(Call::System(frame_system::Call::remark { remark: vec![1, 2, 3], @@ -766,6 +842,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -793,6 +870,7 @@ mod tests { fn should_emit_event_for_rejected_calls() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let call = Call::System(frame_system::Call::fill_block { ratio: Perbill::from_percent(75) }); @@ -804,6 +882,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -831,6 +910,7 @@ mod tests { fn should_emit_event_for_unpaid_calls() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let mut message = prepare_root_message(Call::System(frame_system::Call::remark { remark: vec![1, 2, 3], @@ -839,10 +919,14 @@ mod tests { message.dispatch_fee_payment = DispatchFeePayment::AtTargetChain; System::set_block_number(1); - let result = - Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| { - Err(()) - }); + let result = Dispatch::dispatch( + SOURCE_CHAIN_ID, + TARGET_CHAIN_ID, + &relayer_account, + id, + Ok(message), + |_, _| Err(()), + ); assert_eq!(result.unspent_weight, weight); assert!(!result.dispatch_result); @@ -871,6 +955,7 @@ mod tests { fn should_dispatch_calls_paid_at_target_chain() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let mut message = prepare_root_message(Call::System(frame_system::Call::remark { remark: vec![1, 2, 3], @@ -881,6 +966,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| Ok(()), @@ -907,6 +993,7 @@ mod tests { fn should_return_dispatch_failed_flag_if_dispatch_happened_but_failed() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let call = Call::System(frame_system::Call::set_heap_pages { pages: 1 }); let message = prepare_target_message(call); @@ -915,6 +1002,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -941,6 +1029,7 @@ mod tests { fn should_dispatch_bridge_message_from_root_origin() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let message = prepare_root_message(Call::System(frame_system::Call::remark { remark: vec![1, 2, 3], })); @@ -949,6 +1038,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -975,6 +1065,7 @@ mod tests { fn should_dispatch_bridge_message_from_target_origin() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let call = Call::System(frame_system::Call::remark { remark: vec![] }); let message = prepare_target_message(call); @@ -983,6 +1074,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), @@ -1009,6 +1101,7 @@ mod tests { fn should_dispatch_bridge_message_from_source_origin() { new_test_ext().execute_with(|| { let id = [0; 4]; + let relayer_account = 1; let call = Call::System(frame_system::Call::remark { remark: vec![] }); let message = prepare_source_message(call); @@ -1017,6 +1110,7 @@ mod tests { let result = Dispatch::dispatch( SOURCE_CHAIN_ID, TARGET_CHAIN_ID, + &relayer_account, id, Ok(message), |_, _| unreachable!(), diff --git a/modules/fee-market/Cargo.toml b/modules/fee-market/Cargo.toml index d50a980bf..cc146e814 100644 --- a/modules/fee-market/Cargo.toml +++ b/modules/fee-market/Cargo.toml @@ -15,21 +15,21 @@ bitvec = { version = "1", default-features = false, features = ["alloc"] } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } # paritytech -frame-benchmarking = { optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-benchmarking = { optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } # darwinia-bridges-substrate bp-messages = { default-features = false, path = "../../primitives/messages" } bp-runtime = { default-features = false, path = "../../primitives/runtime" } pallet-bridge-messages = { default-features = false, path = "../messages" } [dev-dependencies] -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/modules/fee-market/src/lib.rs b/modules/fee-market/src/lib.rs index 348f4da04..310570917 100644 --- a/modules/fee-market/src/lib.rs +++ b/modules/fee-market/src/lib.rs @@ -47,6 +47,7 @@ use sp_runtime::{ }; use sp_std::vec::Vec; // --- darwinia-network --- +use s2s::RewardItem; use types::{Order, Relayer, SlashReport}; pub type AccountId = ::AccountId; @@ -107,6 +108,17 @@ pub mod pallet { UpdateAssignedRelayersNumber(u32), /// Slash report FeeMarketSlash(SlashReport>), + /// Create new order. \[lane_id, message_nonce, order_fee, assigned_relayers, + /// out_of_slots_time\] + OrderCreated( + LaneId, + MessageNonce, + BalanceOf, + Vec, + Option, + ), + /// Reward distribute of the order. \[lane_id, message_nonce, rewards\] + OrderReward(LaneId, MessageNonce, RewardItem>), } #[pallet::error] diff --git a/modules/fee-market/src/s2s/callbacks.rs b/modules/fee-market/src/s2s/callbacks.rs index 8a301cfdb..4ba1a470b 100644 --- a/modules/fee-market/src/s2s/callbacks.rs +++ b/modules/fee-market/src/s2s/callbacks.rs @@ -37,15 +37,25 @@ impl, I: 'static> OnMessageAccepted for FeeMarketMessageAcceptedHan *message, now, T::CollateralPerOrder::get(), - assigned_relayers, + assigned_relayers.clone(), T::Slot::get(), ); // Store the create order - >::insert((order.lane, order.message), order); + >::insert((order.lane, order.message), order.clone()); + + let ids: Vec = assigned_relayers.iter().map(|r| r.id.clone()).collect(); + Pallet::::deposit_event(Event::OrderCreated( + order.lane, + order.message, + order.fee(), + ids, + order.range_end(), + )); } - // one read for assigned relayers - // one write for store order + // Storage: FeeMarket AssignedRelayers (r:1 w:0) + // Storage: FeeMarket Orders (r:0 w:1) + // Storage: System Events (r:0 w:1) ::DbWeight::get().reads_writes(1, 1) } } @@ -66,8 +76,7 @@ impl, I: 'static> OnDeliveryConfirmed for FeeMarketMessageConfirmed } } - // one db read for get order - // one db write for update order confirm time + // Storage: FeeMarket Orders (r:1 w:1) ::DbWeight::get().reads_writes(1, 1) } } diff --git a/modules/fee-market/src/s2s/mod.rs b/modules/fee-market/src/s2s/mod.rs index 1aaa10195..5321950d1 100644 --- a/modules/fee-market/src/s2s/mod.rs +++ b/modules/fee-market/src/s2s/mod.rs @@ -17,7 +17,7 @@ // along with Darwinia. If not, see . pub mod payment; -pub use payment::FeeMarketPayment; +pub use payment::{FeeMarketPayment, RewardItem}; pub mod callbacks; pub use callbacks::{FeeMarketMessageAcceptedHandler, FeeMarketMessageConfirmedHandler}; diff --git a/modules/fee-market/src/s2s/payment.rs b/modules/fee-market/src/s2s/payment.rs index c7896b852..efc375c04 100644 --- a/modules/fee-market/src/s2s/payment.rs +++ b/modules/fee-market/src/s2s/payment.rs @@ -25,6 +25,7 @@ use frame_support::{ log, traits::{Currency as CurrencyT, ExistenceRequirement, Get}, }; +use scale_info::TypeInfo; use sp_runtime::traits::{AccountIdConversion, Saturating, Zero}; use sp_std::{ collections::{btree_map::BTreeMap, vec_deque::VecDeque}, @@ -89,61 +90,54 @@ where received_range: &RangeInclusive, relayer_fund_account: &T::AccountId, ) { - let RewardsBook { - messages_relayers_rewards, - confirmation_relayer_rewards, - assigned_relayers_rewards, - treasury_total_rewards, - } = slash_and_calculate_rewards::( - lane_id, - messages_relayers, - received_range, - relayer_fund_account, - ); + let RewardsBook { deliver_sum, confirm_sum, assigned_relayers_sum, treasury_sum } = + slash_and_calculate_rewards::( + lane_id, + messages_relayers, + confirmation_relayer.clone(), + received_range, + relayer_fund_account, + ); // Pay confirmation relayer rewards - do_reward::(relayer_fund_account, confirmation_relayer, confirmation_relayer_rewards); + do_reward::(relayer_fund_account, confirmation_relayer, confirm_sum); // Pay messages relayers rewards - for (relayer, reward) in messages_relayers_rewards { + for (relayer, reward) in deliver_sum { do_reward::(relayer_fund_account, &relayer, reward); } // Pay assign relayer reward - for (relayer, reward) in assigned_relayers_rewards { + for (relayer, reward) in assigned_relayers_sum { do_reward::(relayer_fund_account, &relayer, reward); } - // Pay treasury reward + // Pay treasury_sum reward do_reward::( relayer_fund_account, - &T::TreasuryPalletId::get().into_account(), - treasury_total_rewards, + &T::TreasuryPalletId::get().into_account_truncating(), + treasury_sum, ); } } -/// Slash and calculate rewards for messages_relayers, confirmation relayers, treasury, +/// Slash and calculate rewards for messages_relayers, confirmation relayers, treasury_sum, /// assigned_relayers pub fn slash_and_calculate_rewards( lane_id: LaneId, messages_relayers: VecDeque>, + confirm_relayer: T::AccountId, received_range: &RangeInclusive, relayer_fund_account: &T::AccountId, -) -> RewardsBook> +) -> RewardsBook where T: frame_system::Config + Config, I: 'static, { - let mut confirmation_rewards = BalanceOf::::zero(); - let mut messages_rewards = BTreeMap::>::new(); - let mut assigned_relayers_rewards = BTreeMap::>::new(); - let mut treasury_total_rewards = BalanceOf::::zero(); - + let mut rewards_book = RewardsBook::new(); for entry in messages_relayers { let nonce_begin = sp_std::cmp::max(entry.messages.begin, *received_range.start()); let nonce_end = sp_std::cmp::min(entry.messages.end, *received_range.end()); for message_nonce in nonce_begin..nonce_end + 1 { - // The order created when message was accepted, so we can always get the order info - // below. + // The order created when message was accepted, so we can always get the order info. if let Some(order) = >::get(&(lane_id, message_nonce)) { // The confirm_time of the order is set in the `OnDeliveryConfirmed` callback. And // the callback function was called as source chain received message delivery proof, @@ -152,31 +146,29 @@ where order.confirm_time.unwrap_or_else(|| frame_system::Pallet::::block_number()); let message_fee = order.fee(); + let mut reward_item = RewardItem::new(); let message_reward; let confirm_reward; if let Some((who, base_fee)) = order.required_delivery_relayer_for_time(order_confirm_time) { - // message fee - base fee => treasury - let treasury_reward = message_fee.saturating_sub(base_fee); - treasury_total_rewards = treasury_total_rewards.saturating_add(treasury_reward); + // message fee - base fee => treasury_sum + reward_item.to_treasury = Some(message_fee.saturating_sub(base_fee)); - // 60% * base fee => assigned_relayers_rewards - let assigned_relayers_reward = T::AssignedRelayersRewardRatio::get() * base_fee; - assigned_relayers_rewards - .entry(who) - .and_modify(|r| *r = r.saturating_add(assigned_relayers_reward)) - .or_insert(assigned_relayers_reward); + // AssignedRelayersRewardRatio * base fee => slot relayer + let slot_relayer_reward = T::AssignedRelayersRewardRatio::get() * base_fee; + reward_item.to_slot_relayer = Some((who, slot_relayer_reward)); - let bridger_relayers_reward = base_fee.saturating_sub(assigned_relayers_reward); - - // 80% * (1 - 60%) * base_fee => message relayer + let bridger_relayers_reward = base_fee.saturating_sub(slot_relayer_reward); + // MessageRelayersRewardRatio * (1 - AssignedRelayersRewardRatio) * base_fee => + // message relayer message_reward = T::MessageRelayersRewardRatio::get() * bridger_relayers_reward; - // 20% * (1 - 60%) * base_fee => confirm relayer + // ConfirmRelayersRewardRatio * (1 - AssignedRelayersRewardRatio) * base_fee => + // confirm relayer confirm_reward = T::ConfirmRelayersRewardRatio::get() * bridger_relayers_reward; } else { - // The order delivery is delay + // The order delivery is delay, slash occurs. let mut total_slash = message_fee; // calculate slash amount @@ -202,29 +194,26 @@ where } total_slash += assigned_relayers_slash; - // 80% total slash => confirm relayer + // MessageRelayersRewardRatio total slash => message relayer message_reward = T::MessageRelayersRewardRatio::get() * total_slash; - // 20% total slash => confirm relayer + // ConfirmRelayersRewardRatio total slash => confirm relayer confirm_reward = T::ConfirmRelayersRewardRatio::get() * total_slash; } - // Update confirmation relayer total rewards - confirmation_rewards = confirmation_rewards.saturating_add(confirm_reward); - // Update message relayers total rewards - messages_rewards - .entry(entry.relayer.clone()) - .and_modify(|r| *r = r.saturating_add(message_reward)) - .or_insert(message_reward); + reward_item.to_message_relayer = Some((entry.clone().relayer, message_reward)); + reward_item.to_confirm_relayer = Some((confirm_relayer.clone(), confirm_reward)); + + Pallet::::deposit_event(Event::OrderReward( + lane_id, + message_nonce, + reward_item.clone(), + )); + + rewards_book.add_reward_item(reward_item); } } } - - RewardsBook { - messages_relayers_rewards: messages_rewards, - confirmation_relayer_rewards: confirmation_rewards, - assigned_relayers_rewards, - treasury_total_rewards, - } + rewards_book } /// Do slash for absent assigned relayers @@ -290,10 +279,66 @@ pub(crate) fn do_reward, I: 'static>( } } +/// Record the concrete reward distribution of certain order +#[derive(Clone, Debug, Encode, Decode, Eq, PartialEq, TypeInfo)] +pub struct RewardItem { + pub to_slot_relayer: Option<(AccountId, Balance)>, + pub to_treasury: Option, + pub to_message_relayer: Option<(AccountId, Balance)>, + pub to_confirm_relayer: Option<(AccountId, Balance)>, +} + +impl RewardItem { + fn new() -> Self { + Self { + to_slot_relayer: None, + to_treasury: None, + to_message_relayer: None, + to_confirm_relayer: None, + } + } +} + /// Record the calculation rewards result -pub struct RewardsBook { - pub messages_relayers_rewards: BTreeMap, - pub confirmation_relayer_rewards: Balance, - pub assigned_relayers_rewards: BTreeMap, - pub treasury_total_rewards: Balance, +#[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] +pub struct RewardsBook, I: 'static> { + pub deliver_sum: BTreeMap>, + pub confirm_sum: BalanceOf, + pub assigned_relayers_sum: BTreeMap>, + pub treasury_sum: BalanceOf, +} + +impl, I: 'static> RewardsBook { + fn new() -> Self { + Self { + deliver_sum: BTreeMap::new(), + confirm_sum: BalanceOf::::zero(), + assigned_relayers_sum: BTreeMap::new(), + treasury_sum: BalanceOf::::zero(), + } + } + + fn add_reward_item(&mut self, item: RewardItem>) { + if let Some((id, reward)) = item.to_slot_relayer { + self.assigned_relayers_sum + .entry(id) + .and_modify(|r| *r = r.saturating_add(reward)) + .or_insert(reward); + } + + if let Some(reward) = item.to_treasury { + self.treasury_sum = self.treasury_sum.saturating_add(reward); + } + + if let Some((id, reward)) = item.to_message_relayer { + self.deliver_sum + .entry(id) + .and_modify(|r| *r = r.saturating_add(reward)) + .or_insert(reward); + } + + if let Some((_id, reward)) = item.to_confirm_relayer { + self.confirm_sum = self.confirm_sum.saturating_add(reward); + } + } } diff --git a/modules/fee-market/src/tests.rs b/modules/fee-market/src/tests.rs index 460d2794d..1522fe3ea 100644 --- a/modules/fee-market/src/tests.rs +++ b/modules/fee-market/src/tests.rs @@ -289,34 +289,30 @@ impl MessageDeliveryAndDispatchPayment received_range: &RangeInclusive, relayer_fund_account: &AccountId, ) { - let RewardsBook { - messages_relayers_rewards, - confirmation_relayer_rewards, - assigned_relayers_rewards, - treasury_total_rewards, - } = slash_and_calculate_rewards::( - lane_id, - message_relayers, - received_range, - relayer_fund_account, - ); - let confimation_key = - (b":relayer-reward:", confirmation_relayer, confirmation_relayer_rewards).encode(); + let RewardsBook { deliver_sum, confirm_sum, assigned_relayers_sum, treasury_sum } = + slash_and_calculate_rewards::( + lane_id, + message_relayers, + confirmation_relayer.clone(), + received_range, + relayer_fund_account, + ); + + let confimation_key = (b":relayer-reward:", confirmation_relayer, confirm_sum).encode(); frame_support::storage::unhashed::put(&confimation_key, &true); - for (relayer, reward) in &messages_relayers_rewards { + for (relayer, reward) in &deliver_sum { let key = (b":relayer-reward:", relayer, reward).encode(); frame_support::storage::unhashed::put(&key, &true); } - for (relayer, reward) in &assigned_relayers_rewards { + for (relayer, reward) in &assigned_relayers_sum { let key = (b":relayer-reward:", relayer, reward).encode(); frame_support::storage::unhashed::put(&key, &true); } - let treasury_account: AccountId = ::TreasuryPalletId::get().into_account(); - let treasury_key = - (b":relayer-reward:", &treasury_account, treasury_total_rewards).encode(); + let treasury_account: AccountId = ::TreasuryPalletId::get().into_account_truncating(); + let treasury_key = (b":relayer-reward:", &treasury_account, treasury_sum).encode(); frame_support::storage::unhashed::put(&treasury_key, &true); } } @@ -348,6 +344,13 @@ impl MessageDispatch for TestMessageDispatch { } } + fn pre_dispatch( + _relayer_account: &AccountId, + _message: &DispatchMessage, + ) -> Result<(), &'static str> { + Ok(()) + } + fn dispatch( _relayer_account: &AccountId, message: DispatchMessage, @@ -752,6 +755,14 @@ fn test_callback_order_creation() { assert_eq!(relayers[1].id, assigned_relayers.get(1).unwrap().id); assert_eq!(relayers[2].id, assigned_relayers.get(2).unwrap().id); assert_eq!(order.sent_time, 2); + + System::assert_has_event(Event::FeeMarket(crate::Event::OrderCreated( + lane, + message_nonce, + order.fee(), + vec![relayers[0].id, relayers[1].id, relayers[2].id], + order.range_end(), + ))); }); } @@ -804,7 +815,7 @@ fn test_payment_cal_reward_normally_single_message() { let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(2), 110, Some(50)); let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(3), 120, Some(100)); let market_fee = FeeMarket::market_fee().unwrap(); - let (_, _) = send_regular_message(market_fee); + let (lane, message_nonce) = send_regular_message(market_fee); // Receive delivery message proof System::set_block_number(4); @@ -824,16 +835,27 @@ fn test_payment_cal_reward_normally_single_message() { }, )); - // Analysis: - // 1. assigned_relayers [(1, 30, 2-52),(2, 50, 52-102),(3, 100, 102-152)] -> id: 1, reward = - // 60% * 30 = 18 2. message relayer -> id: 100, reward = 40% * 30 * 80% = 9.6 ~ 10 - // 3. confirmation relayer -> id: 5, reward = 40% * 30 * 20% = 2.4 ~ 2 - // 4. treasury reward -> reward: 100 - 30 = 70 - let t: AccountId = ::TreasuryPalletId::get().into_account(); + // Reward Analysis: assigned_relayers [(1, 30, 2-52),(2, 50, 52-102),(3, 100, 102-152)] + // 1. slot relayer -> id: 1, reward = 60% * 30 = 18 + // 2. message relayer -> id: 100, reward = 40% * 30 * 80% = 9.6 ~ 10 + // 3. confirm relayer -> id: 5, reward = 40% * 30 * 20% = 2.4 ~ 2 + // 4. treasury reward -> reward = 100 - 30 = 70 + let t: AccountId = ::TreasuryPalletId::get().into_account_truncating(); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(t, 70)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(1, 18)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(5, 2)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(TEST_RELAYER_A, 10)); + + System::assert_has_event(Event::FeeMarket(crate::Event::OrderReward( + lane, + message_nonce, + RewardItem { + to_slot_relayer: Some((1, 18)), + to_treasury: Some(70), + to_message_relayer: Some((100, 10)), + to_confirm_relayer: Some((5, 2)), + }, + ))); }); } @@ -874,7 +896,7 @@ fn test_payment_cal_reward_normally_multi_message() { }, )); - let t: AccountId = ::TreasuryPalletId::get().into_account(); + let t: AccountId = ::TreasuryPalletId::get().into_account_truncating(); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(t, 140)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(1, 4)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(5, 36)); @@ -929,7 +951,7 @@ fn test_payment_cal_reward_with_duplicated_delivery_proof() { }, )); - let t: AccountId = ::TreasuryPalletId::get().into_account(); + let t: AccountId = ::TreasuryPalletId::get().into_account_truncating(); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(t, 70)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(1, 18)); assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(5, 2)); diff --git a/modules/grandpa/Cargo.toml b/modules/grandpa/Cargo.toml index 330ef7ec9..eed9c6aa5 100644 --- a/modules/grandpa/Cargo.toml +++ b/modules/grandpa/Cargo.toml @@ -22,20 +22,20 @@ bp-header-chain = { path = "../../primitives/header-chain", default-features = f # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } # Optional Benchmarking Dependencies bp-test-utils = { path = "../../primitives/test-utils", default-features = false, optional = true } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false, optional = true } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false, optional = true } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/modules/messages/Cargo.toml b/modules/messages/Cargo.toml index 1953825df..bd85acdef 100644 --- a/modules/messages/Cargo.toml +++ b/modules/messages/Cargo.toml @@ -22,16 +22,16 @@ bp-runtime = { path = "../../primitives/runtime", default-features = false } # Substrate Dependencies -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false, optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false, optional = true } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/modules/messages/src/inbound_lane.rs b/modules/messages/src/inbound_lane.rs index 2481b1f15..78df0877a 100644 --- a/modules/messages/src/inbound_lane.rs +++ b/modules/messages/src/inbound_lane.rs @@ -58,6 +58,8 @@ pub enum ReceivalResult { TooManyUnrewardedRelayers, /// There are too many unconfirmed messages at the lane. TooManyUnconfirmedMessages, + /// Pre-dispatch validation failed before message dispatch. + PreDispatchValidateFailed, } /// Inbound messages lane. @@ -141,14 +143,17 @@ impl InboundLane { return ReceivalResult::TooManyUnconfirmedMessages; } + let dispatch_message = DispatchMessage { + key: MessageKey { lane_id: self.storage.id(), nonce }, + data: message_data, + }; + // if there are some extra pre-dispatch validation errors, reject this message. + if P::pre_dispatch(relayer_at_this_chain, &dispatch_message).is_err() { + return ReceivalResult::PreDispatchValidateFailed + } + // then, dispatch message - let dispatch_result = P::dispatch( - relayer_at_this_chain, - DispatchMessage { - key: MessageKey { lane_id: self.storage.id(), nonce }, - data: message_data, - }, - ); + let dispatch_result = P::dispatch(relayer_at_this_chain, dispatch_message); // now let's update inbound lane storage let push_new = match data.relayers.back_mut() { diff --git a/modules/messages/src/lib.rs b/modules/messages/src/lib.rs index 157d92505..a6b74db41 100644 --- a/modules/messages/src/lib.rs +++ b/modules/messages/src/lib.rs @@ -466,9 +466,10 @@ pub mod pallet { !dispatch_result.dispatch_fee_paid_during_dispatch, ) }, - ReceivalResult::InvalidNonce - | ReceivalResult::TooManyUnrewardedRelayers - | ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true), + ReceivalResult::InvalidNonce | + ReceivalResult::TooManyUnrewardedRelayers | + ReceivalResult::PreDispatchValidateFailed | + ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true), }; let unspent_weight = sp_std::cmp::min(unspent_weight, dispatch_weight); diff --git a/modules/messages/src/mock.rs b/modules/messages/src/mock.rs index 5d7a21afe..8ab089c7c 100644 --- a/modules/messages/src/mock.rs +++ b/modules/messages/src/mock.rs @@ -489,6 +489,13 @@ impl MessageDispatch for TestMessageDispatch { } } + fn pre_dispatch( + _relayer_account: &AccountId, + _message: &DispatchMessage, + ) -> Result<(), &'static str> { + Ok(()) + } + fn dispatch( _relayer_account: &AccountId, message: DispatchMessage, diff --git a/modules/parachains/Cargo.toml b/modules/parachains/Cargo.toml index 886f5b477..60971d175 100644 --- a/modules/parachains/Cargo.toml +++ b/modules/parachains/Cargo.toml @@ -19,17 +19,17 @@ pallet-bridge-grandpa = { path = "../grandpa", default-features = false } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] bp-header-chain = { path = "../../primitives/header-chain" } bp-test-utils = { path = "../../primitives/test-utils" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/modules/shift-session-manager/Cargo.toml b/modules/shift-session-manager/Cargo.toml deleted file mode 100644 index 1bbe00799..000000000 --- a/modules/shift-session-manager/Cargo.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -name = "pallet-shift-session-manager" -description = "A Substrate Runtime module that selects 2/3 of initial validators for every session" -version = "0.1.0" -authors = ["Parity Technologies "] -edition = "2021" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } - -# Substrate Dependencies - -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-staking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } - -[dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-support/std", - "frame-system/std", - "pallet-session/std", - "scale-info/std", - "sp-staking/std", - "sp-std/std", -] diff --git a/modules/shift-session-manager/src/lib.rs b/modules/shift-session-manager/src/lib.rs deleted file mode 100644 index 4a6a14ffd..000000000 --- a/modules/shift-session-manager/src/lib.rs +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2019-2021 Parity Technologies (UK) Ltd. -// This file is part of Parity Bridges Common. - -// Parity Bridges Common is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Bridges Common is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Bridges Common. If not, see . - -//! Substrate session manager that selects 2/3 validators from initial set, -//! starting from session 2. - -#![cfg_attr(not(feature = "std"), no_std)] - -use sp_std::prelude::*; - -pub use pallet::*; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - #[pallet::config] - #[pallet::disable_frame_system_supertrait_check] - pub trait Config: pallet_session::Config {} - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - #[pallet::without_storage_info] - pub struct Pallet(PhantomData); - - #[pallet::hooks] - impl Hooks> for Pallet {} - - #[pallet::call] - impl Pallet {} - - /// Validators of first two sessions. - #[pallet::storage] - pub(super) type InitialValidators = StorageValue<_, Vec>; -} - -impl pallet_session::SessionManager for Pallet { - fn end_session(_: sp_staking::SessionIndex) {} - - fn start_session(_: sp_staking::SessionIndex) {} - - fn new_session(session_index: sp_staking::SessionIndex) -> Option> { - // we don't want to add even more fields to genesis config => just return None - if session_index == 0 || session_index == 1 { - return None; - } - - // the idea that on first call (i.e. when session 1 ends) we're reading current - // set of validators from session module (they are initial validators) and save - // in our 'local storage'. - // then for every session we select (deterministically) 2/3 of these initial - // validators to serve validators of new session - let available_validators = InitialValidators::::get().unwrap_or_else(|| { - let validators = >::validators(); - InitialValidators::::put(validators.clone()); - validators - }); - - Some(Self::select_validators(session_index, &available_validators)) - } -} - -impl Pallet { - /// Select validators for session. - fn select_validators( - session_index: sp_staking::SessionIndex, - available_validators: &[T::ValidatorId], - ) -> Vec { - let available_validators_count = available_validators.len(); - let count = sp_std::cmp::max(1, 2 * available_validators_count / 3); - let offset = session_index as usize % available_validators_count; - let end = offset + count; - let session_validators = match end.overflowing_sub(available_validators_count) { - (wrapped_end, false) if wrapped_end != 0 => available_validators[offset..] - .iter() - .chain(available_validators[..wrapped_end].iter()) - .cloned() - .collect(), - _ => available_validators[offset..end].to_vec(), - }; - - session_validators - } -} - -#[cfg(test)] -mod tests { - // From construct_runtime macro - #![allow(clippy::from_over_into)] - - use super::*; - use frame_support::{ - parameter_types, - sp_io::TestExternalities, - sp_runtime::{ - testing::{Header, UintAuthorityId}, - traits::{BlakeTwo256, ConvertInto, IdentityLookup}, - Perbill, RuntimeAppPublic, - }, - traits::GenesisBuild, - weights::Weight, - BasicExternalities, - }; - use sp_core::H256; - - type AccountId = u64; - - type Block = frame_system::mocking::MockBlock; - type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; - - frame_support::construct_runtime! { - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Session: pallet_session::{Pallet}, - } - } - - parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const MaximumBlockWeight: Weight = 1024; - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::one(); - } - - impl frame_system::Config for TestRuntime { - type AccountData = (); - type AccountId = AccountId; - type BaseCallFilter = frame_support::traits::Everything; - type BlockHashCount = BlockHashCount; - type BlockLength = (); - type BlockNumber = u64; - type BlockWeights = (); - type Call = Call; - type DbWeight = (); - type Event = (); - type Hash = H256; - type Hashing = BlakeTwo256; - type Header = Header; - type Index = u64; - type Lookup = IdentityLookup; - type MaxConsumers = frame_support::traits::ConstU32<16>; - type OnKilledAccount = (); - type OnNewAccount = (); - type OnSetCode = (); - type Origin = Origin; - type PalletInfo = PalletInfo; - type SS58Prefix = (); - type SystemWeightInfo = (); - type Version = (); - } - - parameter_types! { - pub const Period: u64 = 1; - pub const Offset: u64 = 0; - } - - impl pallet_session::Config for TestRuntime { - type Event = (); - type Keys = UintAuthorityId; - type NextSessionRotation = pallet_session::PeriodicSessions; - type SessionHandler = TestSessionHandler; - type SessionManager = (); - type ShouldEndSession = pallet_session::PeriodicSessions; - type ValidatorId = ::AccountId; - type ValidatorIdOf = ConvertInto; - type WeightInfo = (); - } - - impl Config for TestRuntime {} - - pub struct TestSessionHandler; - impl pallet_session::SessionHandler for TestSessionHandler { - const KEY_TYPE_IDS: &'static [sp_runtime::KeyTypeId] = &[UintAuthorityId::ID]; - - fn on_genesis_session(_validators: &[(AccountId, Ks)]) { - } - - fn on_new_session( - _: bool, - _: &[(AccountId, Ks)], - _: &[(AccountId, Ks)], - ) { - } - - fn on_disabled(_: u32) {} - } - - fn new_test_ext() -> TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - let keys = vec![ - (1, 1, UintAuthorityId(1)), - (2, 2, UintAuthorityId(2)), - (3, 3, UintAuthorityId(3)), - (4, 4, UintAuthorityId(4)), - (5, 5, UintAuthorityId(5)), - ]; - - BasicExternalities::execute_with_storage(&mut t, || { - for (ref k, ..) in &keys { - frame_system::Pallet::::inc_providers(k); - } - }); - - pallet_session::GenesisConfig:: { keys }.assimilate_storage(&mut t).unwrap(); - TestExternalities::new(t) - } - - #[test] - fn shift_session_manager_works() { - new_test_ext().execute_with(|| { - let all_accs = vec![1, 2, 3, 4, 5]; - - // at least 1 validator is selected - assert_eq!(Pallet::::select_validators(0, &[1]), vec![1],); - - // at session#0, shift is also 0 - assert_eq!(Pallet::::select_validators(0, &all_accs), vec![1, 2, 3],); - - // at session#1, shift is also 1 - assert_eq!(Pallet::::select_validators(1, &all_accs), vec![2, 3, 4],); - - // at session#3, we're wrapping - assert_eq!(Pallet::::select_validators(3, &all_accs), vec![4, 5, 1],); - - // at session#5, we're starting from the beginning again - assert_eq!(Pallet::::select_validators(5, &all_accs), vec![1, 2, 3],); - }); - } -} diff --git a/primitives/chain-crab-parachain/Cargo.toml b/primitives/chain-crab-parachain/Cargo.toml index 986b7782c..b8ed1331d 100644 --- a/primitives/chain-crab-parachain/Cargo.toml +++ b/primitives/chain-crab-parachain/Cargo.toml @@ -12,11 +12,11 @@ bp-darwinia-core = { default-features = false, path = "../darwinia-core" } # paritytech bp-messages = { default-features = false, path = "../messages" } bp-runtime = { default-features = false, path = "../runtime" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/primitives/chain-crab/Cargo.toml b/primitives/chain-crab/Cargo.toml index aa0f0605a..6339ad972 100644 --- a/primitives/chain-crab/Cargo.toml +++ b/primitives/chain-crab/Cargo.toml @@ -12,11 +12,11 @@ bp-darwinia-core = { default-features = false, path = "../darwinia-core" } # paritytech bp-messages = { default-features = false, path = "../messages" } bp-runtime = { default-features = false, path = "../runtime" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/primitives/chain-kusama/Cargo.toml b/primitives/chain-kusama/Cargo.toml index d477c0dd7..06f9c6b8f 100644 --- a/primitives/chain-kusama/Cargo.toml +++ b/primitives/chain-kusama/Cargo.toml @@ -17,11 +17,11 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [features] default = ["std"] diff --git a/primitives/chain-pangolin-parachain/Cargo.toml b/primitives/chain-pangolin-parachain/Cargo.toml index 41dd7d0db..0d85efd67 100644 --- a/primitives/chain-pangolin-parachain/Cargo.toml +++ b/primitives/chain-pangolin-parachain/Cargo.toml @@ -12,11 +12,11 @@ bp-darwinia-core = { default-features = false, path = "../darwinia-core" } # paritytech bp-messages = { default-features = false, path = "../messages" } bp-runtime = { default-features = false, path = "../runtime" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/primitives/chain-pangolin/Cargo.toml b/primitives/chain-pangolin/Cargo.toml index 2db077add..25046f88b 100644 --- a/primitives/chain-pangolin/Cargo.toml +++ b/primitives/chain-pangolin/Cargo.toml @@ -12,11 +12,11 @@ bp-darwinia-core = { default-features = false, path = "../darwinia-core" } # paritytech bp-messages = { default-features = false, path = "../messages" } bp-runtime = { default-features = false, path = "../runtime" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/primitives/chain-pangoro/Cargo.toml b/primitives/chain-pangoro/Cargo.toml index 73c0c36bd..4449bb30b 100644 --- a/primitives/chain-pangoro/Cargo.toml +++ b/primitives/chain-pangoro/Cargo.toml @@ -12,11 +12,11 @@ bp-darwinia-core = { default-features = false, path = "../darwinia-core" } # paritytech bp-messages = { default-features = false, path = "../messages" } bp-runtime = { default-features = false, path = "../runtime" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/primitives/chain-polkadot/Cargo.toml b/primitives/chain-polkadot/Cargo.toml index 67ec03f3a..daa4c0a34 100644 --- a/primitives/chain-polkadot/Cargo.toml +++ b/primitives/chain-polkadot/Cargo.toml @@ -17,11 +17,11 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [features] default = ["std"] diff --git a/primitives/chain-rococo/Cargo.toml b/primitives/chain-rococo/Cargo.toml index 2c35071f2..2803b54cb 100644 --- a/primitives/chain-rococo/Cargo.toml +++ b/primitives/chain-rococo/Cargo.toml @@ -16,11 +16,11 @@ 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 = "polkadot-v0.9.22", default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [features] default = ["std"] diff --git a/primitives/chain-wococo/Cargo.toml b/primitives/chain-wococo/Cargo.toml index 87c828af6..26fc3876f 100644 --- a/primitives/chain-wococo/Cargo.toml +++ b/primitives/chain-wococo/Cargo.toml @@ -16,9 +16,9 @@ bp-rococo = { path = "../chain-rococo", default-features = false } bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [features] default = ["std"] diff --git a/primitives/darwinia-core/Cargo.toml b/primitives/darwinia-core/Cargo.toml index 626bc2011..346894815 100644 --- a/primitives/darwinia-core/Cargo.toml +++ b/primitives/darwinia-core/Cargo.toml @@ -13,11 +13,11 @@ scale-info = { version = "2.0.1", default-features = false, features = [ # paritytech bp-messages = { default-features = false, path = "../messages" } bp-runtime = { default-features = false, path = "../runtime" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } [features] default = ["std"] diff --git a/primitives/header-chain/Cargo.toml b/primitives/header-chain/Cargo.toml index 6bac49a68..a0a31fb82 100644 --- a/primitives/header-chain/Cargo.toml +++ b/primitives/header-chain/Cargo.toml @@ -18,11 +18,11 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] assert_matches = "1.5" diff --git a/primitives/message-dispatch/Cargo.toml b/primitives/message-dispatch/Cargo.toml index a7f1f136f..9976f711c 100644 --- a/primitives/message-dispatch/Cargo.toml +++ b/primitives/message-dispatch/Cargo.toml @@ -13,8 +13,9 @@ scale-info = { version = "2.0.1", default-features = false, features = ["derive" # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [features] default = ["std"] @@ -23,5 +24,6 @@ std = [ "codec/std", "frame-support/std", "scale-info/std", + "sp-runtime/std", "sp-std/std", ] diff --git a/primitives/message-dispatch/src/lib.rs b/primitives/message-dispatch/src/lib.rs index 07e448ee7..2cde19ffb 100644 --- a/primitives/message-dispatch/src/lib.rs +++ b/primitives/message-dispatch/src/lib.rs @@ -26,6 +26,7 @@ use bp_runtime::{ use codec::{Decode, Encode}; use frame_support::RuntimeDebug; use scale_info::TypeInfo; +use sp_runtime::transaction_validity::TransactionValidityError; use sp_std::prelude::*; /// Message dispatch weight. @@ -45,6 +46,15 @@ pub trait MessageDispatch { /// of dispatch weight. fn dispatch_weight(message: &Self::Message) -> Weight; + /// Checking in message receiving step before dispatch + /// + /// This will be called before the call enter dispatch phase. If failed, the message(call) will + /// be not be processed by this relayer, latter relayers can still continue process it. + fn pre_dispatch( + relayer_account: &AccountId, + message: Result<&Self::Message, ()>, + ) -> Result<(), &'static str>; + /// Dispatches the message internally. /// /// `source_chain` indicates the chain where the message came from. @@ -61,6 +71,7 @@ pub trait MessageDispatch { fn dispatch Result<(), ()>>( source_chain: ChainId, target_chain: ChainId, + relayer_account: &AccountId, id: BridgeMessageId, message: Result, pay_dispatch_fee: P, @@ -140,3 +151,29 @@ impl Size self.call.len() as _ } } + +/// Customize the dispatch origin before call dispatch. +pub trait IntoDispatchOrigin { + /// Generate the dispatch origin for the given call. + /// + /// Normally, the dispatch origin is one kind of frame_system::RawOrigin, however, sometimes + /// it is useful for a dispatch call with a custom origin. + fn into_dispatch_origin(id: &AccountId, call: &Call) -> Origin; +} + +/// A generic trait to validate message before dispatch. +pub trait CallValidate { + /// Checking in message receiving step before dispatch + /// + /// This will be called before the call enter dispatch phase. If failed, the message(call) will + /// be not be processed by this relayer, latter relayers can still continue process it. + fn check_receiving_before_dispatch(relayer_account: &AccountId, call: &Call) -> Result<(), &'static str>; + /// In-dispatch call validation + /// + /// This will be called in the dispatch process, If failed, return message dispatch errors. + fn call_validate( + relayer_account: &AccountId, + origin: &Origin, + call: &Call, + ) -> Result<(), TransactionValidityError>; +} diff --git a/primitives/messages/Cargo.toml b/primitives/messages/Cargo.toml index ca07e1766..ad2ed65e6 100644 --- a/primitives/messages/Cargo.toml +++ b/primitives/messages/Cargo.toml @@ -19,10 +19,10 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] hex = "0.4" diff --git a/primitives/messages/src/target_chain.rs b/primitives/messages/src/target_chain.rs index a84ea7af9..685a4e9a8 100644 --- a/primitives/messages/src/target_chain.rs +++ b/primitives/messages/src/target_chain.rs @@ -97,6 +97,15 @@ pub trait MessageDispatch { /// of dispatch weight. fn dispatch_weight(message: &DispatchMessage) -> Weight; + /// Checking in message receiving step before dispatch + /// + /// This will be called before the call enter dispatch phase. If failed, the message(call) will + /// be not be processed by this relayer, latter relayers can still continue process it. + fn pre_dispatch( + relayer_account: &AccountId, + message: &DispatchMessage, + ) -> Result<(), &'static str>; + /// Called when inbound message is received. /// /// It is up to the implementers of this trait to determine whether the message @@ -160,6 +169,13 @@ impl MessageDispatch for ForbidInboundMessages { Weight::MAX } + fn pre_dispatch( + _: &AccountId, + _message: &DispatchMessage, + ) -> Result<(), &'static str> { + Ok(()) + } + fn dispatch( _: &AccountId, _: DispatchMessage, diff --git a/primitives/polkadot-core/Cargo.toml b/primitives/polkadot-core/Cargo.toml index d01273239..6b5b71188 100644 --- a/primitives/polkadot-core/Cargo.toml +++ b/primitives/polkadot-core/Cargo.toml @@ -19,13 +19,13 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] hex = "0.4" diff --git a/primitives/runtime/Cargo.toml b/primitives/runtime/Cargo.toml index f8f0ecb55..86a92700e 100644 --- a/primitives/runtime/Cargo.toml +++ b/primitives/runtime/Cargo.toml @@ -14,13 +14,13 @@ scale-info = { version = "2.0.1", default-features = false, features = ["derive" # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [dev-dependencies] hex-literal = "0.3" diff --git a/primitives/test-utils/Cargo.toml b/primitives/test-utils/Cargo.toml index 09c1e6205..2dcae11a8 100644 --- a/primitives/test-utils/Cargo.toml +++ b/primitives/test-utils/Cargo.toml @@ -10,10 +10,10 @@ bp-header-chain = { path = "../header-chain", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] } finality-grandpa = { version = "0.15.0", default-features = false } -sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } +sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23", default-features = false } [features] default = ["std"] diff --git a/relays/client-kusama/Cargo.toml b/relays/client-kusama/Cargo.toml index 2e729f52e..c3bbc75ff 100644 --- a/relays/client-kusama/Cargo.toml +++ b/relays/client-kusama/Cargo.toml @@ -25,6 +25,6 @@ pallet-bridge-dispatch = { path = "../../modules/dispatch" } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } diff --git a/relays/client-polkadot/Cargo.toml b/relays/client-polkadot/Cargo.toml index 9b3aa7b2b..9f97cdea1 100644 --- a/relays/client-polkadot/Cargo.toml +++ b/relays/client-polkadot/Cargo.toml @@ -25,6 +25,6 @@ pallet-bridge-dispatch = { path = "../../modules/dispatch" } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } diff --git a/relays/client-rococo/Cargo.toml b/relays/client-rococo/Cargo.toml index a51d21f98..1243d3da6 100644 --- a/relays/client-rococo/Cargo.toml +++ b/relays/client-rococo/Cargo.toml @@ -26,6 +26,6 @@ pallet-bridge-messages = { path = "../../modules/messages" } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } diff --git a/relays/client-substrate/Cargo.toml b/relays/client-substrate/Cargo.toml index 5cbdcc408..da1fe5537 100644 --- a/relays/client-substrate/Cargo.toml +++ b/relays/client-substrate/Cargo.toml @@ -28,21 +28,21 @@ relay-utils = { path = "../utils" } # Substrate Dependencies -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } #[dev-dependencies] futures = "0.3.7" diff --git a/relays/messages/Cargo.toml b/relays/messages/Cargo.toml index 24f04fa32..285a38143 100644 --- a/relays/messages/Cargo.toml +++ b/relays/messages/Cargo.toml @@ -21,4 +21,4 @@ bp-runtime = { path = "../../primitives/runtime" } finality-relay = { path = "../finality" } relay-utils = { path = "../utils" } -sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } diff --git a/relays/utils/Cargo.toml b/relays/utils/Cargo.toml index 4e4e9b811..aedf6096b 100644 --- a/relays/utils/Cargo.toml +++ b/relays/utils/Cargo.toml @@ -29,4 +29,4 @@ bp-runtime = { path = "../../primitives/runtime" } # Substrate dependencies -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" } +substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.23" } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e399a8ae4..c071e3c0d 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly" +channel = "nightly-2022-05-15" components = ["cargo", "clippy", "rustc", "rustfmt", "rust-src"] profile = "minimal" targets = ["wasm32-unknown-unknown"]