Skip to content

Commit

Permalink
Rename assigner_on_demand to on_demand (#4706)
Browse files Browse the repository at this point in the history
Closes #3425

---------

Co-authored-by: antonva <anton.asgeirsson@parity.io>
Co-authored-by: command-bot <>
  • Loading branch information
s0me0ne-unkn0wn and antonva authored Jul 22, 2024
1 parent d0d8e29 commit f923443
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 215 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

14 changes: 5 additions & 9 deletions polkadot/runtime/parachains/src/assigner_coretime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod mock_helpers;
mod tests;

use crate::{
assigner_on_demand, configuration,
configuration, on_demand,
paras::AssignCoretime,
scheduler::common::{Assignment, AssignmentProvider},
ParaId,
Expand Down Expand Up @@ -201,10 +201,7 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config:
frame_system::Config + configuration::Config + assigner_on_demand::Config
{
}
pub trait Config: frame_system::Config + configuration::Config + on_demand::Config {}

/// Scheduled assignment sets.
///
Expand Down Expand Up @@ -281,8 +278,7 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {

match a_type {
CoreAssignment::Idle => None,
CoreAssignment::Pool =>
assigner_on_demand::Pallet::<T>::pop_assignment_for_core(core_idx),
CoreAssignment::Pool => on_demand::Pallet::<T>::pop_assignment_for_core(core_idx),
CoreAssignment::Task(para_id) => Some(Assignment::Bulk((*para_id).into())),
}
})
Expand All @@ -291,7 +287,7 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {
fn report_processed(assignment: Assignment) {
match assignment {
Assignment::Pool { para_id, core_index } =>
assigner_on_demand::Pallet::<T>::report_processed(para_id, core_index),
on_demand::Pallet::<T>::report_processed(para_id, core_index),
Assignment::Bulk(_) => {},
}
}
Expand All @@ -304,7 +300,7 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {
fn push_back_assignment(assignment: Assignment) {
match assignment {
Assignment::Pool { para_id, core_index } =>
assigner_on_demand::Pallet::<T>::push_back_assignment(para_id, core_index),
on_demand::Pallet::<T>::push_back_assignment(para_id, core_index),
Assignment::Bulk(_) => {
// Session changes are rough. We just drop assignments that did not make it on a
// session boundary. This seems sensible as bulk is region based. Meaning, even if
Expand Down
12 changes: 4 additions & 8 deletions polkadot/runtime/parachains/src/assigner_coretime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::{
assigner_coretime::{mock_helpers::GenesisConfigBuilder, pallet::Error, Schedule},
initializer::SessionChangeNotification,
mock::{
new_test_ext, Balances, CoretimeAssigner, OnDemandAssigner, Paras, ParasShared,
RuntimeOrigin, Scheduler, System, Test,
new_test_ext, Balances, CoretimeAssigner, OnDemand, Paras, ParasShared, RuntimeOrigin,
Scheduler, System, Test,
},
paras::{ParaGenesisArgs, ParaKind},
scheduler::common::Assignment,
Expand Down Expand Up @@ -75,7 +75,7 @@ fn run_to_block(
Scheduler::initializer_initialize(b + 1);

// Update the spot traffic and revenue on every block.
OnDemandAssigner::on_initialize(b + 1);
OnDemand::on_initialize(b + 1);

// In the real runtime this is expected to be called by the `InclusionInherent` pallet.
Scheduler::free_cores_and_fill_claim_queue(BTreeMap::new(), b + 1);
Expand Down Expand Up @@ -527,11 +527,7 @@ fn pop_assignment_for_core_works() {
schedule_blank_para(para_id, ParaKind::Parathread);
Balances::make_free_balance_be(&alice, amt);
run_to_block(1, |n| if n == 1 { Some(Default::default()) } else { None });
assert_ok!(OnDemandAssigner::place_order_allow_death(
RuntimeOrigin::signed(alice),
amt,
para_id
));
assert_ok!(OnDemand::place_order_allow_death(RuntimeOrigin::signed(alice), amt, para_id));

// Case 1: Assignment idle
assert_ok!(CoretimeAssigner::assign_core(
Expand Down
12 changes: 6 additions & 6 deletions polkadot/runtime/parachains/src/coretime/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ mod benchmarks {
#[benchmark]
fn request_revenue_at() {
let root_origin = <T as frame_system::Config>::RuntimeOrigin::root();
let mhr = <T as assigner_on_demand::Config>::MaxHistoricalRevenue::get();
let mhr = <T as on_demand::Config>::MaxHistoricalRevenue::get();
frame_system::Pallet::<T>::set_block_number((mhr + 2).into());
let minimum_balance = <T as assigner_on_demand::Config>::Currency::minimum_balance();
let minimum_balance = <T as on_demand::Config>::Currency::minimum_balance();
let rev: BoundedVec<
<<T as assigner_on_demand::Config>::Currency as frame_support::traits::Currency<
<<T as on_demand::Config>::Currency as frame_support::traits::Currency<
T::AccountId,
>>::Balance,
T::MaxHistoricalRevenue,
> = BoundedVec::try_from((1..=mhr).map(|v| minimum_balance * v.into()).collect::<Vec<_>>())
.unwrap();
assigner_on_demand::Revenue::<T>::put(rev);
on_demand::Revenue::<T>::put(rev);

<T as assigner_on_demand::Config>::Currency::make_free_balance_be(
&<assigner_on_demand::Pallet<T>>::account_id(),
<T as on_demand::Config>::Currency::make_free_balance_be(
&<on_demand::Pallet<T>>::account_id(),
minimum_balance * (mhr * (mhr + 1)).into(),
);

Expand Down
16 changes: 8 additions & 8 deletions polkadot/runtime/parachains/src/coretime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use xcm_executor::traits::TransactAsset;

use crate::{
assigner_coretime::{self, PartsOf57600},
assigner_on_demand,
initializer::{OnNewSession, SessionChangeNotification},
on_demand,
origin::{ensure_parachain, Origin},
};

Expand Down Expand Up @@ -116,6 +116,7 @@ enum CoretimeCalls {

#[frame_support::pallet]
pub mod pallet {

use crate::configuration;
use sp_runtime::traits::TryConvert;
use xcm::v4::InteriorLocation;
Expand All @@ -128,9 +129,7 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config:
frame_system::Config + assigner_coretime::Config + assigner_on_demand::Config
{
pub trait Config: frame_system::Config + assigner_coretime::Config + on_demand::Config {
type RuntimeOrigin: From<<Self as frame_system::Config>::RuntimeOrigin>
+ Into<result::Result<Origin, <Self as Config>::RuntimeOrigin>>;
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -308,7 +307,7 @@ impl<T: Config> Pallet<T> {
// When cannot be in the future.
ensure!(until_bnf <= now, Error::<T>::RequestedFutureRevenue);

let amount = <assigner_on_demand::Pallet<T>>::claim_revenue_until(until_bnf);
let amount = <on_demand::Pallet<T>>::claim_revenue_until(until_bnf);
log::debug!(target: LOG_TARGET, "Revenue info requested: {:?}", amount);

let raw_revenue: Balance = amount.try_into().map_err(|_| {
Expand Down Expand Up @@ -365,14 +364,15 @@ fn do_notify_revenue<T: Config>(when: BlockNumber, raw_revenue: Balance) -> Resu

if raw_revenue > 0 {
let on_demand_pot =
T::AccountToLocation::try_convert(&<assigner_on_demand::Pallet<T>>::account_id())
.map_err(|err| {
T::AccountToLocation::try_convert(&<on_demand::Pallet<T>>::account_id()).map_err(
|err| {
log::error!(
target: LOG_TARGET,
"Failed to convert on-demand pot account to XCM location: {err:?}",
);
XcmError::InvalidLocation
})?;
},
)?;

let withdrawn = T::AssetTransactor::withdraw_asset(&asset, &on_demand_pot, None)?;

Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod assigner_coretime;
pub mod assigner_on_demand;
pub mod assigner_parachains;
pub mod configuration;
pub mod coretime;
Expand All @@ -34,6 +33,7 @@ pub mod hrmp;
pub mod inclusion;
pub mod initializer;
pub mod metrics;
pub mod on_demand;
pub mod origin;
pub mod paras;
pub mod paras_inherent;
Expand Down
13 changes: 6 additions & 7 deletions polkadot/runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
//! Mocks for all the traits.

use crate::{
assigner_coretime, assigner_on_demand, assigner_parachains, configuration, coretime, disputes,
dmp, hrmp,
assigner_coretime, assigner_parachains, configuration, coretime, disputes, dmp, hrmp,
inclusion::{self, AggregateMessageOrigin, UmpQueueId},
initializer, origin, paras,
initializer, on_demand, origin, paras,
paras::ParaKind,
paras_inherent, scheduler,
scheduler::common::AssignmentProvider,
Expand Down Expand Up @@ -78,7 +77,7 @@ frame_support::construct_runtime!(
Scheduler: scheduler,
MockAssigner: mock_assigner,
ParachainsAssigner: assigner_parachains,
OnDemandAssigner: assigner_on_demand,
OnDemand: on_demand,
CoretimeAssigner: assigner_coretime,
Coretime: coretime,
Initializer: initializer,
Expand Down Expand Up @@ -401,11 +400,11 @@ parameter_types! {
pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd");
}

impl assigner_on_demand::Config for Test {
impl on_demand::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type TrafficDefaultValue = OnDemandTrafficDefaultValue;
type WeightInfo = crate::assigner_on_demand::TestWeightInfo;
type WeightInfo = crate::on_demand::TestWeightInfo;
type MaxHistoricalRevenue = MaxHistoricalRevenue;
type PalletId = OnDemandPalletId;
}
Expand Down Expand Up @@ -540,7 +539,7 @@ pub mod mock_assigner {
// We don't care about core affinity in the test assigner
fn report_processed(_assignment: Assignment) {}

// The results of this are tested in assigner_on_demand tests. No need to represent it
// The results of this are tested in on_demand tests. No need to represent it
// in the mock assigner.
fn push_back_assignment(_assignment: Assignment) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod benchmarks {
impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(
crate::assigner_on_demand::mock_helpers::GenesisConfigBuilder::default().build()
crate::on_demand::mock_helpers::GenesisConfigBuilder::default().build()
),
crate::mock::Test
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod v0 {
mod v1 {
use super::*;

use crate::assigner_on_demand::LOG_TARGET;
use crate::on_demand::LOG_TARGET;

/// Migration to V1
pub struct UncheckedMigrateToV1<T>(core::marker::PhantomData<T>);
Expand Down Expand Up @@ -142,7 +142,7 @@ pub type MigrateV0ToV1<T> = VersionedMigration<
#[cfg(test)]
mod tests {
use super::{v0, v1, UncheckedOnRuntimeUpgrade, Weight};
use crate::mock::{new_test_ext, MockGenesisConfig, OnDemandAssigner, Test};
use crate::mock::{new_test_ext, MockGenesisConfig, OnDemand, Test};
use polkadot_primitives::Id as ParaId;

#[test]
Expand All @@ -159,7 +159,7 @@ mod tests {
let old_queue = v0::OnDemandQueue::<Test>::get();
assert_eq!(old_queue.len(), 5);
// New queue has 0 orders
assert_eq!(OnDemandAssigner::get_queue_status().size(), 0);
assert_eq!(OnDemand::get_queue_status().size(), 0);

// For tests, db weight is zero.
assert_eq!(
Expand All @@ -168,10 +168,10 @@ mod tests {
);

// New queue has 5 orders
assert_eq!(OnDemandAssigner::get_queue_status().size(), 5);
assert_eq!(OnDemand::get_queue_status().size(), 5);

// Compare each entry from the old queue with the entry in the new queue.
old_queue.iter().zip(OnDemandAssigner::get_free_entries().iter()).for_each(
old_queue.iter().zip(OnDemand::get_free_entries().iter()).for_each(
|(old_enq, new_enq)| {
assert_eq!(old_enq.para_id, new_enq.para_id);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use types::{
SpotTrafficCalculationErr,
};

const LOG_TARGET: &str = "runtime::parachains::assigner-on-demand";
const LOG_TARGET: &str = "runtime::parachains::on-demand";

pub use pallet::*;

Expand Down
Loading

0 comments on commit f923443

Please sign in to comment.