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 cumulus pallets #3471

Merged
merged 12 commits into from
Mar 18, 2024
6 changes: 3 additions & 3 deletions cumulus/pallets/aura-ext/src/consensus_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ where
let velocity = V.max(1);
let relay_chain_slot = state_proof.read_slot().expect("failed to read relay chain slot");

let (slot, authored) = pallet::Pallet::<T>::slot_info()
.expect("slot info is inserted on block initialization");
let (slot, authored) =
pallet::SlotInfo::<T>::get().expect("slot info is inserted on block initialization");

// Convert relay chain timestamp.
let relay_chain_timestamp =
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<
/// is more recent than the included block itself.
pub fn can_build_upon(included_hash: T::Hash, new_slot: Slot) -> bool {
let velocity = V.max(1);
let (last_slot, authored_so_far) = match pallet::Pallet::<T>::slot_info() {
let (last_slot, authored_so_far) = match pallet::SlotInfo::<T>::get() {
None => return true,
Some(x) => x,
};
Expand Down
1 change: 0 additions & 1 deletion cumulus/pallets/aura-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ pub mod pallet {
///
/// Updated on each block initialization.
#[pallet::storage]
#[pallet::getter(fn slot_info)]
pub(crate) type SlotInfo<T: Config> = StorageValue<_, (Slot, u32), OptionQuery>;

#[pallet::genesis_config]
Expand Down
17 changes: 6 additions & 11 deletions cumulus/pallets/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ pub mod pallet {

/// The invulnerable, permissioned collators. This list must be sorted.
#[pallet::storage]
#[pallet::getter(fn invulnerables)]
pub type Invulnerables<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, T::MaxInvulnerables>, ValueQuery>;

Expand All @@ -206,7 +205,6 @@ pub mod pallet {
/// This list is sorted in ascending order by deposit and when the deposits are equal, the least
/// recently updated is considered greater.
#[pallet::storage]
#[pallet::getter(fn candidate_list)]
pub type CandidateList<T: Config> = StorageValue<
_,
BoundedVec<CandidateInfo<T::AccountId, BalanceOf<T>>, T::MaxCandidates>,
Expand All @@ -215,22 +213,19 @@ pub mod pallet {

/// Last block authored by collator.
#[pallet::storage]
#[pallet::getter(fn last_authored_block)]
pub type LastAuthoredBlock<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, BlockNumberFor<T>, ValueQuery>;

/// Desired number of candidates.
///
/// This should ideally always be less than [`Config::MaxCandidates`] for weights to be correct.
#[pallet::storage]
#[pallet::getter(fn desired_candidates)]
pub type DesiredCandidates<T> = StorageValue<_, u32, ValueQuery>;

/// Fixed amount to deposit to become a collator.
///
/// When a collator calls `leave_intent` they immediately receive the deposit back.
#[pallet::storage]
#[pallet::getter(fn candidacy_bond)]
pub type CandidacyBond<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;

#[pallet::genesis_config]
Expand Down Expand Up @@ -513,7 +508,7 @@ pub mod pallet {
.try_into()
.unwrap_or_default();
ensure!(length < T::MaxCandidates::get(), Error::<T>::TooManyCandidates);
ensure!(!Self::invulnerables().contains(&who), Error::<T>::AlreadyInvulnerable);
ensure!(!Invulnerables::<T>::get().contains(&who), Error::<T>::AlreadyInvulnerable);

let validator_key = T::ValidatorIdOf::convert(who.clone())
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
Expand All @@ -522,7 +517,7 @@ pub mod pallet {
Error::<T>::ValidatorNotRegistered
);

let deposit = Self::candidacy_bond();
let deposit = CandidacyBond::<T>::get();
// First authored block is current block plus kick threshold to handle session delay
<CandidateList<T>>::try_mutate(|candidates| -> Result<(), DispatchError> {
ensure!(
Expand Down Expand Up @@ -723,8 +718,8 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;

ensure!(!Self::invulnerables().contains(&who), Error::<T>::AlreadyInvulnerable);
ensure!(deposit >= Self::candidacy_bond(), Error::<T>::InsufficientBond);
ensure!(!Invulnerables::<T>::get().contains(&who), Error::<T>::AlreadyInvulnerable);
ensure!(deposit >= CandidacyBond::<T>::get(), Error::<T>::InsufficientBond);

let validator_key = T::ValidatorIdOf::convert(who.clone())
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
Expand Down Expand Up @@ -838,7 +833,7 @@ pub mod pallet {
pub fn assemble_collators() -> Vec<T::AccountId> {
// Casting `u32` to `usize` should be safe on all machines running this.
let desired_candidates = <DesiredCandidates<T>>::get() as usize;
let mut collators = Self::invulnerables().to_vec();
let mut collators = Invulnerables::<T>::get().to_vec();
collators.extend(
<CandidateList<T>>::get()
.iter()
Expand All @@ -864,7 +859,7 @@ pub mod pallet {
let last_block = <LastAuthoredBlock<T>>::get(c.clone());
let since_last = now.saturating_sub(last_block);

let is_invulnerable = Self::invulnerables().contains(&c);
let is_invulnerable = Invulnerables::<T>::get().contains(&c);
let is_lazy = since_last >= kick_threshold;

if is_invulnerable {
Expand Down
Loading
Loading