Skip to content

Commit 2539cb5

Browse files
eskimoreskimorseadanda
authored
Adjust to new Broker pallet. (#334)
<!-- Remember that you can run `/merge` to enable auto-merge in the PR --> <!-- Remember to modify the changelog. If you don't need to modify it, you can check the following box. Instead, if you have already modified it, simply delete the following line. --> - [ ] Does not require a CHANGELOG entry --------- Co-authored-by: eskimor <eskimor@no-such-url.com> Co-authored-by: Dónal Murray <donalm@seadanda.dev>
1 parent 40ca073 commit 2539cb5

File tree

5 files changed

+13
-105
lines changed

5 files changed

+13
-105
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010

1111
- Staking runtime api to check if reward is pending for an era ([polkadot-fellows/runtimes#318](https://github.com/polkadot-fellows/runtimes/pull/318))
1212
- Allow any parachain to have bidirectional channel with any system parachains ([polkadot-fellows/runtimes#329](https://github.com/polkadot-fellows/runtimes/pull/329))
13+
- Update price controller of broker pallet to use higher leadin, without adjusting the minimum price too much ([polkadot-fellows/runtimes#334](https://github.com/polkadot-fellows/runtimes/pull/334)
1314
- Enable support for new hardware signers like the generic ledger app ([polkadot-fellows/runtimes#337](https://github.com/polkadot-fellows/runtimes/pull/337))
1415

1516
### Changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pallet-bridge-grandpa = { version = "0.8.0", default-features = false }
9797
pallet-bridge-messages = { version = "0.8.0", default-features = false }
9898
pallet-bridge-parachains = { version = "0.8.0", default-features = false }
9999
pallet-bridge-relayers = { version = "0.8.0", default-features = false }
100-
pallet-broker = { version = "0.7.1", default-features = false }
100+
pallet-broker = { version = "0.7.2", default-features = false }
101101
pallet-child-bounties = { version = "28.0.0", default-features = false }
102102
pallet-collator-selection = { version = "10.0.2", default-features = false }
103103
pallet-collective = { version = "29.0.0", default-features = false }

system-parachains/coretime/coretime-kusama/src/coretime.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ use frame_support::{
2525
OnUnbalanced,
2626
},
2727
};
28-
use pallet_broker::{
29-
AdaptPrice, CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf,
30-
};
31-
use sp_runtime::{
32-
traits::{AccountIdConversion, One, Saturating},
33-
FixedU64,
34-
};
28+
use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf};
29+
use sp_runtime::traits::AccountIdConversion;
3530
use xcm::latest::prelude::*;
3631

3732
/// A type containing the encoding of the coretime pallet in the Relay chain runtime. Used to
@@ -200,40 +195,6 @@ impl CoretimeInterface for CoretimeAllocator {
200195
}
201196
}
202197

203-
/// Implements the [`AdaptPrice`] trait to control the price changes of bulk coretime. This tweaks
204-
/// the [`pallet_broker::Linear`] implementation which hard-corrects to 0 if cores are offered but
205-
/// not sold for just one sale. The monotonic lead-in is increased in magnitude to enable faster
206-
/// price finding. The change in base price between sales has a lower limit of 0.5 to allow downward
207-
/// pressure to be applied, while keeping a conservative upper limit of 1.2 (movements capped at 20%
208-
/// if cores sell out) to avoid runaway prices in the early sales. The intention is that this will
209-
/// be coupled with a low number of cores per sale and a 100% ideal bulk ratio for the first sales.
210-
pub struct PriceAdapter;
211-
impl AdaptPrice for PriceAdapter {
212-
fn leadin_factor_at(when: FixedU64) -> FixedU64 {
213-
// Start at 5x the base price and decrease to the base price at the end of leadin.
214-
FixedU64::from(5).saturating_sub(FixedU64::from(4) * when)
215-
}
216-
217-
fn adapt_price(sold: CoreIndex, target: CoreIndex, limit: CoreIndex) -> FixedU64 {
218-
if sold <= target {
219-
// Range of [0.5, 1.0].
220-
FixedU64::from_rational(1, 2).saturating_add(FixedU64::from_rational(
221-
(sold).into(),
222-
(target.saturating_mul(2)).into(),
223-
))
224-
} else {
225-
// Range of (1.0, 1.2].
226-
227-
// Unchecked math: In this branch we know that sold > target. The limit must be >= sold
228-
// by construction, and thus target must be < limit.
229-
FixedU64::one().saturating_add(FixedU64::from_rational(
230-
(sold - target).into(),
231-
(limit - target).saturating_mul(5).into(),
232-
))
233-
}
234-
}
235-
}
236-
237198
parameter_types! {
238199
pub const BrokerPalletId: PalletId = PalletId(*b"py/broke");
239200
}
@@ -253,8 +214,5 @@ impl pallet_broker::Config for Runtime {
253214
type WeightInfo = weights::pallet_broker::WeightInfo<Runtime>;
254215
type PalletId = BrokerPalletId;
255216
type AdminOrigin = EnsureRoot<AccountId>;
256-
#[cfg(feature = "runtime-benchmarks")]
257-
type PriceAdapter = pallet_broker::Linear;
258-
#[cfg(not(feature = "runtime-benchmarks"))]
259-
type PriceAdapter = PriceAdapter;
217+
type PriceAdapter = pallet_broker::CenterTargetPrice<Balance>;
260218
}

system-parachains/coretime/coretime-kusama/src/tests.rs

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// limitations under the License.
1616

1717
use crate::{
18-
coretime::{BrokerPalletId, CoretimeBurnAccount, PriceAdapter},
18+
coretime::{BrokerPalletId, CoretimeBurnAccount},
1919
*,
2020
};
2121
use frame_support::{
@@ -25,61 +25,9 @@ use frame_support::{
2525
OnInitialize,
2626
},
2727
};
28-
use pallet_broker::{AdaptPrice, ConfigRecordOf, SaleInfo};
28+
use pallet_broker::{ConfigRecordOf, SaleInfo};
2929
use parachains_runtimes_test_utils::ExtBuilder;
30-
use sp_runtime::{
31-
traits::{AccountIdConversion, One},
32-
FixedU64,
33-
};
34-
35-
#[test]
36-
fn adapt_price_no_panic() {
37-
for limit in 0..10 {
38-
for target in 1..10 {
39-
for sold in 0..=limit {
40-
let price = PriceAdapter::adapt_price(sold, target, limit);
41-
42-
if sold > target {
43-
assert!(price > FixedU64::one());
44-
} else {
45-
assert!(price <= FixedU64::one());
46-
}
47-
}
48-
}
49-
}
50-
}
51-
52-
#[test]
53-
fn adapt_price_bound_check() {
54-
// Using assumptions from pallet implementation i.e. `limit >= sold`.
55-
// Check extremes
56-
let limit = 10;
57-
let target = 5;
58-
59-
// Maximally sold: `sold == limit`
60-
assert_eq!(PriceAdapter::adapt_price(limit, target, limit), FixedU64::from_float(1.2));
61-
// Ideally sold: `sold == target`
62-
assert_eq!(PriceAdapter::adapt_price(target, target, limit), FixedU64::one());
63-
// Minimally sold: `sold == 0`
64-
assert_eq!(PriceAdapter::adapt_price(0, target, limit), FixedU64::from_float(0.5));
65-
// Optimistic target: `target == limit`
66-
assert_eq!(PriceAdapter::adapt_price(limit, limit, limit), FixedU64::one());
67-
// Pessimistic target: `target == 0`
68-
assert_eq!(PriceAdapter::adapt_price(limit, 0, limit), FixedU64::from_float(1.2));
69-
}
70-
71-
#[test]
72-
fn leadin_price_bound_check() {
73-
// Using assumptions from pallet implementation i.e. `when` in range [0, 1].
74-
// Linear, therefore we need three points to fully test it
75-
76-
// Start of leadin: 5x
77-
assert_eq!(PriceAdapter::leadin_factor_at(FixedU64::from(0)), FixedU64::from(5));
78-
// Midway through leadin: 3x
79-
assert_eq!(PriceAdapter::leadin_factor_at(FixedU64::from_float(0.5)), FixedU64::from(3));
80-
// End of leadin: 1x
81-
assert_eq!(PriceAdapter::leadin_factor_at(FixedU64::one()), FixedU64::one());
82-
}
30+
use sp_runtime::traits::AccountIdConversion;
8331

8432
fn advance_to(b: BlockNumber) {
8533
while System::block_number() < b {
@@ -124,14 +72,14 @@ fn bulk_revenue_is_burnt() {
12472
let broker_account = BrokerPalletId::get().into_account_truncating();
12573
let coretime_burn_account = CoretimeBurnAccount::get();
12674
let treasury_account = xcm_config::RelayTreasuryPalletAccount::get();
127-
assert_ok!(Balances::mint_into(&AccountId::from(ALICE), 10 * ed));
75+
assert_ok!(Balances::mint_into(&AccountId::from(ALICE), 200 * ed));
12876
let alice_balance_before = Balances::balance(&AccountId::from(ALICE));
12977
let treasury_balance_before = Balances::balance(&treasury_account);
13078
let broker_balance_before = Balances::balance(&broker_account);
13179
let burn_balance_before = Balances::balance(&coretime_burn_account);
13280

13381
// Purchase coretime.
134-
assert_ok!(Broker::purchase(RuntimeOrigin::signed(AccountId::from(ALICE)), 5 * ed));
82+
assert_ok!(Broker::purchase(RuntimeOrigin::signed(AccountId::from(ALICE)), 100 * ed));
13583

13684
// Alice decreases.
13785
assert!(Balances::balance(&AccountId::from(ALICE)) < alice_balance_before);

0 commit comments

Comments
 (0)