Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d598a1e
Price adjustements should be based on price
May 10, 2024
ae90650
AllowedRenewal -> PotentialRenewal
May 20, 2024
2855832
WIP: New price based `AdaptPrice` trait.
May 20, 2024
627acf7
Pub
May 21, 2024
31ea3a9
Also adjust sellout_price on renew.
May 21, 2024
63f5856
Adapt price implementation.
May 21, 2024
3630ccc
Some tests + handle going down to zero gracefully.
May 21, 2024
b615fbe
Fix tests.
May 21, 2024
fd03dc1
More linear tests.
May 21, 2024
6fdc11b
Add prdoc.
May 22, 2024
cb5485d
Put base price in the middle of the range.
May 23, 2024
9299010
new leadin curve.
May 23, 2024
28f13f4
price -> base_price
May 23, 2024
4b5a66d
Fmt
May 23, 2024
fad4aab
base_price -> min_price
May 24, 2024
4979fbb
Merge branch 'master' into rk-broker-new-price-adapter
May 27, 2024
5869882
New example adapter name + more parameters (cores)
May 27, 2024
baeab0e
Fix kitchensink
May 27, 2024
aa4defc
Some logging + test.
May 27, 2024
d5992b4
Fix prdoc
May 27, 2024
03db451
regular_price -> end_price
May 27, 2024
d67dfc4
Fixes.
May 27, 2024
edeaf69
Merge remote-tracking branch 'origin/master' into rk-broker-new-price…
May 27, 2024
890e6ca
Fix benchmarks
May 27, 2024
66bce5a
Update prdoc/pr_4521.prdoc
eskimor May 29, 2024
fbe5241
min_price -> end_price
May 29, 2024
fdf764e
Better docs for target_price.
May 29, 2024
86ec07c
Improved prdoc
May 29, 2024
1ca75af
Merge remote-tracking branch 'origin/rk-broker-new-price-adapter' int…
May 29, 2024
2a940a5
Make change major again.
May 29, 2024
52e0b80
One more test.
May 29, 2024
812f66c
Add migration for name change `PotentialRenewals`.
May 29, 2024
ae20d3c
Merge remote-tracking branch 'origin/master' into rk-broker-new-price…
May 29, 2024
7e2992c
Fix prdoc?
May 29, 2024
654d1e4
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 29, 2024
4cc238a
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 29, 2024
d6857aa
Change bump to minor again to make CI happy.
May 29, 2024
c98a945
Merge remote-tracking branch 'origin/rk-broker-new-price-adapter' int…
May 29, 2024
d179b89
prdoc fix
May 29, 2024
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
Prev Previous commit
Next Next commit
min_price -> end_price
  • Loading branch information
eskimor committed May 29, 2024
commit fbe52414cbe075ad7ae7df9e69b11d0ffaf05a38
40 changes: 20 additions & 20 deletions substrate/frame/broker/src/adapt_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct SalePerformance<Balance> {
pub sellout_price: Option<Balance>,

/// The minimum price that was achieved in this sale.
pub min_price: Balance,
pub end_price: Balance,

/// The number of cores we want to sell, ideally.
pub ideal_cores_sold: CoreIndex,
Expand All @@ -46,7 +46,7 @@ pub struct SalePerformance<Balance> {
#[derive(Copy, Clone)]
pub struct AdaptedPrices<Balance> {
/// New minimum price to use.
pub min_price: Balance,
pub end_price: Balance,
/// Price we optimize for.
pub target_price: Balance,
}
Expand All @@ -56,16 +56,16 @@ impl<Balance: Copy> SalePerformance<Balance> {
pub fn from_sale<BlockNumber>(record: &SaleInfoRecord<Balance, BlockNumber>) -> Self {
Self {
sellout_price: record.sellout_price,
min_price: record.min_price,
end_price: record.end_price,
ideal_cores_sold: record.ideal_cores_sold,
cores_offered: record.cores_offered,
cores_sold: record.cores_sold,
}
}

#[cfg(test)]
fn new(sellout_price: Option<Balance>, min_price: Balance) -> Self {
Self { sellout_price, min_price, ideal_cores_sold: 0, cores_offered: 0, cores_sold: 0 }
fn new(sellout_price: Option<Balance>, end_price: Balance) -> Self {
Self { sellout_price, end_price, ideal_cores_sold: 0, cores_offered: 0, cores_sold: 0 }
}
}

Expand All @@ -87,8 +87,8 @@ impl<Balance: Copy> AdaptPrice<Balance> for () {
FixedU64::one()
}
fn adapt_price(performance: SalePerformance<Balance>) -> AdaptedPrices<Balance> {
let price = performance.sellout_price.unwrap_or(performance.min_price);
AdaptedPrices { min_price: price, target_price: price }
let price = performance.sellout_price.unwrap_or(performance.end_price);
AdaptedPrices { end_price: price, target_price: price }
}
}

Expand All @@ -110,8 +110,8 @@ impl<Balance: FixedPointOperand> AdaptPrice<Balance> for CenterTargetPrice<Balan
fn adapt_price(performance: SalePerformance<Balance>) -> AdaptedPrices<Balance> {
let Some(sellout_price) = performance.sellout_price else {
return AdaptedPrices {
min_price: performance.min_price,
target_price: FixedU64::from(10).saturating_mul_int(performance.min_price),
end_price: performance.end_price,
target_price: FixedU64::from(10).saturating_mul_int(performance.end_price),
}
};

Expand All @@ -123,7 +123,7 @@ impl<Balance: FixedPointOperand> AdaptPrice<Balance> for CenterTargetPrice<Balan
price
};

AdaptedPrices { min_price: price, target_price: sellout_price }
AdaptedPrices { end_price: price, target_price: sellout_price }
}
}

Expand All @@ -145,7 +145,7 @@ mod tests {
fn no_op_sale_is_good() {
let prices = CenterTargetPrice::adapt_price(SalePerformance::new(None, 1));
assert_eq!(prices.target_price, 10);
assert_eq!(prices.min_price, 1);
assert_eq!(prices.end_price, 1);
}

#[test]
Expand All @@ -155,10 +155,10 @@ mod tests {
for _ in 0..10 {
let prices = CenterTargetPrice::adapt_price(performance);
performance.sellout_price = Some(1000);
performance.min_price = prices.min_price;
performance.end_price = prices.end_price;

assert!(prices.min_price <= 101);
assert!(prices.min_price >= 99);
assert!(prices.end_price <= 101);
assert!(prices.end_price >= 99);
assert!(prices.target_price <= 1001);
assert!(prices.target_price >= 999);
}
Expand All @@ -169,15 +169,15 @@ mod tests {
let performance = SalePerformance::new(Some(10_000), 100);
let prices = CenterTargetPrice::adapt_price(performance);
assert_eq!(prices.target_price, 10_000);
assert_eq!(prices.min_price, 1000);
assert_eq!(prices.end_price, 1000);
}

#[test]
fn price_adjusts_correctly_downwards() {
let performance = SalePerformance::new(Some(100), 100);
let prices = CenterTargetPrice::adapt_price(performance);
assert_eq!(prices.target_price, 100);
assert_eq!(prices.min_price, 10);
assert_eq!(prices.end_price, 10);
}

#[test]
Expand All @@ -188,10 +188,10 @@ mod tests {
for _ in 0..11 {
let prices = CenterTargetPrice::adapt_price(performance);
performance.sellout_price = Some(sellout_price);
performance.min_price = prices.min_price;
performance.end_price = prices.end_price;

assert!(prices.min_price <= sellout_price);
assert!(prices.min_price > 0);
assert!(prices.end_price <= sellout_price);
assert!(prices.end_price > 0);
}
}

Expand All @@ -200,7 +200,7 @@ mod tests {
let performance = SalePerformance::new(None, 100);
let prices = CenterTargetPrice::adapt_price(performance);
assert_eq!(prices.target_price, 1000);
assert_eq!(prices.min_price, 100);
assert_eq!(prices.end_price, 100);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/broker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,12 @@ mod benches {
let config = new_config_record::<T>();

let now = frame_system::Pallet::<T>::block_number();
let min_price = 10u32.into();
let end_price = 10u32.into();
let commit_timeslice = Broker::<T>::latest_timeslice_ready_to_commit(&config);
let sale = SaleInfoRecordOf::<T> {
sale_start: now,
leadin_length: Zero::zero(),
min_price,
end_price,
sellout_price: None,
region_begin: commit_timeslice,
region_end: commit_timeslice.saturating_add(config.region_length),
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 @@ -71,7 +71,7 @@ impl<T: Config> Pallet<T> {
}

pub(crate) fn do_start_sales(
min_price: BalanceOf<T>,
end_price: BalanceOf<T>,
extra_cores: CoreIndex,
) -> DispatchResult {
let config = Configuration::<T>::get().ok_or(Error::<T>::Uninitialized)?;
Expand All @@ -96,7 +96,7 @@ impl<T: Config> Pallet<T> {
let old_sale = SaleInfoRecord {
sale_start: now,
leadin_length: Zero::zero(),
min_price,
end_price,
sellout_price: None,
region_begin: commit_timeslice,
region_end: commit_timeslice.saturating_add(config.region_length),
Expand All @@ -105,7 +105,7 @@ impl<T: Config> Pallet<T> {
cores_offered: 0,
cores_sold: 0,
};
Self::deposit_event(Event::<T>::SalesStarted { price: min_price, core_count });
Self::deposit_event(Event::<T>::SalesStarted { price: end_price, core_count });
Self::rotate_sale(old_sale, &config, &status);
Status::<T>::put(&status);
Ok(())
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 @@ -559,7 +559,7 @@ pub mod pallet {
/// Begin the Bulk Coretime sales rotation.
///
/// - `origin`: Must be Root or pass `AdminOrigin`.
/// - `min_price`: The price after the leadin period of Bulk Coretime in the first sale.
/// - `end_price`: The price after the leadin period of Bulk Coretime in the first sale.
/// - `extra_cores`: Number of extra cores that should be requested on top of the cores
/// required for `Reservations` and `Leases`.
///
Expand All @@ -571,11 +571,11 @@ pub mod pallet {
))]
pub fn start_sales(
origin: OriginFor<T>,
min_price: BalanceOf<T>,
end_price: BalanceOf<T>,
extra_cores: CoreIndex,
) -> DispatchResultWithPostInfo {
T::AdminOrigin::ensure_origin_or_root(origin)?;
Self::do_start_sales(min_price, extra_cores)?;
Self::do_start_sales(end_price, extra_cores)?;
Ok(Pays::No.into())
}

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/broker/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ fn purchase_requires_valid_status_and_sale_info() {
let mut dummy_sale = SaleInfoRecord {
sale_start: 0,
leadin_length: 0,
min_price: 200,
end_price: 200,
sellout_price: None,
region_begin: 0,
region_end: 3,
Expand Down Expand Up @@ -1214,7 +1214,7 @@ fn renewal_requires_valid_status_and_sale_info() {
let mut dummy_sale = SaleInfoRecord {
sale_start: 0,
leadin_length: 0,
min_price: 200,
end_price: 200,
sellout_price: None,
region_begin: 0,
region_end: 3,
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/broker/src/tick_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<T: Config> Pallet<T> {

log::debug!(
"Rotated sale, new prices: {:?}, {:?}",
new_prices.min_price,
new_prices.end_price,
new_prices.target_price
);

Expand Down Expand Up @@ -228,7 +228,7 @@ impl<T: Config> Pallet<T> {
let ideal_cores_sold = (config.ideal_bulk_proportion * cores_offered as u32) as u16;
let sellout_price = if cores_offered > 0 {
// No core sold -> price was too high -> we have to adjust downwards.
Some(new_prices.min_price)
Some(new_prices.end_price)
} else {
None
};
Expand All @@ -237,7 +237,7 @@ impl<T: Config> Pallet<T> {
let new_sale = SaleInfoRecord {
sale_start,
leadin_length,
min_price: new_prices.min_price,
end_price: new_prices.end_price,
sellout_price,
region_begin,
region_end,
Expand All @@ -252,7 +252,7 @@ impl<T: Config> Pallet<T> {
sale_start,
leadin_length,
start_price: Self::sale_price(&new_sale, now),
end_price: new_prices.min_price,
end_price: new_prices.end_price,
region_begin,
region_end,
ideal_cores_sold,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/broker/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub struct SaleInfoRecord<Balance, BlockNumber> {
/// The length in blocks of the Leadin Period (where the price is decreasing).
pub leadin_length: BlockNumber,
/// The price of Bulk Coretime after the Leadin Period.
pub min_price: Balance,
pub end_price: Balance,
/// The first timeslice of the Regions which are being sold in this sale.
pub region_begin: Timeslice,
/// The timeslice on which the Regions which are being sold in the sale terminate. (i.e. One
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/broker/src/utility_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<T: Config> Pallet<T> {
pub fn sale_price(sale: &SaleInfoRecordOf<T>, now: BlockNumberFor<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.min_price)
T::PriceAdapter::leadin_factor_at(through).saturating_mul_int(sale.end_price)
}

pub(crate) fn charge(who: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
Expand Down