mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Companion for Weight v1.5 (#5943)
* fix to latest substrate pr
* update weights
* cargo build -p polkadot-runtime-parachains
* fix xcm-builder
* fix import
* fix a bunch
* fix a bunch of weight stuff
* kusama compile
* unused
* builds
* maybe fix
* cargo test -p polkadot-runtime-parachains
* xcm simulator example
* fix tests
* xcm sim fuzz
* fix runtime tests
* remove unused
* fix integration tests
* scalar div
* update lockfile for {"substrate"}
Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
use crate::{fungible as xcm_balances_benchmark, mock::*};
|
||||
use frame_benchmarking::BenchmarkError;
|
||||
use frame_support::{parameter_types, traits::Everything};
|
||||
use frame_support::{parameter_types, traits::Everything, weights::Weight};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
@@ -47,7 +47,7 @@ frame_support::construct_runtime!(
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(1024);
|
||||
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024));
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = Everything;
|
||||
|
||||
@@ -115,7 +115,7 @@ benchmarks! {
|
||||
|
||||
let instruction = Instruction::Transact {
|
||||
origin_type: OriginKind::SovereignAccount,
|
||||
require_weight_at_most: noop_call.get_dispatch_info().weight,
|
||||
require_weight_at_most: noop_call.get_dispatch_info().weight.ref_time(),
|
||||
call: double_encoded_noop_call,
|
||||
};
|
||||
let xcm = Xcm(vec![instruction]);
|
||||
|
||||
@@ -21,6 +21,7 @@ use codec::Decode;
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{Everything, OriginTrait},
|
||||
weights::Weight,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
@@ -51,7 +52,7 @@ frame_support::construct_runtime!(
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(1024);
|
||||
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024));
|
||||
}
|
||||
|
||||
impl frame_system::Config for Test {
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
use frame_support::{parameter_types, weights::Weight};
|
||||
use frame_support::parameter_types;
|
||||
use xcm::latest::Weight as XCMWeight;
|
||||
use xcm_executor::traits::FilterAssetLocation;
|
||||
|
||||
// An xcm sender/receiver akin to > /dev/null
|
||||
@@ -30,7 +31,7 @@ impl xcm_executor::traits::OnResponse for DevNull {
|
||||
fn expecting_response(_: &MultiLocation, _: u64) -> bool {
|
||||
false
|
||||
}
|
||||
fn on_response(_: &MultiLocation, _: u64, _: Response, _: Weight) -> Weight {
|
||||
fn on_response(_: &MultiLocation, _: u64, _: Response, _: XCMWeight) -> XCMWeight {
|
||||
0
|
||||
}
|
||||
}
|
||||
@@ -52,7 +53,7 @@ impl xcm_executor::traits::Convert<MultiLocation, u64> for AccountIdConverter {
|
||||
|
||||
parameter_types! {
|
||||
pub Ancestry: MultiLocation = Junction::Parachain(101).into();
|
||||
pub UnitWeightCost: Weight = 10;
|
||||
pub UnitWeightCost: u64 = 10;
|
||||
pub WeightPrice: (AssetId, u128) = (Concrete(Here.into()), 1_000_000);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use frame_support::{traits::Get, weights::Weight};
|
||||
use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
/// Weights for `{{pallet}}`.
|
||||
|
||||
@@ -404,7 +404,7 @@ pub mod pallet {
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
|
||||
let mut weight_used = 0;
|
||||
let mut weight_used = Weight::new();
|
||||
if let Some(migration) = CurrentMigration::<T>::get() {
|
||||
// Consume 10% of block at most
|
||||
let max_weight = T::BlockWeights::get().max_block / 10;
|
||||
@@ -439,7 +439,7 @@ pub mod pallet {
|
||||
// Start a migration (this happens before on_initialize so it'll happen later in this
|
||||
// block, which should be good enough)...
|
||||
CurrentMigration::<T>::put(VersionMigrationStage::default());
|
||||
T::DbWeight::get().write
|
||||
T::DbWeight::get().writes(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,9 +490,9 @@ pub mod pallet {
|
||||
WithdrawAsset(assets),
|
||||
InitiateTeleport { assets: Wild(All), dest, xcm: Xcm(vec![]) },
|
||||
]);
|
||||
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
|
||||
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| Weight::from_ref_time(100_000_000.saturating_add(w)))
|
||||
},
|
||||
_ => Weight::max_value(),
|
||||
_ => Weight::MAX,
|
||||
}
|
||||
})]
|
||||
pub fn teleport_assets(
|
||||
@@ -528,9 +528,9 @@ pub mod pallet {
|
||||
let mut message = Xcm(vec![
|
||||
TransferReserveAsset { assets, dest, xcm: Xcm(vec![]) }
|
||||
]);
|
||||
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
|
||||
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| Weight::from_ref_time(100_000_000.saturating_add(w)))
|
||||
},
|
||||
_ => Weight::max_value(),
|
||||
_ => Weight::MAX,
|
||||
}
|
||||
})]
|
||||
pub fn reserve_transfer_assets(
|
||||
@@ -561,7 +561,7 @@ pub mod pallet {
|
||||
///
|
||||
/// NOTE: A successful return to this does *not* imply that the `msg` was executed successfully
|
||||
/// to completion; only that *some* of it was executed.
|
||||
#[pallet::weight(max_weight.saturating_add(100_000_000u64))]
|
||||
#[pallet::weight(max_weight.saturating_add(Weight::from_ref_time(100_000_000u64)))]
|
||||
pub fn execute(
|
||||
origin: OriginFor<T>,
|
||||
message: Box<VersionedXcm<<T as SysConfig>::Call>>,
|
||||
@@ -575,8 +575,8 @@ pub mod pallet {
|
||||
let outcome = T::XcmExecutor::execute_xcm_in_credit(
|
||||
origin_location,
|
||||
message,
|
||||
max_weight,
|
||||
max_weight,
|
||||
max_weight.ref_time(),
|
||||
max_weight.ref_time(),
|
||||
);
|
||||
let result = Ok(Some(outcome.weight_used().saturating_add(100_000_000)).into());
|
||||
Self::deposit_event(Event::Attempted(outcome));
|
||||
@@ -690,9 +690,9 @@ pub mod pallet {
|
||||
let mut message = Xcm(vec![
|
||||
TransferReserveAsset { assets, dest, xcm: Xcm(vec![]) }
|
||||
]);
|
||||
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
|
||||
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| Weight::from_ref_time(100_000_000.saturating_add(w)))
|
||||
},
|
||||
_ => Weight::max_value(),
|
||||
_ => Weight::MAX,
|
||||
}
|
||||
})]
|
||||
pub fn limited_reserve_transfer_assets(
|
||||
@@ -740,9 +740,9 @@ pub mod pallet {
|
||||
WithdrawAsset(assets),
|
||||
InitiateTeleport { assets: Wild(All), dest, xcm: Xcm(vec![]) },
|
||||
]);
|
||||
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
|
||||
T::Weigher::weight(&mut message).map_or(Weight::MAX, |w| Weight::from_ref_time(100_000_000.saturating_add(w)))
|
||||
},
|
||||
_ => Weight::max_value(),
|
||||
_ => Weight::MAX,
|
||||
}
|
||||
})]
|
||||
pub fn limited_teleport_assets(
|
||||
@@ -886,12 +886,12 @@ pub mod pallet {
|
||||
mut stage: VersionMigrationStage,
|
||||
weight_cutoff: Weight,
|
||||
) -> (Weight, Option<VersionMigrationStage>) {
|
||||
let mut weight_used = 0;
|
||||
let mut weight_used = Weight::new();
|
||||
|
||||
// TODO: Correct weights for the components of this:
|
||||
let todo_sv_migrate_weight: Weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
let todo_vn_migrate_weight: Weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
let todo_vnt_already_notified_weight: Weight = T::DbWeight::get().read;
|
||||
let todo_vnt_already_notified_weight: Weight = T::DbWeight::get().reads(1);
|
||||
let todo_vnt_notify_weight: Weight = T::DbWeight::get().reads_writes(1, 3);
|
||||
let todo_vnt_migrate_weight: Weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
let todo_vnt_migrate_fail_weight: Weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
@@ -1151,7 +1151,11 @@ pub mod pallet {
|
||||
let notify: <T as Config>::Call = notify.into();
|
||||
let max_response_weight = notify.get_dispatch_info().weight;
|
||||
let query_id = Self::new_notify_query(responder, notify, timeout);
|
||||
let report_error = Xcm(vec![ReportError { dest, query_id, max_response_weight }]);
|
||||
let report_error = Xcm(vec![ReportError {
|
||||
dest,
|
||||
query_id,
|
||||
max_response_weight: max_response_weight.ref_time(),
|
||||
}]);
|
||||
message.0.insert(0, SetAppendix(report_error));
|
||||
Ok(())
|
||||
}
|
||||
@@ -1270,7 +1274,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
impl<T: Config> DropAssets for Pallet<T> {
|
||||
fn drop_assets(origin: &MultiLocation, assets: Assets) -> Weight {
|
||||
fn drop_assets(origin: &MultiLocation, assets: Assets) -> RefTimeWeight {
|
||||
if assets.is_empty() {
|
||||
return 0
|
||||
}
|
||||
@@ -1324,8 +1328,8 @@ pub mod pallet {
|
||||
origin: &MultiLocation,
|
||||
query_id: QueryId,
|
||||
response: Response,
|
||||
max_weight: Weight,
|
||||
) -> Weight {
|
||||
max_weight: RefTimeWeight,
|
||||
) -> RefTimeWeight {
|
||||
match (response, Queries::<T>::get(query_id)) {
|
||||
(
|
||||
Response::Version(v),
|
||||
@@ -1400,6 +1404,7 @@ pub mod pallet {
|
||||
{
|
||||
Queries::<T>::remove(query_id);
|
||||
let weight = call.get_dispatch_info().weight;
|
||||
let max_weight = Weight::from_ref_time(max_weight);
|
||||
if weight > max_weight {
|
||||
let e = Event::NotifyOverweight(
|
||||
query_id,
|
||||
@@ -1431,6 +1436,7 @@ pub mod pallet {
|
||||
},
|
||||
}
|
||||
.unwrap_or(weight)
|
||||
.ref_time()
|
||||
} else {
|
||||
let e =
|
||||
Event::NotifyDecodeFailed(query_id, pallet_index, call_index);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
|
||||
use frame_support::{construct_runtime, parameter_types, traits::Everything};
|
||||
use polkadot_parachain::primitives::Id as ParaId;
|
||||
use polkadot_runtime_parachains::origin;
|
||||
use sp_core::H256;
|
||||
@@ -219,7 +219,7 @@ parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = Here.into();
|
||||
pub const AnyNetwork: NetworkId = NetworkId::Any;
|
||||
pub Ancestry: MultiLocation = Here.into();
|
||||
pub UnitWeightCost: Weight = 1_000;
|
||||
pub UnitWeightCost: u64 = 1_000;
|
||||
}
|
||||
|
||||
pub type SovereignAccountOf =
|
||||
@@ -236,7 +236,7 @@ type LocalOriginConverter = (
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const BaseXcmWeight: Weight = 1_000;
|
||||
pub const BaseXcmWeight: u64 = 1_000;
|
||||
pub CurrencyPerSecond: (AssetId, u128) = (Concrete(RelayLocation::get()), 1);
|
||||
pub TrustedAssets: (MultiAssetFilter, MultiLocation) = (All.into(), Here.into());
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok,
|
||||
traits::{Currency, Hooks},
|
||||
weights::Weight,
|
||||
};
|
||||
use polkadot_parachain::primitives::Id as ParaId;
|
||||
use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, Hash};
|
||||
@@ -509,7 +510,7 @@ fn execute_withdraw_to_deposit_works() {
|
||||
buy_execution((Here, SEND_AMOUNT)),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]))),
|
||||
weight
|
||||
Weight::from_ref_time(weight)
|
||||
));
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT);
|
||||
assert_eq!(Balances::total_balance(&BOB), SEND_AMOUNT);
|
||||
@@ -541,7 +542,7 @@ fn trapped_assets_can_be_claimed() {
|
||||
// This would succeed, but we never get to it.
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest.clone() },
|
||||
]))),
|
||||
weight
|
||||
Weight::from_ref_time(weight)
|
||||
));
|
||||
let source: MultiLocation =
|
||||
Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into() }.into();
|
||||
@@ -571,7 +572,7 @@ fn trapped_assets_can_be_claimed() {
|
||||
buy_execution((Here, SEND_AMOUNT)),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest.clone() },
|
||||
]))),
|
||||
weight
|
||||
Weight::from_ref_time(weight)
|
||||
));
|
||||
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT);
|
||||
@@ -586,7 +587,7 @@ fn trapped_assets_can_be_claimed() {
|
||||
buy_execution((Here, SEND_AMOUNT)),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]))),
|
||||
weight
|
||||
Weight::from_ref_time(weight)
|
||||
));
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
@@ -983,7 +984,7 @@ fn subscription_side_upgrades_work_with_multistage_notify() {
|
||||
let mut counter = 0;
|
||||
while let Some(migration) = maybe_migration.take() {
|
||||
counter += 1;
|
||||
let (_, m) = XcmPallet::check_xcm_version_change(migration, 0);
|
||||
let (_, m) = XcmPallet::check_xcm_version_change(migration, Weight::zero());
|
||||
maybe_migration = m;
|
||||
}
|
||||
assert_eq!(counter, 4);
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
//! Various implementations for `ShouldExecute`.
|
||||
|
||||
use frame_support::{ensure, traits::Contains, weights::Weight};
|
||||
use frame_support::{ensure, traits::Contains};
|
||||
use polkadot_parachain::primitives::IsSystem;
|
||||
use sp_std::{marker::PhantomData, result::Result};
|
||||
use xcm::latest::{Instruction::*, Junction, Junctions, MultiLocation, WeightLimit::*, Xcm};
|
||||
use xcm::latest::{
|
||||
Instruction::*, Junction, Junctions, MultiLocation, Weight, WeightLimit::*, Xcm,
|
||||
};
|
||||
use xcm_executor::traits::{OnResponse, ShouldExecute};
|
||||
|
||||
/// Execution barrier that just takes `max_weight` from `weight_credit`.
|
||||
|
||||
@@ -20,9 +20,7 @@ pub use crate::{
|
||||
FixedRateOfFungible, FixedWeightBounds, LocationInverter, TakeWeightCredit,
|
||||
};
|
||||
pub use frame_support::{
|
||||
dispatch::{
|
||||
DispatchError, DispatchInfo, DispatchResultWithPostInfo, Dispatchable, Parameter, Weight,
|
||||
},
|
||||
dispatch::{DispatchError, DispatchInfo, DispatchResultWithPostInfo, Dispatchable, Parameter},
|
||||
ensure, parameter_types,
|
||||
sp_runtime::DispatchErrorWithPostInfo,
|
||||
traits::{Contains, Get, IsInVec},
|
||||
@@ -35,7 +33,7 @@ pub use sp_std::{
|
||||
fmt::Debug,
|
||||
marker::PhantomData,
|
||||
};
|
||||
pub use xcm::latest::prelude::*;
|
||||
pub use xcm::latest::{prelude::*, Weight};
|
||||
pub use xcm_executor::{
|
||||
traits::{ConvertOrigin, FilterAssetLocation, InvertLocation, OnResponse, TransactAsset},
|
||||
Assets, Config,
|
||||
@@ -66,12 +64,14 @@ impl Dispatchable for TestCall {
|
||||
type PostInfo = PostDispatchInfo;
|
||||
fn dispatch(self, origin: Self::Origin) -> DispatchResultWithPostInfo {
|
||||
let mut post_info = PostDispatchInfo::default();
|
||||
post_info.actual_weight = match self {
|
||||
let maybe_actual = match self {
|
||||
TestCall::OnlyRoot(_, maybe_actual) |
|
||||
TestCall::OnlySigned(_, maybe_actual, _) |
|
||||
TestCall::OnlyParachain(_, maybe_actual, _) |
|
||||
TestCall::Any(_, maybe_actual) => maybe_actual,
|
||||
};
|
||||
post_info.actual_weight =
|
||||
maybe_actual.map(|x| frame_support::weights::Weight::from_ref_time(x));
|
||||
if match (&origin, &self) {
|
||||
(TestOrigin::Parachain(i), TestCall::OnlyParachain(_, _, Some(j))) => i == j,
|
||||
(TestOrigin::Signed(i), TestCall::OnlySigned(_, _, Some(j))) => i == j,
|
||||
@@ -96,7 +96,10 @@ impl GetDispatchInfo for TestCall {
|
||||
TestCall::OnlySigned(estimate, ..) |
|
||||
TestCall::Any(estimate, ..) => estimate,
|
||||
};
|
||||
DispatchInfo { weight, ..Default::default() }
|
||||
DispatchInfo {
|
||||
weight: frame_support::weights::Weight::from_ref_time(weight),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +255,7 @@ pub fn response(query_id: u64) -> Option<Response> {
|
||||
|
||||
parameter_types! {
|
||||
pub TestAncestry: MultiLocation = X1(Parachain(42)).into();
|
||||
pub UnitWeightCost: Weight = 10;
|
||||
pub UnitWeightCost: u64 = 10;
|
||||
}
|
||||
parameter_types! {
|
||||
// Nothing is allowed to be paid/unpaid by default.
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
// Shared test utilities and implementations for the XCM Builder.
|
||||
|
||||
use frame_support::{dispatch::Weight, parameter_types};
|
||||
use frame_support::parameter_types;
|
||||
use sp_std::vec::Vec;
|
||||
pub use xcm::latest::prelude::*;
|
||||
pub use xcm::latest::{prelude::*, Weight};
|
||||
use xcm_executor::traits::{ClaimAssets, DropAssets, VersionChangeNotifier};
|
||||
pub use xcm_executor::{
|
||||
traits::{ConvertOrigin, FilterAssetLocation, InvertLocation, OnResponse, TransactAsset},
|
||||
|
||||
@@ -676,8 +676,8 @@ fn weight_trader_tuple_should_work() {
|
||||
pub const PARA_2: MultiLocation = X1(Parachain(2)).into();
|
||||
|
||||
parameter_types! {
|
||||
pub static HereWeightPrice: (AssetId, u128) = (Here.into().into(), WEIGHT_PER_SECOND.into());
|
||||
pub static PARA1WeightPrice: (AssetId, u128) = (PARA_1.into(), WEIGHT_PER_SECOND.into());
|
||||
pub static HereWeightPrice: (AssetId, u128) = (Here.into().into(), WEIGHT_PER_SECOND.ref_time().into());
|
||||
pub static PARA1WeightPrice: (AssetId, u128) = (PARA_1.into(), WEIGHT_PER_SECOND.ref_time().into());
|
||||
}
|
||||
|
||||
type Traders = (
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
use frame_support::{
|
||||
traits::{tokens::currency::Currency as CurrencyT, Get, OnUnbalanced as OnUnbalancedT},
|
||||
weights::{constants::WEIGHT_PER_SECOND, GetDispatchInfo, Weight, WeightToFee as WeightToFeeT},
|
||||
weights::{constants::WEIGHT_PER_SECOND, GetDispatchInfo, WeightToFee as WeightToFeeT},
|
||||
};
|
||||
use parity_scale_codec::Decode;
|
||||
use sp_runtime::traits::{SaturatedConversion, Saturating, Zero};
|
||||
use sp_std::{marker::PhantomData, result::Result};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm::latest::{prelude::*, Weight};
|
||||
use xcm_executor::{
|
||||
traits::{WeightBounds, WeightTrader},
|
||||
Assets,
|
||||
@@ -152,7 +152,7 @@ impl<T: Get<(MultiLocation, u128)>, R: TakeRevenue> WeightTrader
|
||||
weight, payment,
|
||||
);
|
||||
let (id, units_per_second) = T::get();
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND as u128);
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND.ref_time() as u128);
|
||||
let unused =
|
||||
payment.checked_sub((id, amount).into()).map_err(|_| XcmError::TooExpensive)?;
|
||||
self.0 = self.0.saturating_add(weight);
|
||||
@@ -164,7 +164,7 @@ impl<T: Get<(MultiLocation, u128)>, R: TakeRevenue> WeightTrader
|
||||
log::trace!(target: "xcm::weight", "FixedRateOfConcreteFungible::refund_weight weight: {:?}", weight);
|
||||
let (id, units_per_second) = T::get();
|
||||
let weight = weight.min(self.0);
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND as u128);
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND.ref_time() as u128);
|
||||
self.0 -= weight;
|
||||
self.1 = self.1.saturating_sub(amount);
|
||||
if amount > 0 {
|
||||
@@ -204,7 +204,7 @@ impl<T: Get<(AssetId, u128)>, R: TakeRevenue> WeightTrader for FixedRateOfFungib
|
||||
weight, payment,
|
||||
);
|
||||
let (id, units_per_second) = T::get();
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND as u128);
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND.ref_time() as u128);
|
||||
if amount == 0 {
|
||||
return Ok(payment)
|
||||
}
|
||||
@@ -219,7 +219,7 @@ impl<T: Get<(AssetId, u128)>, R: TakeRevenue> WeightTrader for FixedRateOfFungib
|
||||
log::trace!(target: "xcm::weight", "FixedRateOfFungible::refund_weight weight: {:?}", weight);
|
||||
let (id, units_per_second) = T::get();
|
||||
let weight = weight.min(self.0);
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND as u128);
|
||||
let amount = units_per_second * (weight as u128) / (WEIGHT_PER_SECOND.ref_time() as u128);
|
||||
self.0 -= weight;
|
||||
self.1 = self.1.saturating_sub(amount);
|
||||
if amount > 0 {
|
||||
@@ -265,7 +265,8 @@ impl<
|
||||
|
||||
fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {
|
||||
log::trace!(target: "xcm::weight", "UsingComponents::buy_weight weight: {:?}, payment: {:?}", weight, payment);
|
||||
let amount = WeightToFee::weight_to_fee(&weight);
|
||||
let amount =
|
||||
WeightToFee::weight_to_fee(&frame_support::weights::Weight::from_ref_time(weight));
|
||||
let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;
|
||||
let required = (Concrete(AssetId::get()), u128_amount).into();
|
||||
let unused = payment.checked_sub(required).map_err(|_| XcmError::TooExpensive)?;
|
||||
@@ -277,7 +278,8 @@ impl<
|
||||
fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {
|
||||
log::trace!(target: "xcm::weight", "UsingComponents::refund_weight weight: {:?}", weight);
|
||||
let weight = weight.min(self.0);
|
||||
let amount = WeightToFee::weight_to_fee(&weight);
|
||||
let amount =
|
||||
WeightToFee::weight_to_fee(&frame_support::weights::Weight::from_ref_time(weight));
|
||||
self.0 -= weight;
|
||||
self.1 = self.1.saturating_sub(amount);
|
||||
let amount: u128 = amount.saturated_into();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
use frame_support::{
|
||||
construct_runtime, parameter_types,
|
||||
traits::{Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
|
||||
@@ -141,7 +140,7 @@ type LocalOriginConverter = (
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const BaseXcmWeight: Weight = 1_000_000_000;
|
||||
pub const BaseXcmWeight: u64 = 1_000_000_000;
|
||||
pub KsmPerSecond: (AssetId, u128) = (KsmLocation::get().into(), 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg(test)]
|
||||
|
||||
use frame_support::weights::Weight;
|
||||
use polkadot_test_client::{
|
||||
BlockBuilderExt, ClientBlockImportExt, DefaultTestClientBuilderExt, ExecutionStrategy,
|
||||
InitPolkadotBlockBuilder, TestClientBuilder, TestClientBuilderExt,
|
||||
@@ -46,7 +47,7 @@ fn basic_buy_fees_message_executes() {
|
||||
&client,
|
||||
polkadot_test_runtime::Call::Xcm(pallet_xcm::Call::execute {
|
||||
message: Box::new(VersionedXcm::from(msg)),
|
||||
max_weight: 1_000_000_000,
|
||||
max_weight: Weight::from_ref_time(1_000_000_000),
|
||||
}),
|
||||
sp_keyring::Sr25519Keyring::Alice,
|
||||
0,
|
||||
@@ -126,7 +127,7 @@ fn query_response_fires() {
|
||||
&client,
|
||||
polkadot_test_runtime::Call::Xcm(pallet_xcm::Call::execute {
|
||||
message: msg,
|
||||
max_weight: 1_000_000_000,
|
||||
max_weight: Weight::from_ref_time(1_000_000_000),
|
||||
}),
|
||||
sp_keyring::Sr25519Keyring::Alice,
|
||||
1,
|
||||
@@ -214,7 +215,7 @@ fn query_response_elicits_handler() {
|
||||
&client,
|
||||
polkadot_test_runtime::Call::Xcm(pallet_xcm::Call::execute {
|
||||
message: Box::new(VersionedXcm::from(msg)),
|
||||
max_weight: 1_000_000_000,
|
||||
max_weight: Weight::from_ref_time(1_000_000_000),
|
||||
}),
|
||||
sp_keyring::Sr25519Keyring::Alice,
|
||||
1,
|
||||
|
||||
@@ -16,17 +16,13 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use frame_support::{
|
||||
dispatch::{Dispatchable, Weight},
|
||||
ensure,
|
||||
weights::GetDispatchInfo,
|
||||
};
|
||||
use frame_support::{dispatch::Dispatchable, ensure, weights::GetDispatchInfo};
|
||||
use sp_runtime::traits::Saturating;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
use xcm::latest::{
|
||||
Error as XcmError, ExecuteXcm,
|
||||
Instruction::{self, *},
|
||||
MultiAssets, MultiLocation, Outcome, Response, SendXcm, Xcm,
|
||||
MultiAssets, MultiLocation, Outcome, Response, SendXcm, Weight, Xcm,
|
||||
};
|
||||
|
||||
pub mod traits;
|
||||
@@ -343,7 +339,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
|
||||
let dispatch_origin = Config::OriginConverter::convert_origin(origin, origin_type)
|
||||
.map_err(|_| XcmError::BadOrigin)?;
|
||||
let weight = message_call.get_dispatch_info().weight;
|
||||
ensure!(weight <= require_weight_at_most, XcmError::MaxWeightInvalid);
|
||||
ensure!(weight.ref_time() <= require_weight_at_most, XcmError::MaxWeightInvalid);
|
||||
let actual_weight = match message_call.dispatch(dispatch_origin) {
|
||||
Ok(post_info) => post_info.actual_weight,
|
||||
Err(error_and_info) => {
|
||||
@@ -362,7 +358,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
|
||||
// reported back to the caller and this ensures that they account for the total
|
||||
// weight consumed correctly (potentially allowing them to do more operations in a
|
||||
// block than they otherwise would).
|
||||
self.total_surplus.saturating_accrue(surplus);
|
||||
self.total_surplus.saturating_accrue(surplus.ref_time());
|
||||
Ok(())
|
||||
},
|
||||
QueryResponse { query_id, response, max_weight } => {
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
use crate::Assets;
|
||||
use core::marker::PhantomData;
|
||||
use frame_support::{traits::Contains, weights::Weight};
|
||||
use xcm::latest::{MultiAssets, MultiLocation};
|
||||
use frame_support::traits::Contains;
|
||||
use sp_runtime::traits::Zero;
|
||||
use xcm::latest::{MultiAssets, MultiLocation, Weight};
|
||||
|
||||
/// Define a handler for when some non-empty `Assets` value should be dropped.
|
||||
pub trait DropAssets {
|
||||
@@ -26,7 +27,7 @@ pub trait DropAssets {
|
||||
}
|
||||
impl DropAssets for () {
|
||||
fn drop_assets(_origin: &MultiLocation, _assets: Assets) -> Weight {
|
||||
0
|
||||
Weight::zero()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ impl<D: DropAssets, A: Contains<Assets>> DropAssets for FilterAssets<D, A> {
|
||||
if A::contains(&assets) {
|
||||
D::drop_assets(origin, assets)
|
||||
} else {
|
||||
0
|
||||
Weight::zero()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +55,7 @@ impl<D: DropAssets, O: Contains<MultiLocation>> DropAssets for FilterOrigin<D, O
|
||||
if O::contains(origin) {
|
||||
D::drop_assets(origin, assets)
|
||||
} else {
|
||||
0
|
||||
Weight::zero()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use frame_support::weights::Weight;
|
||||
use xcm::latest::{Error as XcmError, MultiLocation, QueryId, Response, Result as XcmResult};
|
||||
use sp_runtime::traits::Zero;
|
||||
use xcm::latest::{
|
||||
Error as XcmError, MultiLocation, QueryId, Response, Result as XcmResult, Weight,
|
||||
};
|
||||
|
||||
/// Define what needs to be done upon receiving a query response.
|
||||
pub trait OnResponse {
|
||||
@@ -39,7 +41,7 @@ impl OnResponse for () {
|
||||
_response: Response,
|
||||
_max_weight: Weight,
|
||||
) -> Weight {
|
||||
0
|
||||
Weight::zero()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use frame_support::weights::Weight;
|
||||
use sp_std::result::Result;
|
||||
use xcm::latest::{MultiLocation, Xcm};
|
||||
use xcm::latest::{MultiLocation, Weight, Xcm};
|
||||
|
||||
/// Trait to determine whether the execution engine should actually execute a given XCM.
|
||||
///
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::Assets;
|
||||
use frame_support::weights::Weight;
|
||||
use sp_std::result::Result;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm::latest::{prelude::*, Weight};
|
||||
|
||||
/// Determine the weight of an XCM message.
|
||||
pub trait WeightBounds<Call> {
|
||||
|
||||
@@ -97,8 +97,8 @@ impl pallet_balances::Config for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ReservedXcmpWeight: Weight = WEIGHT_PER_SECOND / 4;
|
||||
pub const ReservedDmpWeight: Weight = WEIGHT_PER_SECOND / 4;
|
||||
pub const ReservedXcmpWeight: Weight = WEIGHT_PER_SECOND.scalar_div(4);
|
||||
pub const ReservedDmpWeight: Weight = WEIGHT_PER_SECOND.scalar_div(4);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -120,7 +120,7 @@ pub type XcmOriginToCallOrigin = (
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const UnitWeightCost: Weight = 1;
|
||||
pub const UnitWeightCost: u64 = 1;
|
||||
pub KsmPerSecond: (AssetId, u128) = (Concrete(Parent.into()), 1);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
}
|
||||
@@ -222,12 +222,14 @@ pub mod mock_msg_queue {
|
||||
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
|
||||
Ok(xcm) => {
|
||||
let location = (1, Parachain(sender.into()));
|
||||
match T::XcmExecutor::execute_xcm(location, xcm, max_weight) {
|
||||
match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) {
|
||||
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
|
||||
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
|
||||
Outcome::Complete(w) =>
|
||||
(Ok(Weight::from_ref_time(w)), Event::Success(Some(hash))),
|
||||
// As far as the caller is concerned, this was dispatched without error, so
|
||||
// we just report the weight used.
|
||||
Outcome::Incomplete(w, e) => (Ok(w), Event::Fail(Some(hash), e)),
|
||||
Outcome::Incomplete(w, e) =>
|
||||
(Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e)),
|
||||
}
|
||||
},
|
||||
Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))),
|
||||
@@ -277,7 +279,8 @@ pub mod mock_msg_queue {
|
||||
Self::deposit_event(Event::UnsupportedVersion(id));
|
||||
},
|
||||
Ok(Ok(x)) => {
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x.clone(), limit);
|
||||
let outcome =
|
||||
T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time());
|
||||
<ReceivedDmp<T>>::append(x);
|
||||
Self::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||
},
|
||||
|
||||
@@ -98,7 +98,7 @@ parameter_types! {
|
||||
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
|
||||
pub const AnyNetwork: NetworkId = NetworkId::Any;
|
||||
pub Ancestry: MultiLocation = Here.into();
|
||||
pub UnitWeightCost: Weight = 1_000;
|
||||
pub UnitWeightCost: u64 = 1_000;
|
||||
}
|
||||
|
||||
pub type SovereignAccountOf =
|
||||
@@ -115,7 +115,7 @@ type LocalOriginConverter = (
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const BaseXcmWeight: Weight = 1_000;
|
||||
pub const BaseXcmWeight: u64 = 1_000;
|
||||
pub KsmPerSecond: (AssetId, u128) = (Concrete(KsmLocation::get()), 1);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ impl pallet_xcm::Config for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const FirstMessageFactorPercent: u64 = 100;
|
||||
pub const FirstMessageFactorPercent: Weight = Weight::from_ref_time(100);
|
||||
}
|
||||
|
||||
impl ump::Config for Runtime {
|
||||
|
||||
@@ -97,8 +97,8 @@ impl pallet_balances::Config for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ReservedXcmpWeight: Weight = WEIGHT_PER_SECOND / 4;
|
||||
pub const ReservedDmpWeight: Weight = WEIGHT_PER_SECOND / 4;
|
||||
pub const ReservedXcmpWeight: Weight = WEIGHT_PER_SECOND.scalar_div(4);
|
||||
pub const ReservedDmpWeight: Weight = WEIGHT_PER_SECOND.scalar_div(4);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -120,7 +120,7 @@ pub type XcmOriginToCallOrigin = (
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const UnitWeightCost: Weight = 1;
|
||||
pub const UnitWeightCost: u64 = 1;
|
||||
pub KsmPerSecond: (AssetId, u128) = (Concrete(Parent.into()), 1);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
}
|
||||
@@ -222,12 +222,14 @@ pub mod mock_msg_queue {
|
||||
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
|
||||
Ok(xcm) => {
|
||||
let location = MultiLocation::new(1, X1(Parachain(sender.into())));
|
||||
match T::XcmExecutor::execute_xcm(location, xcm, max_weight) {
|
||||
match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) {
|
||||
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
|
||||
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
|
||||
Outcome::Complete(w) =>
|
||||
(Ok(Weight::from_ref_time(w)), Event::Success(Some(hash))),
|
||||
// As far as the caller is concerned, this was dispatched without error, so
|
||||
// we just report the weight used.
|
||||
Outcome::Incomplete(w, e) => (Ok(w), Event::Fail(Some(hash), e)),
|
||||
Outcome::Incomplete(w, e) =>
|
||||
(Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e)),
|
||||
}
|
||||
},
|
||||
Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))),
|
||||
@@ -277,7 +279,8 @@ pub mod mock_msg_queue {
|
||||
Self::deposit_event(Event::UnsupportedVersion(id));
|
||||
},
|
||||
Ok(Ok(x)) => {
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x.clone(), limit);
|
||||
let outcome =
|
||||
T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time());
|
||||
<ReceivedDmp<T>>::append(x);
|
||||
Self::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||
},
|
||||
|
||||
@@ -98,7 +98,7 @@ parameter_types! {
|
||||
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
|
||||
pub const AnyNetwork: NetworkId = NetworkId::Any;
|
||||
pub Ancestry: MultiLocation = Here.into();
|
||||
pub UnitWeightCost: Weight = 1_000;
|
||||
pub UnitWeightCost: u64 = 1_000;
|
||||
}
|
||||
|
||||
pub type SovereignAccountOf =
|
||||
@@ -115,7 +115,7 @@ type LocalOriginConverter = (
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const BaseXcmWeight: Weight = 1_000;
|
||||
pub const BaseXcmWeight: u64 = 1_000;
|
||||
pub KsmPerSecond: (AssetId, u128) = (Concrete(KsmLocation::get()), 1);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ impl pallet_xcm::Config for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const FirstMessageFactorPercent: u64 = 100;
|
||||
pub const FirstMessageFactorPercent: Weight = Weight::from_ref_time(100);
|
||||
}
|
||||
|
||||
impl ump::Config for Runtime {
|
||||
|
||||
@@ -243,10 +243,10 @@ macro_rules! decl_test_network {
|
||||
let encoded = $crate::encode_xcm(message, $crate::MessageKind::Ump);
|
||||
let r = <$relay_chain>::process_upward_message(
|
||||
para_id, &encoded[..],
|
||||
$crate::Weight::max_value(),
|
||||
$crate::Weight::MAX,
|
||||
);
|
||||
if let Err((id, required)) = r {
|
||||
return Err($crate::XcmError::WeightLimitReached(required));
|
||||
return Err($crate::XcmError::WeightLimitReached(required.ref_time()));
|
||||
}
|
||||
},
|
||||
$(
|
||||
@@ -255,7 +255,7 @@ macro_rules! decl_test_network {
|
||||
let messages = vec![(para_id, 1, &encoded[..])];
|
||||
let _weight = <$parachain>::handle_xcmp_messages(
|
||||
messages.into_iter(),
|
||||
$crate::Weight::max_value(),
|
||||
$crate::Weight::MAX,
|
||||
);
|
||||
},
|
||||
)*
|
||||
@@ -281,7 +281,7 @@ macro_rules! decl_test_network {
|
||||
// NOTE: RelayChainBlockNumber is hard-coded to 1
|
||||
let messages = vec![(1, encoded)];
|
||||
let _weight = <$parachain>::handle_dmp_messages(
|
||||
messages.into_iter(), $crate::Weight::max_value(),
|
||||
messages.into_iter(), $crate::Weight::MAX,
|
||||
);
|
||||
},
|
||||
)*
|
||||
|
||||
Reference in New Issue
Block a user