pallet_broker: Let start_sales calculate and request the correct core count (#4221)

This commit is contained in:
Bastian Köcher
2024-04-23 17:37:24 +02:00
committed by GitHub
parent eda5e5c31f
commit ffbce2a817
5 changed files with 68 additions and 26 deletions
+9 -14
View File
@@ -559,27 +559,22 @@ pub mod pallet {
///
/// - `origin`: Must be Root or pass `AdminOrigin`.
/// - `initial_price`: The price of Bulk Coretime in the first sale.
/// - `total_core_count`: This is the total number of cores the relay chain should have
/// after the sale concludes.
/// - `extra_cores`: Number of extra cores that should be requested on top of the cores
/// required for `Reservations` and `Leases`.
///
/// NOTE: This function does not actually request that new core count from the relay chain.
/// You need to make sure to call `request_core_count` afterwards to bring the relay chain
/// in sync.
///
/// When to call the function depends on the new core count. If it is larger than what it
/// was before, you can call it immediately or even before `start_sales` as non allocated
/// cores will just be `Idle`. If you are actually reducing the number of cores, you should
/// call `request_core_count`, right before the next sale, to avoid shutting down tasks too
/// early.
/// This will call [`Self::request_core_count`] internally to set the correct core count on
/// the relay chain.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::start_sales((*total_core_count).into()))]
#[pallet::weight(T::WeightInfo::start_sales(
T::MaxLeasedCores::get() + T::MaxReservedCores::get() + *extra_cores as u32
))]
pub fn start_sales(
origin: OriginFor<T>,
initial_price: BalanceOf<T>,
total_core_count: CoreIndex,
extra_cores: CoreIndex,
) -> DispatchResultWithPostInfo {
T::AdminOrigin::ensure_origin_or_root(origin)?;
Self::do_start_sales(initial_price, total_core_count)?;
Self::do_start_sales(initial_price, extra_cores)?;
Ok(Pays::No.into())
}