-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Conversation
#[cfg(any(feature = "runtime-benchmarks", test))] | ||
fn lease_period_length() -> (T::BlockNumber, T::BlockNumber) { | ||
(T::LeasePeriod::get(), T::LeaseOffset::get()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is only needed for benchmarks, so we hide it from the public API, and therefore eliminate any chance that a user may try to calculate the current of future lease period index on their own.
runtime/common/src/slots.rs
Outdated
let now = frame_system::Pallet::<T>::block_number(); | ||
let current_lease_period = Self::lease_period_index(now).0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most places where we just called lease_period_index
before, we now need to pass the current block number. This is the same logic and complexity as before, just explicit now.
|
||
Balances::make_free_balance_be(&10, 1_000_000_000); | ||
Balances::make_free_balance_be(&20, 1_000_000_000); | ||
for offset in [0u32, 50, 100, 200].iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is basically unchanged except introducing offset
into the timeline of the setup.
runtime/common/src/slots.rs
Outdated
fn lease_period_index(b: T::BlockNumber) -> (Self::LeasePeriod, bool) { | ||
// Note that lease lease period 0 is artificially extended by the lease offset. | ||
let offset_block_now = b.saturating_sub(T::LeaseOffset::get()); | ||
let lease_period = offset_block_now / T::LeasePeriod::get(); | ||
|
||
// Special logic to handle lease period 0 being extended by the offset. | ||
let first_block = if lease_period.is_zero() { | ||
// Lease period 0 has their first block on only block 0. | ||
b.is_zero() | ||
} else { | ||
(offset_block_now % T::LeasePeriod::get()).is_zero() | ||
}; | ||
|
||
(lease_period, first_block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the core change. This is the one source of truth for calculating the current lease period index given some offset. All other APIs must use this to do stuff.
@shawntabrizi , isn't this feature going to bring even more complexity to the parachain lease computations? I still have today to explain people why Moonriver is not ending 48 weeks after it started :p I'm curious, what is the use case for this change ? |
@crystalin It's very useful for a relay chain's governance to decide the exact date at which parachains go live instead of waiting for the next lease period. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
w.r.t. Gav's suggestion I think it could be nice for a relay chain to have fine grained control over the start of lease period 0. But given that the target use case is already past that point I don't see a compelling reason to add the little bit of complexity in handling an Option
from lease_period_index
.
@rphmeier take a look at the last changes made and if it is good for you, feel free to merge. |
* master: (138 commits) Allow an Offset to Lease Periods (#3980) Bump quote from 1.0.9 to 1.0.10 (#4013) Companion for #9834 (Transaction Priority) (#3901) chore: update `builder` image (#3884) Free disputed cores before processing bitfields (#4008) Make candidate validation timeouts configurable (#4001) Add extrinsic ordering filtering (#3631) chore: ci list files that spellcheck finds (#3992) Use background tasks properly in candidate-validation (#4002) Fix unoccupied bitfields (#4004) Bump syn from 1.0.77 to 1.0.78 (#4006) Bump jsonrpsee-ws-client from 0.3.0 to 0.3.1 (#3931) fix clock drift for assignments issued before the block (#3851) Remove unoccupied bit check (#3999) bump substrate (#4000) change genesis authority set for wococo-local, revert rococo-local (#3998) ignore irrelevant approvals in logs (#3859) avoid expect, on free availability core (#3994) preserve finalized block in active leaves (#3997) some tweaks to rococo-local (#3996) ...
* add slot offset for slots * trying things out * fix test * improve api to return the first block of a new lease period * add an integration test with offset * de-duplicate test * hide lease period_period_length from public api * fix benchmarks * Update runtime/common/src/slots.rs * support the exact same range of crowdloans * fix docs * fix docs again * introduce offset to runtimes * fix and check edge case w/ offset and lease period first block * remove newline * turn into an option * fix benchmarks Co-authored-by: Robert Habermeier <[email protected]>
* v0.9.11 weights * Allow an Offset to Lease Periods (#3980) * add slot offset for slots * trying things out * fix test * improve api to return the first block of a new lease period * add an integration test with offset * de-duplicate test * hide lease period_period_length from public api * fix benchmarks * Update runtime/common/src/slots.rs * support the exact same range of crowdloans * fix docs * fix docs again * introduce offset to runtimes * fix and check edge case w/ offset and lease period first block * remove newline * turn into an option * fix benchmarks Co-authored-by: Robert Habermeier <[email protected]> * Polkadot: Remove configuration's runtime migration and just set StorageVersion (#4035) * wip * Remove unused members Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Robert Habermeier <[email protected]> Co-authored-by: Sergei Shulepov <[email protected]>
* Permanent & Temp parachain slots on Rococo - WIP * Revert test change * Revert test change * Fix formatting * Extract logic to separate assigned_slots pallet * Formatting * Parachain downgrade logic * Pallet doc comment * Revert unnecessary changes * Fix few issues, tweak temp slots allocation logic; add a bunch of tests * Address review comments; track active temp slots * Update runtime/common/src/assigned_slots.rs * Update runtime/common/src/assigned_slots.rs * Remove assigned_slots calls from paras_sudo_wrapper * Unassign is a perfectly valid verb * Remove unneeded collect * Update code following #3980 * Cleanup * Generate storage info for pallet * Address review comments * Add ForceOrigin to slots pallet * Track permanent slot duration in storage * Fix tests build Co-authored-by: Alexander Popiak <[email protected]>
Supersedes: #3960
This PR allows the entire crowdloan, slots, auction system to be delayed by a constant block number to do fine adjustments to when the lease period cycle should start. We do this by extending lease period 0 by
LeaseOffset
blocks, which offsets all lease periods by the same amount.A few core level API changes have been introduced which ensures that no existing APIs break due to this new feature. By doing this, we ensure there is a single point of calculation of the current lease period, and every other API just reads from it. So other APIs should not be exposed to any concept of the lease period offset, and the underlying behavior of calculating the current lease period is completely opaque.
fn lease_period()
was renamed tofn lease_period_length()
, returns the offset in addition to the length, and is removed from the public api. We only use it in benchmarking, so we make sure to hide it behind a feature flag so that no external logic would use it unexpectedly.fn lease_period_index()
use to always return the CURRENT lease period for the current block number. We updated the API so that it always accepts an input of the block number we want to query, and it will return both the current lease period for that block, and if that was the first block of a new lease period.BlockNumber
as a generic argument, slightly changing the signature of theLeaser
andAuctioneer
traits. No big deal.fn lease_period_index()
behaves correct with and without an offset.