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:
Shawn Tabrizi
2022-08-31 12:59:39 +01:00
committed by GitHub
parent 138aae0a22
commit 28e94d97dd
231 changed files with 4577 additions and 4514 deletions
+25 -19
View File
@@ -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);
+3 -3
View File
@@ -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;
+6 -5
View File
@@ -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);