Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed pallet::getter usage from Polkadot Runtime pallets #3660

Merged
merged 23 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a4c726e
removed `pallet::getter` usage from `polkadot-runtime-common`
muraca Mar 12, 2024
802ca2d
removed `pallet::getter` usage from `polkadot-runtime-parachains::{co…
muraca Mar 12, 2024
29f09b3
removed `pallet::getter` usage from `polkadot-runtime-parachains::paras`
muraca Mar 12, 2024
89ba919
removed `pallet::getter` usage from `polkadot-runtime-parachains::{sc…
muraca Mar 12, 2024
905a34e
fixed rococo and westend clippy complaint
muraca Mar 12, 2024
09cc5f8
fixed rococo and westend fmt
muraca Mar 12, 2024
1669d0e
removed `pallet::getter` usage from `polkadot-runtime-parachains::sha…
muraca Mar 12, 2024
2802684
prdoc for #3660
muraca Mar 12, 2024
27e0e3d
fix hrmp benchmarking
muraca Mar 12, 2024
8b481a6
silent removal of turbofish syntax
muraca Mar 13, 2024
05a8e5e
Merge branch 'master' into getters/polkadot-runtime
muraca Mar 15, 2024
704daf9
Merge branch 'master' into getters/polkadot-runtime
muraca Mar 18, 2024
5feb9c2
review comments, clippy
muraca Mar 19, 2024
b1e2b7a
more clippy fixes
muraca Mar 19, 2024
9235f33
Merge branch 'master' into getters/polkadot-runtime
muraca Mar 19, 2024
d374f63
Merge branch 'master' into getters/polkadot-runtime
muraca Mar 20, 2024
d46f4b1
Merge branch 'master' into getters/polkadot-runtime
muraca Mar 24, 2024
2de93b0
fmt
muraca Mar 24, 2024
98c072e
fixed clippy issues
muraca Mar 24, 2024
713240c
Update prdoc/pr_3660.prdoc
ordian Apr 4, 2024
b9bfc7b
Merge branch 'master' into getters/polkadot-runtime
muraca Apr 6, 2024
217a6da
fixed copy-paste mistake
muraca Apr 6, 2024
d075a14
Merge branch 'master' into getters/polkadot-runtime
muraca Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions polkadot/roadmap/implementers-guide/src/runtime/disputes.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ This is currently a `no op`.

* `is_frozen()`: Load the value of `Frozen` from storage. Return true if `Some` and false if `None`.

* `last_valid_block()`: Load the value of `Frozen` from storage and return. None indicates that all blocks in the chain
are potentially valid.

* `revert_and_freeze(BlockNumber)`:
1. If `is_frozen()` return.
1. Set `Frozen` to `Some(BlockNumber)` to indicate a rollback to the block number.
Expand Down
4 changes: 2 additions & 2 deletions polkadot/roadmap/implementers-guide/src/runtime/scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Actions:
[`HostConfiguration`](../types/runtime.md#host-configuration))
1. Fetch `Shared::ActiveValidators` as AV.
1. Determine the number of cores & validator groups as `n_cores`. This is the maximum of
1. `Paras::parachains().len() + configuration.parathread_cores`
1. `paras::Parachains::<T>::get().len() + configuration.parathread_cores`
1. `n_validators / max_validators_per_core` if `configuration.max_validators_per_core` is `Some` and non-zero.
1. Resize `AvailabilityCores` to have length `n_cores` with all `None` entries.
1. Compute new validator groups by shuffling using a secure randomness beacon
Expand Down Expand Up @@ -261,7 +261,7 @@ No finalization routine runs for this module.
- Fails if any on-demand claim on the same parachain is currently indexed.
- Fails if the queue length is >= `config.scheduling_lookahead * config.parathread_cores`.
- The core used for the on-demand claim is the `next_core` field of the `ParathreadQueue` (on-demand queue) and adding
`Paras::parachains().len()` to it.
`paras::Parachains::<T>::get().len()` to it.
- `next_core` is then updated by adding 1 and taking it modulo `config.parathread_cores`.
- The claim is then added to the claim index.
- `free_cores(Vec<(CoreIndex, FreedReason)>)`: indicate previously-occupied cores which are to be considered returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ Sessions: map SessionIndex => Option<SessionInfo>,

## Routines

* `earliest_stored_session() -> SessionIndex`: Yields the earliest session for which we have information stored.
* `session_info(session: SessionIndex) -> Option<SessionInfo>`: Yields the session info for the given session, if
* `EarliestStoredSession::<T>::get() -> SessionIndex`: Yields the earliest session for which we have information stored.
* `Sessions::<T>::get(session: SessionIndex) -> Option<SessionInfo>`: Yields the session info for the given session, if
stored.
8 changes: 4 additions & 4 deletions polkadot/runtime/common/src/assigned_slots/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub mod v1 {
const MAX_PERMANENT_SLOTS: u32 = 100;
const MAX_TEMPORARY_SLOTS: u32 = 100;

<MaxPermanentSlots<T>>::put(MAX_PERMANENT_SLOTS);
<MaxTemporarySlots<T>>::put(MAX_TEMPORARY_SLOTS);
MaxPermanentSlots::<T>::put(MAX_PERMANENT_SLOTS);
MaxTemporarySlots::<T>::put(MAX_TEMPORARY_SLOTS);
// Return the weight consumed by the migration.
T::DbWeight::get().reads_writes(1, 3)
} else {
Expand All @@ -54,8 +54,8 @@ pub mod v1 {
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let on_chain_version = Pallet::<T>::on_chain_storage_version();
ensure!(on_chain_version == 1, "assigned_slots::MigrateToV1 needs to be run");
assert_eq!(<MaxPermanentSlots<T>>::get(), 100);
assert_eq!(<MaxTemporarySlots<T>>::get(), 100);
assert_eq!(MaxPermanentSlots::<T>::get(), 100);
assert_eq!(MaxTemporarySlots::<T>::get(), 100);
Ok(())
}
}
Expand Down
82 changes: 40 additions & 42 deletions polkadot/runtime/common/src/assigned_slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,15 @@ pub mod pallet {

/// Assigned permanent slots, with their start lease period, and duration.
#[pallet::storage]
#[pallet::getter(fn permanent_slots)]
pub type PermanentSlots<T: Config> =
StorageMap<_, Twox64Concat, ParaId, (LeasePeriodOf<T>, LeasePeriodOf<T>), OptionQuery>;

/// Number of assigned (and active) permanent slots.
#[pallet::storage]
#[pallet::getter(fn permanent_slot_count)]
pub type PermanentSlotCount<T: Config> = StorageValue<_, u32, ValueQuery>;

/// Assigned temporary slots.
#[pallet::storage]
#[pallet::getter(fn temporary_slots)]
pub type TemporarySlots<T: Config> = StorageMap<
_,
Twox64Concat,
Expand All @@ -170,12 +167,10 @@ pub mod pallet {

/// Number of assigned temporary slots.
#[pallet::storage]
#[pallet::getter(fn temporary_slot_count)]
pub type TemporarySlotCount<T: Config> = StorageValue<_, u32, ValueQuery>;

/// Number of active temporary slots in current slot lease period.
#[pallet::storage]
#[pallet::getter(fn active_temporary_slot_count)]
pub type ActiveTemporarySlotCount<T: Config> = StorageValue<_, u32, ValueQuery>;

/// The max number of temporary slots that can be assigned.
Expand All @@ -197,8 +192,8 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
<MaxPermanentSlots<T>>::put(&self.max_permanent_slots);
<MaxTemporarySlots<T>>::put(&self.max_temporary_slots);
MaxTemporarySlots::<T>::put(&self.max_permanent_slots);
MaxTemporarySlots::<T>::put(&self.max_temporary_slots);
}
}

Expand Down Expand Up @@ -306,7 +301,7 @@ pub mod pallet {
LeasePeriodOf::<T>::from(T::PermanentSlotLeasePeriodLength::get()),
),
);
<PermanentSlotCount<T>>::mutate(|count| count.saturating_inc());
PermanentSlotCount::<T>::mutate(|count| count.saturating_inc());

Self::deposit_event(Event::<T>::PermanentSlotAssigned(id));
Ok(())
Expand Down Expand Up @@ -364,7 +359,7 @@ pub mod pallet {
};

if lease_period_start == SlotLeasePeriodStart::Current &&
Self::active_temporary_slot_count() < T::MaxTemporarySlotPerLeasePeriod::get()
ActiveTemporarySlotCount::<T>::get() < T::MaxTemporarySlotPerLeasePeriod::get()
{
// Try to allocate slot directly
match Self::configure_slot_lease(
Expand Down Expand Up @@ -394,7 +389,7 @@ pub mod pallet {
}

TemporarySlots::<T>::insert(id, temp_slot);
<TemporarySlotCount<T>>::mutate(|count| count.saturating_inc());
TemporarySlotCount::<T>::mutate(|count| count.saturating_inc());

Self::deposit_event(Event::<T>::TemporarySlotAssigned(id));

Expand All @@ -420,12 +415,12 @@ pub mod pallet {

if PermanentSlots::<T>::contains_key(id) {
PermanentSlots::<T>::remove(id);
<PermanentSlotCount<T>>::mutate(|count| *count = count.saturating_sub(One::one()));
PermanentSlotCount::<T>::mutate(|count| *count = count.saturating_sub(One::one()));
} else if TemporarySlots::<T>::contains_key(id) {
TemporarySlots::<T>::remove(id);
<TemporarySlotCount<T>>::mutate(|count| *count = count.saturating_sub(One::one()));
TemporarySlotCount::<T>::mutate(|count| *count = count.saturating_sub(One::one()));
if is_parachain {
<ActiveTemporarySlotCount<T>>::mutate(|active_count| {
ActiveTemporarySlotCount::<T>::mutate(|active_count| {
*active_count = active_count.saturating_sub(One::one())
});
}
Expand Down Expand Up @@ -456,7 +451,7 @@ pub mod pallet {
pub fn set_max_permanent_slots(origin: OriginFor<T>, slots: u32) -> DispatchResult {
ensure_root(origin)?;

<MaxPermanentSlots<T>>::put(slots);
MaxTemporarySlots::<T>::put(slots);

Self::deposit_event(Event::<T>::MaxPermanentSlotsChanged { slots });
Ok(())
Expand All @@ -468,7 +463,7 @@ pub mod pallet {
pub fn set_max_temporary_slots(origin: OriginFor<T>, slots: u32) -> DispatchResult {
ensure_root(origin)?;

<MaxTemporarySlots<T>>::put(slots);
MaxTemporarySlots::<T>::put(slots);

Self::deposit_event(Event::<T>::MaxTemporarySlotsChanged { slots });
Ok(())
Expand Down Expand Up @@ -965,7 +960,7 @@ mod tests {
RuntimeOrigin::root(),
ParaId::from(2_u32),
));
assert_eq!(AssignedSlots::permanent_slot_count(), 2);
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 2);

assert_noop!(
AssignedSlots::assign_perm_parachain_slot(
Expand All @@ -989,8 +984,8 @@ mod tests {
dummy_validation_code(),
));

assert_eq!(AssignedSlots::permanent_slot_count(), 0);
assert_eq!(AssignedSlots::permanent_slots(ParaId::from(1_u32)), None);
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 0);
assert_eq!(assigned_slots::PermanentSlots::<Test>::get(ParaId::from(1_u32)), None);

assert_ok!(AssignedSlots::assign_perm_parachain_slot(
RuntimeOrigin::root(),
Expand All @@ -1004,9 +999,12 @@ mod tests {

assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(1_u32)), true);

assert_eq!(AssignedSlots::permanent_slot_count(), 1);
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 1);
assert_eq!(AssignedSlots::has_permanent_slot(ParaId::from(1_u32)), true);
assert_eq!(AssignedSlots::permanent_slots(ParaId::from(1_u32)), Some((0, 3)));
assert_eq!(
assigned_slots::PermanentSlots::<Test>::get(ParaId::from(1_u32)),
Some((0, 3))
);

assert_eq!(Slots::already_leased(ParaId::from(1_u32), 0, 2), true);

Expand Down Expand Up @@ -1138,7 +1136,7 @@ mod tests {
));
}

assert_eq!(AssignedSlots::temporary_slot_count(), 6);
assert_eq!(assigned_slots::TemporarySlotCount::<Test>::get(), 6);

// Attempt to assign one more temp slot
assert_ok!(TestRegistrar::<Test>::register(
Expand Down Expand Up @@ -1170,30 +1168,30 @@ mod tests {
dummy_validation_code(),
));

assert_eq!(AssignedSlots::temporary_slots(ParaId::from(1_u32)), None);
assert_eq!(assigned_slots::TemporarySlots::<Test>::get(ParaId::from(1_u32)), None);

assert_ok!(AssignedSlots::assign_temp_parachain_slot(
RuntimeOrigin::root(),
ParaId::from(1_u32),
SlotLeasePeriodStart::Current
));
assert_eq!(AssignedSlots::temporary_slot_count(), 1);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 1);
assert_eq!(assigned_slots::TemporarySlotCount::<Test>::get(), 1);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 1);

// Block 1-5
// Para is a lease holding parachain for TemporarySlotLeasePeriodLength * LeasePeriod
// blocks
while block < 6 {
println!("block #{}", block);
println!("lease period #{}", AssignedSlots::current_lease_period_index());
println!("lease {:?}", Slots::lease(ParaId::from(1_u32)));
println!("lease {:?}", slots::Leases::<Test>::get(ParaId::from(1_u32)));

assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(1_u32)), true);

assert_eq!(AssignedSlots::has_temporary_slot(ParaId::from(1_u32)), true);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 1);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 1);
assert_eq!(
AssignedSlots::temporary_slots(ParaId::from(1_u32)),
assigned_slots::TemporarySlots::<Test>::get(ParaId::from(1_u32)),
Some(ParachainTemporarySlot {
manager: 1,
period_begin: 0,
Expand All @@ -1212,23 +1210,23 @@ mod tests {
// Block 6
println!("block #{}", block);
println!("lease period #{}", AssignedSlots::current_lease_period_index());
println!("lease {:?}", Slots::lease(ParaId::from(1_u32)));
println!("lease {:?}", slots::Leases::<Test>::get(ParaId::from(1_u32)));

// Para lease ended, downgraded back to on-demand parachain
assert_eq!(TestRegistrar::<Test>::is_parathread(ParaId::from(1_u32)), true);
assert_eq!(Slots::already_leased(ParaId::from(1_u32), 0, 3), false);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 0);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 0);

// Block 12
// Para should get a turn after TemporarySlotLeasePeriodLength * LeasePeriod blocks
run_to_block(12);
println!("block #{}", block);
println!("lease period #{}", AssignedSlots::current_lease_period_index());
println!("lease {:?}", Slots::lease(ParaId::from(1_u32)));
println!("lease {:?}", slots::Leases::<Test>::get(ParaId::from(1_u32)));

assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(1_u32)), true);
assert_eq!(Slots::already_leased(ParaId::from(1_u32), 4, 5), true);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 1);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 1);
});
}

Expand Down Expand Up @@ -1270,7 +1268,7 @@ mod tests {
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), false);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
}

// Block 6-11, Period 2-3
Expand All @@ -1282,7 +1280,7 @@ mod tests {
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), true);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), false);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
}

// Block 12-17, Period 4-5
Expand All @@ -1294,7 +1292,7 @@ mod tests {
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), true);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), true);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
}

// Block 18-23, Period 6-7
Expand All @@ -1306,7 +1304,7 @@ mod tests {
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), false);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
}

// Block 24-29, Period 8-9
Expand All @@ -1318,7 +1316,7 @@ mod tests {
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), true);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), false);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
}

// Block 30-35, Period 10-11
Expand All @@ -1330,7 +1328,7 @@ mod tests {
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), false);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), true);
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), true);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
}
});
}
Expand Down Expand Up @@ -1386,9 +1384,9 @@ mod tests {
ParaId::from(1_u32),
));

assert_eq!(AssignedSlots::permanent_slot_count(), 0);
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 0);
assert_eq!(AssignedSlots::has_permanent_slot(ParaId::from(1_u32)), false);
assert_eq!(AssignedSlots::permanent_slots(ParaId::from(1_u32)), None);
assert_eq!(assigned_slots::PermanentSlots::<Test>::get(ParaId::from(1_u32)), None);

assert_eq!(Slots::already_leased(ParaId::from(1_u32), 0, 2), false);
});
Expand Down Expand Up @@ -1419,10 +1417,10 @@ mod tests {
ParaId::from(1_u32),
));

assert_eq!(AssignedSlots::temporary_slot_count(), 0);
assert_eq!(AssignedSlots::active_temporary_slot_count(), 0);
assert_eq!(assigned_slots::TemporarySlotCount::<Test>::get(), 0);
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 0);
assert_eq!(AssignedSlots::has_temporary_slot(ParaId::from(1_u32)), false);
assert_eq!(AssignedSlots::temporary_slots(ParaId::from(1_u32)), None);
assert_eq!(assigned_slots::TemporarySlots::<Test>::get(ParaId::from(1_u32)), None);

assert_eq!(Slots::already_leased(ParaId::from(1_u32), 0, 1), false);
});
Expand Down
Loading
Loading