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

Use Safe Math in XCM Builder #3249

Merged
1 commit merged into from
Jun 16, 2021
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
8 changes: 4 additions & 4 deletions xcm/xcm-builder/src/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl<T: Get<Weight>, C: Decode + GetDispatchInfo> WeightBounds<C> for FixedWeigh
fn shallow(message: &mut Xcm<C>) -> Result<Weight, ()> {
Ok(match message {
Xcm::Transact { call, .. } => {
call.ensure_decoded()?.get_dispatch_info().weight + T::get()
call.ensure_decoded()?.get_dispatch_info().weight.saturating_add(T::get())
}
Xcm::RelayedFrom { ref mut message, .. } => T::get() + Self::shallow(message.as_mut())?,
Xcm::RelayedFrom { ref mut message, .. } => T::get().saturating_add(Self::shallow(message.as_mut())?),
Xcm::WithdrawAsset { effects, .. }
| Xcm::ReserveAssetDeposit { effects, .. }
| Xcm::TeleportAsset { effects, .. }
Expand All @@ -46,7 +46,7 @@ impl<T: Get<Weight>, C: Decode + GetDispatchInfo> WeightBounds<C> for FixedWeigh
},
_ => T::get(),
}).sum();
T::get() + inner
T::get().saturating_add(inner)
}
_ => T::get(),
})
Expand All @@ -63,7 +63,7 @@ impl<T: Get<Weight>, C: Decode + GetDispatchInfo> WeightBounds<C> for FixedWeigh
match effect {
Order::BuyExecution { xcm, .. } => {
for message in xcm.iter_mut() {
extra += Self::shallow(message)? + Self::deep(message)?;
extra.saturating_accrue(Self::shallow(message)?.saturating_add(Self::deep(message)?));
}
},
_ => {}
Expand Down