From 377fd8003f082da73076624771dd34b5f0c7763d Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 29 Mar 2023 17:52:04 +0200 Subject: [PATCH 1/2] pallet nis: remove benchmark hack Signed-off-by: Oliver Tale-Yazdi --- frame/nis/src/benchmarking.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frame/nis/src/benchmarking.rs b/frame/nis/src/benchmarking.rs index 10fee2abe3ba9..0cc9e7421d0e6 100644 --- a/frame/nis/src/benchmarking.rs +++ b/frame/nis/src/benchmarking.rs @@ -164,9 +164,6 @@ benchmarks! { Nis::::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?; Nis::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); frame_system::Pallet::::set_block_number(Receipts::::get(0).unwrap().expiry); - // FIXME: Ensure that the pallet has enough funding. This should already be the case, but - // a rounding error can cause it to fail. - T::Currency::set_balance(&Nis::::account_id(), BalanceOf::::max_value() / 10u32.into()); }: _(RawOrigin::Signed(caller.clone()), 0, None) verify { assert!(Receipts::::get(0).is_none()); @@ -185,9 +182,6 @@ benchmarks! { Nis::::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited()); frame_system::Pallet::::set_block_number(Receipts::::get(0).unwrap().expiry); Nis::::communify(RawOrigin::Signed(caller.clone()).into(), 0)?; - // FIXME: Ensure that the pallet has enough funding. This should already be the case, but - // a rounding error can cause it to fail. - T::Currency::set_balance(&Nis::::account_id(), BalanceOf::::max_value() / 10u32.into()); }: _(RawOrigin::Signed(caller.clone()), 0) verify { assert!(Receipts::::get(0).is_none()); From 1ff7e0def42377b0b14f757808197bfe380c92d4 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 30 Mar 2023 16:01:00 +0200 Subject: [PATCH 2/2] NearestPrefDown -> Down Tested on the kitchensink and in case that n = 10000000000000000 and d = 12000100600000000000000 it rounds the Perquintill up (correctly) since 833326347280+47318160/60000503 should round up. That triggers the path 'amount <= on_hold' in L736. Signed-off-by: Oliver Tale-Yazdi --- frame/nis/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frame/nis/src/lib.rs b/frame/nis/src/lib.rs index 0b8d292ec5f45..4cf5ac801db96 100644 --- a/frame/nis/src/lib.rs +++ b/frame/nis/src/lib.rs @@ -1136,9 +1136,8 @@ pub mod pallet { // Now to activate the bid... let n = amount; let d = issuance.effective; - let proportion = - Perquintill::from_rational_with_rounding(n, d, Rounding::NearestPrefDown) - .defensive_unwrap_or_default(); + let proportion = Perquintill::from_rational_with_rounding(n, d, Rounding::Down) + .defensive_unwrap_or_default(); let who = bid.who; let index = summary.index; summary.proportion_owed.defensive_saturating_accrue(proportion);