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

Commit

Permalink
NIS should retain funds in reserve (#12928)
Browse files Browse the repository at this point in the history
* Keep funds with receipt holder

* Counterpart is optional

* Use named reserves

* Tests

* Benchmarks

* Fixes

* Update frame/nis/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update frame/nis/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update frame/nis/src/lib.rs

* Update frame/nis/src/lib.rs

* Update frame/nis/src/tests.rs

* Update frame/nis/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/nis/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/nis/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/nis/src/lib.rs

* Update frame/nis/src/lib.rs

* Update frame/nis/src/lib.rs

* Update frame/nis/src/lib.rs

* Formatting

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
3 people committed Jan 17, 2023
1 parent 2893730 commit 6bac243
Show file tree
Hide file tree
Showing 7 changed files with 828 additions and 309 deletions.
2 changes: 2 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,7 @@ parameter_types! {
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
pub Target: Perquintill = Perquintill::zero();
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
pub const NisReserveId: [u8; 8] = *b"py/nis ";
}

impl pallet_nis::Config for Runtime {
Expand All @@ -1522,6 +1523,7 @@ impl pallet_nis::Config for Runtime {
type IntakePeriod = IntakePeriod;
type MaxIntakeWeight = MaxIntakeWeight;
type ThawThrottle = ThawThrottle;
type ReserveId = NisReserveId;
}

parameter_types! {
Expand Down
41 changes: 39 additions & 2 deletions frame/nis/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::traits::{Currency, EnsureOrigin, Get};
use frame_support::traits::{nonfungible::Inspect, Currency, EnsureOrigin, Get};
use frame_system::RawOrigin;
use sp_arithmetic::Perquintill;
use sp_runtime::{
Expand Down Expand Up @@ -106,6 +106,7 @@ benchmarks! {
T::Currency::make_free_balance_be(&caller, bid);
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?;
Nis::<T>::process_queues(Perquintill::one(), 1, 1, &mut WeightCounter::unlimited());
Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?;
let original = T::Currency::free_balance(&Nis::<T>::account_id());
T::Currency::make_free_balance_be(&Nis::<T>::account_id(), BalanceOf::<T>::min_value());
}: _<T::RuntimeOrigin>(origin)
Expand All @@ -116,7 +117,7 @@ benchmarks! {
assert!(missing <= Perquintill::one() / 100_000);
}

thaw {
thaw_private {
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Expand All @@ -128,6 +129,42 @@ benchmarks! {
assert!(Receipts::<T>::get(0).is_none());
}

thaw_communal {
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited());
Receipts::<T>::mutate(0, |m_g| if let Some(ref mut g) = m_g { g.expiry = Zero::zero() });
Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?;
}: _(RawOrigin::Signed(caller.clone()), 0)
verify {
assert!(Receipts::<T>::get(0).is_none());
}

privatize {
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited());
Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?;
}: _(RawOrigin::Signed(caller.clone()), 0)
verify {
assert_eq!(Nis::<T>::owner(&0), Some(caller));
}

communify {
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited());
}: _(RawOrigin::Signed(caller.clone()), 0)
verify {
assert_eq!(Nis::<T>::owner(&0), None);
}

process_queues {
fill_queues::<T>()?;
}: {
Expand Down
Loading

0 comments on commit 6bac243

Please sign in to comment.