Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fixes - WeigthToFee + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Nov 14, 2022
1 parent 14861d5 commit bb3562e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ pub struct XcmBlobMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain, Di
sp_std::marker::PhantomData<(SourceBridgeHubChain, TargetBridgeHubChain, DispatchBlob)>,
}

impl<
SourceBridgeHubChain: Chain,
TargetBridgeHubChain: Chain,
BlobDispatcher: DispatchBlob,
> MessageDispatch<AccountIdOf<SourceBridgeHubChain>, BalanceOf<TargetBridgeHubChain>>
impl<SourceBridgeHubChain: Chain, TargetBridgeHubChain: Chain, BlobDispatcher: DispatchBlob>
MessageDispatch<AccountIdOf<SourceBridgeHubChain>, BalanceOf<TargetBridgeHubChain>>
for XcmBlobMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain, BlobDispatcher>
{
type DispatchPayload = XcmAsPlainPayload;
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -142,9 +142,7 @@ impl<H: XcmBlobHauler> HaulBlob for XcmBlobHaulerAdapter<H> {
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

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},
Expand Down Expand Up @@ -54,8 +57,11 @@ pub type OnBridgeHubRococoBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, BridgeHubRococoUniversalLocation>;

/// Export XCM messages to be relayed to the otherside
pub type ToBridgeHubWococoHaulBlobExporter =
HaulBlobExporter<XcmBlobHaulerAdapter<ToBridgeHubWococoXcmBlobHauler>, WococoGlobalConsensusNetwork, ()>;
pub type ToBridgeHubWococoHaulBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToBridgeHubWococoXcmBlobHauler>,
WococoGlobalConsensusNetwork,
(),
>;
pub struct ToBridgeHubWococoXcmBlobHauler;
pub const DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO: LaneId = [0, 0, 0, 2];
impl XcmBlobHauler for ToBridgeHubWococoXcmBlobHauler {
Expand Down Expand Up @@ -186,9 +192,7 @@ impl messages::BridgedChainWithMessages for BridgeHubWococo {
}
}

fn transaction_payment(
transaction: MessageTransaction<Weight>,
) -> messages::BalanceOf<Self> {
fn transaction_payment(transaction: MessageTransaction<Weight>) -> messages::BalanceOf<Self> {
log::info!(
"[BridgeHubWococo::BridgedChainWithMessages] transaction_payment (returns 0 balance, TODO: fix) - transaction: {:?}",
transaction
Expand Down Expand Up @@ -232,9 +236,7 @@ impl ThisChainWithMessages for BridgeHubRococo {
MessageNonce::MAX / 2
}

fn transaction_payment(
transaction: MessageTransaction<Weight>,
) -> messages::BalanceOf<Self> {
fn transaction_payment(transaction: MessageTransaction<Weight>) -> messages::BalanceOf<Self> {
log::info!(
"[BridgeHubRococo::ThisChainWithMessages] transaction_payment (returns 0 balance, TODO: fix) - transaction: {:?}",
transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

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},
Expand Down Expand Up @@ -54,8 +57,11 @@ pub type OnBridgeHubWococoBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, BridgeHubWococoUniversalLocation>;

/// Export XCM messages to be relayed to the otherside
pub type ToBridgeHubRococoHaulBlobExporter =
HaulBlobExporter<XcmBlobHaulerAdapter<ToBridgeHubRococoXcmBlobHauler>, RococoGlobalConsensusNetwork, ()>;
pub type ToBridgeHubRococoHaulBlobExporter = HaulBlobExporter<
XcmBlobHaulerAdapter<ToBridgeHubRococoXcmBlobHauler>,
RococoGlobalConsensusNetwork,
(),
>;
pub struct ToBridgeHubRococoXcmBlobHauler;
pub const DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO: LaneId = [0, 0, 0, 1];
impl XcmBlobHauler for ToBridgeHubRococoXcmBlobHauler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -49,8 +49,8 @@ pub mod fee {
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// 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 {
Expand Down
70 changes: 24 additions & 46 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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::{
Expand All @@ -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;

Expand Down Expand Up @@ -126,7 +125,8 @@ pub type SignedExtra = (
);

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;
Expand All @@ -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<Self::Balance> {
// 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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -492,8 +464,9 @@ impl pallet_bridge_grandpa::Config<BridgeGrandpaWococoInstance> 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<Runtime>;
}

Expand All @@ -503,8 +476,9 @@ impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoInstance> 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<Runtime>;
}

Expand All @@ -525,7 +499,8 @@ impl pallet_bridge_parachains::Config<BridgeParachainWococoInstance> 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
Expand All @@ -537,7 +512,8 @@ impl pallet_bridge_parachains::Config<BridgeParachainRococoInstance> 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
Expand All @@ -553,7 +529,8 @@ impl pallet_bridge_messages::Config<WithBridgeHubWococoMessagesInstance> 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;

Expand Down Expand Up @@ -588,7 +565,8 @@ impl pallet_bridge_messages::Config<WithBridgeHubRococoMessagesInstance> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

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,
Expand All @@ -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! {
Expand Down Expand Up @@ -276,12 +282,22 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
message: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
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),
}
}
Expand Down

0 comments on commit bb3562e

Please sign in to comment.