From bb3562e79554a56864e79dc6a537aa56ba936006 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 14 Nov 2022 15:58:28 +0100 Subject: [PATCH] Fixes - WeigthToFee + fmt --- .../src/bridge_common_config.rs | 22 +++--- .../src/bridge_hub_rococo_config.rs | 20 +++--- .../src/bridge_hub_wococo_config.rs | 12 +++- .../bridge-hub-rococo/src/constants.rs | 8 +-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 70 +++++++------------ .../bridge-hub-rococo/src/weights/mod.rs | 2 +- .../bridge-hub-rococo/src/xcm_config.rs | 34 ++++++--- 7 files changed, 84 insertions(+), 84 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs index 85414d09befa..94c0d1660be2 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs @@ -42,11 +42,8 @@ pub struct XcmBlobMessageDispatch, } -impl< - SourceBridgeHubChain: Chain, - TargetBridgeHubChain: Chain, - BlobDispatcher: DispatchBlob, - > MessageDispatch, BalanceOf> +impl + MessageDispatch, BalanceOf> for XcmBlobMessageDispatch { type DispatchPayload = XcmAsPlainPayload; @@ -79,13 +76,16 @@ impl< let dispatch_result = match BlobDispatcher::dispatch_blob(payload) { Ok(_) => true, Err(e) => { - let e= match e { + let e = match e { DispatchBlobError::Unbridgable => "DispatchBlobError::Unbridgable", DispatchBlobError::InvalidEncoding => "DispatchBlobError::InvalidEncoding", - DispatchBlobError::UnsupportedLocationVersion => "DispatchBlobError::UnsupportedLocationVersion", - DispatchBlobError::UnsupportedXcmVersion => "DispatchBlobError::UnsupportedXcmVersion", + DispatchBlobError::UnsupportedLocationVersion => + "DispatchBlobError::UnsupportedLocationVersion", + DispatchBlobError::UnsupportedXcmVersion => + "DispatchBlobError::UnsupportedXcmVersion", DispatchBlobError::RoutingError => "DispatchBlobError::RoutingError", - DispatchBlobError::NonUniversalDestination => "DispatchBlobError::NonUniversalDestination", + DispatchBlobError::NonUniversalDestination => + "DispatchBlobError::NonUniversalDestination", DispatchBlobError::WrongGlobal => "DispatchBlobError::WrongGlobal", }; log::error!( @@ -142,9 +142,7 @@ impl HaulBlob for XcmBlobHaulerAdapter { let hash = (lane, artifacts.nonce).using_encoded(sp_io::hashing::blake2_256); hash }) - .map_err(|e| { - e - }); + .map_err(|e| e); log::info!(target: "runtime::bridge-hub", "haul_blob result: {:?} on lane: {:?}", result, lane); result.expect("failed to process: TODO:check-parameter - wait for origin/gav-xcm-v3, there is a comment about handliing errors for HaulBlob"); } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs index 475adf131007..cc3aef6aa635 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ParachainInfo, Runtime, WithBridgeHubWococoMessagesInstance, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter}; +use crate::{ + ParachainInfo, Runtime, WithBridgeHubWococoMessagesInstance, XcmAsPlainPayload, XcmBlobHauler, + XcmBlobHaulerAdapter, XcmRouter, +}; use bp_messages::{ source_chain::TargetHeaderChain, target_chain::{ProvedMessages, SourceHeaderChain}, @@ -54,8 +57,11 @@ pub type OnBridgeHubRococoBlobDispatcher = BridgeBlobDispatcher; /// Export XCM messages to be relayed to the otherside -pub type ToBridgeHubWococoHaulBlobExporter = - HaulBlobExporter, WococoGlobalConsensusNetwork, ()>; +pub type ToBridgeHubWococoHaulBlobExporter = HaulBlobExporter< + XcmBlobHaulerAdapter, + WococoGlobalConsensusNetwork, + (), +>; pub struct ToBridgeHubWococoXcmBlobHauler; pub const DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO: LaneId = [0, 0, 0, 2]; impl XcmBlobHauler for ToBridgeHubWococoXcmBlobHauler { @@ -186,9 +192,7 @@ impl messages::BridgedChainWithMessages for BridgeHubWococo { } } - fn transaction_payment( - transaction: MessageTransaction, - ) -> messages::BalanceOf { + fn transaction_payment(transaction: MessageTransaction) -> messages::BalanceOf { log::info!( "[BridgeHubWococo::BridgedChainWithMessages] transaction_payment (returns 0 balance, TODO: fix) - transaction: {:?}", transaction @@ -232,9 +236,7 @@ impl ThisChainWithMessages for BridgeHubRococo { MessageNonce::MAX / 2 } - fn transaction_payment( - transaction: MessageTransaction, - ) -> messages::BalanceOf { + fn transaction_payment(transaction: MessageTransaction) -> messages::BalanceOf { log::info!( "[BridgeHubRococo::ThisChainWithMessages] transaction_payment (returns 0 balance, TODO: fix) - transaction: {:?}", transaction diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs index 99dd24d6a297..a4039e1b9440 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::{ParachainInfo, Runtime, WithBridgeHubRococoMessagesInstance, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter}; +use crate::{ + ParachainInfo, Runtime, WithBridgeHubRococoMessagesInstance, XcmAsPlainPayload, XcmBlobHauler, + XcmBlobHaulerAdapter, XcmRouter, +}; use bp_messages::{ source_chain::TargetHeaderChain, target_chain::{ProvedMessages, SourceHeaderChain}, @@ -54,8 +57,11 @@ pub type OnBridgeHubWococoBlobDispatcher = BridgeBlobDispatcher; /// Export XCM messages to be relayed to the otherside -pub type ToBridgeHubRococoHaulBlobExporter = - HaulBlobExporter, RococoGlobalConsensusNetwork, ()>; +pub type ToBridgeHubRococoHaulBlobExporter = HaulBlobExporter< + XcmBlobHaulerAdapter, + RococoGlobalConsensusNetwork, + (), +>; pub struct ToBridgeHubRococoXcmBlobHauler; pub const DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO: LaneId = [0, 0, 0, 1]; impl XcmBlobHauler for ToBridgeHubRococoXcmBlobHauler { diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs index 4352e3ef554f..641ae6dfe437 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/constants.rs @@ -39,8 +39,8 @@ pub mod fee { /// node's balance type. /// /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] + /// - `[0, MAXIMUM_BLOCK_WEIGHT]` + /// - `[Balance::min, Balance::max]` /// /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: /// - Setting it to `0` will essentially disable the weight fee. @@ -49,8 +49,8 @@ pub mod fee { impl WeightToFeePolynomial for WeightToFee { type Balance = Balance; fn polynomial() -> WeightToFeeCoefficients { - // in Polkadot, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: - // in Statemint, we map to 1/10 of that, or 1/100 CENT + // in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT: + // in BridgeHub, we map to 1/10 of that, or 1/100 CENT let p = super::currency::CENTS; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); smallvec![WeightToFeeCoefficient { diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index d154f9721d71..10a31c9dec67 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -29,11 +29,10 @@ pub mod constants; mod weights; pub mod xcm_config; -use codec::Decode; use bridge_common_config::*; +use codec::Decode; use constants::currency::*; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use smallvec::smallvec; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -49,13 +48,11 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, dispatch::DispatchClass, + parameter_types, traits::Everything, - weights::{ - ConstantMultiplier, Weight, - WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, - }, + weights::{ConstantMultiplier, Weight}, PalletId, }; use frame_system::{ @@ -77,10 +74,12 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use crate::{ bridge_hub_rococo_config::OnBridgeHubRococoBlobDispatcher, - bridge_hub_wococo_config::OnBridgeHubWococoBlobDispatcher, + bridge_hub_wococo_config::OnBridgeHubWococoBlobDispatcher, constants::fee::WeightToFee, xcm_config::XcmRouter, }; -use parachains_common::{AccountId, Signature, AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, MAXIMUM_BLOCK_WEIGHT}; +use parachains_common::{ + AccountId, Signature, AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, +}; use xcm::latest::prelude::BodyId; use xcm_executor::XcmExecutor; @@ -126,7 +125,8 @@ pub type SignedExtra = ( ); /// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; @@ -140,33 +140,6 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; -/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the -/// node's balance type. -/// -/// This should typically create a mapping between the following ranges: -/// - `[0, MAXIMUM_BLOCK_WEIGHT]` -/// - `[Balance::min, Balance::max]` -/// -/// Yet, it can be used for any other sort of change to weight-fee. Some examples being: -/// - Setting it to `0` will essentially disable the weight fee. -/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. -pub struct WeightToFee; -impl WeightToFeePolynomial for WeightToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 MILLIUNIT: - // in our template, we map to 1/10 of that, or 1/10 MILLIUNIT - let p = MILLIUNIT / 10; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } -} - /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats /// of data like extrinsics, allowing for them to continue syncing the network through upgrades @@ -226,7 +199,6 @@ pub const UNIT: Balance = 1_000_000_000_000; pub const MILLIUNIT: Balance = 1_000_000_000; pub const MICROUNIT: Balance = 1_000_000; - /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { @@ -492,8 +464,9 @@ impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_wococo::Wococo; type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = frame_support::traits::ConstU32<{bp_wococo::MAX_AUTHORITIES_COUNT}>; - type MaxBridgedHeaderSize = frame_support::traits::ConstU32<{bp_wococo::MAX_HEADER_SIZE}>; + type MaxBridgedAuthorities = + frame_support::traits::ConstU32<{ bp_wococo::MAX_AUTHORITIES_COUNT }>; + type MaxBridgedHeaderSize = frame_support::traits::ConstU32<{ bp_wococo::MAX_HEADER_SIZE }>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } @@ -503,8 +476,9 @@ impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_rococo::Rococo; type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = frame_support::traits::ConstU32<{bp_rococo::MAX_AUTHORITIES_COUNT}>; - type MaxBridgedHeaderSize = frame_support::traits::ConstU32<{bp_rococo::MAX_HEADER_SIZE}>; + type MaxBridgedAuthorities = + frame_support::traits::ConstU32<{ bp_rococo::MAX_AUTHORITIES_COUNT }>; + type MaxBridgedHeaderSize = frame_support::traits::ConstU32<{ bp_rococo::MAX_HEADER_SIZE }>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } @@ -525,7 +499,8 @@ impl pallet_bridge_parachains::Config for Runtime type ParasPalletName = WococoBridgeParachainPalletName; type TrackedParachains = Everything; type HeadsToKeep = ParachainHeadsToKeep; - type MaxParaHeadSize = frame_support::traits::ConstU32<{bp_wococo::MAX_NESTED_PARACHAIN_HEAD_SIZE}>; + type MaxParaHeadSize = + frame_support::traits::ConstU32<{ bp_wococo::MAX_NESTED_PARACHAIN_HEAD_SIZE }>; } /// Add parachain bridge pallet to track Rococo bridge hub parachain @@ -537,7 +512,8 @@ impl pallet_bridge_parachains::Config for Runtime type ParasPalletName = RococoBridgeParachainPalletName; type TrackedParachains = Everything; type HeadsToKeep = ParachainHeadsToKeep; - type MaxParaHeadSize = frame_support::traits::ConstU32<{bp_rococo::MAX_NESTED_PARACHAIN_HEAD_SIZE}>; + type MaxParaHeadSize = + frame_support::traits::ConstU32<{ bp_rococo::MAX_NESTED_PARACHAIN_HEAD_SIZE }>; } /// Add XCM messages support for BrigdeHubRococo to support Rococo->Wococo XCM messages @@ -553,7 +529,8 @@ impl pallet_bridge_messages::Config for Run type MaxUnconfirmedMessagesAtInboundLane = bridge_hub_rococo_config::MaxUnconfirmedMessagesAtInboundLane; - type MaximalOutboundPayloadSize = bridge_hub_rococo_config::ToBridgeHubWococoMaximalOutboundPayloadSize; + type MaximalOutboundPayloadSize = + bridge_hub_rococo_config::ToBridgeHubWococoMaximalOutboundPayloadSize; type OutboundPayload = XcmAsPlainPayload; type OutboundMessageFee = Balance; @@ -588,7 +565,8 @@ impl pallet_bridge_messages::Config for Run type MaxUnconfirmedMessagesAtInboundLane = bridge_hub_wococo_config::MaxUnconfirmedMessagesAtInboundLane; - type MaximalOutboundPayloadSize = bridge_hub_wococo_config::ToBridgeHubRococoMaximalOutboundPayloadSize; + type MaximalOutboundPayloadSize = + bridge_hub_wococo_config::ToBridgeHubRococoMaximalOutboundPayloadSize; type OutboundPayload = XcmAsPlainPayload; type OutboundMessageFee = Balance; diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs index 504a4280fcd9..8006fb43e5d4 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs @@ -20,8 +20,8 @@ pub mod block_weights; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; -pub mod paritydb_weights; pub mod pallet_balances; +pub mod paritydb_weights; pub mod rocksdb_weights; pub mod xcm; diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 20e72bb30402..c825e780716c 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -15,8 +15,8 @@ // along with Cumulus. If not, see . use super::{ - AccountId, Balance, Balances, RuntimeCall, RuntimeEvent, RuntimeOrigin, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, XcmpQueue, + AccountId, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, + RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue, }; use crate::{ bridge_hub_rococo_config::ToBridgeHubWococoHaulBlobExporter, @@ -30,7 +30,13 @@ use frame_support::{ use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use xcm::latest::prelude::*; -use xcm_builder::{AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds}; +use xcm_builder::{ + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, + EnsureXcmOrigin, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, + WeightInfoBounds, +}; use xcm_executor::{traits::ExportXcm, XcmExecutor}; parameter_types! { @@ -276,12 +282,22 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter { message: &mut Option>, ) -> SendResult { match network { - Rococo => - ToBridgeHubRococoHaulBlobExporter::validate(network, channel, universal_source, destination, message) - .map(|result| ((Rococo, result.0), result.1)), - Wococo => - ToBridgeHubWococoHaulBlobExporter::validate(network, channel, universal_source, destination, message) - .map(|result| ((Wococo, result.0), result.1)), + Rococo => ToBridgeHubRococoHaulBlobExporter::validate( + network, + channel, + universal_source, + destination, + message, + ) + .map(|result| ((Rococo, result.0), result.1)), + Wococo => ToBridgeHubWococoHaulBlobExporter::validate( + network, + channel, + universal_source, + destination, + message, + ) + .map(|result| ((Wococo, result.0), result.1)), _ => unimplemented!("Unsupported network: {:?}", network), } }