From 82a8bdf65931537360861af9320fc68960ddc6c3 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Tue, 27 Apr 2021 16:58:58 -0400 Subject: [PATCH] Squashed 'bridges/' changes from 89a76998..f95cc7a5 f95cc7a5 Merge branch 'master' into hc-add-wococo-support a13ee0bc Bump Substrate (#939) f8680cbf jsonrpsee alpha6 (#938) 6163bcbf reonnect to failed client in on-demand relay background task (#936) 14e82bea Do not spawn additional task for on-demand relays (#933) b1557b88 Relay at least one header for every source chain session (#923) 9420649c Remove deprecated Runtime Header APIs (#932) 9627011e Update README.md (#931) 7b736b9c Truncate output in logs. (#930) faad06e3 Make sure that relayers have dates in logs. (#927) 07734535 Update dump-logs script. (#928) efe215e4 RustFmt 02522249 Fix test 48b41d82 Add support for relaying headers between Rococo and Wococo f16b6b41 Add CLI support for initializing the Wococo<>Rococo bridge 8c6e6443 Add more Wococo boilerplate code c2d56b2e Add pruning to bechmarks & update weights. (#918) a30c51dc Add properties to Chain Spec (#917) 28d3ed2f Add Wococo primitives crate d691c73e Fix issue with on-demand headers relay not starting (#921) 8ee55c1e Fix image publishing. (#922) f51fb59d Prefix in relay loops logs (#920) git-subtree-dir: bridges git-subtree-split: f95cc7a57b48948f17d33f5be3ea01c752deba94 --- .github/workflows/rust.yml | 4 +- Cargo.lock | 335 ++++++++++-------- README.md | 4 +- bin/millau/node/Cargo.toml | 1 + bin/millau/node/src/chain_spec.rs | 13 +- bin/millau/runtime/src/lib.rs | 1 - bin/millau/runtime/src/rialto_messages.rs | 2 +- bin/rialto/node/Cargo.toml | 1 + bin/rialto/node/src/chain_spec.rs | 14 +- bin/rialto/runtime/src/lib.rs | 30 +- bin/rialto/runtime/src/millau_messages.rs | 2 +- bin/runtime-common/src/messages.rs | 4 + modules/dispatch/src/lib.rs | 3 +- modules/grandpa/src/benchmarking.rs | 29 +- modules/grandpa/src/lib.rs | 60 +++- modules/grandpa/src/weights.rs | 50 +-- modules/messages/src/weights.rs | 94 ++--- primitives/chain-millau/src/lib.rs | 25 -- primitives/chain-rialto/src/lib.rs | 25 -- primitives/chain-rococo/src/lib.rs | 8 +- primitives/chain-wococo/Cargo.toml | 36 ++ primitives/chain-wococo/src/lib.rs | 172 +++++++++ primitives/runtime/src/lib.rs | 3 + relays/bin-substrate/Cargo.toml | 2 + relays/bin-substrate/src/chains/mod.rs | 5 +- .../src/chains/rococo_headers_to_wococo.rs | 60 ++++ .../src/chains/westend_headers_to_rococo.rs | 2 +- relays/bin-substrate/src/chains/wococo.rs | 39 ++ .../src/chains/wococo_headers_to_rococo.rs | 60 ++++ relays/bin-substrate/src/cli/init_bridge.rs | 28 +- relays/bin-substrate/src/cli/mod.rs | 15 + relays/bin-substrate/src/cli/relay_headers.rs | 17 + .../src/cli/relay_headers_and_messages.rs | 5 + relays/bin-substrate/src/finality_pipeline.rs | 4 +- relays/bin-substrate/src/main.rs | 3 - relays/bin-substrate/src/messages_lane.rs | 2 +- relays/bin-substrate/src/messages_source.rs | 2 +- relays/bin-substrate/src/messages_target.rs | 2 +- relays/bin-substrate/src/on_demand_headers.rs | 258 ++++++++++++-- relays/client-ethereum/Cargo.toml | 4 +- relays/client-substrate/Cargo.toml | 4 +- relays/client-wococo/Cargo.toml | 23 ++ relays/client-wococo/src/lib.rs | 97 +++++ relays/exchange/src/exchange.rs | 15 +- relays/exchange/src/exchange_loop.rs | 12 +- relays/finality/src/finality_loop.rs | 9 +- relays/finality/src/finality_loop_tests.rs | 3 +- relays/finality/src/lib.rs | 2 +- relays/headers/src/sync_loop.rs | 8 +- relays/headers/src/sync_types.rs | 2 +- relays/messages/src/message_lane.rs | 2 +- relays/messages/src/message_lane_loop.rs | 67 ++-- relays/messages/src/message_race_delivery.rs | 53 ++- relays/utils/src/initialize.rs | 46 ++- relays/utils/src/relay_loop.rs | 146 +++++--- scripts/dump-logs.sh | 8 +- 56 files changed, 1438 insertions(+), 483 deletions(-) create mode 100644 primitives/chain-wococo/Cargo.toml create mode 100644 primitives/chain-wococo/src/lib.rs create mode 100644 relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs create mode 100644 relays/bin-substrate/src/chains/wococo.rs create mode 100644 relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs create mode 100644 relays/client-wococo/Cargo.toml create mode 100644 relays/client-wococo/src/lib.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e6f7939efbcf..14e72ddad02e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -85,8 +85,8 @@ jobs: matrix: toolchain: - stable - #- beta - - nightly + #- beta + - nightly-2021-04-10 runs-on: ubuntu-latest env: RUST_BACKTRACE: full diff --git a/Cargo.lock b/Cargo.lock index 5811d7ad3b12..5828f6d7d4a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,22 +164,9 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "asn1_der" -version = "0.6.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fce6b6a0ffdafebd82c87e79e3f40e8d2c523e5fea5566ff6b90509bf98d638" -dependencies = [ - "asn1_der_derive", -] - -[[package]] -name = "asn1_der_derive" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0864d84b8e07b145449be9a8537db86bf9de5ce03b913214694643b4743502" -dependencies = [ - "quote", - "syn", -] +checksum = "9d6e24d2cce90c53b948c46271bfb053e4bdc2db9b5d3f65e20f8cf28a1b7fc3" [[package]] name = "async-channel" @@ -844,6 +831,21 @@ dependencies = [ "sp-version", ] +[[package]] +name = "bp-wococo" +version = "0.1.0" +dependencies = [ + "bp-header-chain", + "bp-messages", + "bp-polkadot-core", + "bp-runtime", + "parity-scale-codec 2.0.1", + "sp-api", + "sp-runtime", + "sp-std", + "sp-version", +] + [[package]] name = "bridge-runtime-common" version = "0.1.0" @@ -2012,7 +2014,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", ] @@ -2030,7 +2032,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "3.1.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -2049,7 +2051,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "Inflector", "chrono", @@ -2072,7 +2074,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -2087,7 +2089,7 @@ dependencies = [ [[package]] name = "frame-metadata" version = "13.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "serde", @@ -2098,7 +2100,7 @@ dependencies = [ [[package]] name = "frame-support" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "bitflags", "frame-metadata", @@ -2124,7 +2126,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "Inflector", "frame-support-procedural-tools", @@ -2136,7 +2138,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate 1.0.0", @@ -2148,7 +2150,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "proc-macro2", "quote", @@ -2158,7 +2160,7 @@ dependencies = [ [[package]] name = "frame-system" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -2175,7 +2177,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-api", @@ -3232,9 +3234,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.2.0-alpha.5" +version = "0.2.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0cbaee9ca6440e191545a68c7bf28db0ff918359a904e37a6e7cf7edd132f5a" +checksum = "5784ee8bb31988fa2c7a755fe31b0e21aa51894a67e5c99b6d4470f0253bf31a" dependencies = [ "Inflector", "proc-macro-crate 1.0.0", @@ -3245,9 +3247,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.2.0-alpha.5" +version = "0.2.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ce2de6884fb4abee16eca02329a1eec1eb8df8aed751a8e929083820c78ce7" +checksum = "bab3dabceeeeb865897661d532d47202eaae71cd2c606f53cb69f1fbc0555a51" dependencies = [ "async-trait", "beef", @@ -3261,9 +3263,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.2.0-alpha.5" +version = "0.2.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ece6acc5ef1e7877fd53887e8937b273466713dc8c017a32223c2b9b678d63" +checksum = "d6fdb4390bd25358c62e8b778652a564a1723ba07dca0feb3da439c2253fe59f" dependencies = [ "async-std", "async-tls", @@ -3397,9 +3399,9 @@ dependencies = [ [[package]] name = "libp2p" -version = "0.36.0" +version = "0.37.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe5759b526f75102829c15e4d8566603b4bf502ed19b5f35920d98113873470d" +checksum = "08053fbef67cd777049ef7a95ebaca2ece370b4ed7712c3fa404d69a88cb741b" dependencies = [ "atomic", "bytes 1.0.1", @@ -3436,9 +3438,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.28.1" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e1797734bbd4c453664fefb029628f77c356ffc5bce98f06b18a7db3ebb0f7" +checksum = "554d3e7e9e65f939d66b75fd6a4c67f258fe250da61b91f46c545fc4a89b51d9" dependencies = [ "asn1_der", "bs58", @@ -3495,9 +3497,9 @@ dependencies = [ [[package]] name = "libp2p-floodsub" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897645f99e9b396df256a6aa8ba8c4bc019ac6b7c62556f624b5feea9acc82bb" +checksum = "48a9b570f6766301d9c4aa00fce3554cad1598e2f466debbc4dde909028417cf" dependencies = [ "cuckoofilter", "fnv", @@ -3513,9 +3515,9 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.29.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794b0c85f5df1acbc1fc38414d37272594811193b6325c76d3931c3e3f5df8c0" +checksum = "e7b0c8506a6ec3344b9e706d7c7a6dba826f8ede735cfe13dde12a8c263c4af9" dependencies = [ "asynchronous-codec 0.6.0", "base64 0.13.0", @@ -3539,9 +3541,9 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88ebc841d744979176ab4b8b294a3e655a7ba4ef26a905d073a52b49ed4dff5" +checksum = "5f668f00efd9883e8b7bcc582eaf0164615792608f886f6577da18bcbeea0a46" dependencies = [ "futures 0.3.13", "libp2p-core", @@ -3555,9 +3557,9 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb5b90b6bda749023a85f60b49ea74b387c25f17d8df541ae72a3c75dd52e63" +checksum = "b07312ebe5ee4fd2404447a0609814574df55c65d4e20838b957bbd34907d820" dependencies = [ "arrayvec 0.5.2", "asynchronous-codec 0.6.0", @@ -3581,9 +3583,9 @@ dependencies = [ [[package]] name = "libp2p-mdns" -version = "0.29.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be28ca13bb648d249a9baebd750ebc64ce7040ddd5f0ce1035ff1f4549fb596d" +checksum = "41e282f974c4bea56db8acca50387f05189406e346318cb30190b0bde662961e" dependencies = [ "async-io", "data-encoding", @@ -3642,9 +3644,9 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea10fc5209260915ea65b78f612d7ff78a29ab288e7aa3250796866af861c45" +checksum = "bf4bfaffac63bf3c7ec11ed9d8879d455966ddea7e78ee14737f0b6dce0d1cd1" dependencies = [ "futures 0.3.13", "libp2p-core", @@ -3688,9 +3690,9 @@ dependencies = [ [[package]] name = "libp2p-relay" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff268be6a9d6f3c6cca3b81bbab597b15217f9ad8787c6c40fc548c1af7cd24" +checksum = "0b8786aca3f18671d8776289706a5521f6c9124a820f69e358de214b9939440d" dependencies = [ "asynchronous-codec 0.6.0", "bytes 1.0.1", @@ -3711,9 +3713,9 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725367dd2318c54c5ab1a6418592e5b01c63b0dedfbbfb8389220b2bcf691899" +checksum = "1cdbe172f08e6d0f95fa8634e273d4c4268c4063de2e33e7435194b0130c62e3" dependencies = [ "async-trait", "bytes 1.0.1", @@ -3731,9 +3733,9 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75c26980cadd7c25d89071cb23e1f7f5df4863128cc91d83c6ddc72338cecafa" +checksum = "1e04d8e1eef675029ec728ba14e8d0da7975d84b6679b699b4ae91a1de9c3a92" dependencies = [ "either", "futures 0.3.13", @@ -3747,9 +3749,9 @@ dependencies = [ [[package]] name = "libp2p-swarm-derive" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c564ebaa36a64839f51eaddb0243aaaa29ce64affb56129193cc3248b72af273" +checksum = "365b0a699fea5168676840567582a012ea297b1ca02eee467e58301b9c9c5eed" dependencies = [ "quote", "syn", @@ -3818,9 +3820,9 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.31.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d6144cc94143fb0a8dd1e7c2fbcc32a2808168bcd1d69920635424d5993b7b" +checksum = "f35da42cfc6d5cb0dcf3ad6881bc68d146cdf38f98655e09e33fbba4d13eabc4" dependencies = [ "futures 0.3.13", "libp2p-core", @@ -4104,6 +4106,7 @@ dependencies = [ "sc-service", "sc-telemetry", "sc-transaction-pool", + "serde_json", "sp-consensus", "sp-consensus-aura", "sp-core", @@ -4393,7 +4396,7 @@ dependencies = [ [[package]] name = "node-inspect" version = "0.8.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "log", @@ -4573,7 +4576,7 @@ dependencies = [ [[package]] name = "pallet-aura" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -4589,7 +4592,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -4604,7 +4607,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-benchmarking", "frame-support", @@ -4716,7 +4719,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-benchmarking", "frame-support", @@ -4737,7 +4740,7 @@ dependencies = [ [[package]] name = "pallet-randomness-collective-flip" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -4750,7 +4753,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -4784,7 +4787,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -4797,7 +4800,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-benchmarking", "frame-support", @@ -4814,7 +4817,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-support", "frame-system", @@ -4830,7 +4833,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "jsonrpc-core 15.1.0", "jsonrpc-core-client", @@ -4847,7 +4850,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "pallet-transaction-payment", "parity-scale-codec 2.0.1", @@ -6005,6 +6008,23 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "relay-wococo-client" +version = "0.1.0" +dependencies = [ + "bp-wococo", + "frame-support", + "frame-system", + "headers-relay", + "pallet-transaction-payment", + "parity-scale-codec 2.0.1", + "relay-substrate-client", + "relay-utils", + "sp-core", + "sp-keyring", + "sp-runtime", +] + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -6057,6 +6077,7 @@ dependencies = [ "sc-service", "sc-telemetry", "sc-transaction-pool", + "serde_json", "sp-consensus", "sp-consensus-aura", "sp-core", @@ -6293,7 +6314,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "futures-timer 3.0.2", @@ -6316,7 +6337,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sc-client-api", @@ -6332,7 +6353,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec 2.0.1", @@ -6353,7 +6374,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "proc-macro-crate 1.0.0", "proc-macro2", @@ -6364,7 +6385,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "chrono", "fdlimit", @@ -6402,7 +6423,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "fnv", @@ -6436,7 +6457,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "blake2-rfc", "hash-db", @@ -6466,7 +6487,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parking_lot 0.11.1", "sc-client-api", @@ -6478,7 +6499,7 @@ dependencies = [ [[package]] name = "sc-consensus-aura" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "derive_more", @@ -6510,7 +6531,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "derive_more", @@ -6557,7 +6578,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "fork-tree", "parity-scale-codec 2.0.1", @@ -6570,7 +6591,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "futures 0.3.13", @@ -6597,7 +6618,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "sc-client-api", @@ -6611,7 +6632,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "lazy_static", @@ -6641,7 +6662,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "parity-scale-codec 2.0.1", @@ -6658,7 +6679,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "parity-scale-codec 2.0.1", @@ -6673,7 +6694,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "parity-scale-codec 2.0.1", @@ -6691,7 +6712,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "derive_more", @@ -6731,7 +6752,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "finality-grandpa 0.14.0", @@ -6755,7 +6776,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "ansi_term 0.12.1", "futures 0.3.13", @@ -6773,7 +6794,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "derive_more", @@ -6793,7 +6814,7 @@ dependencies = [ [[package]] name = "sc-light" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "hash-db", "lazy_static", @@ -6812,7 +6833,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-std", "async-trait", @@ -6865,7 +6886,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "futures-timer 3.0.2", @@ -6882,7 +6903,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "bytes 0.5.6", "fnv", @@ -6910,7 +6931,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "libp2p", @@ -6923,7 +6944,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -6932,7 +6953,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "hash-db", @@ -6966,7 +6987,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "futures 0.3.13", @@ -6990,7 +7011,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.1.31", "jsonrpc-core 15.1.0", @@ -7008,7 +7029,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "directories", @@ -7072,7 +7093,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "parity-scale-codec 2.0.1", @@ -7087,7 +7108,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "chrono", "futures 0.3.13", @@ -7107,7 +7128,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "ansi_term 0.12.1", "atty", @@ -7134,7 +7155,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "proc-macro-crate 1.0.0", "proc-macro2", @@ -7145,7 +7166,7 @@ dependencies = [ [[package]] name = "sc-transaction-graph" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "futures 0.3.13", @@ -7167,7 +7188,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "futures-diagnose", @@ -7560,7 +7581,7 @@ dependencies = [ [[package]] name = "sp-allocator" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "sp-core", @@ -7572,7 +7593,7 @@ dependencies = [ [[package]] name = "sp-api" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "hash-db", "log", @@ -7589,7 +7610,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "blake2-rfc", "proc-macro-crate 1.0.0", @@ -7601,7 +7622,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "serde", @@ -7613,7 +7634,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "integer-sqrt", "num-traits", @@ -7627,7 +7648,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-inherents", @@ -7638,7 +7659,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-api", @@ -7650,7 +7671,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "log", @@ -7668,7 +7689,7 @@ dependencies = [ [[package]] name = "sp-chain-spec" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "serde", "serde_json", @@ -7677,7 +7698,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "futures 0.3.13", @@ -7704,7 +7725,7 @@ dependencies = [ [[package]] name = "sp-consensus-aura" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-api", @@ -7720,7 +7741,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "merlin", "parity-scale-codec 2.0.1", @@ -7741,7 +7762,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-arithmetic", @@ -7751,7 +7772,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "schnorrkel", @@ -7763,7 +7784,7 @@ dependencies = [ [[package]] name = "sp-core" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "base58", "blake2-rfc", @@ -7807,7 +7828,7 @@ dependencies = [ [[package]] name = "sp-database" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "kvdb", "parking_lot 0.11.1", @@ -7816,7 +7837,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "proc-macro2", "quote", @@ -7826,7 +7847,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "environmental", "parity-scale-codec 2.0.1", @@ -7837,7 +7858,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "finality-grandpa 0.14.0", "log", @@ -7854,7 +7875,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "parking_lot 0.11.1", @@ -7866,7 +7887,7 @@ dependencies = [ [[package]] name = "sp-io" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "hash-db", @@ -7890,7 +7911,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "lazy_static", "sp-core", @@ -7901,7 +7922,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-trait", "derive_more", @@ -7918,7 +7939,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "ruzstd", "zstd", @@ -7927,7 +7948,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "sp-api", "sp-core", @@ -7937,7 +7958,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "backtrace", ] @@ -7945,7 +7966,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "serde", "sp-core", @@ -7954,7 +7975,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "either", "hash256-std-hasher", @@ -7975,7 +7996,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec 2.0.1", @@ -7992,7 +8013,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "Inflector", "proc-macro-crate 1.0.0", @@ -8004,7 +8025,7 @@ dependencies = [ [[package]] name = "sp-serializer" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "serde", "serde_json", @@ -8013,7 +8034,7 @@ dependencies = [ [[package]] name = "sp-session" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-api", @@ -8026,7 +8047,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-runtime", @@ -8036,7 +8057,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "hash-db", "log", @@ -8058,12 +8079,12 @@ dependencies = [ [[package]] name = "sp-std" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" [[package]] name = "sp-storage" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "impl-serde", "parity-scale-codec 2.0.1", @@ -8076,7 +8097,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "sp-core", @@ -8089,7 +8110,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "parity-scale-codec 2.0.1", "sp-api", @@ -8102,7 +8123,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "log", "parity-scale-codec 2.0.1", @@ -8115,7 +8136,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "derive_more", "futures 0.3.13", @@ -8131,7 +8152,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "hash-db", "memory-db", @@ -8145,7 +8166,7 @@ dependencies = [ [[package]] name = "sp-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "futures 0.3.13", "futures-core", @@ -8157,7 +8178,7 @@ dependencies = [ [[package]] name = "sp-version" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "impl-serde", "parity-scale-codec 2.0.1", @@ -8169,7 +8190,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec 2.0.1", @@ -8390,7 +8411,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "frame-system-rpc-runtime-api", "futures 0.3.13", @@ -8413,7 +8434,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#46a64ac817ec909c66203a7e0715ee111762d3f7" +source = "git+https://github.com/paritytech/substrate?branch=master#0856e0729c5f9cd5d398b93680ab154fe486e588" dependencies = [ "async-std", "derive_more", @@ -8440,6 +8461,7 @@ dependencies = [ "bp-rococo", "bp-runtime", "bp-westend", + "bp-wococo", "bridge-runtime-common", "finality-grandpa 0.14.0", "finality-relay", @@ -8465,6 +8487,7 @@ dependencies = [ "relay-substrate-client", "relay-utils", "relay-westend-client", + "relay-wococo-client", "rialto-runtime", "sp-core", "sp-finality-grandpa", @@ -9895,15 +9918,15 @@ checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" [[package]] name = "yamux" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cc7bd8c983209ed5d527f44b01c41b7dc146fd960c61cf9e1d25399841dc271" +checksum = "e7d9028f208dd5e63c614be69f115c1b53cacc1111437d4c765185856666c107" dependencies = [ "futures 0.3.13", "log", "nohash-hasher", "parking_lot 0.11.1", - "rand 0.7.3", + "rand 0.8.3", "static_assertions", ] diff --git a/README.md b/README.md index 8f6446c8875a..84d776c4f8ef 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,8 @@ both Substrate chains it must be run last. ```bash # In `parity-bridges-common` folder -./deployments/local-scripts/run-rialto-bridge-node.sh -./deployments/local-scripts/run-millau-bridge-node.sh +./deployments/local-scripts/run-rialto-node.sh +./deployments/local-scripts/run-millau-node.sh ./deployments/local-scripts/relay-millau-to-rialto.sh ``` diff --git a/bin/millau/node/Cargo.toml b/bin/millau/node/Cargo.toml index e31e2c871a50..cbcb2e710c03 100644 --- a/bin/millau/node/Cargo.toml +++ b/bin/millau/node/Cargo.toml @@ -12,6 +12,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] jsonrpc-core = "15.1.0" structopt = "0.3.21" +serde_json = "1.0.59" # Bridge dependencies diff --git a/bin/millau/node/src/chain_spec.rs b/bin/millau/node/src/chain_spec.rs index f9e9502da72b..340b8fd9dffb 100644 --- a/bin/millau/node/src/chain_spec.rs +++ b/bin/millau/node/src/chain_spec.rs @@ -67,6 +67,15 @@ pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) { impl Alternative { /// Get an actual chain config from one of the alternatives. pub(crate) fn load(self) -> ChainSpec { + let properties = Some( + serde_json::json!({ + "tokenDecimals": 9, + "tokenSymbol": "MLAU", + }) + .as_object() + .expect("Map given; qed") + .clone(), + ); match self { Alternative::Development => ChainSpec::from_genesis( "Development", @@ -88,7 +97,7 @@ impl Alternative { vec![], None, None, - None, + properties, None, ), Alternative::LocalTestnet => ChainSpec::from_genesis( @@ -136,7 +145,7 @@ impl Alternative { vec![], None, None, - None, + properties, None, ), } diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 30cf1bd87cd8..7d25eb90c5e1 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -308,7 +308,6 @@ parameter_types! { // Note that once this is hit the pallet will essentially throttle incoming requests down to one // call per block. pub const MaxRequests: u32 = 50; - pub const WestendValidatorCount: u32 = 255; // Number of headers to keep. // diff --git a/bin/millau/runtime/src/rialto_messages.rs b/bin/millau/runtime/src/rialto_messages.rs index a800117dc551..736301016fa3 100644 --- a/bin/millau/runtime/src/rialto_messages.rs +++ b/bin/millau/runtime/src/rialto_messages.rs @@ -31,7 +31,7 @@ use frame_support::{ weights::{DispatchClass, Weight}, RuntimeDebug, }; -use sp_runtime::{FixedPointNumber, FixedU128}; +use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128}; use sp_std::{convert::TryFrom, ops::RangeInclusive}; /// Initial value of `RialtoToMillauConversionRate` parameter. diff --git a/bin/rialto/node/Cargo.toml b/bin/rialto/node/Cargo.toml index a51ee7a5ab5f..370985d8ae63 100644 --- a/bin/rialto/node/Cargo.toml +++ b/bin/rialto/node/Cargo.toml @@ -12,6 +12,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] jsonrpc-core = "15.1.0" structopt = "0.3.21" +serde_json = "1.0.59" # Bridge dependencies diff --git a/bin/rialto/node/src/chain_spec.rs b/bin/rialto/node/src/chain_spec.rs index 732cf1a4b13a..fb6dc92bf6d4 100644 --- a/bin/rialto/node/src/chain_spec.rs +++ b/bin/rialto/node/src/chain_spec.rs @@ -19,6 +19,7 @@ use rialto_runtime::{ AccountId, AuraConfig, BalancesConfig, BridgeKovanConfig, BridgeRialtoPoAConfig, GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, WASM_BINARY, }; +use serde_json::json; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sr25519, Pair, Public}; use sp_finality_grandpa::AuthorityId as GrandpaId; @@ -67,6 +68,15 @@ pub fn get_authority_keys_from_seed(s: &str) -> (AccountId, AuraId, GrandpaId) { impl Alternative { /// Get an actual chain config from one of the alternatives. pub(crate) fn load(self) -> ChainSpec { + let properties = Some( + json!({ + "tokenDecimals": 9, + "tokenSymbol": "RLT", + }) + .as_object() + .expect("Map given; qed") + .clone(), + ); match self { Alternative::Development => ChainSpec::from_genesis( "Development", @@ -88,7 +98,7 @@ impl Alternative { vec![], None, None, - None, + properties, None, ), Alternative::LocalTestnet => ChainSpec::from_genesis( @@ -136,7 +146,7 @@ impl Alternative { vec![], None, None, - None, + properties, None, ), } diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index 4e81d3efb1fb..69fff6b10c3f 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -409,16 +409,30 @@ impl pallet_session::Config for Runtime { } parameter_types! { - // This is a pretty unscientific cap. - // - // Note that once this is hit the pallet will essentially throttle incoming requests down to one - // call per block. + /// This is a pretty unscientific cap. + /// + /// Note that once this is hit the pallet will essentially throttle incoming requests down to one + /// call per block. pub const MaxRequests: u32 = 50; +} + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + /// Number of headers to keep in benchmarks. + /// + /// In benchmarks we always populate with full number of `HeadersToKeep` to make sure that + /// pruning is taken into account. + /// + /// Note: This is lower than regular value, to speed up benchmarking setup. + pub const HeadersToKeep: u32 = 1024; +} - // Number of headers to keep. - // - // Assuming the worst case of every header being finalized, we will keep headers at least for a - // week. +#[cfg(not(feature = "runtime-benchmarks"))] +parameter_types! { + /// Number of headers to keep. + /// + /// Assuming the worst case of every header being finalized, we will keep headers at least for a + /// week. pub const HeadersToKeep: u32 = 7 * bp_rialto::DAYS as u32; } diff --git a/bin/rialto/runtime/src/millau_messages.rs b/bin/rialto/runtime/src/millau_messages.rs index 8ee2094660c1..77b73c07857b 100644 --- a/bin/rialto/runtime/src/millau_messages.rs +++ b/bin/rialto/runtime/src/millau_messages.rs @@ -31,7 +31,7 @@ use frame_support::{ weights::{DispatchClass, Weight}, RuntimeDebug, }; -use sp_runtime::{FixedPointNumber, FixedU128}; +use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128}; use sp_std::{convert::TryFrom, ops::RangeInclusive}; /// Initial value of `MillauToRialtoConversionRate` parameter. diff --git a/bin/runtime-common/src/messages.rs b/bin/runtime-common/src/messages.rs index 8e83c0f94ada..54e8b30031a4 100644 --- a/bin/runtime-common/src/messages.rs +++ b/bin/runtime-common/src/messages.rs @@ -1407,6 +1407,8 @@ mod tests { #[test] fn transaction_payment_works_with_zero_multiplier() { + use sp_runtime::traits::Zero; + assert_eq!( transaction_payment( 100, @@ -1424,6 +1426,8 @@ mod tests { #[test] fn transaction_payment_works_with_non_zero_multiplier() { + use sp_runtime::traits::One; + assert_eq!( transaction_payment( 100, diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 416d080b0c17..f9649c58c478 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -314,8 +314,7 @@ impl, I: Instance> MessageDispatch for Pallet { // finally dispatch message let origin = RawOrigin::Signed(origin_account).into(); - - log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:?}", &call); + log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:.4096?}", &call); let dispatch_result = call.dispatch(origin); let actual_call_weight = extract_actual_weight(&dispatch_result, &dispatch_info); diff --git a/modules/grandpa/src/benchmarking.rs b/modules/grandpa/src/benchmarking.rs index cb170fdc8b19..b7294e918003 100644 --- a/modules/grandpa/src/benchmarking.rs +++ b/modules/grandpa/src/benchmarking.rs @@ -51,9 +51,10 @@ use bp_test_utils::{ TEST_GRANDPA_ROUND, TEST_GRANDPA_SET_ID, }; use frame_benchmarking::{benchmarks_instance_pallet, whitelisted_caller}; +use frame_support::traits::Get; use frame_system::RawOrigin; use sp_finality_grandpa::AuthorityId; -use sp_runtime::traits::{One, Zero}; +use sp_runtime::traits::Zero; use sp_std::{vec, vec::Vec}; // The maximum number of vote ancestries to include in a justification. @@ -66,6 +67,14 @@ const MAX_VOTE_ANCESTRIES: u32 = 1000; // number of validators. const MAX_VALIDATOR_SET_SIZE: u32 = 1024; +/// Returns number of first header to be imported. +/// +/// Since we boostrap the pallet with `HeadersToKeep` already imported headers, +/// this function computes the next expected header number to import. +fn header_number, I: 'static, N: From>() -> N { + (T::HeadersToKeep::get() + 1).into() +} + benchmarks_instance_pallet! { // This is the "gold standard" benchmark for this extrinsic, and it's what should be used to // annotate the weight in the pallet. @@ -90,9 +99,9 @@ benchmarks_instance_pallet! { is_halted: false, }; - initialize_bridge::(init_data); - let header: BridgedHeader = bp_test_utils::test_header(One::one()); + bootstrap_bridge::(init_data); + let header: BridgedHeader = bp_test_utils::test_header(header_number::()); let params = JustificationGeneratorParams { header: header.clone(), round: TEST_GRANDPA_ROUND, @@ -106,7 +115,7 @@ benchmarks_instance_pallet! { }: _(RawOrigin::Signed(caller), header, justification) verify { - let header: BridgedHeader = bp_test_utils::test_header(One::one()); + let header: BridgedHeader = bp_test_utils::test_header(header_number::()); let expected_hash = header.hash(); assert_eq!(>::get(), expected_hash); @@ -127,8 +136,8 @@ benchmarks_instance_pallet! { is_halted: false, }; - initialize_bridge::(init_data); - let header: BridgedHeader = bp_test_utils::test_header(One::one()); + bootstrap_bridge::(init_data); + let header: BridgedHeader = bp_test_utils::test_header(header_number::()); let params = JustificationGeneratorParams { header: header.clone(), @@ -143,7 +152,7 @@ benchmarks_instance_pallet! { }: submit_finality_proof(RawOrigin::Signed(caller), header, justification) verify { - let header: BridgedHeader = bp_test_utils::test_header(One::one()); + let header: BridgedHeader = bp_test_utils::test_header(header_number::()); let expected_hash = header.hash(); assert_eq!(>::get(), expected_hash); @@ -170,8 +179,8 @@ benchmarks_instance_pallet! { is_halted: false, }; - initialize_bridge::(init_data); - let header: BridgedHeader = bp_test_utils::test_header(One::one()); + bootstrap_bridge::(init_data); + let header: BridgedHeader = bp_test_utils::test_header(header_number::()); let params = JustificationGeneratorParams { header: header.clone(), @@ -186,7 +195,7 @@ benchmarks_instance_pallet! { }: submit_finality_proof(RawOrigin::Signed(caller), header, justification) verify { - let header: BridgedHeader = bp_test_utils::test_header(One::one()); + let header: BridgedHeader = bp_test_utils::test_header(header_number::()); let expected_hash = header.hash(); assert_eq!(>::get(), expected_hash); diff --git a/modules/grandpa/src/lib.rs b/modules/grandpa/src/lib.rs index 9fb7372b0204..80bc8e951aca 100644 --- a/modules/grandpa/src/lib.rs +++ b/modules/grandpa/src/lib.rs @@ -158,20 +158,8 @@ pub mod pallet { verify_justification::(&justification, hash, *number, authority_set)?; let _enacted = try_enact_authority_change::(&finality_target, set_id)?; - let index = >::get(); - let pruning = >::try_get(index); - >::put(hash); - >::insert(hash, finality_target); - >::insert(index, hash); >::mutate(|count| *count += 1); - - // Update ring buffer pointer and remove old header. - >::put((index + 1) % T::HeadersToKeep::get()); - if let Ok(hash) = pruning { - log::debug!(target: "runtime::bridge-grandpa", "Pruning old header: {:?}.", hash); - >::remove(hash); - } - + insert_header::(finality_target, hash); log::info!(target: "runtime::bridge-grandpa", "Succesfully imported finalized header with hash {:?}!", hash); Ok(().into()) @@ -427,6 +415,25 @@ pub mod pallet { ) } + /// Import a previously verified header to the storage. + /// + /// Note this function solely takes care of updating the storage and pruning old entries, + /// but does not verify the validaty of such import. + pub(crate) fn insert_header, I: 'static>(header: BridgedHeader, hash: BridgedBlockHash) { + let index = >::get(); + let pruning = >::try_get(index); + >::put(hash); + >::insert(hash, header); + >::insert(index, hash); + + // Update ring buffer pointer and remove old header. + >::put((index + 1) % T::HeadersToKeep::get()); + if let Ok(hash) = pruning { + log::debug!(target: "runtime::bridge-grandpa", "Pruning old header: {:?}.", hash); + >::remove(hash); + } + } + /// Since this writes to storage with no real checks this should only be used in functions that /// were called by a trusted origin. pub(crate) fn initialize_bridge, I: 'static>( @@ -441,8 +448,8 @@ pub mod pallet { let initial_hash = header.hash(); >::put(initial_hash); - >::put(initial_hash); - >::insert(initial_hash, header); + >::put(0); + insert_header::(header, initial_hash); let authority_set = bp_header_chain::AuthoritySet::new(authority_list, set_id); >::put(authority_set); @@ -450,6 +457,29 @@ pub mod pallet { >::put(is_halted); } + #[cfg(feature = "runtime-benchmarks")] + pub(crate) fn bootstrap_bridge, I: 'static>( + init_params: super::InitializationData>, + ) { + let start_number = *init_params.header.number(); + let end_number = start_number + T::HeadersToKeep::get().into(); + initialize_bridge::(init_params); + + let mut number = start_number; + while number < end_number { + number = number + sp_runtime::traits::One::one(); + let header = >::new( + number, + Default::default(), + Default::default(), + Default::default(), + Default::default(), + ); + let hash = header.hash(); + insert_header::(header, hash); + } + } + /// Ensure that the origin is either root, or `PalletOwner`. fn ensure_owner_or_root, I: 'static>(origin: T::Origin) -> Result<(), BadOrigin> { match origin.into() { diff --git a/modules/grandpa/src/weights.rs b/modules/grandpa/src/weights.rs index a548534a20b7..9e7c2ebc087e 100644 --- a/modules/grandpa/src/weights.rs +++ b/modules/grandpa/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for pallet_bridge_grandpa //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-04-14, STEPS: [50, ], REPEAT: 20 +//! DATE: 2021-04-21, STEPS: [50, ], REPEAT: 20 //! LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled //! CHAIN: Some("dev"), DB CACHE: 128 @@ -60,29 +60,29 @@ pub struct RialtoWeight(PhantomData); impl WeightInfo for RialtoWeight { fn submit_finality_proof(v: u32, p: u32) -> Weight { (0 as Weight) - .saturating_add((837_084_000 as Weight).saturating_mul(v as Weight)) - .saturating_add((874_929_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((756_462_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((791_236_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn submit_finality_proof_on_single_fork(v: u32) -> Weight { - (276_463_000 as Weight) - .saturating_add((14_149_000 as Weight).saturating_mul(v as Weight)) + (280_121_000 as Weight) + .saturating_add((14_098_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn submit_finality_proof_on_many_forks(p: u32) -> Weight { - (10_676_019_000 as Weight) - .saturating_add((97_598_000 as Weight).saturating_mul(p as Weight)) + (10_370_940_000 as Weight) + .saturating_add((96_902_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn find_scheduled_change(n: u32) -> Weight { - (618_000 as Weight).saturating_add((8_000 as Weight).saturating_mul(n as Weight)) + (479_000 as Weight).saturating_add((11_000 as Weight).saturating_mul(n as Weight)) } fn read_write_authority_sets(n: u32) -> Weight { - (8_582_000 as Weight) - .saturating_add((234_000 as Weight).saturating_mul(n as Weight)) + (8_030_000 as Weight) + .saturating_add((232_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -92,29 +92,29 @@ impl WeightInfo for RialtoWeight { impl WeightInfo for () { fn submit_finality_proof(v: u32, p: u32) -> Weight { (0 as Weight) - .saturating_add((837_084_000 as Weight).saturating_mul(v as Weight)) - .saturating_add((874_929_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((756_462_000 as Weight).saturating_mul(v as Weight)) + .saturating_add((791_236_000 as Weight).saturating_mul(p as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn submit_finality_proof_on_single_fork(v: u32) -> Weight { - (276_463_000 as Weight) - .saturating_add((14_149_000 as Weight).saturating_mul(v as Weight)) + (280_121_000 as Weight) + .saturating_add((14_098_000 as Weight).saturating_mul(v as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn submit_finality_proof_on_many_forks(p: u32) -> Weight { - (10_676_019_000 as Weight) - .saturating_add((97_598_000 as Weight).saturating_mul(p as Weight)) + (10_370_940_000 as Weight) + .saturating_add((96_902_000 as Weight).saturating_mul(p as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn find_scheduled_change(n: u32) -> Weight { - (618_000 as Weight).saturating_add((8_000 as Weight).saturating_mul(n as Weight)) + (479_000 as Weight).saturating_add((11_000 as Weight).saturating_mul(n as Weight)) } fn read_write_authority_sets(n: u32) -> Weight { - (8_582_000 as Weight) - .saturating_add((234_000 as Weight).saturating_mul(n as Weight)) + (8_030_000 as Weight) + .saturating_add((232_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } diff --git a/modules/messages/src/weights.rs b/modules/messages/src/weights.rs index 0eecd0d84623..f86a21e3ed90 100644 --- a/modules/messages/src/weights.rs +++ b/modules/messages/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for pallet_bridge_messages //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-04-14, STEPS: [50, ], REPEAT: 20 +//! DATE: 2021-04-21, STEPS: [50, ], REPEAT: 20 //! LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled //! CHAIN: Some("dev"), DB CACHE: 128 @@ -73,105 +73,105 @@ pub trait WeightInfo { pub struct RialtoWeight(PhantomData); impl WeightInfo for RialtoWeight { fn send_minimal_message_worst_case() -> Weight { - (149_497_000 as Weight) + (149_643_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) } fn send_1_kb_message_worst_case() -> Weight { - (154_339_000 as Weight) + (153_329_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) } fn send_16_kb_message_worst_case() -> Weight { - (200_066_000 as Weight) + (200_113_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) } fn increase_message_fee() -> Weight { - (6_432_637_000 as Weight) + (6_407_252_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn receive_single_message_proof() -> Weight { - (141_671_000 as Weight) + (141_256_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_two_messages_proof() -> Weight { - (247_393_000 as Weight) + (247_723_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_with_outbound_lane_state() -> Weight { - (159_312_000 as Weight) + (159_731_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_1_kb() -> Weight { - (167_935_000 as Weight) + (168_546_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_16_kb() -> Weight { - (449_846_000 as Weight) + (450_087_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_delivery_proof_for_single_message() -> Weight { - (127_322_000 as Weight) + (164_519_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { - (134_120_000 as Weight) + (173_300_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { - (191_193_000 as Weight) + (246_205_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn send_messages_of_various_lengths(i: u32) -> Weight { - (115_699_000 as Weight) + (149_551_000 as Weight) .saturating_add((3_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) } fn receive_multiple_messages_proof(i: u32) -> Weight { (0 as Weight) - .saturating_add((113_551_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((114_817_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_message_proofs_with_extra_nodes(i: u32) -> Weight { - (458_731_000 as Weight) - .saturating_add((9_000 as Weight).saturating_mul(i as Weight)) + (437_797_000 as Weight) + .saturating_add((10_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_message_proofs_with_large_leaf(i: u32) -> Weight { - (82_314_000 as Weight) + (137_633_000 as Weight) .saturating_add((7_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight { - (16_766_000 as Weight) - .saturating_add((115_533_000 as Weight).saturating_mul(i as Weight)) + (0 as Weight) + .saturating_add((118_482_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight { - (122_146_000 as Weight) - .saturating_add((6_789_000 as Weight).saturating_mul(i as Weight)) + (116_036_000 as Weight) + .saturating_add((7_118_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight { - (155_671_000 as Weight) - .saturating_add((63_020_000 as Weight).saturating_mul(i as Weight)) + (172_780_000 as Weight) + .saturating_add((63_718_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().writes(3 as Weight)) @@ -182,105 +182,105 @@ impl WeightInfo for RialtoWeight { // For backwards compatibility and tests impl WeightInfo for () { fn send_minimal_message_worst_case() -> Weight { - (149_497_000 as Weight) + (149_643_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } fn send_1_kb_message_worst_case() -> Weight { - (154_339_000 as Weight) + (153_329_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } fn send_16_kb_message_worst_case() -> Weight { - (200_066_000 as Weight) + (200_113_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } fn increase_message_fee() -> Weight { - (6_432_637_000 as Weight) + (6_407_252_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn receive_single_message_proof() -> Weight { - (141_671_000 as Weight) + (141_256_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_two_messages_proof() -> Weight { - (247_393_000 as Weight) + (247_723_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_with_outbound_lane_state() -> Weight { - (159_312_000 as Weight) + (159_731_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_1_kb() -> Weight { - (167_935_000 as Weight) + (168_546_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_single_message_proof_16_kb() -> Weight { - (449_846_000 as Weight) + (450_087_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_delivery_proof_for_single_message() -> Weight { - (127_322_000 as Weight) + (164_519_000 as Weight) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { - (134_120_000 as Weight) + (173_300_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { - (191_193_000 as Weight) + (246_205_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn send_messages_of_various_lengths(i: u32) -> Weight { - (115_699_000 as Weight) + (149_551_000 as Weight) .saturating_add((3_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } fn receive_multiple_messages_proof(i: u32) -> Weight { (0 as Weight) - .saturating_add((113_551_000 as Weight).saturating_mul(i as Weight)) + .saturating_add((114_817_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_message_proofs_with_extra_nodes(i: u32) -> Weight { - (458_731_000 as Weight) - .saturating_add((9_000 as Weight).saturating_mul(i as Weight)) + (437_797_000 as Weight) + .saturating_add((10_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_message_proofs_with_large_leaf(i: u32) -> Weight { - (82_314_000 as Weight) + (137_633_000 as Weight) .saturating_add((7_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight { - (16_766_000 as Weight) - .saturating_add((115_533_000 as Weight).saturating_mul(i as Weight)) + (0 as Weight) + .saturating_add((118_482_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight { - (122_146_000 as Weight) - .saturating_add((6_789_000 as Weight).saturating_mul(i as Weight)) + (116_036_000 as Weight) + .saturating_add((7_118_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight { - (155_671_000 as Weight) - .saturating_add((63_020_000 as Weight).saturating_mul(i as Weight)) + (172_780_000 as Weight) + .saturating_add((63_718_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight))) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) diff --git a/primitives/chain-millau/src/lib.rs b/primitives/chain-millau/src/lib.rs index 22f09cb5b093..a5f3a888f9ad 100644 --- a/primitives/chain-millau/src/lib.rs +++ b/primitives/chain-millau/src/lib.rs @@ -259,31 +259,6 @@ pub const FROM_MILLAU_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromMillauInboundLa pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str = "FromMillauInboundLaneApi_unrewarded_relayers_state"; sp_api::decl_runtime_apis! { - /// API for querying information about Millau headers from the Bridge Pallet instance. - /// - /// This API is implemented by runtimes that are bridging with the Millau chain, not the - /// Millau runtime itself. - pub trait MillauHeaderApi { - /// Returns number and hash of the best blocks known to the bridge module. - /// - /// Will return multiple headers if there are many headers at the same "best" height. - /// - /// The caller should only submit an `import_header` transaction that makes - /// (or leads to making) other header the best one. - fn best_blocks() -> Vec<(BlockNumber, Hash)>; - /// Returns number and hash of the best finalized block known to the bridge module. - fn finalized_block() -> (BlockNumber, Hash); - /// Returns numbers and hashes of headers that require finality proofs. - /// - /// An empty response means that there are no headers which currently require a - /// finality proof. - fn incomplete_headers() -> Vec<(BlockNumber, Hash)>; - /// Returns true if the header is known to the runtime. - fn is_known_block(hash: Hash) -> bool; - /// Returns true if the header is considered finalized by the runtime. - fn is_finalized_block(hash: Hash) -> bool; - } - /// API for querying information about the finalized Millau headers. /// /// This API is implemented by runtimes that are bridging with the Millau chain, not the diff --git a/primitives/chain-rialto/src/lib.rs b/primitives/chain-rialto/src/lib.rs index c10f31bae33f..c063dc72a7f2 100644 --- a/primitives/chain-rialto/src/lib.rs +++ b/primitives/chain-rialto/src/lib.rs @@ -220,31 +220,6 @@ pub const FROM_RIALTO_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromRialtoInboundLa pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str = "FromRialtoInboundLaneApi_unrewarded_relayers_state"; sp_api::decl_runtime_apis! { - /// API for querying information about Rialto headers from the Bridge Pallet instance. - /// - /// This API is implemented by runtimes that are bridging with the Rialto chain, not the - /// Rialto runtime itself. - pub trait RialtoHeaderApi { - /// Returns number and hash of the best blocks known to the bridge module. - /// - /// Will return multiple headers if there are many headers at the same "best" height. - /// - /// The caller should only submit an `import_header` transaction that makes - /// (or leads to making) other header the best one. - fn best_blocks() -> Vec<(BlockNumber, Hash)>; - /// Returns number and hash of the best finalized block known to the bridge module. - fn finalized_block() -> (BlockNumber, Hash); - /// Returns numbers and hashes of headers that require finality proofs. - /// - /// An empty response means that there are no headers which currently require a - /// finality proof. - fn incomplete_headers() -> Vec<(BlockNumber, Hash)>; - /// Returns true if the header is known to the runtime. - fn is_known_block(hash: Hash) -> bool; - /// Returns true if the header is considered finalized by the runtime. - fn is_finalized_block(hash: Hash) -> bool; - } - /// API for querying information about the finalized Rialto headers. /// /// This API is implemented by runtimes that are bridging with the Rialto chain, not the diff --git a/primitives/chain-rococo/src/lib.rs b/primitives/chain-rococo/src/lib.rs index b79fdf6cfcf0..2e64fc419007 100644 --- a/primitives/chain-rococo/src/lib.rs +++ b/primitives/chain-rococo/src/lib.rs @@ -57,12 +57,16 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { pub enum Call { /// Westend bridge pallet. #[codec(index = 40)] - BridgeGrandpaWestend(BridgeGrandpaWestendCall), + BridgeGrandpaWestend(BridgeGrandpaCall), + + /// Wococo bridge pallet. + #[codec(index = 41)] + BridgeGrandpaWococo(BridgeGrandpaCall), } #[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)] #[allow(non_camel_case_types)] -pub enum BridgeGrandpaWestendCall { +pub enum BridgeGrandpaCall { #[codec(index = 0)] submit_finality_proof( ::Header, diff --git a/primitives/chain-wococo/Cargo.toml b/primitives/chain-wococo/Cargo.toml new file mode 100644 index 000000000000..ecf783a51eeb --- /dev/null +++ b/primitives/chain-wococo/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "bp-wococo" +description = "Primitives of Wococo runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] +parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] } + +# Bridge Dependencies +bp-header-chain = { path = "../header-chain", default-features = false } +bp-messages = { path = "../messages", default-features = false } +bp-polkadot-core = { path = "../polkadot-core", default-features = false } +bp-runtime = { path = "../runtime", default-features = false } + +# Substrate Based Dependencies +sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-header-chain/std", + "bp-messages/std", + "bp-polkadot-core/std", + "bp-runtime/std", + "parity-scale-codec/std", + "sp-api/std", + "sp-runtime/std", + "sp-std/std", + "sp-version/std", +] diff --git a/primitives/chain-wococo/src/lib.rs b/primitives/chain-wococo/src/lib.rs new file mode 100644 index 000000000000..43225bcc6406 --- /dev/null +++ b/primitives/chain-wococo/src/lib.rs @@ -0,0 +1,172 @@ +// 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 . + +#![cfg_attr(not(feature = "std"), no_std)] +// RuntimeApi generated functions +#![allow(clippy::too_many_arguments)] +// Runtime-generated DecodeLimit::decode_all_with_depth_limit +#![allow(clippy::unnecessary_mut_passed)] + +use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use bp_runtime::Chain; +use sp_std::prelude::*; +use sp_version::RuntimeVersion; + +pub use bp_polkadot_core::*; + +/// Wococo Chain +pub type Wococo = PolkadotLike; + +pub type UncheckedExtrinsic = bp_polkadot_core::UncheckedExtrinsic; + +// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo. +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: sp_version::create_runtime_str!("rococo"), + impl_name: sp_version::create_runtime_str!("parity-rococo-v1.5"), + authoring_version: 0, + spec_version: 231, + impl_version: 0, + apis: sp_version::create_apis_vec![[]], + transaction_version: 0, +}; + +/// Wococo Runtime `Call` enum. +/// +/// The enum represents a subset of possible `Call`s we can send to Rococo chain. +/// Ideally this code would be auto-generated from Metadata, because we want to +/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s. +/// +/// All entries here (like pretty much in the entire file) must be kept in sync with Rococo +/// `construct_runtime`, so that we maintain SCALE-compatibility. +/// +/// See: https://github.com/paritytech/polkadot/blob/master/runtime/rococo/src/lib.rs +#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)] +pub enum Call { + /// Westend bridge pallet. + #[codec(index = 40)] + BridgeGrandpaRococo(BridgeGrandpaRococoCall), +} + +#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)] +#[allow(non_camel_case_types)] +pub enum BridgeGrandpaRococoCall { + #[codec(index = 0)] + submit_finality_proof( + ::Header, + bp_header_chain::justification::GrandpaJustification<::Header>, + ), + #[codec(index = 1)] + initialize(bp_header_chain::InitializationData<::Header>), +} + +impl sp_runtime::traits::Dispatchable for Call { + type Origin = (); + type Config = (); + type Info = (); + type PostInfo = (); + + fn dispatch(self, _origin: Self::Origin) -> sp_runtime::DispatchResultWithInfo { + unimplemented!("The Call is not expected to be dispatched.") + } +} + +// We use this to get the account on Wococo (target) which is derived from Rococo's (source) +// account. +pub fn derive_account_from_rococo_id(id: bp_runtime::SourceAccount) -> AccountId { + let encoded_id = bp_runtime::derive_account_id(bp_runtime::ROCOCO_BRIDGE_INSTANCE, id); + AccountIdConverter::convert(encoded_id) +} + +/// Name of the `WococoFinalityApi::best_finalized` runtime method. +pub const BEST_FINALIZED_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_best_finalized"; +/// Name of the `WococoFinalityApi::is_known_header` runtime method. +pub const IS_KNOWN_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_is_known_header"; + +/// Name of the `ToWococoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. +pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str = + "ToWococoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; +/// Name of the `ToWococoOutboundLaneApi::messages_dispatch_weight` runtime method. +pub const TO_WOCOCO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToWococoOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToWococoOutboundLaneApi::latest_generated_nonce` runtime method. +pub const TO_WOCOCO_LATEST_GENERATED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_generated_nonce"; +/// Name of the `ToWococoOutboundLaneApi::latest_received_nonce` runtime method. +pub const TO_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_received_nonce"; + +/// Name of the `FromWococoInboundLaneApi::latest_received_nonce` runtime method. +pub const FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "FromWococoInboundLaneApi_latest_received_nonce"; +/// Name of the `FromWococoInboundLaneApi::latest_onfirmed_nonce` runtime method. +pub const FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromWococoInboundLaneApi_latest_confirmed_nonce"; +/// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method. +pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str = "FromWococoInboundLaneApi_unrewarded_relayers_state"; + +sp_api::decl_runtime_apis! { + /// API for querying information about the finalized Wococo headers. + /// + /// This API is implemented by runtimes that are bridging with the Wococo chain, not the + /// Wococo runtime itself. + pub trait WococoFinalityApi { + /// Returns number and hash of the best finalized header known to the bridge module. + fn best_finalized() -> (BlockNumber, Hash); + /// Returns true if the header is known to the runtime. + fn is_known_header(hash: Hash) -> bool; + } + + /// Outbound message lane API for messages that are sent to Wococo chain. + /// + /// This API is implemented by runtimes that are sending messages to Wococo chain, not the + /// Wococo runtime itself. + pub trait ToWococoOutboundLaneApi { + /// Estimate message delivery and dispatch fee that needs to be paid by the sender on + /// this chain. + /// + /// Returns `None` if message is too expensive to be sent to Wococo from this chain. + /// + /// Please keep in mind that this method returns lowest message fee required for message + /// to be accepted to the lane. It may be good idea to pay a bit over this price to account + /// future exchange rate changes and guarantee that relayer would deliver your message + /// to the target chain. + fn estimate_message_delivery_and_dispatch_fee( + lane_id: LaneId, + payload: OutboundPayload, + ) -> Option; + /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// + /// If some (or all) messages are missing from the storage, they'll also will + /// be missing from the resulting vector. The vector is ordered by the nonce. + fn messages_dispatch_weight( + lane: LaneId, + begin: MessageNonce, + end: MessageNonce, + ) -> Vec<(MessageNonce, Weight, u32)>; + /// Returns nonce of the latest message, received by bridged chain. + fn latest_received_nonce(lane: LaneId) -> MessageNonce; + /// Returns nonce of the latest message, generated by given lane. + fn latest_generated_nonce(lane: LaneId) -> MessageNonce; + } + + /// Inbound message lane API for messages sent by Wococo chain. + /// + /// This API is implemented by runtimes that are receiving messages from Wococo chain, not the + /// Wococo runtime itself. + pub trait FromWococoInboundLaneApi { + /// Returns nonce of the latest message, received by given lane. + fn latest_received_nonce(lane: LaneId) -> MessageNonce; + /// Nonce of latest message that has been confirmed to the bridged chain. + fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce; + /// State of the unrewarded relayers set at given lane. + fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; + } +} diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index e7f990d28309..6f58b47a0960 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -50,6 +50,9 @@ pub const KUSAMA_BRIDGE_INSTANCE: InstanceId = *b"ksma"; /// Bridge-with-Rococo instance id. pub const ROCOCO_BRIDGE_INSTANCE: InstanceId = *b"roco"; +/// Bridge-with-Wococo instance id. +pub const WOCOCO_BRIDGE_INSTANCE: InstanceId = *b"woco"; + /// Bridge-with-Westend instance id. pub const WESTEND_BRIDGE_INSTANCE: InstanceId = *b"wend"; diff --git a/relays/bin-substrate/Cargo.toml b/relays/bin-substrate/Cargo.toml index d203201e60a4..f5711e0766d1 100644 --- a/relays/bin-substrate/Cargo.toml +++ b/relays/bin-substrate/Cargo.toml @@ -27,6 +27,7 @@ bp-millau = { path = "../../primitives/chain-millau" } bp-polkadot = { path = "../../primitives/chain-polkadot" } bp-rialto = { path = "../../primitives/chain-rialto" } bp-rococo = { path = "../../primitives/chain-rococo" } +bp-wococo = { path = "../../primitives/chain-wococo" } bp-runtime = { path = "../../primitives/runtime" } bp-westend = { path = "../../primitives/chain-westend" } bridge-runtime-common = { path = "../../bin/runtime-common" } @@ -42,6 +43,7 @@ relay-millau-client = { path = "../client-millau" } relay-polkadot-client = { path = "../client-polkadot" } relay-rialto-client = { path = "../client-rialto" } relay-rococo-client = { path = "../client-rococo" } +relay-wococo-client = { path = "../client-wococo" } relay-substrate-client = { path = "../client-substrate" } relay-utils = { path = "../utils" } relay-westend-client = { path = "../client-westend" } diff --git a/relays/bin-substrate/src/chains/mod.rs b/relays/bin-substrate/src/chains/mod.rs index 9e6a7361d5fd..18092518d057 100644 --- a/relays/bin-substrate/src/chains/mod.rs +++ b/relays/bin-substrate/src/chains/mod.rs @@ -21,13 +21,16 @@ pub mod millau_messages_to_rialto; pub mod rialto_headers_to_millau; pub mod rialto_messages_to_millau; pub mod rococo_headers_to_westend; +pub mod rococo_headers_to_wococo; pub mod westend_headers_to_millau; pub mod westend_headers_to_rococo; +pub mod wococo_headers_to_rococo; mod millau; mod rialto; mod rococo; mod westend; +mod wococo; use relay_utils::metrics::{FloatJsonValueMetric, MetricsParams}; @@ -270,7 +273,7 @@ mod rococo_tests { votes_ancestries: vec![], }; - let actual = bp_rococo::BridgeGrandpaWestendCall::submit_finality_proof(header.clone(), justification.clone()); + let actual = bp_rococo::BridgeGrandpaCall::submit_finality_proof(header.clone(), justification.clone()); let expected = millau_runtime::BridgeGrandpaRialtoCall::::submit_finality_proof( header, justification, diff --git a/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs b/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs new file mode 100644 index 000000000000..5247c6068b5e --- /dev/null +++ b/relays/bin-substrate/src/chains/rococo_headers_to_wococo.rs @@ -0,0 +1,60 @@ +// 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 . + +//! Rococo-to-Wococo headers sync entrypoint. + +use crate::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; + +use bp_header_chain::justification::GrandpaJustification; +use codec::Encode; +use relay_rococo_client::{Rococo, SyncHeader as RococoSyncHeader}; +use relay_substrate_client::{Chain, TransactionSignScheme}; +use relay_utils::metrics::MetricsParams; +use relay_wococo_client::{SigningParams as WococoSigningParams, Wococo}; +use sp_core::{Bytes, Pair}; + +/// Rococo-to-Wococo finality sync pipeline. +pub(crate) type RococoFinalityToWococo = SubstrateFinalityToSubstrate; + +impl SubstrateFinalitySyncPipeline for RococoFinalityToWococo { + const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD; + + type TargetChain = Wococo; + + fn customize_metrics(params: MetricsParams) -> anyhow::Result { + crate::chains::add_polkadot_kusama_price_metrics::(params) + } + + fn transactions_author(&self) -> bp_wococo::AccountId { + (*self.target_sign.public().as_array_ref()).into() + } + + fn make_submit_finality_proof_transaction( + &self, + transaction_nonce: ::Index, + header: RococoSyncHeader, + proof: GrandpaJustification, + ) -> Bytes { + let call = bp_wococo::Call::BridgeGrandpaRococo(bp_wococo::BridgeGrandpaRococoCall::submit_finality_proof( + header.into_inner(), + proof, + )); + let genesis_hash = *self.target_client.genesis_hash(); + let transaction = Wococo::sign_transaction(genesis_hash, &self.target_sign, transaction_nonce, call); + + Bytes(transaction.encode()) + } +} diff --git a/relays/bin-substrate/src/chains/westend_headers_to_rococo.rs b/relays/bin-substrate/src/chains/westend_headers_to_rococo.rs index 577a858d9229..f1b390215748 100644 --- a/relays/bin-substrate/src/chains/westend_headers_to_rococo.rs +++ b/relays/bin-substrate/src/chains/westend_headers_to_rococo.rs @@ -48,7 +48,7 @@ impl SubstrateFinalitySyncPipeline for WestendFinalityToRococo { header: WestendSyncHeader, proof: GrandpaJustification, ) -> Bytes { - let call = bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaWestendCall::submit_finality_proof( + let call = bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaCall::submit_finality_proof( header.into_inner(), proof, )); diff --git a/relays/bin-substrate/src/chains/wococo.rs b/relays/bin-substrate/src/chains/wococo.rs new file mode 100644 index 000000000000..549aa8a882c7 --- /dev/null +++ b/relays/bin-substrate/src/chains/wococo.rs @@ -0,0 +1,39 @@ +// 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 . + +use crate::cli::{encode_message, CliChain}; +use frame_support::weights::Weight; +use relay_wococo_client::Wococo; +use sp_version::RuntimeVersion; + +impl CliChain for Wococo { + const RUNTIME_VERSION: RuntimeVersion = bp_wococo::VERSION; + + type KeyPair = sp_core::sr25519::Pair; + type MessagePayload = (); + + fn ss58_format() -> u16 { + 42 + } + + fn max_extrinsic_weight() -> Weight { + 0 + } + + fn encode_message(_message: encode_message::MessagePayload) -> Result { + Err("Sending messages from Wococo is not yet supported.".into()) + } +} diff --git a/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs b/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs new file mode 100644 index 000000000000..84f970440c20 --- /dev/null +++ b/relays/bin-substrate/src/chains/wococo_headers_to_rococo.rs @@ -0,0 +1,60 @@ +// 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 . + +//! Wococo-to-Rococo headers sync entrypoint. + +use crate::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate}; + +use bp_header_chain::justification::GrandpaJustification; +use codec::Encode; +use relay_rococo_client::{Rococo, SigningParams as RococoSigningParams}; +use relay_substrate_client::{Chain, TransactionSignScheme}; +use relay_utils::metrics::MetricsParams; +use relay_wococo_client::{SyncHeader as WococoSyncHeader, Wococo}; +use sp_core::{Bytes, Pair}; + +/// Wococo-to-Rococo finality sync pipeline. +pub(crate) type WococoFinalityToRococo = SubstrateFinalityToSubstrate; + +impl SubstrateFinalitySyncPipeline for WococoFinalityToRococo { + const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD; + + type TargetChain = Rococo; + + fn customize_metrics(params: MetricsParams) -> anyhow::Result { + crate::chains::add_polkadot_kusama_price_metrics::(params) + } + + fn transactions_author(&self) -> bp_rococo::AccountId { + (*self.target_sign.public().as_array_ref()).into() + } + + fn make_submit_finality_proof_transaction( + &self, + transaction_nonce: ::Index, + header: WococoSyncHeader, + proof: GrandpaJustification, + ) -> Bytes { + let call = bp_rococo::Call::BridgeGrandpaWococo(bp_rococo::BridgeGrandpaCall::submit_finality_proof( + header.into_inner(), + proof, + )); + let genesis_hash = *self.target_client.genesis_hash(); + let transaction = Rococo::sign_transaction(genesis_hash, &self.target_sign, transaction_nonce, call); + + Bytes(transaction.encode()) + } +} diff --git a/relays/bin-substrate/src/cli/init_bridge.rs b/relays/bin-substrate/src/cli/init_bridge.rs index cdd8ec369161..df7786447d73 100644 --- a/relays/bin-substrate/src/cli/init_bridge.rs +++ b/relays/bin-substrate/src/cli/init_bridge.rs @@ -46,6 +46,8 @@ arg_enum! { WestendToMillau, WestendToRococo, RococoToWestend, + RococoToWococo, + WococoToRococo, } } @@ -109,7 +111,7 @@ macro_rules! select_bridge { fn encode_init_bridge( init_data: InitializationData<::Header>, ) -> ::Call { - bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaWestendCall::initialize(init_data)) + bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaCall::initialize(init_data)) } $generic @@ -124,6 +126,30 @@ macro_rules! select_bridge { bp_westend::Call::BridgeGrandpaRococo(bp_westend::BridgeGrandpaRococoCall::initialize(init_data)) } + $generic + } + InitBridgeName::RococoToWococo => { + type Source = relay_rococo_client::Rococo; + type Target = relay_wococo_client::Wococo; + + fn encode_init_bridge( + init_data: InitializationData<::Header>, + ) -> ::Call { + bp_wococo::Call::BridgeGrandpaRococo(bp_wococo::BridgeGrandpaRococoCall::initialize(init_data)) + } + + $generic + } + InitBridgeName::WococoToRococo => { + type Source = relay_wococo_client::Wococo; + type Target = relay_rococo_client::Rococo; + + fn encode_init_bridge( + init_data: InitializationData<::Header>, + ) -> ::Call { + bp_rococo::Call::BridgeGrandpaWococo(bp_rococo::BridgeGrandpaCall::initialize(init_data)) + } + $generic } } diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 505ef11ee2a5..341051de5c27 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -89,8 +89,23 @@ pub enum Command { } impl Command { + // Initialize logger depending on the command. + fn init_logger(&self) { + use relay_utils::initialize::{initialize_logger, initialize_relay}; + + match self { + Self::RelayHeaders(_) | Self::RelayMessages(_) | Self::RelayHeadersAndMessages(_) | Self::InitBridge(_) => { + initialize_relay(); + } + _ => { + initialize_logger(false); + } + } + } + /// Run the command. pub async fn run(self) -> anyhow::Result<()> { + self.init_logger(); match self { Self::RelayHeaders(arg) => arg.run().await?, Self::RelayMessages(arg) => arg.run().await?, diff --git a/relays/bin-substrate/src/cli/relay_headers.rs b/relays/bin-substrate/src/cli/relay_headers.rs index 346790f2ae74..78b9818c5492 100644 --- a/relays/bin-substrate/src/cli/relay_headers.rs +++ b/relays/bin-substrate/src/cli/relay_headers.rs @@ -44,6 +44,8 @@ arg_enum! { WestendToMillau, WestendToRococo, RococoToWestend, + RococoToWococo, + WococoToRococo, } } @@ -83,6 +85,20 @@ macro_rules! select_bridge { type Target = relay_westend_client::Westend; type Finality = crate::chains::rococo_headers_to_westend::RococoFinalityToWestend; + $generic + } + RelayHeadersBridge::RococoToWococo => { + type Source = relay_rococo_client::Rococo; + type Target = relay_wococo_client::Wococo; + type Finality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo; + + $generic + } + RelayHeadersBridge::WococoToRococo => { + type Source = relay_wococo_client::Wococo; + type Target = relay_rococo_client::Rococo; + type Finality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo; + $generic } } @@ -102,6 +118,7 @@ impl RelayHeaders { Finality::new(target_client.clone(), target_sign), source_client, target_client, + false, metrics_params, ) .await diff --git a/relays/bin-substrate/src/cli/relay_headers_and_messages.rs b/relays/bin-substrate/src/cli/relay_headers_and_messages.rs index 98ff1268fae9..f2238ba5763c 100644 --- a/relays/bin-substrate/src/cli/relay_headers_and_messages.rs +++ b/relays/bin-substrate/src/cli/relay_headers_and_messages.rs @@ -96,6 +96,9 @@ macro_rules! select_bridge { type LeftToRightMessages = crate::chains::millau_messages_to_rialto::MillauMessagesToRialto; type RightToLeftMessages = crate::chains::rialto_messages_to_millau::RialtoMessagesToMillau; + const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_millau::BlockNumber = bp_millau::SESSION_LENGTH; + const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_rialto::BlockNumber = bp_rialto::SESSION_LENGTH; + use crate::chains::millau_messages_to_rialto::run as left_to_right_messages; use crate::chains::rialto_messages_to_millau::run as right_to_left_messages; @@ -131,11 +134,13 @@ impl RelayHeadersAndMessages { left_client.clone(), right_client.clone(), LeftToRightFinality::new(right_client.clone(), right_sign.clone()), + MAX_MISSING_LEFT_HEADERS_AT_RIGHT, ); let right_to_left_on_demand_headers = OnDemandHeadersRelay::new( right_client.clone(), left_client.clone(), RightToLeftFinality::new(left_client.clone(), left_sign.clone()), + MAX_MISSING_RIGHT_HEADERS_AT_LEFT, ); let left_to_right_messages = left_to_right_messages(MessagesRelayParams { diff --git a/relays/bin-substrate/src/finality_pipeline.rs b/relays/bin-substrate/src/finality_pipeline.rs index bc8461f6a838..dad69b1576b0 100644 --- a/relays/bin-substrate/src/finality_pipeline.rs +++ b/relays/bin-substrate/src/finality_pipeline.rs @@ -96,7 +96,7 @@ where SourceChain: Clone + Chain + Debug, BlockNumberOf: BlockNumberBase, TargetChain: Clone + Chain + Debug, - TargetSign: Clone + Send + Sync, + TargetSign: 'static + Clone + Send + Sync, { const SOURCE_NAME: &'static str = SourceChain::NAME; const TARGET_NAME: &'static str = TargetChain::NAME; @@ -112,6 +112,7 @@ pub async fn run( pipeline: P, source_client: Client, target_client: Client, + is_on_demand_task: bool, metrics_params: MetricsParams, ) -> anyhow::Result<()> where @@ -137,6 +138,7 @@ where FinalitySource::new(source_client), SubstrateFinalityTarget::new(target_client, pipeline), FinalitySyncParams { + is_on_demand_task, tick: std::cmp::max(SourceChain::AVERAGE_BLOCK_INTERVAL, TargetChain::AVERAGE_BLOCK_INTERVAL), recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT, stall_timeout: STALL_TIMEOUT, diff --git a/relays/bin-substrate/src/main.rs b/relays/bin-substrate/src/main.rs index 6bf7561fcdb3..d119042b0d8d 100644 --- a/relays/bin-substrate/src/main.rs +++ b/relays/bin-substrate/src/main.rs @@ -18,8 +18,6 @@ #![warn(missing_docs)] -use relay_utils::initialize::initialize_logger; - mod chains; mod cli; mod finality_pipeline; @@ -31,7 +29,6 @@ mod messages_target; mod on_demand_headers; fn main() { - initialize_logger(false); let command = cli::parse_args(); let run = command.run(); let result = async_std::task::block_on(run); diff --git a/relays/bin-substrate/src/messages_lane.rs b/relays/bin-substrate/src/messages_lane.rs index 9948b6ec0836..616e2253a6b0 100644 --- a/relays/bin-substrate/src/messages_lane.rs +++ b/relays/bin-substrate/src/messages_lane.rs @@ -203,7 +203,7 @@ mod tests { // reserved for messages dispatch allows dispatch of non-trivial messages. // // Any significant change in this values should attract additional attention. - (1020, 216_583_333_334), + (1013, 216_583_333_334), ); } } diff --git a/relays/bin-substrate/src/messages_source.rs b/relays/bin-substrate/src/messages_source.rs index cf98f3276be6..0ccf8bbde885 100644 --- a/relays/bin-substrate/src/messages_source.rs +++ b/relays/bin-substrate/src/messages_source.rs @@ -93,7 +93,7 @@ impl RelayClient for SubstrateMessagesSource where C: Chain, P: SubstrateMessageLane, - R: Send + Sync, + R: 'static + Send + Sync, I: Send + Sync + Instance, { type Error = SubstrateError; diff --git a/relays/bin-substrate/src/messages_target.rs b/relays/bin-substrate/src/messages_target.rs index 176083273069..39f638d7e91c 100644 --- a/relays/bin-substrate/src/messages_target.rs +++ b/relays/bin-substrate/src/messages_target.rs @@ -93,7 +93,7 @@ impl RelayClient for SubstrateMessagesTarget where C: Chain, P: SubstrateMessageLane, - R: Send + Sync, + R: 'static + Send + Sync, I: Send + Sync + Instance, { type Error = SubstrateError; diff --git a/relays/bin-substrate/src/on_demand_headers.rs b/relays/bin-substrate/src/on_demand_headers.rs index 4c86b6a17018..77d2b3705410 100644 --- a/relays/bin-substrate/src/on_demand_headers.rs +++ b/relays/bin-substrate/src/on_demand_headers.rs @@ -20,14 +20,22 @@ use crate::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityT use crate::finality_target::SubstrateFinalityTarget; use bp_header_chain::justification::GrandpaJustification; -use finality_relay::TargetClient as FinalityTargetClient; +use finality_relay::{ + FinalitySyncPipeline, SourceClient as FinalitySourceClient, TargetClient as FinalityTargetClient, +}; use futures::{ channel::{mpsc, oneshot}, select, FutureExt, StreamExt, }; -use num_traits::Zero; -use relay_substrate_client::{BlockNumberOf, Chain, Client, HashOf, HeaderIdOf, SyncHeader}; -use relay_utils::{metrics::MetricsParams, BlockNumberBase, HeaderId}; +use num_traits::{CheckedSub, Zero}; +use relay_substrate_client::{ + finality_source::FinalitySource as SubstrateFinalitySource, BlockNumberOf, Chain, Client, HashOf, HeaderIdOf, + SyncHeader, +}; +use relay_utils::{ + metrics::MetricsParams, relay_loop::Client as RelayClient, BlockNumberBase, FailedClient, HeaderId, + MaybeConnectionError, +}; use std::fmt::Debug; /// On-demand Substrate <-> Substrate headers relay. @@ -49,6 +57,7 @@ impl OnDemandHeadersRelay { source_client: Client, target_client: Client, pipeline: SubstrateFinalityToSubstrate, + maximal_headers_difference: SourceChain::BlockNumber, ) -> Self where SourceChain: Chain + Debug, @@ -68,7 +77,14 @@ impl OnDemandHeadersRelay { { let (required_header_tx, required_header_rx) = mpsc::channel(1); async_std::task::spawn(async move { - background_task(source_client, target_client, pipeline, required_header_rx).await; + background_task( + source_client, + target_client, + pipeline, + maximal_headers_difference, + required_header_rx, + ) + .await; }); let background_task_name = format!( @@ -100,6 +116,7 @@ async fn background_task( source_client: Client, target_client: Client, pipeline: SubstrateFinalityToSubstrate, + maximal_headers_difference: SourceChain::BlockNumber, mut required_header_rx: mpsc::Receiver>, ) where SourceChain: Chain + Debug, @@ -118,7 +135,11 @@ async fn background_task( FinalityTargetClient>, { let relay_task_name = on_demand_headers_relay_name::(); - let finality_target = SubstrateFinalityTarget::new(target_client.clone(), pipeline.clone()); + let mut finality_source = SubstrateFinalitySource::< + _, + SubstrateFinalityToSubstrate, + >::new(source_client.clone()); + let mut finality_target = SubstrateFinalityTarget::new(target_client.clone(), pipeline.clone()); let mut active_headers_relay = None; let mut required_header_number = Zero::zero(); @@ -150,30 +171,45 @@ async fn background_task( }, } - // read best finalized source block from target - let available_header_number = match finality_target.best_finalized_source_block_number().await { - Ok(available_header_number) => available_header_number, - Err(error) => { - log::error!( - target: "bridge", - "Failed to read best finalized {} header from {} in {} relay: {:?}", - SourceChain::NAME, - TargetChain::NAME, - relay_task_name, - error, - ); + // read best finalized source header number from source + let best_finalized_source_header_at_source = + best_finalized_source_header_at_source(&finality_source, &relay_task_name).await; + if matches!(best_finalized_source_header_at_source, Err(ref e) if e.is_connection_error()) { + relay_utils::relay_loop::reconnect_failed_client( + FailedClient::Source, + relay_utils::relay_loop::RECONNECT_DELAY, + &mut finality_source, + &mut finality_target, + ) + .await; + continue; + } - // we don't know what's happening with target client, so better to stop on-demand relay than - // submit unneeded transactions - // => assume that required header is known to the target node - required_header_number - } - }; + // read best finalized source header number from target + let best_finalized_source_header_at_target = + best_finalized_source_header_at_target::(&finality_target, &relay_task_name).await; + if matches!(best_finalized_source_header_at_target, Err(ref e) if e.is_connection_error()) { + relay_utils::relay_loop::reconnect_failed_client( + FailedClient::Target, + relay_utils::relay_loop::RECONNECT_DELAY, + &mut finality_source, + &mut finality_target, + ) + .await; + continue; + } // start or stop headers relay if required - let activate = required_header_number > available_header_number; - match (activate, active_headers_relay.is_some()) { - (true, false) => { + let action = select_on_demand_relay_action::( + best_finalized_source_header_at_source.ok(), + best_finalized_source_header_at_target.ok(), + required_header_number, + maximal_headers_difference, + &relay_task_name, + active_headers_relay.is_some(), + ); + match action { + OnDemandRelayAction::Start => { let (relay_exited_tx, new_relay_exited_rx) = oneshot::channel(); active_headers_relay = start_on_demand_headers_relay( relay_task_name.clone(), @@ -186,14 +222,127 @@ async fn background_task( relay_exited_rx = new_relay_exited_rx.right_future(); } } - (false, true) => { + OnDemandRelayAction::Stop => { stop_on_demand_headers_relay(active_headers_relay.take()).await; } - _ => (), + OnDemandRelayAction::None => (), } } } +/// Read best finalized source block number from source client. +/// +/// Returns `None` if we have failed to read the number. +async fn best_finalized_source_header_at_source( + finality_source: &SubstrateFinalitySource, + relay_task_name: &str, +) -> Result as RelayClient>::Error> +where + SubstrateFinalitySource: FinalitySourceClient

, + P: FinalitySyncPipeline, +{ + finality_source.best_finalized_block_number().await.map_err(|error| { + log::error!( + target: "bridge", + "Failed to read best finalized source header from source in {} relay: {:?}", + relay_task_name, + error, + ); + + error + }) +} + +/// Read best finalized source block number from target client. +/// +/// Returns `None` if we have failed to read the number. +async fn best_finalized_source_header_at_target( + finality_target: &SubstrateFinalityTarget, + relay_task_name: &str, +) -> Result as RelayClient>::Error> +where + SubstrateFinalityTarget: FinalityTargetClient

, + P: FinalitySyncPipeline, +{ + finality_target + .best_finalized_source_block_number() + .await + .map_err(|error| { + log::error!( + target: "bridge", + "Failed to read best finalized source header from target in {} relay: {:?}", + relay_task_name, + error, + ); + + error + }) +} + +/// What to do with the on-demand relay task? +#[derive(Debug, PartialEq)] +enum OnDemandRelayAction { + Start, + Stop, + None, +} + +fn select_on_demand_relay_action( + best_finalized_source_header_at_source: Option, + best_finalized_source_header_at_target: Option, + mut required_source_header_at_target: C::BlockNumber, + maximal_headers_difference: C::BlockNumber, + relay_task_name: &str, + is_active: bool, +) -> OnDemandRelayAction { + // if we have been unable to read header number from the target, then let's assume + // that it is the same as required header number. Otherwise we risk submitting + // unneeded transactions + let best_finalized_source_header_at_target = + best_finalized_source_header_at_target.unwrap_or(required_source_header_at_target); + + // if we have been unable to read header number from the source, then let's assume + // that it is the same as at the target + let best_finalized_source_header_at_source = + best_finalized_source_header_at_source.unwrap_or(best_finalized_source_header_at_target); + + // if there are too many source headers missing from the target node, require some + // new headers at target + // + // why do we need that? When complex headers+messages relay is used, it'll normally only relay + // headers when there are undelivered messages/confirmations. But security model of the + // `pallet-bridge-grandpa` module relies on the fact that headers are synced in real-time and + // that it'll see authorities-change header before unbonding period will end for previous + // authorities set. + let current_headers_difference = best_finalized_source_header_at_source + .checked_sub(&best_finalized_source_header_at_target) + .unwrap_or_else(Zero::zero); + if current_headers_difference > maximal_headers_difference { + required_source_header_at_target = best_finalized_source_header_at_source; + + // don't log if relay is already running + if !is_active { + log::trace!( + target: "bridge", + "Too many {} headers missing at target in {} relay ({} vs {}). Going to sync up to the {}", + C::NAME, + relay_task_name, + best_finalized_source_header_at_source, + best_finalized_source_header_at_target, + best_finalized_source_header_at_source, + ); + } + } + + // now let's select what to do with relay + let needs_to_be_active = required_source_header_at_target > best_finalized_source_header_at_target; + match (needs_to_be_active, is_active) { + (true, false) => OnDemandRelayAction::Start, + (false, true) => OnDemandRelayAction::Stop, + _ => OnDemandRelayAction::None, + } +} + /// On-demand headers relay task name. fn on_demand_headers_relay_name() -> String { format!("on-demand-{}-to-{}", SourceChain::NAME, TargetChain::NAME) @@ -219,7 +368,7 @@ where TargetSign: 'static, { let headers_relay_future = - crate::finality_pipeline::run(pipeline, source_client, target_client, MetricsParams::disabled()); + crate::finality_pipeline::run(pipeline, source_client, target_client, true, MetricsParams::disabled()); let closure_task_name = task_name.clone(); async_std::task::Builder::new() .name(task_name.clone()) @@ -253,3 +402,52 @@ async fn stop_on_demand_headers_relay(task: Option = Some(10); + const AT_TARGET: Option = Some(1); + + #[test] + fn starts_relay_when_headers_are_required() { + assert_eq!( + select_on_demand_relay_action::(AT_SOURCE, AT_TARGET, 5, 100, "test", false), + OnDemandRelayAction::Start, + ); + + assert_eq!( + select_on_demand_relay_action::(AT_SOURCE, AT_TARGET, 5, 100, "test", true), + OnDemandRelayAction::None, + ); + } + + #[test] + fn starts_relay_when_too_many_headers_missing() { + assert_eq!( + select_on_demand_relay_action::(AT_SOURCE, AT_TARGET, 0, 5, "test", false), + OnDemandRelayAction::Start, + ); + + assert_eq!( + select_on_demand_relay_action::(AT_SOURCE, AT_TARGET, 0, 5, "test", true), + OnDemandRelayAction::None, + ); + } + + #[test] + fn stops_relay_if_required_header_is_synced() { + assert_eq!( + select_on_demand_relay_action::(AT_SOURCE, AT_TARGET, AT_TARGET.unwrap(), 100, "test", true), + OnDemandRelayAction::Stop, + ); + + assert_eq!( + select_on_demand_relay_action::(AT_SOURCE, AT_TARGET, AT_TARGET.unwrap(), 100, "test", false), + OnDemandRelayAction::None, + ); + } +} diff --git a/relays/client-ethereum/Cargo.toml b/relays/client-ethereum/Cargo.toml index ebae252ed5ab..da4e7ef59efe 100644 --- a/relays/client-ethereum/Cargo.toml +++ b/relays/client-ethereum/Cargo.toml @@ -10,8 +10,8 @@ bp-eth-poa = { path = "../../primitives/ethereum-poa" } codec = { package = "parity-scale-codec", version = "2.0.0" } headers-relay = { path = "../headers" } hex-literal = "0.3" -jsonrpsee-proc-macros = "=0.2.0-alpha.5" -jsonrpsee-ws-client = "=0.2.0-alpha.5" +jsonrpsee-proc-macros = "=0.2.0-alpha.6" +jsonrpsee-ws-client = "=0.2.0-alpha.6" libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] } log = "0.4.11" relay-utils = { path = "../utils" } diff --git a/relays/client-substrate/Cargo.toml b/relays/client-substrate/Cargo.toml index 7b3f46230fce..699c3da400ff 100644 --- a/relays/client-substrate/Cargo.toml +++ b/relays/client-substrate/Cargo.toml @@ -9,8 +9,8 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" async-std = "1.6.5" async-trait = "0.1.40" codec = { package = "parity-scale-codec", version = "2.0.0" } -jsonrpsee-proc-macros = "=0.2.0-alpha.5" -jsonrpsee-ws-client = "=0.2.0-alpha.5" +jsonrpsee-proc-macros = "=0.2.0-alpha.6" +jsonrpsee-ws-client = "=0.2.0-alpha.6" log = "0.4.11" num-traits = "0.2" rand = "0.7" diff --git a/relays/client-wococo/Cargo.toml b/relays/client-wococo/Cargo.toml new file mode 100644 index 000000000000..22d710ca3d7b --- /dev/null +++ b/relays/client-wococo/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "relay-wococo-client" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "2.0.0" } +headers-relay = { path = "../headers" } +relay-substrate-client = { path = "../client-substrate" } +relay-utils = { path = "../utils" } + +# Bridge dependencies +bp-wococo = { path = "../../primitives/chain-wococo" } + +# Substrate Dependencies +frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/relays/client-wococo/src/lib.rs b/relays/client-wococo/src/lib.rs new file mode 100644 index 000000000000..be2f872b7d77 --- /dev/null +++ b/relays/client-wococo/src/lib.rs @@ -0,0 +1,97 @@ +// 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 . + +//! Types used to connect to the Wococo-Substrate chain. + +use codec::Encode; +use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, TransactionSignScheme}; +use sp_core::{storage::StorageKey, Pair}; +use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; +use std::time::Duration; + +/// Wococo header id. +pub type HeaderId = relay_utils::HeaderId; + +/// Wococo header type used in headers sync. +pub type SyncHeader = relay_substrate_client::SyncHeader; + +/// Wococo chain definition +#[derive(Debug, Clone, Copy)] +pub struct Wococo; + +impl ChainBase for Wococo { + type BlockNumber = bp_wococo::BlockNumber; + type Hash = bp_wococo::Hash; + type Hasher = bp_wococo::Hashing; + type Header = bp_wococo::Header; +} + +impl Chain for Wococo { + const NAME: &'static str = "Wococo"; + const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(6); + + type AccountId = bp_wococo::AccountId; + type Index = bp_wococo::Index; + type SignedBlock = bp_wococo::SignedBlock; + type Call = bp_wococo::Call; +} + +impl ChainWithBalances for Wococo { + type NativeBalance = bp_wococo::Balance; + + fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { + StorageKey(bp_wococo::account_info_storage_key(account_id)) + } +} + +impl TransactionSignScheme for Wococo { + type Chain = Wococo; + type AccountKeyPair = sp_core::sr25519::Pair; + type SignedTransaction = bp_wococo::UncheckedExtrinsic; + + fn sign_transaction( + genesis_hash: ::Hash, + signer: &Self::AccountKeyPair, + signer_nonce: ::Index, + call: ::Call, + ) -> Self::SignedTransaction { + let raw_payload = SignedPayload::new( + call, + bp_wococo::SignedExtensions::new( + bp_wococo::VERSION, + sp_runtime::generic::Era::Immortal, + genesis_hash, + signer_nonce, + 0, + ), + ) + .expect("SignedExtension never fails."); + + let signature = raw_payload.using_encoded(|payload| signer.sign(payload)); + let signer: sp_runtime::MultiSigner = signer.public().into(); + let (call, extra, _) = raw_payload.deconstruct(); + + bp_wococo::UncheckedExtrinsic::new_signed( + call, + sp_runtime::MultiAddress::Id(signer.into_account()), + signature.into(), + extra, + ) + } +} + +/// Wococo signing params. +pub type SigningParams = sp_core::sr25519::Pair; diff --git a/relays/exchange/src/exchange.rs b/relays/exchange/src/exchange.rs index cec0d7cba1fa..4a2f07fa7f97 100644 --- a/relays/exchange/src/exchange.rs +++ b/relays/exchange/src/exchange.rs @@ -26,7 +26,7 @@ use std::{ }; /// Transaction proof pipeline. -pub trait TransactionProofPipeline { +pub trait TransactionProofPipeline: 'static { /// Name of the transaction proof source. const SOURCE_NAME: &'static str; /// Name of the transaction proof target. @@ -35,18 +35,21 @@ pub trait TransactionProofPipeline { /// Block type. type Block: SourceBlock; /// Transaction inclusion proof type. - type TransactionProof; + type TransactionProof: 'static + Send + Sync; } /// Block that is participating in exchange. -pub trait SourceBlock { +pub trait SourceBlock: 'static + Send + Sync { /// Block hash type. - type Hash: Clone + Debug + Display; + type Hash: 'static + Clone + Send + Sync + Debug + Display; /// Block number type. - type Number: Debug + type Number: 'static + + Debug + Display + Clone + Copy + + Send + + Sync + Into + std::cmp::Ord + std::ops::Add @@ -61,7 +64,7 @@ pub trait SourceBlock { } /// Transaction that is participating in exchange. -pub trait SourceTransaction { +pub trait SourceTransaction: 'static + Send { /// Transaction hash type. type Hash: Debug + Display; diff --git a/relays/exchange/src/exchange_loop.rs b/relays/exchange/src/exchange_loop.rs index b46d34e047a8..4525c33e36a1 100644 --- a/relays/exchange/src/exchange_loop.rs +++ b/relays/exchange/src/exchange_loop.rs @@ -39,9 +39,9 @@ pub struct TransactionProofsRelayState { } /// Transactions proofs relay storage. -pub trait TransactionProofsRelayStorage: Clone { +pub trait TransactionProofsRelayStorage: 'static + Clone + Send + Sync { /// Associated block number. - type BlockNumber; + type BlockNumber: 'static + Send + Sync; /// Get relay state. fn state(&self) -> TransactionProofsRelayState; @@ -64,7 +64,7 @@ impl InMemoryStorage { } } -impl TransactionProofsRelayStorage for InMemoryStorage { +impl TransactionProofsRelayStorage for InMemoryStorage { type BlockNumber = BlockNumber; fn state(&self) -> TransactionProofsRelayState { @@ -89,7 +89,7 @@ pub async fn run( source_client: impl SourceClient

, target_client: impl TargetClient

, metrics_params: MetricsParams, - exit_signal: impl Future, + exit_signal: impl Future + 'static + Send, ) -> Result<(), String> { let exit_signal = exit_signal.shared(); @@ -99,7 +99,7 @@ pub async fn run( .standalone_metric(|registry, prefix| GlobalMetrics::new(registry, prefix))? .expose() .await? - .run(|source_client, target_client, metrics| { + .run(metrics_prefix::

(), move |source_client, target_client, metrics| { run_until_connection_lost( storage.clone(), source_client, @@ -117,7 +117,7 @@ async fn run_until_connection_lost( source_client: impl SourceClient

, target_client: impl TargetClient

, metrics_exch: Option, - exit_signal: impl Future, + exit_signal: impl Future + Send, ) -> Result<(), FailedClient> { let mut retry_backoff = retry_backoff(); let mut state = storage.state(); diff --git a/relays/finality/src/finality_loop.rs b/relays/finality/src/finality_loop.rs index aff32e46de44..3aa55a8ac591 100644 --- a/relays/finality/src/finality_loop.rs +++ b/relays/finality/src/finality_loop.rs @@ -39,6 +39,8 @@ use std::{ /// Finality proof synchronization loop parameters. #[derive(Debug, Clone)] pub struct FinalitySyncParams { + /// If `true`, then the separate async task for running finality loop is NOT spawned. + pub is_on_demand_task: bool, /// Interval at which we check updates on both clients. Normally should be larger than /// `min(source_block_time, target_block_time)`. /// @@ -65,7 +67,7 @@ pub struct FinalitySyncParams { pub trait SourceClient: RelayClient { /// Stream of new finality proofs. The stream is allowed to miss proofs for some /// headers, even if those headers are mandatory. - type FinalityProofsStream: Stream; + type FinalityProofsStream: Stream + Send; /// Get best finalized block number. async fn best_finalized_block_number(&self) -> Result; @@ -101,16 +103,17 @@ pub async fn run( target_client: impl TargetClient

, sync_params: FinalitySyncParams, metrics_params: MetricsParams, - exit_signal: impl Future, + exit_signal: impl Future + 'static + Send, ) -> Result<(), String> { let exit_signal = exit_signal.shared(); relay_utils::relay_loop(source_client, target_client) + .spawn_loop_task(!sync_params.is_on_demand_task) .with_metrics(Some(metrics_prefix::

()), metrics_params) .loop_metric(|registry, prefix| SyncLoopMetrics::new(registry, prefix))? .standalone_metric(|registry, prefix| GlobalMetrics::new(registry, prefix))? .expose() .await? - .run(|source_client, target_client, metrics| { + .run(metrics_prefix::

(), move |source_client, target_client, metrics| { run_until_connection_lost( source_client, target_client, diff --git a/relays/finality/src/finality_loop_tests.rs b/relays/finality/src/finality_loop_tests.rs index eedd90200330..645aeb1777c6 100644 --- a/relays/finality/src/finality_loop_tests.rs +++ b/relays/finality/src/finality_loop_tests.rs @@ -106,7 +106,7 @@ impl RelayClient for TestSourceClient { #[async_trait] impl SourceClient for TestSourceClient { - type FinalityProofsStream = Pin>>; + type FinalityProofsStream = Pin + 'static + Send>>; async fn best_finalized_block_number(&self) -> Result { let mut data = self.data.lock(); @@ -197,6 +197,7 @@ fn run_sync_loop(state_function: impl Fn(&mut ClientsData) -> bool + Send + Sync data: clients_data.clone(), }; let sync_params = FinalitySyncParams { + is_on_demand_task: false, tick: Duration::from_secs(0), recent_finality_proofs_limit: 1024, stall_timeout: Duration::from_secs(1), diff --git a/relays/finality/src/lib.rs b/relays/finality/src/lib.rs index d5048aa1607d..64ec5bed0500 100644 --- a/relays/finality/src/lib.rs +++ b/relays/finality/src/lib.rs @@ -28,7 +28,7 @@ mod finality_loop; mod finality_loop_tests; /// Finality proofs synchronization pipeline. -pub trait FinalitySyncPipeline: Clone + Debug + Send + Sync { +pub trait FinalitySyncPipeline: 'static + Clone + Debug + Send + Sync { /// Name of the finality proofs source. const SOURCE_NAME: &'static str; /// Name of the finality proofs target. diff --git a/relays/headers/src/sync_loop.rs b/relays/headers/src/sync_loop.rs index e4f1b7b04507..b20493205650 100644 --- a/relays/headers/src/sync_loop.rs +++ b/relays/headers/src/sync_loop.rs @@ -102,7 +102,7 @@ pub trait TargetClient: RelayClient { /// Synchronization maintain procedure. #[async_trait] -pub trait SyncMaintain: Clone + Send + Sync { +pub trait SyncMaintain: 'static + Clone + Send + Sync { /// Run custom maintain procedures. This is guaranteed to be called when both source and target /// clients are unoccupied. async fn maintain(&self, _sync: &mut HeadersSync

) {} @@ -125,7 +125,7 @@ pub async fn run>( sync_maintain: impl SyncMaintain

, sync_params: HeadersSyncParams, metrics_params: MetricsParams, - exit_signal: impl Future, + exit_signal: impl Future + 'static + Send, ) -> Result<(), String> { let exit_signal = exit_signal.shared(); relay_utils::relay_loop(source_client, target_client) @@ -134,7 +134,7 @@ pub async fn run>( .standalone_metric(|registry, prefix| GlobalMetrics::new(registry, prefix))? .expose() .await? - .run(|source_client, target_client, metrics| { + .run(metrics_prefix::

(), move |source_client, target_client, metrics| { run_until_connection_lost( source_client, source_tick, @@ -159,7 +159,7 @@ async fn run_until_connection_lost>( sync_maintain: impl SyncMaintain

, sync_params: HeadersSyncParams, metrics_sync: Option, - exit_signal: impl Future, + exit_signal: impl Future + Send, ) -> Result<(), FailedClient> { let mut progress_context = (Instant::now(), None, None); diff --git a/relays/headers/src/sync_types.rs b/relays/headers/src/sync_types.rs index e6500ad5facb..5809ebab59e1 100644 --- a/relays/headers/src/sync_types.rs +++ b/relays/headers/src/sync_types.rs @@ -43,7 +43,7 @@ pub enum HeaderStatus { } /// Headers synchronization pipeline. -pub trait HeadersSyncPipeline: Clone + Send + Sync { +pub trait HeadersSyncPipeline: 'static + Clone + Send + Sync { /// Name of the headers source. const SOURCE_NAME: &'static str; /// Name of the headers target. diff --git a/relays/messages/src/message_lane.rs b/relays/messages/src/message_lane.rs index 5090ef124e7f..6473ec987500 100644 --- a/relays/messages/src/message_lane.rs +++ b/relays/messages/src/message_lane.rs @@ -23,7 +23,7 @@ use relay_utils::{BlockNumberBase, HeaderId}; use std::fmt::Debug; /// One-way message lane. -pub trait MessageLane: Clone + Send + Sync { +pub trait MessageLane: 'static + Clone + Send + Sync { /// Name of the messages source. const SOURCE_NAME: &'static str; /// Name of the messages target. diff --git a/relays/messages/src/message_lane_loop.rs b/relays/messages/src/message_lane_loop.rs index 41eee606d82b..af04bf984e1f 100644 --- a/relays/messages/src/message_lane_loop.rs +++ b/relays/messages/src/message_lane_loop.rs @@ -227,7 +227,7 @@ pub async fn run( source_client: impl SourceClient

, target_client: impl TargetClient

, metrics_params: MetricsParams, - exit_signal: impl Future, + exit_signal: impl Future + Send + 'static, ) -> Result<(), String> { let exit_signal = exit_signal.shared(); relay_utils::relay_loop(source_client, target_client) @@ -237,15 +237,18 @@ pub async fn run( .standalone_metric(|registry, prefix| GlobalMetrics::new(registry, prefix))? .expose() .await? - .run(|source_client, target_client, metrics| { - run_until_connection_lost( - params.clone(), - source_client, - target_client, - metrics, - exit_signal.clone(), - ) - }) + .run( + metrics_prefix::

(¶ms.lane), + move |source_client, target_client, metrics| { + run_until_connection_lost( + params.clone(), + source_client, + target_client, + metrics, + exit_signal.clone(), + ) + }, + ) .await } @@ -579,6 +582,9 @@ pub(crate) mod tests { ) -> Result<(), TestError> { let mut data = self.data.lock(); (self.tick)(&mut *data); + data.source_state.best_self = + HeaderId(data.source_state.best_self.0 + 1, data.source_state.best_self.1 + 1); + data.source_state.best_finalized_self = data.source_state.best_self; data.submitted_messages_receiving_proofs.push(proof); data.source_latest_confirmed_received_nonce = proof; Ok(()) @@ -681,6 +687,7 @@ pub(crate) mod tests { } data.target_state.best_self = HeaderId(data.target_state.best_self.0 + 1, data.target_state.best_self.1 + 1); + data.target_state.best_finalized_self = data.target_state.best_self; data.target_latest_received_nonce = *proof.0.end(); if let Some(target_latest_confirmed_received_nonce) = proof.1 { data.target_latest_confirmed_received_nonce = target_latest_confirmed_received_nonce; @@ -701,7 +708,7 @@ pub(crate) mod tests { data: TestClientData, source_tick: Arc, target_tick: Arc, - exit_signal: impl Future, + exit_signal: impl Future + 'static + Send, ) -> TestClientData { async_std::task::block_on(async { let data = Arc::new(Mutex::new(data)); @@ -809,37 +816,37 @@ pub(crate) mod tests { ..Default::default() }, Arc::new(|data: &mut TestClientData| { + // blocks are produced on every tick + data.source_state.best_self = + HeaderId(data.source_state.best_self.0 + 1, data.source_state.best_self.1 + 1); + data.source_state.best_finalized_self = data.source_state.best_self; // headers relay must only be started when we need new target headers at source node if data.target_to_source_header_required.is_some() { assert!(data.source_state.best_finalized_peer_at_best_self.0 < data.target_state.best_self.0); data.target_to_source_header_required = None; } + // syncing target headers -> source chain + if let Some(last_requirement) = data.target_to_source_header_requirements.last() { + if *last_requirement != data.source_state.best_finalized_peer_at_best_self { + data.source_state.best_finalized_peer_at_best_self = *last_requirement; + } + } }), Arc::new(move |data: &mut TestClientData| { + // blocks are produced on every tick + data.target_state.best_self = + HeaderId(data.target_state.best_self.0 + 1, data.target_state.best_self.1 + 1); + data.target_state.best_finalized_self = data.target_state.best_self; // headers relay must only be started when we need new source headers at target node if data.source_to_target_header_required.is_some() { assert!(data.target_state.best_finalized_peer_at_best_self.0 < data.source_state.best_self.0); data.source_to_target_header_required = None; } - // syncing source headers -> target chain (all at once) - if data.target_state.best_finalized_peer_at_best_self.0 < data.source_state.best_finalized_self.0 { - data.target_state.best_finalized_peer_at_best_self = data.source_state.best_finalized_self; - } - // syncing source headers -> target chain (all at once) - if data.source_state.best_finalized_peer_at_best_self.0 < data.target_state.best_finalized_self.0 { - data.source_state.best_finalized_peer_at_best_self = data.target_state.best_finalized_self; - } - // if target has received messages batch => increase blocks so that confirmations may be sent - if data.target_latest_received_nonce == 4 - || data.target_latest_received_nonce == 8 - || data.target_latest_received_nonce == 10 - { - data.target_state.best_self = - HeaderId(data.target_state.best_self.0 + 1, data.target_state.best_self.0 + 1); - data.target_state.best_finalized_self = data.target_state.best_self; - data.source_state.best_self = - HeaderId(data.source_state.best_self.0 + 1, data.source_state.best_self.0 + 1); - data.source_state.best_finalized_self = data.source_state.best_self; + // syncing source headers -> target chain + if let Some(last_requirement) = data.source_to_target_header_requirements.last() { + if *last_requirement != data.target_state.best_finalized_peer_at_best_self { + data.target_state.best_finalized_peer_at_best_self = *last_requirement; + } } // if source has received all messages receiving confirmations => stop if data.source_latest_confirmed_received_nonce == 10 { diff --git a/relays/messages/src/message_race_delivery.rs b/relays/messages/src/message_race_delivery.rs index 225c59f23ca3..b50b0ffe31ba 100644 --- a/relays/messages/src/message_race_delivery.rs +++ b/relays/messages/src/message_race_delivery.rs @@ -292,7 +292,16 @@ impl RaceStrategy, TargetHeaderIdOf

, P::M } fn required_source_header_at_target(&self, current_best: &SourceHeaderIdOf

) -> Option> { - self.strategy.required_source_header_at_target(current_best) + let header_required_for_messages_delivery = self.strategy.required_source_header_at_target(current_best); + let header_required_for_reward_confirmations_delivery = + self.latest_confirmed_nonces_at_source.back().map(|(id, _)| id.clone()); + match ( + header_required_for_messages_delivery, + header_required_for_reward_confirmations_delivery, + ) { + (Some(id1), Some(id2)) => Some(if id1.0 > id2.0 { id1 } else { id2 }), + (a, b) => a.or(b), + } } fn best_at_source(&self) -> Option { @@ -876,4 +885,46 @@ mod tests { Some(((20..=23), proof_parameters(true, 4))) ); } + + #[test] + fn source_header_is_requied_when_confirmations_are_required() { + // let's prepare situation when: + // - all messages [20; 23] have been generated at source block#1; + let (mut state, mut strategy) = prepare_strategy(); + // - messages [20; 21] have been delivered, but messages [11; 20] can't be delivered because of unrewarded + // relayers vector capacity; + strategy.max_unconfirmed_nonces_at_target = 2; + assert_eq!( + strategy.select_nonces_to_deliver(&state), + Some(((20..=21), proof_parameters(false, 2))) + ); + strategy.finalized_target_nonces_updated( + TargetClientNonces { + latest_nonce: 21, + nonces_data: DeliveryRaceTargetNoncesData { + confirmed_nonce: 19, + unrewarded_relayers: UnrewardedRelayersState { + unrewarded_relayer_entries: 2, + messages_in_oldest_entry: 2, + total_messages: 2, + }, + }, + }, + &mut state, + ); + assert_eq!(strategy.select_nonces_to_deliver(&state), None); + // - messages [1; 10] receiving confirmation has been delivered at source block#2; + strategy.source_nonces_updated( + header_id(2), + SourceClientNonces { + new_nonces: BTreeMap::new(), + confirmed_nonce: Some(21), + }, + ); + // - so now we'll need to relay source block#11 to be able to accept messages [11; 20]. + assert_eq!( + strategy.required_source_header_at_target(&header_id(1)), + Some(header_id(2)) + ); + } } diff --git a/relays/utils/src/initialize.rs b/relays/utils/src/initialize.rs index 7d5f66a53815..b87937923bd4 100644 --- a/relays/utils/src/initialize.rs +++ b/relays/utils/src/initialize.rs @@ -16,7 +16,11 @@ //! Relayer initialization functions. -use std::{fmt::Display, io::Write}; +use std::{cell::RefCell, fmt::Display, io::Write}; + +async_std::task_local! { + pub(crate) static LOOP_NAME: RefCell = RefCell::new(String::default()); +} /// Initialize relay environment. pub fn initialize_relay() { @@ -43,20 +47,56 @@ pub fn initialize_logger(with_timestamp: bool) { Either::Right(ansi_term::Colour::Fixed(8).bold().paint(timestamp)) }; - writeln!(buf, "{} {} {} {}", timestamp, log_level, log_target, record.args(),) + writeln!( + buf, + "{}{} {} {} {}", + loop_name_prefix(), + timestamp, + log_level, + log_target, + record.args(), + ) }); } else { builder.format(move |buf, record| { let log_level = color_level(record.level()); let log_target = color_target(record.target()); - writeln!(buf, "{} {} {}", log_level, log_target, record.args(),) + writeln!( + buf, + "{}{} {} {}", + loop_name_prefix(), + log_level, + log_target, + record.args(), + ) }); } builder.init(); } +/// Initialize relay loop. Must only be called once per every loop task. +pub(crate) fn initialize_loop(loop_name: String) { + LOOP_NAME.with(|g_loop_name| *g_loop_name.borrow_mut() = loop_name); +} + +/// Returns loop name prefix to use in logs. The prefix is initialized with the `initialize_loop` call. +fn loop_name_prefix() -> String { + // try_with to avoid panic outside of async-std task context + LOOP_NAME + .try_with(|loop_name| { + // using borrow is ok here, because loop is only initialized once (=> borrow_mut will only be called once) + let loop_name = loop_name.borrow(); + if loop_name.is_empty() { + String::new() + } else { + format!("[{}] ", loop_name) + } + }) + .unwrap_or_else(|_| String::new()) +} + enum Either { Left(A), Right(B), diff --git a/relays/utils/src/relay_loop.rs b/relays/utils/src/relay_loop.rs index 8790b0913e17..8fcaabe4430c 100644 --- a/relays/utils/src/relay_loop.rs +++ b/relays/utils/src/relay_loop.rs @@ -26,9 +26,9 @@ pub const RECONNECT_DELAY: Duration = Duration::from_secs(10); /// Basic blockchain client from relay perspective. #[async_trait] -pub trait Client: Clone + Send + Sync { +pub trait Client: 'static + Clone + Send + Sync { /// Type of error this clients returns. - type Error: Debug + MaybeConnectionError; + type Error: 'static + Debug + MaybeConnectionError + Send + Sync; /// Try to reconnect to source node. async fn reconnect(&mut self) -> Result<(), Self::Error>; @@ -38,6 +38,7 @@ pub trait Client: Clone + Send + Sync { pub fn relay_loop(source_client: SC, target_client: TC) -> Loop { Loop { reconnect_delay: RECONNECT_DELAY, + spawn_loop_task: true, source_client, target_client, loop_metric: None, @@ -49,6 +50,7 @@ pub fn relay_metrics(prefix: Option, params: MetricsParams) -> LoopMetri LoopMetrics { relay_loop: Loop { reconnect_delay: RECONNECT_DELAY, + spawn_loop_task: true, source_client: (), target_client: (), loop_metric: None, @@ -63,6 +65,7 @@ pub fn relay_metrics(prefix: Option, params: MetricsParams) -> LoopMetri /// Generic relay loop. pub struct Loop { reconnect_delay: Duration, + spawn_loop_task: bool, source_client: SC, target_client: TC, loop_metric: Option, @@ -84,11 +87,23 @@ impl Loop { self } + /// Set spawn-dedicated-loop-task flag. + /// + /// If `true` (default), separate async task is spawned to run relay loop. This is the default + /// behavior for all loops. If `false`, then loop is executed as a part of the current + /// task. The `false` is used for on-demand tasks, which are cancelled from time to time + /// and there's already a dedicated on-demand task for running such loops. + pub fn spawn_loop_task(mut self, spawn_loop_task: bool) -> Self { + self.spawn_loop_task = spawn_loop_task; + self + } + /// Start building loop metrics using given prefix. pub fn with_metrics(self, prefix: Option, params: MetricsParams) -> LoopMetrics { LoopMetrics { relay_loop: Loop { reconnect_delay: self.reconnect_delay, + spawn_loop_task: self.spawn_loop_task, source_client: self.source_client, target_client: self.target_client, loop_metric: None, @@ -105,63 +120,47 @@ impl Loop { /// This function represents an outer loop, which in turn calls provided `run_loop` function to do /// actual job. When `run_loop` returns, this outer loop reconnects to failed client (source, /// target or both) and calls `run_loop` again. - pub async fn run(mut self, run_loop: R) -> Result<(), String> + pub async fn run(mut self, loop_name: String, run_loop: R) -> Result<(), String> where - R: Fn(SC, TC, Option) -> F, - F: Future>, - SC: Client, - TC: Client, - LM: Clone, + R: 'static + Send + Fn(SC, TC, Option) -> F, + F: 'static + Send + Future>, + SC: 'static + Client, + TC: 'static + Client, + LM: 'static + Send + Clone, { - loop { - let result = run_loop( - self.source_client.clone(), - self.target_client.clone(), - self.loop_metric.clone(), - ) - .await; - - match result { - Ok(()) => break, - Err(failed_client) => loop { - async_std::task::sleep(self.reconnect_delay).await; - if failed_client == FailedClient::Both || failed_client == FailedClient::Source { - match self.source_client.reconnect().await { - Ok(()) => (), - Err(error) => { - log::warn!( - target: "bridge", - "Failed to reconnect to source client. Going to retry in {}s: {:?}", - self.reconnect_delay.as_secs(), - error, - ); - continue; - } - } - } - if failed_client == FailedClient::Both || failed_client == FailedClient::Target { - match self.target_client.reconnect().await { - Ok(()) => (), - Err(error) => { - log::warn!( - target: "bridge", - "Failed to reconnect to target client. Going to retry in {}s: {:?}", - self.reconnect_delay.as_secs(), - error, - ); - continue; - } - } + let spawn_loop_task = self.spawn_loop_task; + let run_loop_task = async move { + crate::initialize::initialize_loop(loop_name); + + loop { + let loop_metric = self.loop_metric.clone(); + let future_result = run_loop(self.source_client.clone(), self.target_client.clone(), loop_metric); + let result = future_result.await; + + match result { + Ok(()) => break, + Err(failed_client) => { + reconnect_failed_client( + failed_client, + self.reconnect_delay, + &mut self.source_client, + &mut self.target_client, + ) + .await } + } - break; - }, + log::debug!(target: "bridge", "Restarting relay loop"); } - log::debug!(target: "bridge", "Restarting relay loop"); - } + Ok(()) + }; - Ok(()) + if spawn_loop_task { + async_std::task::spawn(run_loop_task).await + } else { + run_loop_task.await + } } } @@ -237,6 +236,7 @@ impl LoopMetrics { Ok(Loop { reconnect_delay: self.relay_loop.reconnect_delay, + spawn_loop_task: self.relay_loop.spawn_loop_task, source_client: self.relay_loop.source_client, target_client: self.relay_loop.target_client, loop_metric: self.loop_metric, @@ -244,6 +244,48 @@ impl LoopMetrics { } } +/// Deal with the client who has returned connection error. +pub async fn reconnect_failed_client( + failed_client: FailedClient, + reconnect_delay: Duration, + source_client: &mut impl Client, + target_client: &mut impl Client, +) { + loop { + async_std::task::sleep(reconnect_delay).await; + if failed_client == FailedClient::Both || failed_client == FailedClient::Source { + match source_client.reconnect().await { + Ok(()) => (), + Err(error) => { + log::warn!( + target: "bridge", + "Failed to reconnect to source client. Going to retry in {}s: {:?}", + reconnect_delay.as_secs(), + error, + ); + continue; + } + } + } + if failed_client == FailedClient::Both || failed_client == FailedClient::Target { + match target_client.reconnect().await { + Ok(()) => (), + Err(error) => { + log::warn!( + target: "bridge", + "Failed to reconnect to target client. Going to retry in {}s: {:?}", + reconnect_delay.as_secs(), + error, + ); + continue; + } + } + } + + break; + } +} + /// Create new registry with global metrics. fn create_metrics_registry(prefix: Option) -> Registry { match prefix { diff --git a/scripts/dump-logs.sh b/scripts/dump-logs.sh index f076cbccbca1..02aa4af2f756 100644 --- a/scripts/dump-logs.sh +++ b/scripts/dump-logs.sh @@ -15,10 +15,10 @@ cd $LOGS_DIR SERVICES=(\ deployments_relay-messages-millau-to-rialto-generator_1 \ deployments_relay-messages-rialto-to-millau-generator_1 \ - deployments_relay-messages-millau-to-rialto_1 \ - deployments_relay-messages-rialto-to-millau_1 \ - deployments_relay-headers-millau-to-rialto_1 \ - deployments_relay-headers-rialto-to-millau_1 \ + deployments_relay-messages-millau-to-rialto-lane-00000001_1 \ + deployments_relay-messages-rialto-to-millau-lane-00000001_1 \ + deployments_relay-millau-rialto_1 \ + deployments_relay-headers-westend-to-millau_1 \ deployments_rialto-node-alice_1 \ deployments_rialto-node-bob_1 \ deployments_millau-node-alice_1 \