From b64d9885ada8f575a58cdc5e05b4b2172ed1297b Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 16 Jun 2021 11:19:41 +0100 Subject: [PATCH] use safe math (#3249) --- polkadot/xcm/xcm-builder/src/weight.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/xcm/xcm-builder/src/weight.rs b/polkadot/xcm/xcm-builder/src/weight.rs index 529f0c7cb1..b627db9c75 100644 --- a/polkadot/xcm/xcm-builder/src/weight.rs +++ b/polkadot/xcm/xcm-builder/src/weight.rs @@ -27,9 +27,9 @@ impl, C: Decode + GetDispatchInfo> WeightBounds for FixedWeigh fn shallow(message: &mut Xcm) -> Result { 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, .. } @@ -46,7 +46,7 @@ impl, C: Decode + GetDispatchInfo> WeightBounds for FixedWeigh }, _ => T::get(), }).sum(); - T::get() + inner + T::get().saturating_add(inner) } _ => T::get(), }) @@ -63,7 +63,7 @@ impl, C: Decode + GetDispatchInfo> WeightBounds 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)?)); } }, _ => {}