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

add slot offset for slots #3960

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions runtime/common/src/crowdloan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ pub mod pallet {
ensure!(end > <frame_system::Pallet<T>>::block_number(), Error::<T>::CannotEndInPast);
let last_possible_win_date = (first_period.saturating_add(One::one()))
.saturating_mul(T::Auctioneer::lease_period());

// TODO [now]: sanity check doesn't seem to account for lease offset.
ensure!(end <= last_possible_win_date, Error::<T>::EndTooFarInFuture);
ensure!(
first_period >= T::Auctioneer::lease_period_index(),
Expand Down
3 changes: 3 additions & 0 deletions runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@ impl auctions::Config for Test {

parameter_types! {
pub const LeasePeriod: BlockNumber = 100;
pub const LeaseOffset: BlockNumber = 0;
// TODO [now]: test with non-zero offset
}

impl slots::Config for Test {
type Event = Event;
type Currency = Balances;
type Registrar = Registrar;
type LeasePeriod = LeasePeriod;
type LeaseOffset = LeaseOffset;
type WeightInfo = crate::slots::TestWeightInfo;
}

Expand Down
18 changes: 16 additions & 2 deletions runtime/common/src/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ pub mod pallet {
#[pallet::constant]
type LeasePeriod: Get<Self::BlockNumber>;

/// The number of blocks to offset each lease period by.
#[pallet::constant]
type LeaseOffset: Get<Self::BlockNumber>;

/// Weight Information for the Extrinsics in the Pallet
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -140,7 +144,9 @@ pub mod pallet {
fn on_initialize(n: T::BlockNumber) -> Weight {
// If we're beginning a new lease period then handle that.
let lease_period = T::LeasePeriod::get();
if (n % lease_period).is_zero() {
let lease_offset = T::LeaseOffset::get();

if n >= lease_offset && ((n - lease_offset) % lease_period).is_zero() {
let lease_period_index = n / lease_period;
Self::manage_lease_period_start(lease_period_index)
} else {
Expand Down Expand Up @@ -432,7 +438,12 @@ impl<T: Config> Leaser for Pallet<T> {
}

fn lease_period_index() -> Self::LeasePeriod {
<frame_system::Pallet<T>>::block_number() / T::LeasePeriod::get()
// TODO [now]: perhaps this should be an 'Option'? Lease period
// 0 is artificially extended by this implementation.
let offset_block_now = <frame_system::Pallet<T>>::block_number()
.saturating_sub(T::LeaseOffset::get());

offset_block_now / T::LeasePeriod::get()
}

fn already_leased(
Expand Down Expand Up @@ -545,6 +556,8 @@ mod tests {

parameter_types! {
pub const LeasePeriod: BlockNumber = 10;
pub const LeaseOffset: BlockNumber = 0;
// TODO [now]: test with non-zero offset.
pub const ParaDeposit: u64 = 1;
}

Expand All @@ -553,6 +566,7 @@ mod tests {
type Currency = Balances;
type Registrar = TestRegistrar<Test>;
type LeasePeriod = LeasePeriod;
type LeaseOffset = LeaseOffset;
type WeightInfo = crate::slots::TestWeightInfo;
}

Expand Down