From 2e806ef640ca493c55c7758a4152f58988825944 Mon Sep 17 00:00:00 2001 From: fewensa Date: Wed, 29 Jun 2022 11:31:59 +0800 Subject: [PATCH] Code clean --- bin/runtime-common/src/lib.rs | 1 - bin/runtime-common/src/messages_api.rs | 51 -------- primitives/chain-crab-parachain/src/lib.rs | 90 ------------- primitives/chain-crab/src/lib.rs | 92 -------------- primitives/chain-darwinia/src/lib.rs | 93 -------------- primitives/chain-kusama/src/lib.rs | 115 ----------------- .../chain-pangolin-parachain/src/lib.rs | 59 --------- primitives/chain-pangolin/src/lib.rs | 58 --------- primitives/chain-pangoro/src/lib.rs | 58 --------- primitives/chain-polkadot/src/lib.rs | 119 +----------------- primitives/chain-rococo/src/lib.rs | 111 ---------------- 11 files changed, 2 insertions(+), 845 deletions(-) delete mode 100644 bin/runtime-common/src/messages_api.rs diff --git a/bin/runtime-common/src/lib.rs b/bin/runtime-common/src/lib.rs index c7fb98aba..dd2fa8c2d 100644 --- a/bin/runtime-common/src/lib.rs +++ b/bin/runtime-common/src/lib.rs @@ -19,7 +19,6 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod messages; -pub mod messages_api; pub mod messages_benchmarking; #[cfg(feature = "integrity-test")] diff --git a/bin/runtime-common/src/messages_api.rs b/bin/runtime-common/src/messages_api.rs deleted file mode 100644 index b09a88e62..000000000 --- a/bin/runtime-common/src/messages_api.rs +++ /dev/null @@ -1,51 +0,0 @@ -// 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 . - -//! Helpers for implementing various message-related runtime API mthods. - -use crate::messages::{source::FromThisChainMessagePayload, MessageBridge}; - -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use codec::Decode; -use sp_std::vec::Vec; - -/// Implementation of the `To*OutboundLaneApi::message_details`. -pub fn outbound_message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, -) -> Vec> -where - Runtime: pallet_bridge_messages::Config, - MessagesPalletInstance: 'static, - BridgeConfig: MessageBridge, -{ - (begin..=end) - .filter_map(|nonce| { - let message_data = - pallet_bridge_messages::Pallet::::outbound_message_data(lane, nonce)?; - let decoded_payload = - FromThisChainMessagePayload::::decode(&mut &message_data.payload[..]).ok()?; - Some(MessageDetails { - nonce, - dispatch_weight: decoded_payload.weight, - size: message_data.payload.len() as _, - delivery_and_dispatch_fee: message_data.fee, - dispatch_fee_payment: decoded_payload.dispatch_fee_payment, - }) - }) - .collect() -} diff --git a/primitives/chain-crab-parachain/src/lib.rs b/primitives/chain-crab-parachain/src/lib.rs index f2c7b2fa0..2d4705058 100644 --- a/primitives/chain-crab-parachain/src/lib.rs +++ b/primitives/chain-crab-parachain/src/lib.rs @@ -21,19 +21,6 @@ mod copy_paste_from_darwinia { // --- darwinia-network --- use bp_darwinia_core::*; - // --- paritytech --- - use sp_version::RuntimeVersion; - - pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_runtime::create_runtime_str!("Crab Parachain"), - impl_name: sp_runtime::create_runtime_str!("Darwinia Crab Parachain"), - authoring_version: 1, - spec_version: 4, - impl_version: 1, - apis: sp_version::create_apis_vec![[]], - transaction_version: 1, - state_version: 0, - }; pub const EXISTENTIAL_DEPOSIT: Balance = 0; } @@ -41,82 +28,5 @@ pub use copy_paste_from_darwinia::*; pub use bp_darwinia_core::*; -// --- paritytech --- -use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; -use frame_support::Parameter; -use sp_std::prelude::*; - /// CrabParachain Chain. pub type CrabParachain = DarwiniaLike; - -/// Name of the With-CrabParachain messages pallet instance that is deployed at bridged chains. -pub const WITH_CRAB_PARACHAIN_MESSAGES_PALLET_NAME: &str = "BridgeCrabParachainMessages"; - -/// Name of the `CrabParachainFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_CRAB_PARACHAIN_HEADER_METHOD: &str = - "CrabParachainFinalityApi_best_finalized"; - -/// Name of the `ToCrabParachainOutboundLaneApi::message_details` runtime method. -pub const TO_CRAB_PARACHAIN_MESSAGE_DETAILS_METHOD: &str = - "ToCrabParachainOutboundLaneApi_message_details"; -/// Name of the `ToCrabParachainOutboundLaneApi::latest_received_nonce` runtime method. -pub const TO_CRAB_PARACHAIN_LATEST_RECEIVED_NONCE_METHOD: &str = - "ToCrabParachainOutboundLaneApi_latest_received_nonce"; -/// Name of the `ToCrabParachainOutboundLaneApi::latest_generated_nonce` runtime method. -pub const TO_CRAB_PARACHAIN_LATEST_GENERATED_NONCE_METHOD: &str = - "ToCrabParachainOutboundLaneApi_latest_generated_nonce"; - -/// Name of the `FromCrabParachainInboundLaneApi::latest_received_nonce` runtime method. -pub const FROM_CRAB_PARACHAIN_LATEST_RECEIVED_NONCE_METHOD: &str = - "FromCrabParachainInboundLaneApi_latest_received_nonce"; -/// Name of the `FromCrabParachainInboundLaneApi::latest_onfirmed_nonce` runtime method. -pub const FROM_CRAB_PARACHAIN_LATEST_CONFIRMED_NONCE_METHOD: &str = - "FromCrabParachainInboundLaneApi_latest_confirmed_nonce"; -/// Name of the `FromCrabParachainInboundLaneApi::unrewarded_relayers_state` runtime method. -pub const FROM_CRAB_PARACHAIN_UNREWARDED_RELAYERS_STATE: &str = - "FromCrabParachainInboundLaneApi_unrewarded_relayers_state"; - -sp_api::decl_runtime_apis! { - /// API for querying information about the finalized CrabParachain headers. - /// - /// This API is implemented by runtimes that are bridging with the CrabParachain chain, not the - /// CrabParachain runtime itself. - pub trait CrabParachainFinalityApi { - /// Returns number and hash of the best finalized header known to the bridge module. - fn best_finalized() -> (BlockNumber, Hash); - } - - /// Outbound message lane API for messages that are sent to CrabParachain chain. - /// - /// This API is implemented by runtimes that are sending messages to CrabParachain chain, not the - /// CrabParachain runtime itself. - pub trait ToCrabParachainOutboundLaneApi { - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - /// 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 CrabParachain chain. - /// - /// This API is implemented by runtimes that are receiving messages from CrabParachain chain, not the - /// CrabParachain runtime itself. - pub trait FromCrabParachainInboundLaneApi { - /// Returns nonce of the latest message, received by given lane. - fn latest_received_nonce(lane: LaneId) -> MessageNonce; - /// Nonce of latest message that has been confirmed to the bridged chain. - fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce; - /// State of the unrewarded relayers set at given lane. - fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; - } -} diff --git a/primitives/chain-crab/src/lib.rs b/primitives/chain-crab/src/lib.rs index 1b503cf7a..c575a3964 100644 --- a/primitives/chain-crab/src/lib.rs +++ b/primitives/chain-crab/src/lib.rs @@ -21,19 +21,6 @@ mod copy_paste_from_darwinia { // --- darwinia-network --- use bp_darwinia_core::*; - // --- paritytech --- - use sp_version::RuntimeVersion; - - pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_runtime::create_runtime_str!("Crab"), - impl_name: sp_runtime::create_runtime_str!("Darwinia Crab"), - authoring_version: 0, - spec_version: 12_0_0, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 0, - state_version: 0, - }; pub const EXISTENTIAL_DEPOSIT: Balance = 0; @@ -43,84 +30,5 @@ pub use copy_paste_from_darwinia::*; pub use bp_darwinia_core::*; -// --- paritytech --- -use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; -use frame_support::Parameter; -use sp_std::prelude::*; - /// Crab Chain. pub type Crab = DarwiniaLike; - -/// Name of the With-Crab GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_CRAB_GRANDPA_PALLET_NAME: &str = "BridgeCrabGrandpa"; -/// Name of the With-Crab messages pallet instance that is deployed at bridged chains. -pub const WITH_CRAB_MESSAGES_PALLET_NAME: &str = "BridgeCrabMessages"; -/// Name of the With-Crab parachains bridge pallet name in the Crab runtime. -pub const BRIDGE_PARAS_PALLET_NAME: &str = "BridgeCrabParachains"; - -/// Name of the `CrabFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_CRAB_HEADER_METHOD: &str = "CrabFinalityApi_best_finalized"; - -/// Name of the `ToCrabOutboundLaneApi::message_details` runtime method. -pub const TO_CRAB_MESSAGE_DETAILS_METHOD: &str = "ToCrabOutboundLaneApi_message_details"; -/// Name of the `ToCrabOutboundLaneApi::latest_received_nonce` runtime method. -pub const TO_CRAB_LATEST_RECEIVED_NONCE_METHOD: &str = - "ToCrabOutboundLaneApi_latest_received_nonce"; -/// Name of the `ToCrabOutboundLaneApi::latest_generated_nonce` runtime method. -pub const TO_CRAB_LATEST_GENERATED_NONCE_METHOD: &str = - "ToCrabOutboundLaneApi_latest_generated_nonce"; - -/// Name of the `FromCrabInboundLaneApi::latest_received_nonce` runtime method. -pub const FROM_CRAB_LATEST_RECEIVED_NONCE_METHOD: &str = - "FromCrabInboundLaneApi_latest_received_nonce"; -/// Name of the `FromCrabInboundLaneApi::latest_cnfirmed_nonce` runtime method. -pub const FROM_CRAB_LATEST_CONFIRMED_NONCE_METHOD: &str = - "FromCrabInboundLaneApi_latest_confirmed_nonce"; -/// Name of the `FromCrabInboundLaneApi::unrewarded_relayers_state` runtime method. -pub const FROM_CRAB_UNREWARDED_RELAYERS_STATE: &str = - "FromCrabInboundLaneApi_unrewarded_relayers_state"; - -sp_api::decl_runtime_apis! { - /// API for querying information about the finalized Crab headers. - /// - /// This API is implemented by runtimes that are bridging with the Crab chain, not the - /// Crab runtime itself. - pub trait CrabFinalityApi { - /// Returns number and hash of the best finalized header known to the bridge module. - fn best_finalized() -> (BlockNumber, Hash); - } - - /// Outbound message lane API for messages that are sent to Crab chain. - /// - /// This API is implemented by runtimes that are sending messages to Crab chain, not the - /// Crab runtime itself. - pub trait ToCrabOutboundLaneApi { - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - /// 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 Crab chain. - /// - /// This API is implemented by runtimes that are receiving messages from Crab chain, not the - /// Crab runtime itself. - pub trait FromCrabInboundLaneApi { - /// Returns nonce of the latest message, received by given lane. - fn latest_received_nonce(lane: LaneId) -> MessageNonce; - /// Nonce of latest message that has been confirmed to the bridged chain. - fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce; - /// State of the unrewarded relayers set at given lane. - fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; - } -} diff --git a/primitives/chain-darwinia/src/lib.rs b/primitives/chain-darwinia/src/lib.rs index 1265c8604..2ce266556 100644 --- a/primitives/chain-darwinia/src/lib.rs +++ b/primitives/chain-darwinia/src/lib.rs @@ -21,20 +21,6 @@ mod copy_paste_from_darwinia { // --- darwinia-network --- use bp_darwinia_core::*; - // --- paritytech --- - use sp_version::RuntimeVersion; - - pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_runtime::create_runtime_str!("Darwinia"), - impl_name: sp_runtime::create_runtime_str!("Darwinia"), - authoring_version: 0, - #[allow(clippy::inconsistent_digit_grouping)] - spec_version: 12_0_0, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 0, - state_version: 0, - }; pub const EXISTENTIAL_DEPOSIT: Balance = 100 * MICRO; @@ -44,84 +30,5 @@ pub use copy_paste_from_darwinia::*; pub use bp_darwinia_core::*; -// --- paritytech --- -use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; -use frame_support::Parameter; -use sp_std::prelude::*; - /// Darwinia Chain. pub type Darwinia = DarwiniaLike; - -/// Name of the With-Darwinia GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_DARWINIA_GRANDPA_PALLET_NAME: &str = "BridgeDarwiniaGrandpa"; -/// Name of the With-Darwinia messages pallet instance that is deployed at bridged chains. -pub const WITH_DARWINIA_MESSAGES_PALLET_NAME: &str = "BridgeDarwiniaMessages"; -/// Name of the With-Darwinia parachains bridge pallet name in the Darwinia runtime. -pub const BRIDGE_PARAS_PALLET_NAME: &str = "BridgeDarwiniaParachains"; - -/// Name of the `DarwiniaFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_DARWINIA_HEADER_METHOD: &str = "DarwiniaFinalityApi_best_finalized"; - -/// Name of the `ToDarwiniaOutboundLaneApi::message_details` runtime method. -pub const TO_DARWINIA_MESSAGE_DETAILS_METHOD: &str = "ToDarwiniaOutboundLaneApi_message_details"; -/// Name of the `ToDarwiniaOutboundLaneApi::latest_received_nonce` runtime method. -pub const TO_DARWINIA_LATEST_RECEIVED_NONCE_METHOD: &str = - "ToDarwiniaOutboundLaneApi_latest_received_nonce"; -/// Name of the `ToDarwiniaOutboundLaneApi::latest_generated_nonce` runtime method. -pub const TO_DARWINIA_LATEST_GENERATED_NONCE_METHOD: &str = - "ToDarwiniaOutboundLaneApi_latest_generated_nonce"; - -/// Name of the `FromDarwiniaInboundLaneApi::latest_received_nonce` runtime method. -pub const FROM_DARWINIA_LATEST_RECEIVED_NONCE_METHOD: &str = - "FromDarwiniaInboundLaneApi_latest_received_nonce"; -/// Name of the `FromDarwiniaInboundLaneApi::latest_cnfirmed_nonce` runtime method. -pub const FROM_DARWINIA_LATEST_CONFIRMED_NONCE_METHOD: &str = - "FromDarwiniaInboundLaneApi_latest_confirmed_nonce"; -/// Name of the `FromDarwiniaInboundLaneApi::unrewarded_relayers_state` runtime method. -pub const FROM_DARWINIA_UNREWARDED_RELAYERS_STATE: &str = - "FromDarwiniaInboundLaneApi_unrewarded_relayers_state"; - -sp_api::decl_runtime_apis! { - /// API for querying information about the finalized Darwinia headers. - /// - /// This API is implemented by runtimes that are bridging with the Darwinia chain, not the - /// Darwinia runtime itself. - pub trait DarwiniaFinalityApi { - /// Returns number and hash of the best finalized header known to the bridge module. - fn best_finalized() -> (BlockNumber, Hash); - } - - /// Outbound message lane API for messages that are sent to Darwinia chain. - /// - /// This API is implemented by runtimes that are sending messages to Darwinia chain, not the - /// Darwinia runtime itself. - pub trait ToDarwiniaOutboundLaneApi { - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - /// 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 Darwinia chain. - /// - /// This API is implemented by runtimes that are receiving messages from Darwinia chain, not the - /// Darwinia runtime itself. - pub trait FromDarwiniaInboundLaneApi { - /// Returns nonce of the latest message, received by given lane. - fn latest_received_nonce(lane: LaneId) -> MessageNonce; - /// Nonce of latest message that has been confirmed to the bridged chain. - fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce; - /// State of the unrewarded relayers set at given lane. - fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; - } -} diff --git a/primitives/chain-kusama/src/lib.rs b/primitives/chain-kusama/src/lib.rs index d362fd164..e22c7fcea 100644 --- a/primitives/chain-kusama/src/lib.rs +++ b/primitives/chain-kusama/src/lib.rs @@ -18,60 +18,11 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use frame_support::weights::{ - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; - pub use bp_polkadot_core::*; /// Kusama Chain pub type Kusama = PolkadotLike; -// NOTE: This needs to be kept up to date with the Kusama runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("kusama"), - impl_name: sp_version::create_runtime_str!("parity-kusama"), - authoring_version: 2, - spec_version: 9180, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 11, - state_version: 0, -}; - -// NOTE: This needs to be kept up to date with the Kusama runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 1_000_000_000_000 / 30_000; - // in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - -// 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_CHAIN_ID, id); - AccountIdConverter::convert(encoded_id) -} - -/// Per-byte fee for Kusama transactions. -pub const TRANSACTION_BYTE_FEE: Balance = 10 * 1_000_000_000_000 / 30_000 / 1_000; - /// Existential deposit on Kusama. pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 30_000; @@ -81,69 +32,3 @@ pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 30_000; /// Note that since this is a target sessions may change before/after this time depending on network /// conditions. pub const SESSION_LENGTH: BlockNumber = time_units::HOURS; - -/// Name of the With-Kusama GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_KUSAMA_GRANDPA_PALLET_NAME: &str = "BridgeKusamaGrandpa"; -/// Name of the With-Kusama messages pallet instance that is deployed at bridged chains. -pub const WITH_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessages"; - -/// Name of the transaction payment pallet at the Kusama runtime. -pub const TRANSACTION_PAYMENT_PALLET_NAME: &str = "TransactionPayment"; - -/// Name of the DOT->KSM conversion rate stored in the Kusama runtime. -pub const POLKADOT_TO_KUSAMA_CONVERSION_RATE_PARAMETER_NAME: &str = - "PolkadotToKusamaConversionRate"; -/// Name of the Polkadot fee multiplier parameter, stored in the Polkadot runtime. -pub const POLKADOT_FEE_MULTIPLIER_PARAMETER_NAME: &str = "PolkadotFeeMultiplier"; - -/// Name of the `KusamaFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_KUSAMA_HEADER_METHOD: &str = "KusamaFinalityApi_best_finalized"; - -/// 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::message_details` runtime method. -pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details"; - -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); - } - - /// 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 the 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, - kusama_to_this_conversion_rate: Option, - ) -> Option; - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - } -} diff --git a/primitives/chain-pangolin-parachain/src/lib.rs b/primitives/chain-pangolin-parachain/src/lib.rs index ec8b61017..5a9e6eca5 100644 --- a/primitives/chain-pangolin-parachain/src/lib.rs +++ b/primitives/chain-pangolin-parachain/src/lib.rs @@ -21,19 +21,6 @@ mod copy_paste_from_darwinia { // --- darwinia-network --- use bp_darwinia_core::*; - // --- paritytech --- - use sp_version::RuntimeVersion; - - pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_runtime::create_runtime_str!("Pangolin Parachain"), - impl_name: sp_runtime::create_runtime_str!("Pangolin Parachain"), - authoring_version: 1, - spec_version: 3, - impl_version: 1, - apis: sp_version::create_apis_vec![[]], - transaction_version: 1, - state_version: 0, - }; pub const EXISTENTIAL_DEPOSIT: Balance = 0; } @@ -41,51 +28,5 @@ pub use copy_paste_from_darwinia::*; pub use bp_darwinia_core::*; -// --- paritytech --- -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use frame_support::Parameter; -use sp_std::prelude::*; - /// PangolinParachain Chain. pub type PangolinParachain = DarwiniaLike; - -/// Name of the With-PangolinParachain GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_PANGOLIN_PARACHAIN_GRANDPA_PALLET_NAME: &str = "BridgePangolinParachainGrandpa"; -/// Name of the With-PangolinParachain messages pallet instance that is deployed at bridged chains. -pub const WITH_PANGOLIN_PARACHAIN_MESSAGES_PALLET_NAME: &str = "BridgePangolinParachainMessages"; - -/// Name of the `PangolinParachainFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_PANGOLIN_PARACHAIN_HEADER_METHOD: &str = - "PangolinParachainFinalityApi_best_finalized"; - -/// Name of the `ToPangolinParachainOutboundLaneApi::message_details` runtime method. -pub const TO_PANGOLIN_PARACHAIN_MESSAGE_DETAILS_METHOD: &str = - "ToPangolinParachainOutboundLaneApi_message_details"; - -sp_api::decl_runtime_apis! { - /// API for querying information about the finalized PangolinParachain headers. - /// - /// This API is implemented by runtimes that are bridging with the PangolinParachain chain, not the - /// PangolinParachain runtime itself. - pub trait PangolinParachainFinalityApi { - /// Returns number and hash of the best finalized header known to the bridge module. - fn best_finalized() -> (BlockNumber, Hash); - } - - /// Outbound message lane API for messages that are sent to PangolinParachain chain. - /// - /// This API is implemented by runtimes that are sending messages to PangolinParachain chain, not the - /// PangolinParachain runtime itself. - pub trait ToPangolinParachainOutboundLaneApi { - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - } -} diff --git a/primitives/chain-pangolin/src/lib.rs b/primitives/chain-pangolin/src/lib.rs index a1f1b2cd9..0acb5aa46 100644 --- a/primitives/chain-pangolin/src/lib.rs +++ b/primitives/chain-pangolin/src/lib.rs @@ -21,20 +21,6 @@ mod copy_paste_from_darwinia { // --- darwinia-network --- use bp_darwinia_core::*; - // --- paritytech --- - use sp_version::RuntimeVersion; - - pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_runtime::create_runtime_str!("Pangolin"), - impl_name: sp_runtime::create_runtime_str!("Pangolin"), - authoring_version: 0, - #[allow(clippy::inconsistent_digit_grouping)] - spec_version: 2_8_06_0, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 0, - state_version: 0, - }; pub const EXISTENTIAL_DEPOSIT: Balance = 0; @@ -44,49 +30,5 @@ pub use copy_paste_from_darwinia::*; pub use bp_darwinia_core::*; -// --- paritytech --- -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use frame_support::Parameter; -use sp_std::prelude::*; - /// Pangolin Chain. pub type Pangolin = DarwiniaLike; - -/// Name of the With-Pangolin GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_PANGOLIN_GRANDPA_PALLET_NAME: &str = "BridgePangolinGrandpa"; -/// Name of the With-Pangolin messages pallet instance that is deployed at bridged chains. -pub const WITH_PANGOLIN_MESSAGES_PALLET_NAME: &str = "BridgePangolinMessages"; - -/// Name of the `PangolinFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_PANGOLIN_HEADER_METHOD: &str = "PangolinFinalityApi_best_finalized"; - -/// Name of the `ToPangolinOutboundLaneApi::message_details` runtime method. -pub const TO_PANGOLIN_MESSAGE_DETAILS_METHOD: &str = "ToPangolinOutboundLaneApi_message_details"; - -sp_api::decl_runtime_apis! { - /// API for querying information about the finalized Pangolin headers. - /// - /// This API is implemented by runtimes that are bridging with the Pangolin chain, not the - /// Pangolin runtime itself. - pub trait PangolinFinalityApi { - /// Returns number and hash of the best finalized header known to the bridge module. - fn best_finalized() -> (BlockNumber, Hash); - } - - /// Outbound message lane API for messages that are sent to Pangolin chain. - /// - /// This API is implemented by runtimes that are sending messages to Pangolin chain, not the - /// Pangolin runtime itself. - pub trait ToPangolinOutboundLaneApi { - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - } -} diff --git a/primitives/chain-pangoro/src/lib.rs b/primitives/chain-pangoro/src/lib.rs index a14ee3473..d8880f215 100644 --- a/primitives/chain-pangoro/src/lib.rs +++ b/primitives/chain-pangoro/src/lib.rs @@ -21,20 +21,6 @@ mod copy_paste_from_darwinia { // --- darwinia-network --- use bp_darwinia_core::*; - // --- paritytech --- - use sp_version::RuntimeVersion; - - pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_runtime::create_runtime_str!("Pangoro"), - impl_name: sp_runtime::create_runtime_str!("Pangoro"), - authoring_version: 0, - #[allow(clippy::inconsistent_digit_grouping)] - spec_version: 2_8_06_0, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 0, - state_version: 0, - }; pub const EXISTENTIAL_DEPOSIT: Balance = 0; @@ -44,49 +30,5 @@ pub use copy_paste_from_darwinia::*; pub use bp_darwinia_core::*; -// --- paritytech --- -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use frame_support::Parameter; -use sp_std::prelude::*; - /// Pangoro Chain. pub type Pangoro = DarwiniaLike; - -/// Name of the With-Pangoro GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_PANGORO_GRANDPA_PALLET_NAME: &str = "BridgePangoroGrandpa"; -/// Name of the With-Pangoro messages pallet instance that is deployed at bridged chains. -pub const WITH_PANGORO_MESSAGES_PALLET_NAME: &str = "BridgePangoroMessages"; - -/// Name of the `PangoroFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_PANGORO_HEADER_METHOD: &str = "PangoroFinalityApi_best_finalized"; - -/// Name of the `ToPangoroOutboundLaneApi::message_details` runtime method. -pub const TO_PANGORO_MESSAGE_DETAILS_METHOD: &str = "ToPangoroOutboundLaneApi_message_details"; - -sp_api::decl_runtime_apis! { - /// API for querying information about the finalized Pangoro headers. - /// - /// This API is implemented by runtimes that are bridging with the Pangoro chain, not the - /// Pangoro runtime itself. - pub trait PangoroFinalityApi { - /// Returns number and hash of the best finalized header known to the bridge module. - fn best_finalized() -> (BlockNumber, Hash); - } - - /// Outbound message lane API for messages that are sent to Pangoro chain. - /// - /// This API is implemented by runtimes that are sending messages to Pangoro chain, not the - /// Pangoro runtime itself. - pub trait ToPangoroOutboundLaneApi { - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - } -} diff --git a/primitives/chain-polkadot/src/lib.rs b/primitives/chain-polkadot/src/lib.rs index 7194eb090..bb12047c1 100644 --- a/primitives/chain-polkadot/src/lib.rs +++ b/primitives/chain-polkadot/src/lib.rs @@ -18,63 +18,11 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use frame_support::weights::{ - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; - pub use bp_polkadot_core::*; /// Polkadot Chain pub type Polkadot = PolkadotLike; -// NOTE: This needs to be kept up to date with the Polkadot runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("polkadot"), - impl_name: sp_version::create_runtime_str!("parity-polkadot"), - authoring_version: 0, - spec_version: 9180, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 12, - state_version: 0, -}; - -// NOTE: This needs to be kept up to date with the Polkadot runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 10_000_000_000 / 100; - // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - -// 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_CHAIN_ID, id); - AccountIdConverter::convert(encoded_id) -} - -/// Per-byte fee for Polkadot transactions. -pub const TRANSACTION_BYTE_FEE: Balance = 10 * 10_000_000_000 / 100 / 1_000; - -/// Existential deposit on Polkadot. -pub const EXISTENTIAL_DEPOSIT: Balance = 10_000_000_000; - /// The target length of a session (how often authorities change) on Polkadot measured in of number /// of blocks. /// @@ -82,68 +30,5 @@ pub const EXISTENTIAL_DEPOSIT: Balance = 10_000_000_000; /// conditions. pub const SESSION_LENGTH: BlockNumber = 4 * time_units::HOURS; -/// Name of the With-Polkadot GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_POLKADOT_GRANDPA_PALLET_NAME: &str = "BridgePolkadotGrandpa"; -/// Name of the With-Polkadot messages pallet instance that is deployed at bridged chains. -pub const WITH_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotMessages"; - -/// Name of the transaction payment pallet at the Polkadot runtime. -pub const TRANSACTION_PAYMENT_PALLET_NAME: &str = "TransactionPayment"; - -/// Name of the KSM->DOT conversion rate parameter, stored in the Polkadot runtime. -pub const KUSAMA_TO_POLKADOT_CONVERSION_RATE_PARAMETER_NAME: &str = - "KusamaToPolkadotConversionRate"; -/// Name of the Kusama fee multiplier parameter, stored in the Polkadot runtime. -pub const KUSAMA_FEE_MULTIPLIER_PARAMETER_NAME: &str = "KusamaFeeMultiplier"; - -/// Name of the `PolkadotFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_POLKADOT_HEADER_METHOD: &str = "PolkadotFinalityApi_best_finalized"; - -/// 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::message_details` runtime method. -pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details"; - -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); - } - - /// 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 the 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, - polkadot_to_this_conversion_rate: Option, - ) -> Option; - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - } -} +/// Existential deposit on Polkadot. +pub const EXISTENTIAL_DEPOSIT: Balance = 10_000_000_000; diff --git a/primitives/chain-rococo/src/lib.rs b/primitives/chain-rococo/src/lib.rs index a4108443b..c75f54d15 100644 --- a/primitives/chain-rococo/src/lib.rs +++ b/primitives/chain-rococo/src/lib.rs @@ -18,14 +18,6 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use bp_messages::{LaneId, MessageDetails, MessageNonce}; -use frame_support::weights::{ - Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, -}; -use sp_runtime::FixedU128; -use sp_std::prelude::*; -use sp_version::RuntimeVersion; - pub use bp_polkadot_core::*; /// Rococo Chain @@ -38,108 +30,5 @@ pub type Rococo = PolkadotLike; /// conditions. pub const SESSION_LENGTH: BlockNumber = time_units::HOURS; -// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo. -pub const VERSION: RuntimeVersion = RuntimeVersion { - spec_name: sp_version::create_runtime_str!("rococo"), - impl_name: sp_version::create_runtime_str!("parity-rococo-v2.0"), - authoring_version: 0, - spec_version: 9180, - impl_version: 0, - apis: sp_version::create_apis_vec![[]], - transaction_version: 0, - state_version: 0, -}; - -// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - - fn polynomial() -> WeightToFeeCoefficients { - const CENTS: Balance = 1_000_000_000_000 / 100; - let p = CENTS; - let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); - smallvec::smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - -// We use this to get the account on Rococo (target) which is derived from Wococo's (source) -// account. -pub fn derive_account_from_wococo_id(id: bp_runtime::SourceAccount) -> AccountId { - let encoded_id = bp_runtime::derive_account_id(bp_runtime::WOCOCO_CHAIN_ID, id); - AccountIdConverter::convert(encoded_id) -} - -/// Name of the With-Rococo GRANDPA pallet instance that is deployed at bridged chains. -pub const WITH_ROCOCO_GRANDPA_PALLET_NAME: &str = "BridgeRococoGrandpa"; -/// Name of the With-Rococo messages pallet instance that is deployed at bridged chains. -pub const WITH_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages"; - -/// Name of the `RococoFinalityApi::best_finalized` runtime method. -pub const BEST_FINALIZED_ROCOCO_HEADER_METHOD: &str = "RococoFinalityApi_best_finalized"; - -/// 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::message_details` runtime method. -pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details"; - /// Existential deposit on Rococo. pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100; - -/// Weight of pay-dispatch-fee operation for inbound messages at Rococo chain. -/// -/// This value corresponds to the result of -/// `pallet_bridge_messages::WeightInfoExt::pay_inbound_dispatch_fee_overhead()` call for your -/// chain. Don't put too much reserve there, because it is used to **decrease** -/// `DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT` cost. So putting large reserve would make delivery -/// transactions cheaper. -pub const PAY_INBOUND_DISPATCH_FEE_WEIGHT: Weight = 600_000_000; - -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); - } - - /// 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 the 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, - rococo_to_this_conversion_rate: Option, - ) -> Option; - /// Returns dispatch weight, encoded payload size and delivery+dispatch fee 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 message_details( - lane: LaneId, - begin: MessageNonce, - end: MessageNonce, - ) -> Vec>; - } -}