Skip to content

Commit 650b124

Browse files
Improve On_demand_assigner events (#4339)
title: Improving `on_demand_assigner` emitted events doc: - audience: Rutime User description: OnDemandOrderPlaced event that is useful for indexers to save data related to on demand orders. Check [discussion here](https://substrate.stackexchange.com/questions/11366/ondemandassignmentprovider-ondemandorderplaced-event-was-removed/11389#11389). Closes #4254 crates: [ 'runtime-parachain] --------- Co-authored-by: Maciej <maciej.zyszkiewicz@parity.io>
1 parent ea46ad5 commit 650b124

2 files changed

Lines changed: 37 additions & 14 deletions

File tree

polkadot/runtime/parachains/src/assigner_on_demand/mod.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl QueueStatusType {
173173
fn consume_index(&mut self, removed_index: QueueIndex) {
174174
if removed_index != self.smallest_index {
175175
self.freed_indices.push(removed_index.reverse());
176-
return
176+
return;
177177
}
178178
let mut index = self.smallest_index.0.overflowing_add(1).0;
179179
// Even more to advance?
@@ -368,10 +368,10 @@ pub mod pallet {
368368
#[pallet::event]
369369
#[pallet::generate_deposit(pub(super) fn deposit_event)]
370370
pub enum Event<T: Config> {
371-
/// An order was placed at some spot price amount.
372-
OnDemandOrderPlaced { para_id: ParaId, spot_price: BalanceOf<T> },
373-
/// The value of the spot traffic multiplier changed.
374-
SpotTrafficSet { traffic: FixedU128 },
371+
/// An order was placed at some spot price amount by orderer ordered_by
372+
OnDemandOrderPlaced { para_id: ParaId, spot_price: BalanceOf<T>, ordered_by: T::AccountId },
373+
/// The value of the spot price has likely changed
374+
SpotPriceSet { spot_price: BalanceOf<T> },
375375
}
376376

377377
#[pallet::error]
@@ -410,12 +410,11 @@ pub mod pallet {
410410
///
411411
/// Errors:
412412
/// - `InsufficientBalance`: from the Currency implementation
413-
/// - `InvalidParaId`
414413
/// - `QueueFull`
415414
/// - `SpotPriceHigherThanMaxAmount`
416415
///
417416
/// Events:
418-
/// - `SpotOrderPlaced`
417+
/// - `OnDemandOrderPlaced`
419418
#[pallet::call_index(0)]
420419
#[pallet::weight(<T as Config>::WeightInfo::place_order_allow_death(QueueStatus::<T>::get().size()))]
421420
pub fn place_order_allow_death(
@@ -437,12 +436,11 @@ pub mod pallet {
437436
///
438437
/// Errors:
439438
/// - `InsufficientBalance`: from the Currency implementation
440-
/// - `InvalidParaId`
441439
/// - `QueueFull`
442440
/// - `SpotPriceHigherThanMaxAmount`
443441
///
444442
/// Events:
445-
/// - `SpotOrderPlaced`
443+
/// - `OnDemandOrderPlaced`
446444
#[pallet::call_index(1)]
447445
#[pallet::weight(<T as Config>::WeightInfo::place_order_keep_alive(QueueStatus::<T>::get().size()))]
448446
pub fn place_order_keep_alive(
@@ -539,12 +537,11 @@ where
539537
///
540538
/// Errors:
541539
/// - `InsufficientBalance`: from the Currency implementation
542-
/// - `InvalidParaId`
543540
/// - `QueueFull`
544541
/// - `SpotPriceHigherThanMaxAmount`
545542
///
546543
/// Events:
547-
/// - `SpotOrderPlaced`
544+
/// - `OnDemandOrderPlaced`
548545
fn do_place_order(
549546
sender: <T as frame_system::Config>::AccountId,
550547
max_amount: BalanceOf<T>,
@@ -578,6 +575,12 @@ where
578575
Error::<T>::QueueFull
579576
);
580577
Pallet::<T>::add_on_demand_order(queue_status, para_id, QueuePushDirection::Back);
578+
Pallet::<T>::deposit_event(Event::<T>::OnDemandOrderPlaced {
579+
para_id,
580+
spot_price,
581+
ordered_by: sender,
582+
});
583+
581584
Ok(())
582585
})
583586
}
@@ -599,7 +602,14 @@ where
599602
// Only update storage on change
600603
if new_traffic != old_traffic {
601604
queue_status.traffic = new_traffic;
602-
Pallet::<T>::deposit_event(Event::<T>::SpotTrafficSet { traffic: new_traffic });
605+
606+
// calculate the new spot price
607+
let spot_price: BalanceOf<T> = new_traffic.saturating_mul_int(
608+
config.scheduler_params.on_demand_base_fee.saturated_into::<BalanceOf<T>>(),
609+
);
610+
611+
// emit the event for updated new price
612+
Pallet::<T>::deposit_event(Event::<T>::SpotPriceSet { spot_price });
603613
}
604614
},
605615
Err(err) => {
@@ -721,7 +731,7 @@ where
721731
"Decreased affinity for a para that has not been served on a core?"
722732
);
723733
if affinity != Some(0) {
724-
return
734+
return;
725735
}
726736
// No affinity more for entries on this core, free any entries:
727737
//
@@ -754,7 +764,7 @@ where
754764
} else {
755765
*maybe_affinity = None;
756766
}
757-
return Some(new_count)
767+
return Some(new_count);
758768
} else {
759769
None
760770
}

prdoc/pr_4339.prdoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Improving on_demand_assigner emitted events
5+
6+
doc:
7+
- audience: Runtime User
8+
description: |
9+
Registering OnDemandOrderPlaced event that is useful for indexers to save data related to on demand orders. Adds SpotPriceSet as a new event to monitor on-demand spot prices. It updates whenever the price changes due to traffic.
10+
11+
crates:
12+
- name: polkadot-runtime-parachains
13+
bump: minor

0 commit comments

Comments
 (0)