Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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: 1 addition & 1 deletion substrate/frame/broker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ mod benches {
let core_count = n.try_into().unwrap();
let config = new_config_record::<T>();

let now = frame_system::Pallet::<T>::block_number();
let now = Broker::<T>::now();
let price = 10u32.into();
let commit_timeslice = Broker::<T>::latest_timeslice_ready_to_commit(&config);
let sale = SaleInfoRecordOf::<T> {
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/broker/src/dispatchable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<T: Config> Pallet<T> {
last_committed_timeslice: commit_timeslice.saturating_sub(1),
last_timeslice: Self::current_timeslice(),
};
let now = frame_system::Pallet::<T>::block_number();
let now = Self::now();
let new_sale = SaleInfoRecord {
sale_start: now,
leadin_length: Zero::zero(),
Expand All @@ -107,7 +107,7 @@ impl<T: Config> Pallet<T> {
let mut sale = SaleInfo::<T>::get().ok_or(Error::<T>::NoSales)?;
ensure!(sale.first_core < status.core_count, Error::<T>::Unavailable);
ensure!(sale.cores_sold < sale.cores_offered, Error::<T>::SoldOut);
let now = frame_system::Pallet::<T>::block_number();
let now = Self::now();
ensure!(now > sale.sale_start, Error::<T>::TooEarly);
let price = Self::sale_price(&sale, now);
ensure!(price_limit >= price, Error::<T>::Overpriced);
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<T: Config> Pallet<T> {

let begin = sale.region_end;
let price_cap = record.price + config.renewal_bump * record.price;
let now = frame_system::Pallet::<T>::block_number();
let now = Self::now();
let price = Self::sale_price(&sale, now).min(price_cap);
let new_record = AllowedRenewalRecord { price, completion: Complete(workload) };
AllowedRenewals::<T>::remove(renewal_id);
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ pub mod pallet {
},
/// A new sale has been initialized.
SaleInitialized {
/// The local block number at which the sale will/did start.
sale_start: BlockNumberFor<T>,
/// The relay block number at which the sale will/did start.
sale_start: RelayBlockNumberOf<T>,
/// The length in blocks of the Leadin Period (where the price is decreasing).
leadin_length: BlockNumberFor<T>,
leadin_length: RelayBlockNumberOf<T>,
/// The price of Bulk Coretime at the beginning of the Leadin Period.
start_price: BalanceOf<T>,
/// The price of Bulk Coretime after the Leadin Period.
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/broker/src/test_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ where
_provenance: Provenance,
) -> DepositConsequence {
if !Self::asset_exists(asset) {
return DepositConsequence::UnknownAsset
return DepositConsequence::UnknownAsset;
}
if amount + Self::balance(asset, who) < Self::minimum_balance(asset) {
return DepositConsequence::BelowMinimum
return DepositConsequence::BelowMinimum;
}
DepositConsequence::Success
}
Expand All @@ -112,10 +112,10 @@ where
) -> WithdrawConsequence<Self::Balance> {
if Self::reducible_balance(asset, who, Preservation::Expendable, Fortitude::Polite) < amount
{
return WithdrawConsequence::BalanceLow
return WithdrawConsequence::BalanceLow;
}
if Self::total_balance(asset, who) < Self::minimum_balance(asset) + amount {
return WithdrawConsequence::WouldDie
return WithdrawConsequence::WouldDie;
}
WithdrawConsequence::Success
}
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/broker/src/tick_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<T: Config> Pallet<T> {
if let Some(core_count) = CoreCountInbox::<T>::take() {
status.core_count = core_count;
Self::deposit_event(Event::<T>::CoreCountChanged { core_count });
return true
return true;
}
false
}
Expand All @@ -103,12 +103,12 @@ impl<T: Config> Pallet<T> {
if revenue.is_zero() {
Self::deposit_event(Event::<T>::HistoryDropped { when, revenue });
InstaPoolHistory::<T>::remove(when);
return true
return true;
}
let mut r = InstaPoolHistory::<T>::get(when).unwrap_or_default();
if r.maybe_payout.is_some() {
Self::deposit_event(Event::<T>::HistoryIgnored { when, revenue });
return true
return true;
}
// Payout system InstaPool Cores.
let total_contrib = r.system_contributions.saturating_add(r.private_contributions);
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<T: Config> Pallet<T> {
config: &ConfigRecordOf<T>,
status: &StatusRecord,
) -> Option<()> {
let now = frame_system::Pallet::<T>::block_number();
let now = Self::now();

let pool_item =
ScheduleItem { assignment: CoreAssignment::Pool, mask: CoreMask::complete() };
Expand Down Expand Up @@ -320,7 +320,7 @@ impl<T: Config> Pallet<T> {
if let Some(ref mut last) = assignment.last_mut() {
if last.0 == i.0 {
last.1 += i.1;
continue
continue;
}
}
assignment.push(i);
Expand Down
20 changes: 10 additions & 10 deletions substrate/frame/broker/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::traits::fungible::Inspect;
use frame_system::{pallet_prelude::BlockNumberFor, Config as SConfig};
use frame_system::Config as SConfig;
use scale_info::TypeInfo;
use sp_arithmetic::Perbill;
use sp_core::{ConstU32, RuntimeDebug};
Expand Down Expand Up @@ -206,7 +206,7 @@ pub struct PoolIoRecord {
/// The status of a Bulk Coretime Sale.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct SaleInfoRecord<Balance, BlockNumber> {
/// The local block number at which the sale will/did start.
/// The relay block number at which the sale will/did start.
pub sale_start: BlockNumber,
/// The length in blocks of the Leadin Period (where the price is decreasing).
pub leadin_length: BlockNumber,
Expand All @@ -231,7 +231,7 @@ pub struct SaleInfoRecord<Balance, BlockNumber> {
/// Number of cores which have been sold; never more than cores_offered.
pub cores_sold: CoreIndex,
}
pub type SaleInfoRecordOf<T> = SaleInfoRecord<BalanceOf<T>, BlockNumberFor<T>>;
pub type SaleInfoRecordOf<T> = SaleInfoRecord<BalanceOf<T>, RelayBlockNumberOf<T>>;

/// Record for Polkadot Core reservations (generally tasked with the maintenance of System
/// Chains).
Expand All @@ -253,14 +253,14 @@ pub type LeasesRecordOf<T> = LeasesRecord<<T as Config>::MaxLeasedCores>;

/// Configuration of this pallet.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct ConfigRecord<BlockNumber, RelayBlockNumber> {
pub struct ConfigRecord<RelayBlockNumber> {
/// The number of Relay-chain blocks in advance which scheduling should be fixed and the
/// `Coretime::assign` API used to inform the Relay-chain.
pub advance_notice: RelayBlockNumber,
/// The length in blocks of the Interlude Period for forthcoming sales.
pub interlude_length: BlockNumber,
pub interlude_length: RelayBlockNumber,
/// The length in blocks of the Leadin Period for forthcoming sales.
pub leadin_length: BlockNumber,
pub leadin_length: RelayBlockNumber,
/// The length in timeslices of Regions which are up for sale in forthcoming sales.
pub region_length: Timeslice,
/// The proportion of cores available for sale which should be sold in order for the price
Expand All @@ -274,16 +274,16 @@ pub struct ConfigRecord<BlockNumber, RelayBlockNumber> {
/// The duration by which rewards for contributions to the InstaPool must be collected.
pub contribution_timeout: Timeslice,
}
pub type ConfigRecordOf<T> = ConfigRecord<BlockNumberFor<T>, RelayBlockNumberOf<T>>;
pub type ConfigRecordOf<T> = ConfigRecord<RelayBlockNumberOf<T>>;

impl<BlockNumber, RelayBlockNumber> ConfigRecord<BlockNumber, RelayBlockNumber>
impl<RelayBlockNumber> ConfigRecord<RelayBlockNumber>
where
BlockNumber: sp_arithmetic::traits::Zero,
RelayBlockNumber: sp_arithmetic::traits::Zero,
{
/// Check the config for basic validity constraints.
pub(crate) fn validate(&self) -> Result<(), ()> {
if self.leadin_length.is_zero() {
return Err(())
return Err(());
}

Ok(())
Expand Down
10 changes: 7 additions & 3 deletions substrate/frame/broker/src/utility_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use frame_support::{
OnUnbalanced,
},
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_arithmetic::{
traits::{SaturatedConversion, Saturating},
FixedPointNumber, FixedU64,
Expand Down Expand Up @@ -60,7 +59,7 @@ impl<T: Config> Pallet<T> {
T::PalletId::get().into_account_truncating()
}

pub fn sale_price(sale: &SaleInfoRecordOf<T>, now: BlockNumberFor<T>) -> BalanceOf<T> {
pub fn sale_price(sale: &SaleInfoRecordOf<T>, now: RelayBlockNumberOf<T>) -> BalanceOf<T> {
let num = now.saturating_sub(sale.sale_start).min(sale.leadin_length).saturated_into();
let through = FixedU64::from_rational(num, sale.leadin_length.saturated_into());
T::PriceAdapter::leadin_factor_at(through).saturating_mul_int(sale.price)
Expand Down Expand Up @@ -105,7 +104,7 @@ impl<T: Config> Pallet<T> {
region_id.begin = last_committed_timeslice + 1;
if region_id.begin >= region.end {
Self::deposit_event(Event::RegionDropped { region_id, duration });
return Ok(None)
return Ok(None);
}
} else {
Workplan::<T>::mutate_extant((region_id.begin, region_id.core), |p| {
Expand All @@ -118,4 +117,9 @@ impl<T: Config> Pallet<T> {

Ok(Some((region_id, region)))
}

/// Returns the current block number of Relay Chain
pub(crate) fn now() -> RelayBlockNumberOf<T> {
<<<T as crate::Config>::Coretime as CoretimeInterface>::RelayChainBlockNumberProvider as BlockNumberProvider>::current_block_number()
}
}