mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
Fixes for Polkadot Integration (#586)
* Add AccountIdConverter impl to Kusama and Polkadot primitives * Add missing message lane config constants * Add more consts * Add another missing const * Move consts in primitives so that they're consistent across files * Move types and consts to more intuitive locations * Downgrade hyper from v0.13.8 to v0.13.6 This conflicts with a requirement on the Polkadot side which requires that hyper is =v0.13.6 * Update hyper to v0.13.9 * Update async-io to v1.3.1 * Update socket2 from v0.3.15 to v0.3.18 * Update message weight/size constants * Make BlockWeights/Length parameter types Allows us to re-use these types from both the runtime and the message lane config files without creating a new instance of them. * Remove uneccesary weight constants These can be found in the `runtime-common` crate used by Polkadot/Kusama. The constants there will also be the most up-to-date versions.
This commit is contained in:
committed by
Bastian Köcher
parent
5cafbaa0ad
commit
a6c3de51d3
@@ -31,7 +31,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
|||||||
pub mod rialto_messages;
|
pub mod rialto_messages;
|
||||||
|
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use frame_system::limits;
|
|
||||||
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
||||||
use sp_api::impl_runtime_apis;
|
use sp_api::impl_runtime_apis;
|
||||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||||
@@ -155,9 +154,6 @@ parameter_types! {
|
|||||||
read: 60_000_000, // ~0.06 ms = ~60 µs
|
read: 60_000_000, // ~0.06 ms = ~60 µs
|
||||||
write: 200_000_000, // ~0.2 ms = 200 µs
|
write: 200_000_000, // ~0.2 ms = 200 µs
|
||||||
};
|
};
|
||||||
|
|
||||||
pub RuntimeBlockLength: limits::BlockLength = bp_millau::runtime_block_length();
|
|
||||||
pub RuntimeBlockWeights: limits::BlockWeights = bp_millau::runtime_block_weights();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl frame_system::Config for Runtime {
|
impl frame_system::Config for Runtime {
|
||||||
@@ -199,9 +195,9 @@ impl frame_system::Config for Runtime {
|
|||||||
/// Weight information for the extrinsics of this pallet.
|
/// Weight information for the extrinsics of this pallet.
|
||||||
type SystemWeightInfo = ();
|
type SystemWeightInfo = ();
|
||||||
/// Block and extrinsics weights: base values and limits.
|
/// Block and extrinsics weights: base values and limits.
|
||||||
type BlockWeights = RuntimeBlockWeights;
|
type BlockWeights = bp_millau::BlockWeights;
|
||||||
/// The maximum length of a block (in bytes).
|
/// The maximum length of a block (in bytes).
|
||||||
type BlockLength = RuntimeBlockLength;
|
type BlockLength = bp_millau::BlockLength;
|
||||||
/// The weight of database operations that the runtime can invoke.
|
/// The weight of database operations that the runtime can invoke.
|
||||||
type DbWeight = DbWeight;
|
type DbWeight = DbWeight;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ pub mod millau_messages;
|
|||||||
pub mod rialto_poa;
|
pub mod rialto_poa;
|
||||||
|
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use frame_system::limits;
|
|
||||||
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
||||||
use sp_api::impl_runtime_apis;
|
use sp_api::impl_runtime_apis;
|
||||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||||
@@ -163,9 +162,6 @@ parameter_types! {
|
|||||||
read: 60_000_000, // ~0.06 ms = ~60 µs
|
read: 60_000_000, // ~0.06 ms = ~60 µs
|
||||||
write: 200_000_000, // ~0.2 ms = 200 µs
|
write: 200_000_000, // ~0.2 ms = 200 µs
|
||||||
};
|
};
|
||||||
|
|
||||||
pub RuntimeBlockLength: limits::BlockLength = bp_rialto::runtime_block_length();
|
|
||||||
pub RuntimeBlockWeights: limits::BlockWeights = bp_rialto::runtime_block_weights();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl frame_system::Config for Runtime {
|
impl frame_system::Config for Runtime {
|
||||||
@@ -207,9 +203,9 @@ impl frame_system::Config for Runtime {
|
|||||||
/// Weight information for the extrinsics of this pallet.
|
/// Weight information for the extrinsics of this pallet.
|
||||||
type SystemWeightInfo = ();
|
type SystemWeightInfo = ();
|
||||||
/// Block and extrinsics weights: base values and limits.
|
/// Block and extrinsics weights: base values and limits.
|
||||||
type BlockWeights = RuntimeBlockWeights;
|
type BlockWeights = bp_rialto::BlockWeights;
|
||||||
/// The maximum length of a block (in bytes).
|
/// The maximum length of a block (in bytes).
|
||||||
type BlockLength = RuntimeBlockLength;
|
type BlockLength = bp_rialto::BlockLength;
|
||||||
/// The weight of database operations that the runtime can invoke.
|
/// The weight of database operations that the runtime can invoke.
|
||||||
type DbWeight = DbWeight;
|
type DbWeight = DbWeight;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ bp-runtime = { path = "../runtime", default-features = false }
|
|||||||
# Substrate Based Dependencies
|
# Substrate Based Dependencies
|
||||||
|
|
||||||
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||||
|
frame-system = { 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-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-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-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
|
||||||
@@ -27,6 +28,7 @@ std = [
|
|||||||
"bp-message-lane/std",
|
"bp-message-lane/std",
|
||||||
"bp-runtime/std",
|
"bp-runtime/std",
|
||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
|
"frame-system/std",
|
||||||
"sp-api/std",
|
"sp-api/std",
|
||||||
"sp-core/std",
|
"sp-core/std",
|
||||||
"sp-runtime/std",
|
"sp-runtime/std",
|
||||||
|
|||||||
@@ -31,6 +31,18 @@ use sp_runtime::{
|
|||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
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.
|
/// Block number type used in Kusama.
|
||||||
pub type BlockNumber = u32;
|
pub type BlockNumber = u32;
|
||||||
|
|
||||||
@@ -75,6 +87,15 @@ impl Chain for Kusama {
|
|||||||
type Header = Header;
|
type Header = Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a 256-bit hash into an AccountId.
|
||||||
|
pub struct AccountIdConverter;
|
||||||
|
|
||||||
|
impl sp_runtime::traits::Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
||||||
|
fn convert(hash: sp_core::H256) -> AccountId {
|
||||||
|
hash.to_fixed_bytes().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Name of the `KusamaHeaderApi::best_blocks` runtime method.
|
/// Name of the `KusamaHeaderApi::best_blocks` runtime method.
|
||||||
pub const BEST_KUSAMA_BLOCKS_METHOD: &str = "KusamaHeaderApi_best_blocks";
|
pub const BEST_KUSAMA_BLOCKS_METHOD: &str = "KusamaHeaderApi_best_blocks";
|
||||||
/// Name of the `KusamaHeaderApi::finalized_block` runtime method.
|
/// Name of the `KusamaHeaderApi::finalized_block` runtime method.
|
||||||
@@ -84,13 +105,6 @@ pub const IS_KNOWN_KUSAMA_BLOCK_METHOD: &str = "KusamaHeaderApi_is_known_block";
|
|||||||
/// Name of the `KusamaHeaderApi::incomplete_headers` runtime method.
|
/// Name of the `KusamaHeaderApi::incomplete_headers` runtime method.
|
||||||
pub const INCOMPLETE_KUSAMA_HEADERS_METHOD: &str = "KusamaHeaderApi_incomplete_headers";
|
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! {
|
sp_api::decl_runtime_apis! {
|
||||||
/// API for querying information about Kusama headers from the Bridge Pallet instance.
|
/// API for querying information about Kusama headers from the Bridge Pallet instance.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use frame_support::{
|
|||||||
weights::{constants::WEIGHT_PER_MILLIS, DispatchClass, Weight},
|
weights::{constants::WEIGHT_PER_MILLIS, DispatchClass, Weight},
|
||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
|
use frame_system::limits;
|
||||||
use sp_core::Hasher as HasherT;
|
use sp_core::Hasher as HasherT;
|
||||||
use sp_runtime::traits::Convert;
|
use sp_runtime::traits::Convert;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
@@ -42,36 +43,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
pub use millau_hash::MillauHash;
|
pub use millau_hash::MillauHash;
|
||||||
|
|
||||||
/// Millau Hasher (Blake2-256 ++ Keccak-256) implementation.
|
|
||||||
#[derive(PartialEq, Eq, Clone, Copy, RuntimeDebug)]
|
|
||||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
||||||
pub struct BlakeTwoAndKeccak256;
|
|
||||||
|
|
||||||
impl sp_core::Hasher for BlakeTwoAndKeccak256 {
|
|
||||||
type Out = MillauHash;
|
|
||||||
type StdHasher = hash256_std_hasher::Hash256StdHasher;
|
|
||||||
const LENGTH: usize = 64;
|
|
||||||
|
|
||||||
fn hash(s: &[u8]) -> Self::Out {
|
|
||||||
let mut combined_hash = MillauHash::default();
|
|
||||||
combined_hash.as_mut()[..32].copy_from_slice(&sp_io::hashing::blake2_256(s));
|
|
||||||
combined_hash.as_mut()[32..].copy_from_slice(&sp_io::hashing::keccak_256(s));
|
|
||||||
combined_hash
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl sp_runtime::traits::Hash for BlakeTwoAndKeccak256 {
|
|
||||||
type Output = MillauHash;
|
|
||||||
|
|
||||||
fn trie_root(input: Vec<(Vec<u8>, Vec<u8>)>) -> Self::Output {
|
|
||||||
Layout::<BlakeTwoAndKeccak256>::trie_root(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ordered_trie_root(input: Vec<Vec<u8>>) -> Self::Output {
|
|
||||||
Layout::<BlakeTwoAndKeccak256>::ordered_trie_root(input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Maximum weight of single Millau block.
|
/// Maximum weight of single Millau block.
|
||||||
///
|
///
|
||||||
/// This represents 0.1 seconds of compute assuming a target block time of six seconds.
|
/// This represents 0.1 seconds of compute assuming a target block time of six seconds.
|
||||||
@@ -102,6 +73,19 @@ pub type Hasher = BlakeTwoAndKeccak256;
|
|||||||
/// The header type used by Millau.
|
/// The header type used by Millau.
|
||||||
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
||||||
|
|
||||||
|
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
||||||
|
pub type Signature = MultiSignature;
|
||||||
|
|
||||||
|
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
||||||
|
/// to the public key of our transaction signing scheme.
|
||||||
|
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
|
||||||
|
|
||||||
|
/// Public key of the chain account that may be used to verify signatures.
|
||||||
|
pub type AccountSigner = MultiSigner;
|
||||||
|
|
||||||
|
/// Balance of an account.
|
||||||
|
pub type Balance = u64;
|
||||||
|
|
||||||
/// Millau chain.
|
/// Millau chain.
|
||||||
#[derive(RuntimeDebug)]
|
#[derive(RuntimeDebug)]
|
||||||
pub struct Millau;
|
pub struct Millau;
|
||||||
@@ -113,6 +97,91 @@ impl Chain for Millau {
|
|||||||
type Header = Header;
|
type Header = Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Millau Hasher (Blake2-256 ++ Keccak-256) implementation.
|
||||||
|
#[derive(PartialEq, Eq, Clone, Copy, RuntimeDebug)]
|
||||||
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||||
|
pub struct BlakeTwoAndKeccak256;
|
||||||
|
|
||||||
|
impl sp_core::Hasher for BlakeTwoAndKeccak256 {
|
||||||
|
type Out = MillauHash;
|
||||||
|
type StdHasher = hash256_std_hasher::Hash256StdHasher;
|
||||||
|
const LENGTH: usize = 64;
|
||||||
|
|
||||||
|
fn hash(s: &[u8]) -> Self::Out {
|
||||||
|
let mut combined_hash = MillauHash::default();
|
||||||
|
combined_hash.as_mut()[..32].copy_from_slice(&sp_io::hashing::blake2_256(s));
|
||||||
|
combined_hash.as_mut()[32..].copy_from_slice(&sp_io::hashing::keccak_256(s));
|
||||||
|
combined_hash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_runtime::traits::Hash for BlakeTwoAndKeccak256 {
|
||||||
|
type Output = MillauHash;
|
||||||
|
|
||||||
|
fn trie_root(input: Vec<(Vec<u8>, Vec<u8>)>) -> Self::Output {
|
||||||
|
Layout::<BlakeTwoAndKeccak256>::trie_root(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ordered_trie_root(input: Vec<Vec<u8>>) -> Self::Output {
|
||||||
|
Layout::<BlakeTwoAndKeccak256>::ordered_trie_root(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a 256-bit hash into an AccountId.
|
||||||
|
pub struct AccountIdConverter;
|
||||||
|
|
||||||
|
impl sp_runtime::traits::Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
||||||
|
fn convert(hash: sp_core::H256) -> AccountId {
|
||||||
|
hash.to_fixed_bytes().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// We use this to get the account on Millau (target) which is derived from Rialto's (source)
|
||||||
|
/// account. We do this so we can fund the derived account on Millau at Genesis to it can pay
|
||||||
|
/// transaction fees.
|
||||||
|
///
|
||||||
|
/// The reason we can use the same `AccountId` type for both chains is because they share the same
|
||||||
|
/// development seed phrase.
|
||||||
|
///
|
||||||
|
/// Note that this should only be used for testing.
|
||||||
|
pub fn derive_account_from_rialto_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
|
||||||
|
let encoded_id = bp_runtime::derive_account_id(bp_runtime::RIALTO_BRIDGE_INSTANCE, id);
|
||||||
|
AccountIdConverter::convert(encoded_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
frame_support::parameter_types! {
|
||||||
|
pub BlockLength: limits::BlockLength =
|
||||||
|
limits::BlockLength::max_with_normal_ratio(2 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
|
||||||
|
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
|
||||||
|
// Allowance for Normal class
|
||||||
|
.for_class(DispatchClass::Normal, |weights| {
|
||||||
|
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||||
|
})
|
||||||
|
// Allowance for Operational class
|
||||||
|
.for_class(DispatchClass::Operational, |weights| {
|
||||||
|
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
|
||||||
|
// Extra reserved space for Operational class
|
||||||
|
weights.reserved = Some(MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||||
|
})
|
||||||
|
// By default Mandatory class is not limited at all.
|
||||||
|
// This parameter is used to derive maximal size of a single extrinsic.
|
||||||
|
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
|
||||||
|
.build_or_panic();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
|
||||||
|
pub fn max_extrinsic_weight() -> Weight {
|
||||||
|
BlockWeights::get()
|
||||||
|
.get(DispatchClass::Normal)
|
||||||
|
.max_extrinsic
|
||||||
|
.unwrap_or(Weight::MAX)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
|
||||||
|
pub fn max_extrinsic_size() -> u32 {
|
||||||
|
*BlockLength::get().max.get(DispatchClass::Normal)
|
||||||
|
}
|
||||||
|
|
||||||
/// Name of the `MillauHeaderApi::best_block` runtime method.
|
/// Name of the `MillauHeaderApi::best_block` runtime method.
|
||||||
pub const BEST_MILLAU_BLOCKS_METHOD: &str = "MillauHeaderApi_best_blocks";
|
pub const BEST_MILLAU_BLOCKS_METHOD: &str = "MillauHeaderApi_best_blocks";
|
||||||
/// Name of the `MillauHeaderApi::finalized_block` runtime method.
|
/// Name of the `MillauHeaderApi::finalized_block` runtime method.
|
||||||
@@ -136,78 +205,6 @@ pub const FROM_MILLAU_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromMillauInboundLa
|
|||||||
/// Name of the `FromMillauInboundLaneApi::unrewarded_relayers_state` runtime method.
|
/// Name of the `FromMillauInboundLaneApi::unrewarded_relayers_state` runtime method.
|
||||||
pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str = "FromMillauInboundLaneApi_unrewarded_relayers_state";
|
pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str = "FromMillauInboundLaneApi_unrewarded_relayers_state";
|
||||||
|
|
||||||
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
|
||||||
pub type Signature = MultiSignature;
|
|
||||||
|
|
||||||
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
|
||||||
/// to the public key of our transaction signing scheme.
|
|
||||||
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
|
|
||||||
|
|
||||||
/// Public key of the chain account that may be used to verify signatures.
|
|
||||||
pub type AccountSigner = MultiSigner;
|
|
||||||
|
|
||||||
/// Balance of an account.
|
|
||||||
pub type Balance = u64;
|
|
||||||
|
|
||||||
/// Convert a 256-bit hash into an AccountId.
|
|
||||||
pub struct AccountIdConverter;
|
|
||||||
|
|
||||||
impl sp_runtime::traits::Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
|
||||||
fn convert(hash: sp_core::H256) -> AccountId {
|
|
||||||
hash.to_fixed_bytes().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// We use this to get the account on Millau (target) which is derived from Rialto's (source)
|
|
||||||
/// account. We do this so we can fund the derived account on Millau at Genesis to it can pay
|
|
||||||
/// transaction fees.
|
|
||||||
///
|
|
||||||
/// The reason we can use the same `AccountId` type for both chains is because they share the same
|
|
||||||
/// development seed phrase.
|
|
||||||
///
|
|
||||||
/// Note that this should only be used for testing.
|
|
||||||
pub fn derive_account_from_rialto_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
|
|
||||||
let encoded_id = bp_runtime::derive_account_id(bp_runtime::RIALTO_BRIDGE_INSTANCE, id);
|
|
||||||
AccountIdConverter::convert(encoded_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a struct which defines the weight limits and values used during extrinsic execution.
|
|
||||||
pub fn runtime_block_weights() -> frame_system::limits::BlockWeights {
|
|
||||||
frame_system::limits::BlockWeights::builder()
|
|
||||||
// Allowance for Normal class
|
|
||||||
.for_class(DispatchClass::Normal, |weights| {
|
|
||||||
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
|
||||||
})
|
|
||||||
// Allowance for Operational class
|
|
||||||
.for_class(DispatchClass::Operational, |weights| {
|
|
||||||
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
|
|
||||||
// Extra reserved space for Operational class
|
|
||||||
weights.reserved = Some(MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
|
||||||
})
|
|
||||||
// By default Mandatory class is not limited at all.
|
|
||||||
// This parameter is used to derive maximal size of a single extrinsic.
|
|
||||||
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
|
|
||||||
.build_or_panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
|
|
||||||
pub fn max_extrinsic_weight() -> Weight {
|
|
||||||
runtime_block_weights()
|
|
||||||
.get(DispatchClass::Normal)
|
|
||||||
.max_extrinsic
|
|
||||||
.unwrap_or(Weight::MAX)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a struct which tracks the length in bytes for each extrinsic class in a Millau block.
|
|
||||||
pub fn runtime_block_length() -> frame_system::limits::BlockLength {
|
|
||||||
frame_system::limits::BlockLength::max_with_normal_ratio(2 * 1024 * 1024, NORMAL_DISPATCH_RATIO)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
|
|
||||||
pub fn max_extrinsic_size() -> u32 {
|
|
||||||
*runtime_block_length().max.get(DispatchClass::Normal)
|
|
||||||
}
|
|
||||||
|
|
||||||
sp_api::decl_runtime_apis! {
|
sp_api::decl_runtime_apis! {
|
||||||
/// API for querying information about Millau headers from the Bridge Pallet instance.
|
/// API for querying information about Millau headers from the Bridge Pallet instance.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ bp-runtime = { path = "../runtime", default-features = false }
|
|||||||
# Substrate Based Dependencies
|
# Substrate Based Dependencies
|
||||||
|
|
||||||
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
|
||||||
|
frame-system = { 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-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-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-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false }
|
||||||
@@ -27,6 +28,7 @@ std = [
|
|||||||
"bp-message-lane/std",
|
"bp-message-lane/std",
|
||||||
"bp-runtime/std",
|
"bp-runtime/std",
|
||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
|
"frame-system/std",
|
||||||
"sp-api/std",
|
"sp-api/std",
|
||||||
"sp-core/std",
|
"sp-core/std",
|
||||||
"sp-runtime/std",
|
"sp-runtime/std",
|
||||||
|
|||||||
@@ -31,6 +31,18 @@ use sp_runtime::{
|
|||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
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.
|
/// Block number type used in Polkadot.
|
||||||
pub type BlockNumber = u32;
|
pub type BlockNumber = u32;
|
||||||
|
|
||||||
@@ -75,6 +87,15 @@ impl Chain for Polkadot {
|
|||||||
type Header = Header;
|
type Header = Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a 256-bit hash into an AccountId.
|
||||||
|
pub struct AccountIdConverter;
|
||||||
|
|
||||||
|
impl sp_runtime::traits::Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
||||||
|
fn convert(hash: sp_core::H256) -> AccountId {
|
||||||
|
hash.to_fixed_bytes().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Name of the `PolkadotHeaderApi::best_blocks` runtime method.
|
/// Name of the `PolkadotHeaderApi::best_blocks` runtime method.
|
||||||
pub const BEST_POLKADOT_BLOCKS_METHOD: &str = "PolkadotHeaderApi_best_blocks";
|
pub const BEST_POLKADOT_BLOCKS_METHOD: &str = "PolkadotHeaderApi_best_blocks";
|
||||||
/// Name of the `PolkadotHeaderApi::finalized_block` runtime method.
|
/// Name of the `PolkadotHeaderApi::finalized_block` runtime method.
|
||||||
@@ -84,13 +105,6 @@ pub const IS_KNOWN_POLKADOT_BLOCK_METHOD: &str = "PolkadotHeaderApi_is_known_blo
|
|||||||
/// Name of the `PolkadotHeaderApi::incomplete_headers` runtime method.
|
/// Name of the `PolkadotHeaderApi::incomplete_headers` runtime method.
|
||||||
pub const INCOMPLETE_POLKADOT_HEADERS_METHOD: &str = "PolkadotHeaderApi_incomplete_headers";
|
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! {
|
sp_api::decl_runtime_apis! {
|
||||||
/// API for querying information about Polkadot headers from the Bridge Pallet instance.
|
/// API for querying information about Polkadot headers from the Bridge Pallet instance.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ use frame_support::{
|
|||||||
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, Weight},
|
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, Weight},
|
||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
|
use frame_system::limits;
|
||||||
use sp_core::Hasher as HasherT;
|
use sp_core::Hasher as HasherT;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{BlakeTwo256, Convert, IdentifyAccount, Verify},
|
traits::{BlakeTwo256, Convert, IdentifyAccount, Verify},
|
||||||
@@ -63,6 +64,19 @@ pub type Hasher = BlakeTwo256;
|
|||||||
/// The header type used by Rialto.
|
/// The header type used by Rialto.
|
||||||
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
pub type Header = sp_runtime::generic::Header<BlockNumber, Hasher>;
|
||||||
|
|
||||||
|
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
||||||
|
pub type Signature = MultiSignature;
|
||||||
|
|
||||||
|
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
||||||
|
/// to the public key of our transaction signing scheme.
|
||||||
|
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
|
||||||
|
|
||||||
|
/// Public key of the chain account that may be used to verify signatures.
|
||||||
|
pub type AccountSigner = MultiSigner;
|
||||||
|
|
||||||
|
/// Balance of an account.
|
||||||
|
pub type Balance = u128;
|
||||||
|
|
||||||
/// Rialto chain.
|
/// Rialto chain.
|
||||||
#[derive(RuntimeDebug)]
|
#[derive(RuntimeDebug)]
|
||||||
pub struct Rialto;
|
pub struct Rialto;
|
||||||
@@ -74,6 +88,61 @@ impl Chain for Rialto {
|
|||||||
type Header = Header;
|
type Header = Header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a 256-bit hash into an AccountId.
|
||||||
|
pub struct AccountIdConverter;
|
||||||
|
|
||||||
|
impl Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
||||||
|
fn convert(hash: sp_core::H256) -> AccountId {
|
||||||
|
hash.to_fixed_bytes().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We use this to get the account on Rialto (target) which is derived from Millau's (source)
|
||||||
|
// account. We do this so we can fund the derived account on Rialto at Genesis to it can pay
|
||||||
|
// transaction fees.
|
||||||
|
//
|
||||||
|
// The reason we can use the same `AccountId` type for both chains is because they share the same
|
||||||
|
// development seed phrase.
|
||||||
|
//
|
||||||
|
// Note that this should only be used for testing.
|
||||||
|
pub fn derive_account_from_millau_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
|
||||||
|
let encoded_id = bp_runtime::derive_account_id(bp_runtime::MILLAU_BRIDGE_INSTANCE, id);
|
||||||
|
AccountIdConverter::convert(encoded_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
frame_support::parameter_types! {
|
||||||
|
pub BlockLength: limits::BlockLength =
|
||||||
|
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
|
||||||
|
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
|
||||||
|
// Allowance for Normal class
|
||||||
|
.for_class(DispatchClass::Normal, |weights| {
|
||||||
|
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||||
|
})
|
||||||
|
// Allowance for Operational class
|
||||||
|
.for_class(DispatchClass::Operational, |weights| {
|
||||||
|
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
|
||||||
|
// Extra reserved space for Operational class
|
||||||
|
weights.reserved = Some(MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||||
|
})
|
||||||
|
// By default Mandatory class is not limited at all.
|
||||||
|
// This parameter is used to derive maximal size of a single extrinsic.
|
||||||
|
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
|
||||||
|
.build_or_panic();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
|
||||||
|
pub fn max_extrinsic_weight() -> Weight {
|
||||||
|
BlockWeights::get()
|
||||||
|
.get(DispatchClass::Normal)
|
||||||
|
.max_extrinsic
|
||||||
|
.unwrap_or(Weight::MAX)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
|
||||||
|
pub fn max_extrinsic_size() -> u32 {
|
||||||
|
*BlockLength::get().max.get(DispatchClass::Normal)
|
||||||
|
}
|
||||||
|
|
||||||
/// Name of the `RialtoHeaderApi::best_blocks` runtime method.
|
/// Name of the `RialtoHeaderApi::best_blocks` runtime method.
|
||||||
pub const BEST_RIALTO_BLOCKS_METHOD: &str = "RialtoHeaderApi_best_blocks";
|
pub const BEST_RIALTO_BLOCKS_METHOD: &str = "RialtoHeaderApi_best_blocks";
|
||||||
/// Name of the `RialtoHeaderApi::finalized_block` runtime method.
|
/// Name of the `RialtoHeaderApi::finalized_block` runtime method.
|
||||||
@@ -97,78 +166,6 @@ pub const FROM_RIALTO_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromRialtoInboundLa
|
|||||||
/// Name of the `FromRialtoInboundLaneApi::unrewarded_relayers_state` runtime method.
|
/// Name of the `FromRialtoInboundLaneApi::unrewarded_relayers_state` runtime method.
|
||||||
pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str = "FromRialtoInboundLaneApi_unrewarded_relayers_state";
|
pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str = "FromRialtoInboundLaneApi_unrewarded_relayers_state";
|
||||||
|
|
||||||
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
|
||||||
pub type Signature = MultiSignature;
|
|
||||||
|
|
||||||
/// Some way of identifying an account on the chain. We intentionally make it equivalent
|
|
||||||
/// to the public key of our transaction signing scheme.
|
|
||||||
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
|
|
||||||
|
|
||||||
/// Public key of the chain account that may be used to verify signatures.
|
|
||||||
pub type AccountSigner = MultiSigner;
|
|
||||||
|
|
||||||
/// Balance of an account.
|
|
||||||
pub type Balance = u128;
|
|
||||||
|
|
||||||
/// Convert a 256-bit hash into an AccountId.
|
|
||||||
pub struct AccountIdConverter;
|
|
||||||
|
|
||||||
impl Convert<sp_core::H256, AccountId> for AccountIdConverter {
|
|
||||||
fn convert(hash: sp_core::H256) -> AccountId {
|
|
||||||
hash.to_fixed_bytes().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We use this to get the account on Rialto (target) which is derived from Millau's (source)
|
|
||||||
// account. We do this so we can fund the derived account on Rialto at Genesis to it can pay
|
|
||||||
// transaction fees.
|
|
||||||
//
|
|
||||||
// The reason we can use the same `AccountId` type for both chains is because they share the same
|
|
||||||
// development seed phrase.
|
|
||||||
//
|
|
||||||
// Note that this should only be used for testing.
|
|
||||||
pub fn derive_account_from_millau_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
|
|
||||||
let encoded_id = bp_runtime::derive_account_id(bp_runtime::MILLAU_BRIDGE_INSTANCE, id);
|
|
||||||
AccountIdConverter::convert(encoded_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a struct which defines the weight limits and values used during extrinsic execution.
|
|
||||||
pub fn runtime_block_weights() -> frame_system::limits::BlockWeights {
|
|
||||||
frame_system::limits::BlockWeights::builder()
|
|
||||||
// Allowance for Normal class
|
|
||||||
.for_class(DispatchClass::Normal, |weights| {
|
|
||||||
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
|
||||||
})
|
|
||||||
// Allowance for Operational class
|
|
||||||
.for_class(DispatchClass::Operational, |weights| {
|
|
||||||
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
|
|
||||||
// Extra reserved space for Operational class
|
|
||||||
weights.reserved = Some(MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
|
||||||
})
|
|
||||||
// By default Mandatory class is not limited at all.
|
|
||||||
// This parameter is used to derive maximal size of a single extrinsic.
|
|
||||||
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
|
|
||||||
.build_or_panic()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
|
|
||||||
pub fn max_extrinsic_weight() -> Weight {
|
|
||||||
runtime_block_weights()
|
|
||||||
.get(DispatchClass::Normal)
|
|
||||||
.max_extrinsic
|
|
||||||
.unwrap_or(Weight::MAX)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a struct which tracks the length in bytes for each extrinsic class in a Millau block.
|
|
||||||
pub fn runtime_block_length() -> frame_system::limits::BlockLength {
|
|
||||||
frame_system::limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
|
|
||||||
pub fn max_extrinsic_size() -> u32 {
|
|
||||||
*runtime_block_length().max.get(DispatchClass::Normal)
|
|
||||||
}
|
|
||||||
|
|
||||||
sp_api::decl_runtime_apis! {
|
sp_api::decl_runtime_apis! {
|
||||||
/// API for querying information about Rialto headers from the Bridge Pallet instance.
|
/// API for querying information about Rialto headers from the Bridge Pallet instance.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user