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

Use Saturating Math in XCM #5845

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ pub mod pallet {
// by the destinations being most sent to.
let mut q = VersionDiscoveryQueue::<T>::take().into_inner();
// TODO: correct weights.
weight_used += T::DbWeight::get().read + T::DbWeight::get().write;
weight_used.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
q.sort_by_key(|i| i.1);
while let Some((versioned_dest, _)) = q.pop() {
if let Ok(dest) = MultiLocation::try_from(versioned_dest) {
if Self::request_version_notify(dest).is_ok() {
// TODO: correct weights.
weight_used += T::DbWeight::get().read + T::DbWeight::get().write;
weight_used.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
break
}
}
Expand Down Expand Up @@ -490,7 +490,7 @@ 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 + w)
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
},
_ => Weight::max_value(),
}
Expand Down Expand Up @@ -528,7 +528,7 @@ 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 + w)
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
},
_ => Weight::max_value(),
}
Expand Down Expand Up @@ -690,7 +690,7 @@ 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 + w)
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
},
_ => Weight::max_value(),
}
Expand Down Expand Up @@ -740,7 +740,7 @@ 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 + w)
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000.saturating_add(w))
},
_ => Weight::max_value(),
}
Expand Down Expand Up @@ -889,17 +889,13 @@ pub mod pallet {
let mut weight_used = 0;

// TODO: Correct weights for the components of this:
let todo_sv_migrate_weight: Weight = T::DbWeight::get().read + T::DbWeight::get().write;
let todo_vn_migrate_weight: Weight = T::DbWeight::get().read + T::DbWeight::get().write;
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_notify_weight: Weight =
T::DbWeight::get().read + T::DbWeight::get().write * 3;
let todo_vnt_migrate_weight: Weight =
T::DbWeight::get().read + T::DbWeight::get().write;
let todo_vnt_migrate_fail_weight: Weight =
T::DbWeight::get().read + T::DbWeight::get().write;
let todo_vnt_notify_migrate_weight: Weight =
T::DbWeight::get().read + T::DbWeight::get().write * 3;
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);
let todo_vnt_notify_migrate_weight: Weight = T::DbWeight::get().reads_writes(1, 3);

use VersionMigrationStage::*;

Expand Down