diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index 24c379ffb2..982a58fd72 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -31,7 +31,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod rialto_messages; use codec::Decode; -use frame_system::limits; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -155,9 +154,6 @@ parameter_types! { read: 60_000_000, // ~0.06 ms = ~60 µ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 { @@ -199,9 +195,9 @@ impl frame_system::Config for Runtime { /// Weight information for the extrinsics of this pallet. type SystemWeightInfo = (); /// Block and extrinsics weights: base values and limits. - type BlockWeights = RuntimeBlockWeights; + type BlockWeights = bp_millau::BlockWeights; /// 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. type DbWeight = DbWeight; } diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index 89e9aea484..aeecebe3a2 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -37,7 +37,6 @@ pub mod millau_messages; pub mod rialto_poa; use codec::Decode; -use frame_system::limits; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -163,9 +162,6 @@ parameter_types! { read: 60_000_000, // ~0.06 ms = ~60 µ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 { @@ -207,9 +203,9 @@ impl frame_system::Config for Runtime { /// Weight information for the extrinsics of this pallet. type SystemWeightInfo = (); /// Block and extrinsics weights: base values and limits. - type BlockWeights = RuntimeBlockWeights; + type BlockWeights = bp_rialto::BlockWeights; /// 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. type DbWeight = DbWeight; } diff --git a/bridges/primitives/kusama/Cargo.toml b/bridges/primitives/kusama/Cargo.toml index 619a194712..1a4142f75a 100644 --- a/bridges/primitives/kusama/Cargo.toml +++ b/bridges/primitives/kusama/Cargo.toml @@ -16,6 +16,7 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies 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-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 } @@ -27,6 +28,7 @@ std = [ "bp-message-lane/std", "bp-runtime/std", "frame-support/std", + "frame-system/std", "sp-api/std", "sp-core/std", "sp-runtime/std", diff --git a/bridges/primitives/kusama/src/lib.rs b/bridges/primitives/kusama/src/lib.rs index e6d69a6539..9ec032dbd5 100644 --- a/bridges/primitives/kusama/src/lib.rs +++ b/bridges/primitives/kusama/src/lib.rs @@ -31,6 +31,18 @@ use sp_runtime::{ }; 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; @@ -75,6 +87,15 @@ impl Chain for Kusama { 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. @@ -84,13 +105,6 @@ 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. /// diff --git a/bridges/primitives/millau/src/lib.rs b/bridges/primitives/millau/src/lib.rs index c9e90501ff..38cbf37a4b 100644 --- a/bridges/primitives/millau/src/lib.rs +++ b/bridges/primitives/millau/src/lib.rs @@ -28,6 +28,7 @@ use frame_support::{ weights::{constants::WEIGHT_PER_MILLIS, DispatchClass, Weight}, RuntimeDebug, }; +use frame_system::limits; use sp_core::Hasher as HasherT; use sp_runtime::traits::Convert; use sp_runtime::{ @@ -42,36 +43,6 @@ use serde::{Deserialize, Serialize}; 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, Vec)>) -> Self::Output { - Layout::::trie_root(input) - } - - fn ordered_trie_root(input: Vec>) -> Self::Output { - Layout::::ordered_trie_root(input) - } -} - /// Maximum weight of single Millau block. /// /// 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. pub type Header = sp_runtime::generic::Header; +/// 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 = <::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. #[derive(RuntimeDebug)] pub struct Millau; @@ -113,6 +97,91 @@ impl Chain for Millau { 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, Vec)>) -> Self::Output { + Layout::::trie_root(input) + } + + fn ordered_trie_root(input: Vec>) -> Self::Output { + Layout::::ordered_trie_root(input) + } +} + +/// 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() + } +} + +/// 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 { + 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. pub const BEST_MILLAU_BLOCKS_METHOD: &str = "MillauHeaderApi_best_blocks"; /// 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. 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 = <::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 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 { - 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! { /// API for querying information about Millau headers from the Bridge Pallet instance. /// diff --git a/bridges/primitives/polkadot/Cargo.toml b/bridges/primitives/polkadot/Cargo.toml index 6f79e6bd1b..396cbd5b47 100644 --- a/bridges/primitives/polkadot/Cargo.toml +++ b/bridges/primitives/polkadot/Cargo.toml @@ -16,6 +16,7 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies 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-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 } @@ -27,6 +28,7 @@ std = [ "bp-message-lane/std", "bp-runtime/std", "frame-support/std", + "frame-system/std", "sp-api/std", "sp-core/std", "sp-runtime/std", diff --git a/bridges/primitives/polkadot/src/lib.rs b/bridges/primitives/polkadot/src/lib.rs index 83cb7db41c..a82dd5075b 100644 --- a/bridges/primitives/polkadot/src/lib.rs +++ b/bridges/primitives/polkadot/src/lib.rs @@ -31,6 +31,18 @@ use sp_runtime::{ }; 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; @@ -75,6 +87,15 @@ impl Chain for Polkadot { 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. @@ -84,13 +105,6 @@ pub const IS_KNOWN_POLKADOT_BLOCK_METHOD: &str = "PolkadotHeaderApi_is_known_blo /// 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. /// diff --git a/bridges/primitives/rialto/src/lib.rs b/bridges/primitives/rialto/src/lib.rs index fffa556f72..2b293d70f9 100644 --- a/bridges/primitives/rialto/src/lib.rs +++ b/bridges/primitives/rialto/src/lib.rs @@ -26,6 +26,7 @@ use frame_support::{ weights::{constants::WEIGHT_PER_SECOND, DispatchClass, Weight}, RuntimeDebug, }; +use frame_system::limits; use sp_core::Hasher as HasherT; use sp_runtime::{ traits::{BlakeTwo256, Convert, IdentifyAccount, Verify}, @@ -63,6 +64,19 @@ pub type Hasher = BlakeTwo256; /// The header type used by Rialto. pub type Header = sp_runtime::generic::Header; +/// 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 = <::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. #[derive(RuntimeDebug)] pub struct Rialto; @@ -74,6 +88,61 @@ impl Chain for Rialto { 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() + } +} + +// 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 { + 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. pub const BEST_RIALTO_BLOCKS_METHOD: &str = "RialtoHeaderApi_best_blocks"; /// 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. 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 = <::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 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 { - 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! { /// API for querying information about Rialto headers from the Bridge Pallet instance. ///