From 03c80850963e35187e966b48955ebb3af1e64273 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 1 Aug 2022 02:19:34 +0100 Subject: [PATCH 1/2] saturating xcm --- xcm/pallet-xcm/src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 4959c440ff06..ac732a72127f 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -417,13 +417,17 @@ pub mod pallet { // by the destinations being most sent to. let mut q = VersionDiscoveryQueue::::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 } } @@ -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(), } @@ -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(), } @@ -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(), } @@ -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(), } From 44598c8919b72dbfcdcfbbf44fea00cb062305e8 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 1 Aug 2022 12:13:23 +0200 Subject: [PATCH 2/2] Even more saturating Signed-off-by: Oliver Tale-Yazdi --- xcm/pallet-xcm/src/lib.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index ac732a72127f..6fc6285a600e 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -417,17 +417,13 @@ pub mod pallet { // by the destinations being most sent to. let mut q = VersionDiscoveryQueue::::take().into_inner(); // TODO: correct weights. - weight_used.saturating_accrue( - T::DbWeight::get().read.saturating_add(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.saturating_accrue( - T::DbWeight::get().read.saturating_add(T::DbWeight::get().write), - ); + weight_used.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); break } } @@ -893,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::*;