Polkadot integration (#542)

* kusama primitives + client

* polkadot primitives + client

* lost Chain definitions

* fix compilation and fmt

* Update primitives/runtime/src/lib.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2020-12-04 18:46:35 +03:00
committed by Bastian Köcher
parent 81a3e7cce3
commit 2d08a9d213
12 changed files with 526 additions and 2 deletions
+34
View File
@@ -0,0 +1,34 @@
[package]
name = "bp-kusama"
description = "Primitives of Kusama runtime."
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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.git", branch = "master" , default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
[features]
default = ["std"]
std = [
"bp-message-lane/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]
+150
View File
@@ -0,0 +1,150 @@
// 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 <http://www.gnu.org/licenses/>.
#![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::*;
/// Block number type used in Kusama.
pub type BlockNumber = u32;
/// Hash type used in Kusama.
pub type Hash = <BlakeTwo256 as HasherT>::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<BlockNumber, Hasher>;
/// Signature type used by Kusama.
pub type Signature = MultiSignature;
/// Public key of account on Kusama chain.
pub type AccountPublic = <Signature as Verify>::Signer;
/// Id of account on Kusama chain.
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
/// Index of a transaction on the Kusama chain.
pub type Nonce = u32;
/// Block type of Kusama.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Kusama block signed with a Justification.
pub type SignedBlock = generic::SignedBlock<Block>;
/// 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;
}
/// 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";
/// Maximal weight of single Kusama extrinsic.
pub const MAXIMUM_EXTRINSIC_WEIGHT: Weight = 725_000_000_000;
// 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;
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 dispatch weight 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)>;
/// 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;
}
}
+34
View File
@@ -0,0 +1,34 @@
[package]
name = "bp-polkadot"
description = "Primitives of Polkadot runtime."
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
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.git", branch = "master" , default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
[features]
default = ["std"]
std = [
"bp-message-lane/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]
+150
View File
@@ -0,0 +1,150 @@
// 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 <http://www.gnu.org/licenses/>.
#![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::*;
/// Block number type used in Polkadot.
pub type BlockNumber = u32;
/// Hash type used in Polkadot.
pub type Hash = <BlakeTwo256 as HasherT>::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<BlockNumber, Hasher>;
/// Signature type used by Polkadot.
pub type Signature = MultiSignature;
/// Public key of account on Polkadot chain.
pub type AccountPublic = <Signature as Verify>::Signer;
/// Id of account on Polkadot chain.
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
/// Index of a transaction on the Polkadot chain.
pub type Nonce = u32;
/// Block type of Polkadot.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Polkadot block signed with a Justification.
pub type SignedBlock = generic::SignedBlock<Block>;
/// 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;
}
/// 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";
/// Maximal weight of single Polkadot extrinsic.
pub const MAXIMUM_EXTRINSIC_WEIGHT: Weight = 725_000_000_000;
// 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;
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 dispatch weight 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)>;
/// 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;
}
}
+6
View File
@@ -35,6 +35,12 @@ pub const RIALTO_BRIDGE_INSTANCE: InstanceId = *b"rlto";
/// Bridge-with-Millau instance id.
pub const MILLAU_BRIDGE_INSTANCE: InstanceId = *b"mlau";
/// Bridge-with-Polkadot instance id.
pub const POLKADOT_BRIDGE_INSTANCE: InstanceId = *b"pdot";
/// Bridge-with-Kusama instance id.
pub const KUSAMA_BRIDGE_INSTANCE: InstanceId = *b"ksma";
/// Call-dispatch module prefix.
pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/call-dispatch";
+25
View File
@@ -0,0 +1,25 @@
[package]
name = "relay-kusama-client"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.4" }
headers-relay = { path = "../headers-relay" }
relay-substrate-client = { path = "../substrate-client" }
relay-utils = { path = "../utils" }
# Bridge dependencies
bp-kusama = { path = "../../primitives/kusama" }
# Substrate Dependencies
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
+47
View File
@@ -0,0 +1,47 @@
// 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 <http://www.gnu.org/licenses/>.
//! Types used to connect to the Kusama chain.
use relay_substrate_client::{Chain, ChainBase};
use std::time::Duration;
/// Kusama header id.
pub type HeaderId = relay_utils::HeaderId<bp_kusama::Hash, bp_kusama::BlockNumber>;
/// Kusama chain definition
#[derive(Debug, Clone, Copy)]
pub struct Kusama;
impl ChainBase for Kusama {
type BlockNumber = bp_kusama::BlockNumber;
type Hash = bp_kusama::Hash;
type Hasher = bp_kusama::Hasher;
type Header = bp_kusama::Header;
}
impl Chain for Kusama {
const NAME: &'static str = "Kusama";
const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(6);
type AccountId = bp_kusama::AccountId;
type Index = bp_kusama::Nonce;
type SignedBlock = bp_kusama::SignedBlock;
type Call = ();
}
/// Kusama header type used in headers sync.
pub type SyncHeader = relay_substrate_client::SyncHeader<bp_kusama::Header>;
+25
View File
@@ -0,0 +1,25 @@
[package]
name = "relay-polkadot-client"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.4" }
headers-relay = { path = "../headers-relay" }
relay-substrate-client = { path = "../substrate-client" }
relay-utils = { path = "../utils" }
# Bridge dependencies
bp-polkadot = { path = "../../primitives/polkadot" }
# Substrate Dependencies
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
+47
View File
@@ -0,0 +1,47 @@
// 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 <http://www.gnu.org/licenses/>.
//! Types used to connect to the Polkadot chain.
use relay_substrate_client::{Chain, ChainBase};
use std::time::Duration;
/// Polkadot header id.
pub type HeaderId = relay_utils::HeaderId<bp_polkadot::Hash, bp_polkadot::BlockNumber>;
/// Polkadot chain definition
#[derive(Debug, Clone, Copy)]
pub struct Polkadot;
impl ChainBase for Polkadot {
type BlockNumber = bp_polkadot::BlockNumber;
type Hash = bp_polkadot::Hash;
type Hasher = bp_polkadot::Hasher;
type Header = bp_polkadot::Header;
}
impl Chain for Polkadot {
const NAME: &'static str = "Polkadot";
const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(6);
type AccountId = bp_polkadot::AccountId;
type Index = bp_polkadot::Nonce;
type SignedBlock = bp_polkadot::SignedBlock;
type Call = ();
}
/// Polkadot header type used in headers sync.
pub type SyncHeader = relay_substrate_client::SyncHeader<bp_polkadot::Header>;
+1 -2
View File
@@ -40,8 +40,7 @@ pub trait Chain: ChainBase {
/// The user account identifier type for the runtime.
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default;
/// Account index (aka nonce) type. This stores the number of previous transactions associated
/// with a sender account.
/// Index of a transaction used by the chain.
type Index: Parameter
+ Member
+ MaybeSerialize
+4
View File
@@ -18,8 +18,10 @@ structopt = "0.3"
# Bridge dependencies
bp-kusama = { path = "../../primitives/kusama" }
bp-message-lane = { path = "../../primitives/message-lane" }
bp-millau = { path = "../../primitives/millau" }
bp-polkadot = { path = "../../primitives/polkadot" }
bp-runtime = { path = "../../primitives/runtime" }
bp-rialto = { path = "../../primitives/rialto" }
headers-relay = { path = "../headers-relay" }
@@ -27,7 +29,9 @@ messages-relay = { path = "../messages-relay" }
millau-runtime = { path = "../../bin/millau/runtime" }
pallet-bridge-call-dispatch = { path = "../../modules/call-dispatch" }
pallet-substrate-bridge = { path = "../../modules/substrate" }
relay-kusama-client = { path = "../kusama-client" }
relay-millau-client = { path = "../millau-client" }
relay-polkadot-client = { path = "../polkadot-client" }
relay-rialto-client = { path = "../rialto-client" }
relay-substrate-client = { path = "../substrate-client" }
relay-utils = { path = "../utils" }
+3
View File
@@ -21,6 +21,7 @@
use codec::Encode;
use frame_support::weights::GetDispatchInfo;
use pallet_bridge_call_dispatch::{CallOrigin, MessagePayload};
use relay_kusama_client::Kusama;
use relay_millau_client::{Millau, SigningParams as MillauSigningParams};
use relay_rialto_client::{Rialto, SigningParams as RialtoSigningParams};
use relay_substrate_client::{ConnectionParams, TransactionSignScheme};
@@ -28,6 +29,8 @@ use relay_utils::initialize::initialize_relay;
use sp_core::{Bytes, Pair};
use sp_runtime::traits::IdentifyAccount;
/// Kusama node client.
pub type KusamaClient = relay_substrate_client::Client<Kusama>;
/// Millau node client.
pub type MillauClient = relay_substrate_client::Client<Millau>;
/// Rialto node client.