From e89a8d653034590f75da00485b2c35a282e7c5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 10 Mar 2021 15:54:18 +0100 Subject: [PATCH] Add Westend & Rococo primitives (#808) * Move chain primitives to a sub-folder. * Update workspace members. * Extract core parts of polkadot. * cargo fmt --all * Remove TODO. * cargo fmt --all * Fix crate names. * Add to the latest API. * cargo fmt --all * Add nested lock files to ignore (generated during cargo fmt) * Fix compilation. * cargo fmt --all * Fix ignore pattern. * Address review comments. --- bridges/bin/millau/node/Cargo.toml | 2 +- bridges/bin/millau/runtime/Cargo.toml | 4 +- bridges/bin/rialto/node/Cargo.toml | 2 +- bridges/bin/rialto/runtime/Cargo.toml | 4 +- bridges/modules/message-lane/Cargo.toml | 2 +- bridges/primitives/chains/kusama/Cargo.toml | 28 +++ bridges/primitives/chains/kusama/src/lib.rs | 117 +++++++++++++ .../primitives/{ => chains}/millau/Cargo.toml | 4 +- .../primitives/{ => chains}/millau/src/lib.rs | 0 .../{ => chains}/millau/src/millau_hash.rs | 0 bridges/primitives/chains/polkadot/Cargo.toml | 29 ++++ bridges/primitives/chains/polkadot/src/lib.rs | 117 +++++++++++++ .../primitives/{ => chains}/rialto/Cargo.toml | 4 +- .../primitives/{ => chains}/rialto/src/lib.rs | 0 bridges/primitives/chains/rococo/Cargo.toml | 28 +++ bridges/primitives/chains/rococo/src/lib.rs | 117 +++++++++++++ bridges/primitives/chains/westend/Cargo.toml | 28 +++ bridges/primitives/chains/westend/src/lib.rs | 117 +++++++++++++ bridges/primitives/kusama/src/lib.rs | 164 ------------------ .../{kusama => polkadot-core}/Cargo.toml | 4 +- bridges/primitives/polkadot-core/src/lib.rs | 96 ++++++++++ bridges/primitives/polkadot/Cargo.toml | 36 ---- bridges/primitives/polkadot/src/lib.rs | 164 ------------------ bridges/primitives/runtime/src/lib.rs | 6 + bridges/relays/ethereum-client/Cargo.toml | 2 +- bridges/relays/ethereum/Cargo.toml | 6 +- bridges/relays/kusama-client/Cargo.toml | 2 +- bridges/relays/polkadot-client/Cargo.toml | 2 +- bridges/relays/substrate/Cargo.toml | 8 +- 29 files changed, 706 insertions(+), 387 deletions(-) create mode 100644 bridges/primitives/chains/kusama/Cargo.toml create mode 100644 bridges/primitives/chains/kusama/src/lib.rs rename bridges/primitives/{ => chains}/millau/Cargo.toml (93%) rename bridges/primitives/{ => chains}/millau/src/lib.rs (100%) rename bridges/primitives/{ => chains}/millau/src/millau_hash.rs (100%) create mode 100644 bridges/primitives/chains/polkadot/Cargo.toml create mode 100644 bridges/primitives/chains/polkadot/src/lib.rs rename bridges/primitives/{ => chains}/rialto/Cargo.toml (88%) rename bridges/primitives/{ => chains}/rialto/src/lib.rs (100%) create mode 100644 bridges/primitives/chains/rococo/Cargo.toml create mode 100644 bridges/primitives/chains/rococo/src/lib.rs create mode 100644 bridges/primitives/chains/westend/Cargo.toml create mode 100644 bridges/primitives/chains/westend/src/lib.rs delete mode 100644 bridges/primitives/kusama/src/lib.rs rename bridges/primitives/{kusama => polkadot-core}/Cargo.toml (93%) create mode 100644 bridges/primitives/polkadot-core/src/lib.rs delete mode 100644 bridges/primitives/polkadot/Cargo.toml delete mode 100644 bridges/primitives/polkadot/src/lib.rs diff --git a/bridges/bin/millau/node/Cargo.toml b/bridges/bin/millau/node/Cargo.toml index d41f23fb03d1b..4e8606b497ef4 100644 --- a/bridges/bin/millau/node/Cargo.toml +++ b/bridges/bin/millau/node/Cargo.toml @@ -16,7 +16,7 @@ structopt = "0.3.21" # Bridge dependencies bp-message-lane = { path = "../../../primitives/message-lane" } -bp-millau= { path = "../../../primitives/millau" } +bp-millau= { path = "../../../primitives/chains/millau" } bp-runtime = { path = "../../../primitives/runtime" } millau-runtime = { path = "../runtime" } pallet-message-lane = { path = "../../../modules/message-lane" } diff --git a/bridges/bin/millau/runtime/Cargo.toml b/bridges/bin/millau/runtime/Cargo.toml index 8b54741f19f5e..058598e5c1c01 100644 --- a/bridges/bin/millau/runtime/Cargo.toml +++ b/bridges/bin/millau/runtime/Cargo.toml @@ -16,8 +16,8 @@ serde = { version = "1.0.124", optional = true, features = ["derive"] } bp-header-chain = { path = "../../../primitives/header-chain", default-features = false } bp-message-lane = { path = "../../../primitives/message-lane", default-features = false } -bp-millau = { path = "../../../primitives/millau", default-features = false } -bp-rialto = { path = "../../../primitives/rialto", default-features = false } +bp-millau = { path = "../../../primitives/chains/millau", default-features = false } +bp-rialto = { path = "../../../primitives/chains/rialto", default-features = false } bp-runtime = { path = "../../../primitives/runtime", default-features = false } bridge-runtime-common = { path = "../../runtime-common", default-features = false } pallet-bridge-call-dispatch = { path = "../../../modules/call-dispatch", default-features = false } diff --git a/bridges/bin/rialto/node/Cargo.toml b/bridges/bin/rialto/node/Cargo.toml index cda8c7fa95762..d287b0c3c9f3f 100644 --- a/bridges/bin/rialto/node/Cargo.toml +++ b/bridges/bin/rialto/node/Cargo.toml @@ -17,7 +17,7 @@ structopt = "0.3.21" bp-message-lane = { path = "../../../primitives/message-lane" } bp-runtime = { path = "../../../primitives/runtime" } -bp-rialto = { path = "../../../primitives/rialto" } +bp-rialto = { path = "../../../primitives/chains/rialto" } pallet-message-lane = { path = "../../../modules/message-lane" } pallet-message-lane-rpc = { path = "../../../modules/message-lane/rpc" } rialto-runtime = { path = "../runtime" } diff --git a/bridges/bin/rialto/runtime/Cargo.toml b/bridges/bin/rialto/runtime/Cargo.toml index 1fa22e22fe96b..bb4740071e86e 100644 --- a/bridges/bin/rialto/runtime/Cargo.toml +++ b/bridges/bin/rialto/runtime/Cargo.toml @@ -21,8 +21,8 @@ bp-eth-poa = { path = "../../../primitives/ethereum-poa", default-features = fal bp-header-chain = { path = "../../../primitives/header-chain", default-features = false } bp-message-dispatch = { path = "../../../primitives/message-dispatch", default-features = false } bp-message-lane = { path = "../../../primitives/message-lane", default-features = false } -bp-millau = { path = "../../../primitives/millau", default-features = false } -bp-rialto = { path = "../../../primitives/rialto", default-features = false } +bp-millau = { path = "../../../primitives/chains/millau", default-features = false } +bp-rialto = { path = "../../../primitives/chains/rialto", default-features = false } bp-runtime = { path = "../../../primitives/runtime", default-features = false } bridge-runtime-common = { path = "../../runtime-common", default-features = false } pallet-bridge-eth-poa = { path = "../../../modules/ethereum", default-features = false } diff --git a/bridges/modules/message-lane/Cargo.toml b/bridges/modules/message-lane/Cargo.toml index 8a411dcb91679..d4bced08110b6 100644 --- a/bridges/modules/message-lane/Cargo.toml +++ b/bridges/modules/message-lane/Cargo.toml @@ -15,7 +15,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] } # Bridge dependencies bp-message-lane = { path = "../../primitives/message-lane", default-features = false } -bp-rialto = { path = "../../primitives/rialto", default-features = false } +bp-rialto = { path = "../../primitives/chains/rialto", default-features = false } bp-runtime = { path = "../../primitives/runtime", default-features = false } # Substrate Dependencies diff --git a/bridges/primitives/chains/kusama/Cargo.toml b/bridges/primitives/chains/kusama/Cargo.toml new file mode 100644 index 0000000000000..bb65292883b07 --- /dev/null +++ b/bridges/primitives/chains/kusama/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "bp-kusama" +description = "Primitives of Kusama runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] + +# Bridge Dependencies +bp-message-lane = { path = "../../message-lane", 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-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-message-lane/std", + "bp-polkadot-core/std", + "bp-runtime/std", + "sp-api/std", + "sp-std/std", +] diff --git a/bridges/primitives/chains/kusama/src/lib.rs b/bridges/primitives/chains/kusama/src/lib.rs new file mode 100644 index 0000000000000..4e1134f162d37 --- /dev/null +++ b/bridges/primitives/chains/kusama/src/lib.rs @@ -0,0 +1,117 @@ +// 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_message_lane::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use sp_std::prelude::*; + +pub use bp_polkadot_core::*; + +/// Kusama Chain +pub type Kusama = PolkadotLike; + +// We use this to get the account on Kusama (target) which is derived from Polkadot's (source) +// account. +pub fn derive_account_from_polkadot_id(id: bp_runtime::SourceAccount) -> AccountId { + let encoded_id = bp_runtime::derive_account_id(bp_runtime::POLKADOT_BRIDGE_INSTANCE, id); + AccountIdConverter::convert(encoded_id) +} + +/// Name of the `KusamaFinalityApi::best_finalized` runtime method. +pub const BEST_FINALIZED_KUSAMA_HEADER_METHOD: &str = "KusamaFinalityApi_best_finalized"; +/// Name of the `KusamaFinalityApi::is_known_header` runtime method. +pub const IS_KNOWN_KUSAMA_HEADER_METHOD: &str = "KusamaFinalityApi_is_known_header"; + +/// Name of the `ToKusamaOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. +pub const TO_KUSAMA_ESTIMATE_MESSAGE_FEE_METHOD: &str = + "ToKusamaOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; +/// Name of the `ToKusamaOutboundLaneApi::messages_dispatch_weight` runtime method. +pub const TO_KUSAMA_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToKusamaOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToKusamaOutboundLaneApi::latest_generated_nonce` runtime method. +pub const TO_KUSAMA_LATEST_GENERATED_NONCE_METHOD: &str = "ToKusamaOutboundLaneApi_latest_generated_nonce"; +/// Name of the `ToKusamaOutboundLaneApi::latest_received_nonce` runtime method. +pub const TO_KUSAMA_LATEST_RECEIVED_NONCE_METHOD: &str = "ToKusamaOutboundLaneApi_latest_received_nonce"; + +/// Name of the `FromKusamaInboundLaneApi::latest_received_nonce` runtime method. +pub const FROM_KUSAMA_LATEST_RECEIVED_NONCE_METHOD: &str = "FromKusamaInboundLaneApi_latest_received_nonce"; +/// Name of the `FromKusamaInboundLaneApi::latest_onfirmed_nonce` runtime method. +pub const FROM_KUSAMA_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromKusamaInboundLaneApi_latest_confirmed_nonce"; +/// Name of the `FromKusamaInboundLaneApi::unrewarded_relayers_state` runtime method. +pub const FROM_KUSAMA_UNREWARDED_RELAYERS_STATE: &str = "FromKusamaInboundLaneApi_unrewarded_relayers_state"; + +sp_api::decl_runtime_apis! { + /// API for querying information about the finalized Kusama headers. + /// + /// This API is implemented by runtimes that are bridging with the Kusama chain, not the + /// Kusama runtime itself. + pub trait KusamaFinalityApi { + /// 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 Kusama chain. + /// + /// This API is implemented by runtimes that are sending messages to Kusama chain, not the + /// Kusama runtime itself. + pub trait ToKusamaOutboundLaneApi { + /// 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 Kusama 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 Kusama chain. + /// + /// This API is implemented by runtimes that are receiving messages from Kusama chain, not the + /// Kusama runtime itself. + pub trait FromKusamaInboundLaneApi { + /// 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/bridges/primitives/millau/Cargo.toml b/bridges/primitives/chains/millau/Cargo.toml similarity index 93% rename from bridges/primitives/millau/Cargo.toml rename to bridges/primitives/chains/millau/Cargo.toml index 124d8199e2c23..a7df6f6bbd7ea 100644 --- a/bridges/primitives/millau/Cargo.toml +++ b/bridges/primitives/chains/millau/Cargo.toml @@ -10,8 +10,8 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies -bp-message-lane = { path = "../message-lane", default-features = false } -bp-runtime = { path = "../runtime", default-features = false } +bp-message-lane = { path = "../../message-lane", default-features = false } +bp-runtime = { path = "../../runtime", default-features = false } fixed-hash = { version = "0.7.0", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } impl-codec = { version = "0.5.0", default-features = false } diff --git a/bridges/primitives/millau/src/lib.rs b/bridges/primitives/chains/millau/src/lib.rs similarity index 100% rename from bridges/primitives/millau/src/lib.rs rename to bridges/primitives/chains/millau/src/lib.rs diff --git a/bridges/primitives/millau/src/millau_hash.rs b/bridges/primitives/chains/millau/src/millau_hash.rs similarity index 100% rename from bridges/primitives/millau/src/millau_hash.rs rename to bridges/primitives/chains/millau/src/millau_hash.rs diff --git a/bridges/primitives/chains/polkadot/Cargo.toml b/bridges/primitives/chains/polkadot/Cargo.toml new file mode 100644 index 0000000000000..e1e646d5a1209 --- /dev/null +++ b/bridges/primitives/chains/polkadot/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "bp-polkadot" +description = "Primitives of Polkadot runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] + +# Bridge Dependencies +bp-message-lane = { path = "../../message-lane", 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-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-message-lane/std", + "bp-polkadot-core/std", + "bp-runtime/std", + "sp-api/std", + "sp-std/std", +] diff --git a/bridges/primitives/chains/polkadot/src/lib.rs b/bridges/primitives/chains/polkadot/src/lib.rs new file mode 100644 index 0000000000000..53fe1917ea7b7 --- /dev/null +++ b/bridges/primitives/chains/polkadot/src/lib.rs @@ -0,0 +1,117 @@ +// 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_message_lane::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use sp_std::prelude::*; + +pub use bp_polkadot_core::*; + +/// Polkadot Chain +pub type Polkadot = PolkadotLike; + +// We use this to get the account on Polkadot (target) which is derived from Kusama's (source) +// account. +pub fn derive_account_from_kusama_id(id: bp_runtime::SourceAccount) -> AccountId { + let encoded_id = bp_runtime::derive_account_id(bp_runtime::KUSAMA_BRIDGE_INSTANCE, id); + AccountIdConverter::convert(encoded_id) +} + +/// Name of the `PolkadotFinalityApi::best_finalized` runtime method. +pub const BEST_FINALIZED_POLKADOT_HEADER_METHOD: &str = "PolkadotFinalityApi_best_finalized"; +/// Name of the `PolkadotFinalityApi::is_known_header` runtime method. +pub const IS_KNOWN_POLKADOT_HEADER_METHOD: &str = "PolkadotFinalityApi_is_known_header"; + +/// Name of the `ToPolkadotOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. +pub const TO_POLKADOT_ESTIMATE_MESSAGE_FEE_METHOD: &str = + "ToPolkadotOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; +/// Name of the `ToPolkadotOutboundLaneApi::messages_dispatch_weight` runtime method. +pub const TO_POLKADOT_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToPolkadotOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToPolkadotOutboundLaneApi::latest_generated_nonce` runtime method. +pub const TO_POLKADOT_LATEST_GENERATED_NONCE_METHOD: &str = "ToPolkadotOutboundLaneApi_latest_generated_nonce"; +/// Name of the `ToPolkadotOutboundLaneApi::latest_received_nonce` runtime method. +pub const TO_POLKADOT_LATEST_RECEIVED_NONCE_METHOD: &str = "ToPolkadotOutboundLaneApi_latest_received_nonce"; + +/// Name of the `FromPolkadotInboundLaneApi::latest_received_nonce` runtime method. +pub const FROM_POLKADOT_LATEST_RECEIVED_NONCE_METHOD: &str = "FromPolkadotInboundLaneApi_latest_received_nonce"; +/// Name of the `FromPolkadotInboundLaneApi::latest_onfirmed_nonce` runtime method. +pub const FROM_POLKADOT_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromPolkadotInboundLaneApi_latest_confirmed_nonce"; +/// Name of the `FromPolkadotInboundLaneApi::unrewarded_relayers_state` runtime method. +pub const FROM_POLKADOT_UNREWARDED_RELAYERS_STATE: &str = "FromPolkadotInboundLaneApi_unrewarded_relayers_state"; + +sp_api::decl_runtime_apis! { + /// API for querying information about the finalized Polkadot headers. + /// + /// This API is implemented by runtimes that are bridging with the Polkadot chain, not the + /// Polkadot runtime itself. + pub trait PolkadotFinalityApi { + /// 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 Polkadot chain. + /// + /// This API is implemented by runtimes that are sending messages to Polkadot chain, not the + /// Polkadot runtime itself. + pub trait ToPolkadotOutboundLaneApi { + /// 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 Polkadot 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 Polkadot chain. + /// + /// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the + /// Polkadot runtime itself. + pub trait FromPolkadotInboundLaneApi { + /// 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/bridges/primitives/rialto/Cargo.toml b/bridges/primitives/chains/rialto/Cargo.toml similarity index 88% rename from bridges/primitives/rialto/Cargo.toml rename to bridges/primitives/chains/rialto/Cargo.toml index d6c12fc84809b..a225f79b3432b 100644 --- a/bridges/primitives/rialto/Cargo.toml +++ b/bridges/primitives/chains/rialto/Cargo.toml @@ -10,8 +10,8 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies -bp-message-lane = { path = "../message-lane", default-features = false } -bp-runtime = { path = "../runtime", default-features = false } +bp-message-lane = { path = "../../message-lane", default-features = false } +bp-runtime = { path = "../../runtime", default-features = false } # Substrate Based Dependencies diff --git a/bridges/primitives/rialto/src/lib.rs b/bridges/primitives/chains/rialto/src/lib.rs similarity index 100% rename from bridges/primitives/rialto/src/lib.rs rename to bridges/primitives/chains/rialto/src/lib.rs diff --git a/bridges/primitives/chains/rococo/Cargo.toml b/bridges/primitives/chains/rococo/Cargo.toml new file mode 100644 index 0000000000000..dc09d1a3bf305 --- /dev/null +++ b/bridges/primitives/chains/rococo/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "bp-rococo" +description = "Primitives of Rococo runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] + +# Bridge Dependencies +bp-message-lane = { path = "../../message-lane", 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-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-message-lane/std", + "bp-polkadot-core/std", + "bp-runtime/std", + "sp-api/std", + "sp-std/std", +] diff --git a/bridges/primitives/chains/rococo/src/lib.rs b/bridges/primitives/chains/rococo/src/lib.rs new file mode 100644 index 0000000000000..ef372540a340a --- /dev/null +++ b/bridges/primitives/chains/rococo/src/lib.rs @@ -0,0 +1,117 @@ +// 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_message_lane::{LaneId, Weight, MessageNonce, UnrewardedRelayersState}; +use sp_std::prelude::*; + +pub use bp_polkadot_core::*; + +/// Rococo Chain +pub type Rococo = PolkadotLike; + +// We use this to get the account on Rococo (target) which is derived from Westend's (source) +// account. +pub fn derive_account_from_westend_id(id: bp_runtime::SourceAccount) -> AccountId { + let encoded_id = bp_runtime::derive_account_id(bp_runtime::WESTEND_BRIDGE_INSTANCE, id); + AccountIdConverter::convert(encoded_id) +} + +/// Name of the `RococoFinalityApi::best_finalized` runtime method. +pub const BEST_FINALIZED_ROCOCO_HEADER_METHOD: &str = "RococoFinalityApi_best_finalized"; +/// Name of the `RococoFinalityApi::is_known_header` runtime method. +pub const IS_KNOWN_ROCOCO_HEADER_METHOD: &str = "RococoFinalityApi_is_known_header"; + +/// Name of the `ToRococoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. +pub const TO_ROCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str = + "ToRococoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; +/// Name of the `ToRococoOutboundLaneApi::messages_dispatch_weight` runtime method. +pub const TO_ROCOCO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToRococoOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToRococoOutboundLaneApi::latest_generated_nonce` runtime method. +pub const TO_ROCOCO_LATEST_GENERATED_NONCE_METHOD: &str = "ToRococoOutboundLaneApi_latest_generated_nonce"; +/// Name of the `ToRococoOutboundLaneApi::latest_received_nonce` runtime method. +pub const TO_ROCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "ToRococoOutboundLaneApi_latest_received_nonce"; + +/// Name of the `FromRococoInboundLaneApi::latest_received_nonce` runtime method. +pub const FROM_ROCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "FromRococoInboundLaneApi_latest_received_nonce"; +/// Name of the `FromRococoInboundLaneApi::latest_onfirmed_nonce` runtime method. +pub const FROM_ROCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromRococoInboundLaneApi_latest_confirmed_nonce"; +/// Name of the `FromRococoInboundLaneApi::unrewarded_relayers_state` runtime method. +pub const FROM_ROCOCO_UNREWARDED_RELAYERS_STATE: &str = "FromRococoInboundLaneApi_unrewarded_relayers_state"; + +sp_api::decl_runtime_apis! { + /// API for querying information about the finalized Rococo headers. + /// + /// This API is implemented by runtimes that are bridging with the Rococo chain, not the + /// Rococo runtime itself. + pub trait RococoFinalityApi { + /// 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 Rococo chain. + /// + /// This API is implemented by runtimes that are sending messages to Rococo chain, not the + /// Rococo runtime itself. + pub trait ToRococoOutboundLaneApi { + /// 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 Rococo 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 Rococo chain. + /// + /// This API is implemented by runtimes that are receiving messages from Rococo chain, not the + /// Rococo runtime itself. + pub trait FromRococoInboundLaneApi { + /// 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/bridges/primitives/chains/westend/Cargo.toml b/bridges/primitives/chains/westend/Cargo.toml new file mode 100644 index 0000000000000..6253f4bef9694 --- /dev/null +++ b/bridges/primitives/chains/westend/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "bp-westend" +description = "Primitives of Westend runtime." +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] + +# Bridge Dependencies +bp-message-lane = { path = "../../message-lane", 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-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-message-lane/std", + "bp-polkadot-core/std", + "bp-runtime/std", + "sp-api/std", + "sp-std/std", +] diff --git a/bridges/primitives/chains/westend/src/lib.rs b/bridges/primitives/chains/westend/src/lib.rs new file mode 100644 index 0000000000000..a2345e3b76daa --- /dev/null +++ b/bridges/primitives/chains/westend/src/lib.rs @@ -0,0 +1,117 @@ +// 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_message_lane::{LaneId, Weight, MessageNonce, UnrewardedRelayersState}; +use sp_std::prelude::*; + +pub use bp_polkadot_core::*; + +/// Westend Chain +pub type Westend = PolkadotLike; + +// We use this to get the account on Westend (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 `WestendFinalityApi::best_finalized` runtime method. +pub const BEST_FINALIZED_WESTEND_HEADER_METHOD: &str = "WestendFinalityApi_best_finalized"; +/// Name of the `WestendFinalityApi::is_known_header` runtime method. +pub const IS_KNOWN_WESTEND_HEADER_METHOD: &str = "WestendFinalityApi_is_known_header"; + +/// Name of the `ToWestendOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. +pub const TO_WESTEND_ESTIMATE_MESSAGE_FEE_METHOD: &str = + "ToWestendOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; +/// Name of the `ToWestendOutboundLaneApi::messages_dispatch_weight` runtime method. +pub const TO_WESTEND_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToWestendOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToWestendOutboundLaneApi::latest_generated_nonce` runtime method. +pub const TO_WESTEND_LATEST_GENERATED_NONCE_METHOD: &str = "ToWestendOutboundLaneApi_latest_generated_nonce"; +/// Name of the `ToWestendOutboundLaneApi::latest_received_nonce` runtime method. +pub const TO_WESTEND_LATEST_RECEIVED_NONCE_METHOD: &str = "ToWestendOutboundLaneApi_latest_received_nonce"; + +/// Name of the `FromWestendInboundLaneApi::latest_received_nonce` runtime method. +pub const FROM_WESTEND_LATEST_RECEIVED_NONCE_METHOD: &str = "FromWestendInboundLaneApi_latest_received_nonce"; +/// Name of the `FromWestendInboundLaneApi::latest_onfirmed_nonce` runtime method. +pub const FROM_WESTEND_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromWestendInboundLaneApi_latest_confirmed_nonce"; +/// Name of the `FromWestendInboundLaneApi::unrewarded_relayers_state` runtime method. +pub const FROM_WESTEND_UNREWARDED_RELAYERS_STATE: &str = "FromWestendInboundLaneApi_unrewarded_relayers_state"; + +sp_api::decl_runtime_apis! { + /// API for querying information about the finalized Westend headers. + /// + /// This API is implemented by runtimes that are bridging with the Westend chain, not the + /// Westend runtime itself. + pub trait WestendFinalityApi { + /// 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 Westend chain. + /// + /// This API is implemented by runtimes that are sending messages to Westend chain, not the + /// Westend runtime itself. + pub trait ToWestendOutboundLaneApi { + /// 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 Westend 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 Westend chain. + /// + /// This API is implemented by runtimes that are receiving messages from Westend chain, not the + /// Westend runtime itself. + pub trait FromWestendInboundLaneApi { + /// 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/bridges/primitives/kusama/src/lib.rs b/bridges/primitives/kusama/src/lib.rs deleted file mode 100644 index 9ec032dbd5138..0000000000000 --- a/bridges/primitives/kusama/src/lib.rs +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2019-2020 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_message_lane::{LaneId, MessageNonce}; -use bp_runtime::Chain; -use frame_support::{weights::Weight, RuntimeDebug}; -use sp_core::Hasher as HasherT; -use sp_runtime::{ - generic, - traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, OpaqueExtrinsic as UncheckedExtrinsic, -}; -use sp_std::prelude::*; - -// TODO: may need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78 -/// Maximal number of messages in single delivery transaction. -pub const MAX_MESSAGES_IN_DELIVERY_TRANSACTION: MessageNonce = 128; - -/// Maximal number of unrewarded relayer entries at inbound lane. -pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128; - -// TODO: should be selected keeping in mind: -// finality delay on both chains + reward payout cost + messages throughput. -/// Maximal number of unconfirmed messages at inbound lane. -pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 8192; - -/// Block number type used in Kusama. -pub type BlockNumber = u32; - -/// Hash type used in Kusama. -pub type Hash = ::Out; - -/// The type of an object that can produce hashes on Kusama. -pub type Hasher = BlakeTwo256; - -/// The header type used by Kusama. -pub type Header = generic::Header; - -/// Signature type used by Kusama. -pub type Signature = MultiSignature; - -/// Public key of account on Kusama chain. -pub type AccountPublic = ::Signer; - -/// Id of account on Kusama chain. -pub type AccountId = ::AccountId; - -/// Index of a transaction on the Kusama chain. -pub type Nonce = u32; - -/// Block type of Kusama. -pub type Block = generic::Block; - -/// Kusama block signed with a Justification. -pub type SignedBlock = generic::SignedBlock; - -/// The balance of an account on Polkadot. -pub type Balance = u128; - -/// Kusama chain. -#[derive(RuntimeDebug)] -pub struct Kusama; - -impl Chain for Kusama { - type BlockNumber = BlockNumber; - type Hash = Hash; - type Hasher = Hasher; - type Header = Header; -} - -/// Convert a 256-bit hash into an AccountId. -pub struct AccountIdConverter; - -impl sp_runtime::traits::Convert for AccountIdConverter { - fn convert(hash: sp_core::H256) -> AccountId { - hash.to_fixed_bytes().into() - } -} - -/// Name of the `KusamaHeaderApi::best_blocks` runtime method. -pub const BEST_KUSAMA_BLOCKS_METHOD: &str = "KusamaHeaderApi_best_blocks"; -/// Name of the `KusamaHeaderApi::finalized_block` runtime method. -pub const FINALIZED_KUSAMA_BLOCK_METHOD: &str = "KusamaHeaderApi_finalized_block"; -/// Name of the `KusamaHeaderApi::is_known_block` runtime method. -pub const IS_KNOWN_KUSAMA_BLOCK_METHOD: &str = "KusamaHeaderApi_is_known_block"; -/// Name of the `KusamaHeaderApi::incomplete_headers` runtime method. -pub const INCOMPLETE_KUSAMA_HEADERS_METHOD: &str = "KusamaHeaderApi_incomplete_headers"; - -sp_api::decl_runtime_apis! { - /// API for querying information about Kusama headers from the Bridge Pallet instance. - /// - /// This API is implemented by runtimes that are bridging with Kusama chain, not the - /// Kusama runtime itself. - pub trait KusamaHeaderApi { - /// 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; - } - - /// Outbound message lane API for messages that are sent to Kusama chain. - /// - /// This API is implemented by runtimes that are sending messages to Kusama chain, not the - /// Kusama runtime itself. - pub trait ToKusamaOutboundLaneApi { - /// 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 Kusama chain. - /// - /// This API is implemented by runtimes that are receiving messages from Kusama chain, not the - /// Kusama runtime itself. - pub trait FromKusamaInboundLaneApi { - /// 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; - } -} diff --git a/bridges/primitives/kusama/Cargo.toml b/bridges/primitives/polkadot-core/Cargo.toml similarity index 93% rename from bridges/primitives/kusama/Cargo.toml rename to bridges/primitives/polkadot-core/Cargo.toml index 784f0b013289a..0a19bad97aaec 100644 --- a/bridges/primitives/kusama/Cargo.toml +++ b/bridges/primitives/polkadot-core/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "bp-kusama" -description = "Primitives of Kusama runtime." +name = "bp-polkadot-core" +description = "Primitives of Polkadot-like runtime." version = "0.1.0" authors = ["Parity Technologies "] edition = "2018" diff --git a/bridges/primitives/polkadot-core/src/lib.rs b/bridges/primitives/polkadot-core/src/lib.rs new file mode 100644 index 0000000000000..78a9fe8480c4d --- /dev/null +++ b/bridges/primitives/polkadot-core/src/lib.rs @@ -0,0 +1,96 @@ +// 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)] + +use bp_message_lane::MessageNonce; +use bp_runtime::Chain; +use frame_support::RuntimeDebug; +use sp_core::Hasher as HasherT; +use sp_runtime::{ + generic, + traits::{BlakeTwo256, IdentifyAccount, Verify}, + MultiSignature, OpaqueExtrinsic as UncheckedExtrinsic, +}; + +// Re-export's to avoid extra substrate dependencies in chain-specific crates. +pub use frame_support::Parameter; +pub use sp_runtime::traits::Convert; + +// TODO [#78] may need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78 +/// Maximal number of messages in single delivery transaction. +pub const MAX_MESSAGES_IN_DELIVERY_TRANSACTION: MessageNonce = 128; + +/// Maximal number of unrewarded relayer entries at inbound lane. +pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128; + +// TODO [#438] should be selected keeping in mind: +// finality delay on both chains + reward payout cost + messages throughput. +/// Maximal number of unconfirmed messages at inbound lane. +pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 8192; + +/// Block number type used in Polkadot-like chains. +pub type BlockNumber = u32; + +/// Hash type used in Polkadot-like chains. +pub type Hash = ::Out; + +/// The type of an object that can produce hashes on Polkadot-like chains. +pub type Hasher = BlakeTwo256; + +/// The header type used by Polkadot-like chains. +pub type Header = generic::Header; + +/// Signature type used by Polkadot-like chains. +pub type Signature = MultiSignature; + +/// Public key of account on Polkadot-like chains. +pub type AccountPublic = ::Signer; + +/// Id of account on Polkadot-like chains. +pub type AccountId = ::AccountId; + +/// Index of a transaction on the Polkadot-like chains. +pub type Nonce = u32; + +/// Block type of Polkadot-like chains. +pub type Block = generic::Block; + +/// Polkadot-like block signed with a Justification. +pub type SignedBlock = generic::SignedBlock; + +/// The balance of an account on Polkadot-like chain. +pub type Balance = u128; + +/// Polkadot-like chain. +#[derive(RuntimeDebug)] +pub struct PolkadotLike; + +impl Chain for PolkadotLike { + type BlockNumber = BlockNumber; + type Hash = Hash; + type Hasher = Hasher; + type Header = Header; +} + +/// Convert a 256-bit hash into an AccountId. +pub struct AccountIdConverter; + +impl Convert for AccountIdConverter { + fn convert(hash: sp_core::H256) -> AccountId { + hash.to_fixed_bytes().into() + } +} diff --git a/bridges/primitives/polkadot/Cargo.toml b/bridges/primitives/polkadot/Cargo.toml deleted file mode 100644 index f7c9b9717d1cd..0000000000000 --- a/bridges/primitives/polkadot/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "bp-polkadot" -description = "Primitives of Polkadot runtime." -version = "0.1.0" -authors = ["Parity Technologies "] -edition = "2018" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" - -[dependencies] - -# Bridge Dependencies - -bp-message-lane = { path = "../message-lane", default-features = false } -bp-runtime = { path = "../runtime", default-features = false } - -# Substrate Based Dependencies - -frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } - -[features] -default = ["std"] -std = [ - "bp-message-lane/std", - "bp-runtime/std", - "frame-support/std", - "frame-system/std", - "sp-api/std", - "sp-core/std", - "sp-runtime/std", - "sp-std/std", -] diff --git a/bridges/primitives/polkadot/src/lib.rs b/bridges/primitives/polkadot/src/lib.rs deleted file mode 100644 index a82dd5075bb67..0000000000000 --- a/bridges/primitives/polkadot/src/lib.rs +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2019-2020 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_message_lane::{LaneId, MessageNonce}; -use bp_runtime::Chain; -use frame_support::{weights::Weight, RuntimeDebug}; -use sp_core::Hasher as HasherT; -use sp_runtime::{ - generic, - traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, OpaqueExtrinsic as UncheckedExtrinsic, -}; -use sp_std::prelude::*; - -// TODO: may need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78 -/// Maximal number of messages in single delivery transaction. -pub const MAX_MESSAGES_IN_DELIVERY_TRANSACTION: MessageNonce = 128; - -/// Maximal number of unrewarded relayer entries at inbound lane. -pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128; - -// TODO: should be selected keeping in mind: -// finality delay on both chains + reward payout cost + messages throughput. -/// Maximal number of unconfirmed messages at inbound lane. -pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 8192; - -/// Block number type used in Polkadot. -pub type BlockNumber = u32; - -/// Hash type used in Polkadot. -pub type Hash = ::Out; - -/// The type of an object that can produce hashes on Polkadot. -pub type Hasher = BlakeTwo256; - -/// The header type used by Polkadot. -pub type Header = generic::Header; - -/// Signature type used by Polkadot. -pub type Signature = MultiSignature; - -/// Public key of account on Polkadot chain. -pub type AccountPublic = ::Signer; - -/// Id of account on Polkadot chain. -pub type AccountId = ::AccountId; - -/// Index of a transaction on the Polkadot chain. -pub type Nonce = u32; - -/// Block type of Polkadot. -pub type Block = generic::Block; - -/// Polkadot block signed with a Justification. -pub type SignedBlock = generic::SignedBlock; - -/// The balance of an account on Polkadot. -pub type Balance = u128; - -/// Polkadot chain. -#[derive(RuntimeDebug)] -pub struct Polkadot; - -impl Chain for Polkadot { - type BlockNumber = BlockNumber; - type Hash = Hash; - type Hasher = Hasher; - type Header = Header; -} - -/// Convert a 256-bit hash into an AccountId. -pub struct AccountIdConverter; - -impl sp_runtime::traits::Convert for AccountIdConverter { - fn convert(hash: sp_core::H256) -> AccountId { - hash.to_fixed_bytes().into() - } -} - -/// Name of the `PolkadotHeaderApi::best_blocks` runtime method. -pub const BEST_POLKADOT_BLOCKS_METHOD: &str = "PolkadotHeaderApi_best_blocks"; -/// Name of the `PolkadotHeaderApi::finalized_block` runtime method. -pub const FINALIZED_POLKADOT_BLOCK_METHOD: &str = "PolkadotHeaderApi_finalized_block"; -/// Name of the `PolkadotHeaderApi::is_known_block` runtime method. -pub const IS_KNOWN_POLKADOT_BLOCK_METHOD: &str = "PolkadotHeaderApi_is_known_block"; -/// Name of the `PolkadotHeaderApi::incomplete_headers` runtime method. -pub const INCOMPLETE_POLKADOT_HEADERS_METHOD: &str = "PolkadotHeaderApi_incomplete_headers"; - -sp_api::decl_runtime_apis! { - /// API for querying information about Polkadot headers from the Bridge Pallet instance. - /// - /// This API is implemented by runtimes that are bridging with Polkadot chain, not the - /// Polkadot runtime itself. - pub trait PolkadotHeaderApi { - /// 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; - } - - /// Outbound message lane API for messages that are sent to Polkadot chain. - /// - /// This API is implemented by runtimes that are sending messages to Polkadot chain, not the - /// Polkadot runtime itself. - pub trait ToPolkadotOutboundLaneApi { - /// 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 Polkadot chain. - /// - /// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the - /// Polkadot runtime itself. - pub trait FromPolkadotInboundLaneApi { - /// 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; - } -} diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 3eb2c53771786..862edf7b972d3 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -47,6 +47,12 @@ pub const POLKADOT_BRIDGE_INSTANCE: InstanceId = *b"pdot"; /// Bridge-with-Kusama instance id. pub const KUSAMA_BRIDGE_INSTANCE: InstanceId = *b"ksma"; +/// Bridge-with-Rococo instance id. +pub const ROCOCO_BRIDGE_INSTANCE: InstanceId = *b"roco"; + +/// Bridge-with-Westend instance id. +pub const WESTEND_BRIDGE_INSTANCE: InstanceId = *b"wend"; + /// Call-dispatch module prefix. pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/call-dispatch"; diff --git a/bridges/relays/ethereum-client/Cargo.toml b/bridges/relays/ethereum-client/Cargo.toml index ac5930145888f..4c04f4889469b 100644 --- a/bridges/relays/ethereum-client/Cargo.toml +++ b/bridges/relays/ethereum-client/Cargo.toml @@ -16,4 +16,4 @@ jsonrpsee-ws-client = "0.2.0-alpha" libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] } log = "0.4.11" relay-utils = { path = "../utils" } -web3 = { version = "0.15", git = "https://github.com/tomusdrw/rust-web3.git", branch ="td-ethabi", default-features = false } +web3 = { version = "0.15", git = "https://github.com/tomusdrw/rust-web3", branch ="td-ethabi", default-features = false } diff --git a/bridges/relays/ethereum/Cargo.toml b/bridges/relays/ethereum/Cargo.toml index b7fe7273c155f..fbc1ef00fcaa9 100644 --- a/bridges/relays/ethereum/Cargo.toml +++ b/bridges/relays/ethereum/Cargo.toml @@ -12,9 +12,9 @@ async-trait = "0.1.42" clap = { version = "2.33.3", features = ["yaml"] } codec = { package = "parity-scale-codec", version = "2.0.0" } env_logger = "0.8.3" -ethabi = { git = "https://github.com/paritytech/ethabi.git", branch = "td-eth-types-11" } -ethabi-contract = { git = "https://github.com/paritytech/ethabi.git", branch = "td-eth-types-11" } -ethabi-derive = { git = "https://github.com/paritytech/ethabi.git", branch = "td-eth-types-11" } +ethabi = { git = "https://github.com/paritytech/ethabi", branch = "td-eth-types-11" } +ethabi-contract = { git = "https://github.com/paritytech/ethabi", branch = "td-eth-types-11" } +ethabi-derive = { git = "https://github.com/paritytech/ethabi", branch = "td-eth-types-11" } futures = "0.3.12" hex = "0.4" hex-literal = "0.3" diff --git a/bridges/relays/kusama-client/Cargo.toml b/bridges/relays/kusama-client/Cargo.toml index 04958cf2b3618..cd311830ae615 100644 --- a/bridges/relays/kusama-client/Cargo.toml +++ b/bridges/relays/kusama-client/Cargo.toml @@ -13,7 +13,7 @@ relay-utils = { path = "../utils" } # Bridge dependencies -bp-kusama = { path = "../../primitives/kusama" } +bp-kusama = { path = "../../primitives/chains/kusama" } # Substrate Dependencies diff --git a/bridges/relays/polkadot-client/Cargo.toml b/bridges/relays/polkadot-client/Cargo.toml index 8764b6509b242..a1d82758f8d62 100644 --- a/bridges/relays/polkadot-client/Cargo.toml +++ b/bridges/relays/polkadot-client/Cargo.toml @@ -13,7 +13,7 @@ relay-utils = { path = "../utils" } # Bridge dependencies -bp-polkadot = { path = "../../primitives/polkadot" } +bp-polkadot = { path = "../../primitives/chains/polkadot" } # Substrate Dependencies diff --git a/bridges/relays/substrate/Cargo.toml b/bridges/relays/substrate/Cargo.toml index 7aeefb3cab56a..fb5d48120c46b 100644 --- a/bridges/relays/substrate/Cargo.toml +++ b/bridges/relays/substrate/Cargo.toml @@ -19,12 +19,12 @@ structopt = "0.3" # Bridge dependencies bp-header-chain = { path = "../../primitives/header-chain" } -bp-kusama = { path = "../../primitives/kusama" } +bp-kusama = { path = "../../primitives/chains/kusama" } bp-message-lane = { path = "../../primitives/message-lane" } -bp-millau = { path = "../../primitives/millau" } -bp-polkadot = { path = "../../primitives/polkadot" } +bp-millau = { path = "../../primitives/chains/millau" } +bp-polkadot = { path = "../../primitives/chains/polkadot" } bp-runtime = { path = "../../primitives/runtime" } -bp-rialto = { path = "../../primitives/rialto" } +bp-rialto = { path = "../../primitives/chains/rialto" } bridge-runtime-common = { path = "../../bin/runtime-common" } finality-relay = { path = "../finality-relay" } headers-relay = { path = "../headers-relay" }