From 67ee7858c29a166037d9d6f1dadeefbba62dfa02 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Sat, 23 Nov 2024 16:52:01 -0800 Subject: [PATCH 1/4] init --- substrate/frame/broker/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 10745544fadf..8f0000282f36 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -345,6 +345,8 @@ pub mod pallet { price: BalanceOf, /// The maximum number of cores which this pallet will attempt to assign. core_count: CoreIndex, + /// + sale_id: u32, }, /// The act of claiming revenue has begun. RevenueClaimBegun { From dd0f4813347bae3e12467ffc3bdc42fdb171fe40 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Mon, 25 Nov 2024 03:22:01 -0800 Subject: [PATCH 2/4] add storage item --- substrate/frame/broker/src/dispatchable_impls.rs | 10 +++++++++- substrate/frame/broker/src/lib.rs | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 5fbd957d7908..a6809823c0db 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -105,7 +105,15 @@ impl Pallet { cores_offered: 0, cores_sold: 0, }; - Self::deposit_event(Event::::SalesStarted { price: end_price, core_count }); + + // Get current sale_id and increment it + let current_sale_id = SaleId::::get(); + let new_sale_id = current_sale_id.saturating_add(1); + + // Store the new sale_id for the next sale + SaleId::::put(new_sale_id); + + Self::deposit_event(Event::::SalesStarted { price: end_price, core_count, sale_id: new_sale_id }); Self::rotate_sale(old_sale, &config, &status); Status::::put(&status); Ok(()) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 8f0000282f36..08435160b505 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -194,6 +194,10 @@ pub mod pallet { #[pallet::storage] pub type RevenueInbox = StorageValue<_, OnDemandRevenueRecordOf, OptionQuery>; + /// Id of the current sale. + #[pallet::storage] + pub type SaleId = StorageValue<_, u32, ValueQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { From 4978cfed24711f2506ef8ad9081f8ac7aafc56a9 Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Mon, 25 Nov 2024 04:04:33 -0800 Subject: [PATCH 3/4] add prdoc --- prdoc/pr_6626.prdoc | 13 +++++++++++++ substrate/frame/broker/src/lib.rs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_6626.prdoc diff --git a/prdoc/pr_6626.prdoc b/prdoc/pr_6626.prdoc new file mode 100644 index 000000000000..8c60493f3f95 --- /dev/null +++ b/prdoc/pr_6626.prdoc @@ -0,0 +1,13 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: coretime sale id + +doc: + - audience: Runtime Dev + description: | + This pull request adds a `sale_id` in the event emitted when coretime sale starts. + +crates: + - name: pallet-broker + bump: minor diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 08435160b505..7df943295047 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -349,7 +349,7 @@ pub mod pallet { price: BalanceOf, /// The maximum number of cores which this pallet will attempt to assign. core_count: CoreIndex, - /// + /// Identifier for the current sale. sale_id: u32, }, /// The act of claiming revenue has begun. From 1f1a7773e8365a5e241a373f6ebd4f9f68d7555e Mon Sep 17 00:00:00 2001 From: FereMouSiopi Date: Sun, 1 Dec 2024 19:31:04 -0800 Subject: [PATCH 4/4] SaleInfo for sale_index(id) --- prdoc/pr_6626.prdoc | 4 ++-- substrate/frame/broker/src/benchmarking.rs | 3 +++ substrate/frame/broker/src/dispatchable_impls.rs | 10 ++-------- substrate/frame/broker/src/lib.rs | 8 ++------ substrate/frame/broker/src/migration.rs | 3 +++ substrate/frame/broker/src/tests.rs | 2 ++ substrate/frame/broker/src/tick_impls.rs | 7 +++++++ substrate/frame/broker/src/types.rs | 2 ++ 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/prdoc/pr_6626.prdoc b/prdoc/pr_6626.prdoc index 8c60493f3f95..961e7d0f1554 100644 --- a/prdoc/pr_6626.prdoc +++ b/prdoc/pr_6626.prdoc @@ -4,10 +4,10 @@ title: coretime sale id doc: - - audience: Runtime Dev + - audience: Runtime Dev & Runtime Users description: | This pull request adds a `sale_id` in the event emitted when coretime sale starts. crates: - name: pallet-broker - bump: minor + bump: major diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 9ef9b1254435..b0b488e8ac1d 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -233,6 +233,7 @@ mod benches { .saturating_sub(T::MaxLeasedCores::get()) .try_into() .unwrap(), + sale_index: 0u32, } .into(), ); @@ -803,6 +804,7 @@ mod benches { ideal_cores_sold: 0, cores_offered: 0, cores_sold: 0, + sale_index: 0u32, }; let status = StatusRecord { @@ -862,6 +864,7 @@ mod benches { .saturating_sub(T::MaxLeasedCores::get()) .try_into() .unwrap(), + sale_index: 1u32, } .into(), ); diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 5871fa09342a..08cb40f64ac0 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -104,16 +104,10 @@ impl Pallet { ideal_cores_sold: 0, cores_offered: 0, cores_sold: 0, + sale_index: 0, }; - // Get current sale_id and increment it - let current_sale_id = SaleId::::get(); - let new_sale_id = current_sale_id.saturating_add(1); - - // Store the new sale_id for the next sale - SaleId::::put(new_sale_id); - - Self::deposit_event(Event::::SalesStarted { price: end_price, core_count, sale_id: new_sale_id }); + Self::deposit_event(Event::::SalesStarted { price: end_price, core_count }); Self::rotate_sale(old_sale, &config, &status); Status::::put(&status); Ok(()) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 9c60d80a0e75..cf4c0dc06706 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -194,10 +194,6 @@ pub mod pallet { #[pallet::storage] pub type RevenueInbox = StorageValue<_, OnDemandRevenueRecordOf, OptionQuery>; - /// Id of the current sale. - #[pallet::storage] - pub type SaleId = StorageValue<_, u32, ValueQuery>; - #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -327,6 +323,8 @@ pub mod pallet { ideal_cores_sold: CoreIndex, /// Number of cores which are/have been offered for sale. cores_offered: CoreIndex, + /// Identifier for the current sale + sale_index: u32, }, /// A new lease has been created. Leased { @@ -350,8 +348,6 @@ pub mod pallet { price: BalanceOf, /// The maximum number of cores which this pallet will attempt to assign. core_count: CoreIndex, - /// Identifier for the current sale. - sale_id: u32, }, /// The act of claiming revenue has begun. RevenueClaimBegun { diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index f19b1e19bdd1..476458865de5 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -224,6 +224,8 @@ mod v3 { pub sellout_price: Option, /// Number of cores which have been sold; never more than cores_offered. pub cores_sold: CoreIndex, + /// Identifier for the current sale. + pub sale_index: u32, } } @@ -328,6 +330,7 @@ pub mod v4 { first_core: sale_info.first_core, sellout_price: sale_info.sellout_price, cores_sold: sale_info.cores_sold, + sale_index: sale_info.sale_index, }; SaleInfo::::put(updated_sale_info); } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index f3fd5234e4ca..f4d2dade4512 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1231,6 +1231,7 @@ fn purchase_requires_valid_status_and_sale_info() { ideal_cores_sold: 0, cores_offered: 1, cores_sold: 2, + sale_index: 0, }; SaleInfo::::put(&dummy_sale); assert_noop!(Broker::do_purchase(1, 100), Error::::Unavailable); @@ -1273,6 +1274,7 @@ fn renewal_requires_valid_status_and_sale_info() { ideal_cores_sold: 0, cores_offered: 1, cores_sold: 2, + sale_index: 0, }; SaleInfo::::put(&dummy_sale); assert_noop!(Broker::do_renew(1, 1), Error::::Unavailable); diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index e0b4932f11e2..45939d48f627 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -247,6 +247,11 @@ impl Pallet { } else { None }; + let sale_index = if let Some(sale) = SaleInfo::::get() { + sale.sale_index.saturating_add(1) + } else { + old_sale.sale_index + }; // Update SaleInfo let new_sale = SaleInfoRecord { @@ -260,6 +265,7 @@ impl Pallet { ideal_cores_sold, cores_offered, cores_sold: 0, + sale_index, }; SaleInfo::::put(&new_sale); @@ -275,6 +281,7 @@ impl Pallet { region_end, ideal_cores_sold, cores_offered, + sale_index, }); Some(()) diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index f970b310a3cb..74d1dd1ea28d 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -234,6 +234,8 @@ pub struct SaleInfoRecord { pub sellout_price: Option, /// Number of cores which have been sold; never more than cores_offered. pub cores_sold: CoreIndex, + /// Identifier for the current sale. + pub sale_index: u32, } pub type SaleInfoRecordOf = SaleInfoRecord, RelayBlockNumberOf>;