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 1 commit
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
16 changes: 10 additions & 6 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,17 @@ 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().read.saturating_add(T::DbWeight::get().write),
);
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().read.saturating_add(T::DbWeight::get().write),
);
break
}
}
Expand Down Expand Up @@ -490,7 +494,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 +532,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 +694,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 +744,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