Skip to content

Commit

Permalink
Broker new price adapter (paritytech#4521)
Browse files Browse the repository at this point in the history
Fixes paritytech#4360 

Also rename: AllowedRenewals -> PotentialRenewals to avoid confusion of
future readers. (An entry in `AllowedRenewals` is not enough to allow a
renewal, the assignment also has to be complete, which is only checked
afterwards.)

- [x] Does not work with renewals as is - fix.
- [x] More tests
- [x] PR docs

Edit 1:
(Relevant blog post:
https://grillapp.net/12935/agile-coretime-pricing-explained-166522?ref=29715)

---------

Co-authored-by: eskimor <[email protected]>
Co-authored-by: Dónal Murray <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
3 people authored and hitchhooker committed Jun 5, 2024
1 parent b28e434 commit 6dd8b52
Show file tree
Hide file tree
Showing 21 changed files with 703 additions and 395 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,5 @@ impl pallet_broker::Config for Runtime {
type WeightInfo = weights::pallet_broker::WeightInfo<Runtime>;
type PalletId = BrokerPalletId;
type AdminOrigin = EnsureRoot<AccountId>;
type PriceAdapter = pallet_broker::Linear;
type PriceAdapter = pallet_broker::CenterTargetPrice<Balance>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub type Migrations = (
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5<Runtime>,
pallet_broker::migration::MigrateV0ToV1<Runtime>,
pallet_broker::migration::MigrateV1ToV2<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
/// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`)
/// Storage: `Broker::SaleInfo` (r:1 w:1)
/// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`)
/// Storage: `Broker::AllowedRenewals` (r:1 w:2)
/// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
/// Storage: `Broker::PotentialRenewals` (r:1 w:2)
/// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:0)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Broker::Workplan` (r:0 w:1)
Expand Down Expand Up @@ -337,8 +337,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
}
/// Storage: `Broker::Status` (r:1 w:0)
/// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`)
/// Storage: `Broker::AllowedRenewals` (r:1 w:1)
/// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
/// Storage: `Broker::PotentialRenewals` (r:1 w:1)
/// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
fn drop_renewal() -> Weight {
// Proof Size summary in bytes:
// Measured: `957`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,5 @@ impl pallet_broker::Config for Runtime {
type WeightInfo = weights::pallet_broker::WeightInfo<Runtime>;
type PalletId = BrokerPalletId;
type AdminOrigin = EnsureRoot<AccountId>;
type PriceAdapter = pallet_broker::Linear;
type PriceAdapter = pallet_broker::CenterTargetPrice<Balance>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub type Migrations = (
pallet_collator_selection::migration::v2::MigrationToV2<Runtime>,
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
pallet_broker::migration::MigrateV0ToV1<Runtime>,
pallet_broker::migration::MigrateV1ToV2<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
/// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`)
/// Storage: `Broker::SaleInfo` (r:1 w:1)
/// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`)
/// Storage: `Broker::AllowedRenewals` (r:1 w:2)
/// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
/// Storage: `Broker::PotentialRenewals` (r:1 w:2)
/// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:0)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Broker::Workplan` (r:0 w:1)
Expand Down Expand Up @@ -335,8 +335,8 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
}
/// Storage: `Broker::Status` (r:1 w:0)
/// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`)
/// Storage: `Broker::AllowedRenewals` (r:1 w:1)
/// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
/// Storage: `Broker::PotentialRenewals` (r:1 w:1)
/// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`)
fn drop_renewal() -> Weight {
// Proof Size summary in bytes:
// Measured: `556`
Expand Down
28 changes: 28 additions & 0 deletions prdoc/pr_4521.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
title: AdaptPrice trait is now price controlled

doc:
- audience: Runtime Dev
description: |
The broker pallet price adaptation interface is changed to be less opinionated and more
information is made available to the `AdaptPrice` trait. A new example impl is included which
adapts the price based not on the number of cores sold, but rather on the price that was
achieved during the sale to mitigate a potential price manipulation vector. More information
here:

https://github.com/paritytech/polkadot-sdk/issues/4360

- audience: Runtime User
description: |
The price controller of the Rococo and Westend Coretime chain will be
adjusted with this release. This will very likely be used in the
fellowship production runtime to have a much larger leadin. This fixes a
price manipulation issue we discovered with the Kusama launch.

crates:
- name: pallet-broker
bump: minor
- name: coretime-rococo-runtime
bump: minor
- name: coretime-westend-runtime
bump: minor

2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ impl pallet_broker::Config for Runtime {
type WeightInfo = ();
type PalletId = BrokerPalletId;
type AdminOrigin = EnsureRoot<AccountId>;
type PriceAdapter = pallet_broker::Linear;
type PriceAdapter = pallet_broker::CenterTargetPrice<Balance>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/broker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frame-system = { path = "../system", default-features = false }

[dev-dependencies]
sp-io = { path = "../../primitives/io" }
sp-tracing = { path = "../../primitives/tracing" }
pretty_assertions = "1.3.0"

[features]
Expand Down
Loading

0 comments on commit 6dd8b52

Please sign in to comment.