Skip to content

Commit

Permalink
solve timeslice issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Aug 9, 2024
1 parent 613d2da commit 58245a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pallets/regions/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ mod benchmarks {
let caller: T::AccountId = whitelisted_caller();
let owner: T::AccountId = account("alice", 0, SEED);

let region_id = RegionId { begin: 1, core: 72, mask: CoreMask::complete() };
let record: RegionRecordOf<T> = RegionRecord { end: 2, owner, paid: None };
let region_id = RegionId { begin: 0, core: 72, mask: CoreMask::complete() };
let record: RegionRecordOf<T> = RegionRecord { end: 0, owner, paid: None };

assert_ok!(crate::Pallet::<T>::mint_into(&region_id.into(), &caller));
assert_ok!(crate::Pallet::<T>::request_region_record(RawOrigin::None.into(), region_id));
Expand Down
7 changes: 7 additions & 0 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,14 @@ pub mod pallet {

if let Record::Available(record) = region.record {
// Cannot drop a region that is not expired yet.

// Allowing region removal 1 timeslice before it truly expires makes writing
// benchmarks much easier. With this we can set the start and end to 0 and be able to
// drop the region without having to modify the current timeslice.
let current_timeslice = Self::current_timeslice();
#[cfg(feature = "runtime-benchmarks")]
ensure!(record.end <= current_timeslice, Error::<T>::RegionNotExpired);
#[cfg(not(feature = "runtime-benchmarks"))]
ensure!(record.end < current_timeslice, Error::<T>::RegionNotExpired);

Regions::<T>::remove(region_id);
Expand Down

0 comments on commit 58245a1

Please sign in to comment.