Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 92e1425

Browse files
muracaordian
andauthored
Removed pallet::getter usage from Polkadot Runtime pallets (paritytech#3660)
Part of paritytech#3326 @kianenigma @ggwpez polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Signed-off-by: Matteo Muraca <[email protected]> Co-authored-by: ordian <[email protected]>
1 parent d96a975 commit 92e1425

File tree

58 files changed

+834
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+834
-820
lines changed

polkadot/roadmap/implementers-guide/src/runtime/disputes.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ This is currently a `no op`.
121121

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

124-
* `last_valid_block()`: Load the value of `Frozen` from storage and return. None indicates that all blocks in the chain
125-
are potentially valid.
126-
127124
* `revert_and_freeze(BlockNumber)`:
128125
1. If `is_frozen()` return.
129126
1. Set `Frozen` to `Some(BlockNumber)` to indicate a rollback to the block number.

polkadot/roadmap/implementers-guide/src/runtime/scheduler.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Actions:
229229
[`HostConfiguration`](../types/runtime.md#host-configuration))
230230
1. Fetch `Shared::ActiveValidators` as AV.
231231
1. Determine the number of cores & validator groups as `n_cores`. This is the maximum of
232-
1. `Paras::parachains().len() + configuration.parathread_cores`
232+
1. `paras::Parachains::<T>::get().len() + configuration.parathread_cores`
233233
1. `n_validators / max_validators_per_core` if `configuration.max_validators_per_core` is `Some` and non-zero.
234234
1. Resize `AvailabilityCores` to have length `n_cores` with all `None` entries.
235235
1. Compute new validator groups by shuffling using a secure randomness beacon
@@ -261,7 +261,7 @@ No finalization routine runs for this module.
261261
- Fails if any on-demand claim on the same parachain is currently indexed.
262262
- Fails if the queue length is >= `config.scheduling_lookahead * config.parathread_cores`.
263263
- The core used for the on-demand claim is the `next_core` field of the `ParathreadQueue` (on-demand queue) and adding
264-
`Paras::parachains().len()` to it.
264+
`paras::Parachains::<T>::get().len()` to it.
265265
- `next_core` is then updated by adding 1 and taking it modulo `config.parathread_cores`.
266266
- The claim is then added to the claim index.
267267
- `free_cores(Vec<(CoreIndex, FreedReason)>)`: indicate previously-occupied cores which are to be considered returned

polkadot/roadmap/implementers-guide/src/runtime/session_info.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ Sessions: map SessionIndex => Option<SessionInfo>,
7676

7777
## Routines
7878

79-
* `earliest_stored_session() -> SessionIndex`: Yields the earliest session for which we have information stored.
80-
* `session_info(session: SessionIndex) -> Option<SessionInfo>`: Yields the session info for the given session, if
79+
* `EarliestStoredSession::<T>::get() -> SessionIndex`: Yields the earliest session for which we have information stored.
80+
* `Sessions::<T>::get(session: SessionIndex) -> Option<SessionInfo>`: Yields the session info for the given session, if
8181
stored.

polkadot/runtime/common/src/assigned_slots/migration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub mod v1 {
3939
const MAX_PERMANENT_SLOTS: u32 = 100;
4040
const MAX_TEMPORARY_SLOTS: u32 = 100;
4141

42-
<MaxPermanentSlots<T>>::put(MAX_PERMANENT_SLOTS);
43-
<MaxTemporarySlots<T>>::put(MAX_TEMPORARY_SLOTS);
42+
MaxPermanentSlots::<T>::put(MAX_PERMANENT_SLOTS);
43+
MaxTemporarySlots::<T>::put(MAX_TEMPORARY_SLOTS);
4444
// Return the weight consumed by the migration.
4545
T::DbWeight::get().reads_writes(1, 3)
4646
} else {
@@ -53,8 +53,8 @@ pub mod v1 {
5353
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
5454
let on_chain_version = Pallet::<T>::on_chain_storage_version();
5555
ensure!(on_chain_version == 1, "assigned_slots::MigrateToV1 needs to be run");
56-
assert_eq!(<MaxPermanentSlots<T>>::get(), 100);
57-
assert_eq!(<MaxTemporarySlots<T>>::get(), 100);
56+
assert_eq!(MaxPermanentSlots::<T>::get(), 100);
57+
assert_eq!(MaxTemporarySlots::<T>::get(), 100);
5858
Ok(())
5959
}
6060
}

polkadot/runtime/common/src/assigned_slots/mod.rs

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,15 @@ pub mod pallet {
148148

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

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

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

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

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

181176
/// The max number of temporary slots that can be assigned.
@@ -197,8 +192,8 @@ pub mod pallet {
197192
#[pallet::genesis_build]
198193
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
199194
fn build(&self) {
200-
<MaxPermanentSlots<T>>::put(&self.max_permanent_slots);
201-
<MaxTemporarySlots<T>>::put(&self.max_temporary_slots);
195+
MaxPermanentSlots::<T>::put(&self.max_permanent_slots);
196+
MaxTemporarySlots::<T>::put(&self.max_temporary_slots);
202197
}
203198
}
204199

@@ -306,7 +301,7 @@ pub mod pallet {
306301
LeasePeriodOf::<T>::from(T::PermanentSlotLeasePeriodLength::get()),
307302
),
308303
);
309-
<PermanentSlotCount<T>>::mutate(|count| count.saturating_inc());
304+
PermanentSlotCount::<T>::mutate(|count| count.saturating_inc());
310305

311306
Self::deposit_event(Event::<T>::PermanentSlotAssigned(id));
312307
Ok(())
@@ -364,7 +359,7 @@ pub mod pallet {
364359
};
365360

366361
if lease_period_start == SlotLeasePeriodStart::Current &&
367-
Self::active_temporary_slot_count() < T::MaxTemporarySlotPerLeasePeriod::get()
362+
ActiveTemporarySlotCount::<T>::get() < T::MaxTemporarySlotPerLeasePeriod::get()
368363
{
369364
// Try to allocate slot directly
370365
match Self::configure_slot_lease(
@@ -394,7 +389,7 @@ pub mod pallet {
394389
}
395390

396391
TemporarySlots::<T>::insert(id, temp_slot);
397-
<TemporarySlotCount<T>>::mutate(|count| count.saturating_inc());
392+
TemporarySlotCount::<T>::mutate(|count| count.saturating_inc());
398393

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

@@ -420,12 +415,12 @@ pub mod pallet {
420415

421416
if PermanentSlots::<T>::contains_key(id) {
422417
PermanentSlots::<T>::remove(id);
423-
<PermanentSlotCount<T>>::mutate(|count| *count = count.saturating_sub(One::one()));
418+
PermanentSlotCount::<T>::mutate(|count| *count = count.saturating_sub(One::one()));
424419
} else if TemporarySlots::<T>::contains_key(id) {
425420
TemporarySlots::<T>::remove(id);
426-
<TemporarySlotCount<T>>::mutate(|count| *count = count.saturating_sub(One::one()));
421+
TemporarySlotCount::<T>::mutate(|count| *count = count.saturating_sub(One::one()));
427422
if is_parachain {
428-
<ActiveTemporarySlotCount<T>>::mutate(|active_count| {
423+
ActiveTemporarySlotCount::<T>::mutate(|active_count| {
429424
*active_count = active_count.saturating_sub(One::one())
430425
});
431426
}
@@ -456,7 +451,7 @@ pub mod pallet {
456451
pub fn set_max_permanent_slots(origin: OriginFor<T>, slots: u32) -> DispatchResult {
457452
ensure_root(origin)?;
458453

459-
<MaxPermanentSlots<T>>::put(slots);
454+
MaxPermanentSlots::<T>::put(slots);
460455

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

471-
<MaxTemporarySlots<T>>::put(slots);
466+
MaxTemporarySlots::<T>::put(slots);
472467

473468
Self::deposit_event(Event::<T>::MaxTemporarySlotsChanged { slots });
474469
Ok(())
@@ -965,7 +960,7 @@ mod tests {
965960
RuntimeOrigin::root(),
966961
ParaId::from(2_u32),
967962
));
968-
assert_eq!(AssignedSlots::permanent_slot_count(), 2);
963+
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 2);
969964

970965
assert_noop!(
971966
AssignedSlots::assign_perm_parachain_slot(
@@ -989,8 +984,8 @@ mod tests {
989984
dummy_validation_code(),
990985
));
991986

992-
assert_eq!(AssignedSlots::permanent_slot_count(), 0);
993-
assert_eq!(AssignedSlots::permanent_slots(ParaId::from(1_u32)), None);
987+
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 0);
988+
assert_eq!(assigned_slots::PermanentSlots::<Test>::get(ParaId::from(1_u32)), None);
994989

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

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

1007-
assert_eq!(AssignedSlots::permanent_slot_count(), 1);
1002+
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 1);
10081003
assert_eq!(AssignedSlots::has_permanent_slot(ParaId::from(1_u32)), true);
1009-
assert_eq!(AssignedSlots::permanent_slots(ParaId::from(1_u32)), Some((0, 3)));
1004+
assert_eq!(
1005+
assigned_slots::PermanentSlots::<Test>::get(ParaId::from(1_u32)),
1006+
Some((0, 3))
1007+
);
10101008

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

@@ -1138,7 +1136,7 @@ mod tests {
11381136
));
11391137
}
11401138

1141-
assert_eq!(AssignedSlots::temporary_slot_count(), 6);
1139+
assert_eq!(assigned_slots::TemporarySlotCount::<Test>::get(), 6);
11421140

11431141
// Attempt to assign one more temp slot
11441142
assert_ok!(TestRegistrar::<Test>::register(
@@ -1170,30 +1168,30 @@ mod tests {
11701168
dummy_validation_code(),
11711169
));
11721170

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

11751173
assert_ok!(AssignedSlots::assign_temp_parachain_slot(
11761174
RuntimeOrigin::root(),
11771175
ParaId::from(1_u32),
11781176
SlotLeasePeriodStart::Current
11791177
));
1180-
assert_eq!(AssignedSlots::temporary_slot_count(), 1);
1181-
assert_eq!(AssignedSlots::active_temporary_slot_count(), 1);
1178+
assert_eq!(assigned_slots::TemporarySlotCount::<Test>::get(), 1);
1179+
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 1);
11821180

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

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

11931191
assert_eq!(AssignedSlots::has_temporary_slot(ParaId::from(1_u32)), true);
1194-
assert_eq!(AssignedSlots::active_temporary_slot_count(), 1);
1192+
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 1);
11951193
assert_eq!(
1196-
AssignedSlots::temporary_slots(ParaId::from(1_u32)),
1194+
assigned_slots::TemporarySlots::<Test>::get(ParaId::from(1_u32)),
11971195
Some(ParachainTemporarySlot {
11981196
manager: 1,
11991197
period_begin: 0,
@@ -1212,23 +1210,23 @@ mod tests {
12121210
// Block 6
12131211
println!("block #{}", block);
12141212
println!("lease period #{}", AssignedSlots::current_lease_period_index());
1215-
println!("lease {:?}", Slots::lease(ParaId::from(1_u32)));
1213+
println!("lease {:?}", slots::Leases::<Test>::get(ParaId::from(1_u32)));
12161214

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

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

12291227
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(1_u32)), true);
12301228
assert_eq!(Slots::already_leased(ParaId::from(1_u32), 4, 5), true);
1231-
assert_eq!(AssignedSlots::active_temporary_slot_count(), 1);
1229+
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 1);
12321230
});
12331231
}
12341232

@@ -1270,7 +1268,7 @@ mod tests {
12701268
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), false);
12711269
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), false);
12721270
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), false);
1273-
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
1271+
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
12741272
}
12751273

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

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

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

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

13241322
// Block 30-35, Period 10-11
@@ -1330,7 +1328,7 @@ mod tests {
13301328
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(3_u32)), false);
13311329
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(4_u32)), true);
13321330
assert_eq!(TestRegistrar::<Test>::is_parachain(ParaId::from(5_u32)), true);
1333-
assert_eq!(AssignedSlots::active_temporary_slot_count(), 2);
1331+
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 2);
13341332
}
13351333
});
13361334
}
@@ -1386,9 +1384,9 @@ mod tests {
13861384
ParaId::from(1_u32),
13871385
));
13881386

1389-
assert_eq!(AssignedSlots::permanent_slot_count(), 0);
1387+
assert_eq!(assigned_slots::PermanentSlotCount::<Test>::get(), 0);
13901388
assert_eq!(AssignedSlots::has_permanent_slot(ParaId::from(1_u32)), false);
1391-
assert_eq!(AssignedSlots::permanent_slots(ParaId::from(1_u32)), None);
1389+
assert_eq!(assigned_slots::PermanentSlots::<Test>::get(ParaId::from(1_u32)), None);
13921390

13931391
assert_eq!(Slots::already_leased(ParaId::from(1_u32), 0, 2), false);
13941392
});
@@ -1419,10 +1417,10 @@ mod tests {
14191417
ParaId::from(1_u32),
14201418
));
14211419

1422-
assert_eq!(AssignedSlots::temporary_slot_count(), 0);
1423-
assert_eq!(AssignedSlots::active_temporary_slot_count(), 0);
1420+
assert_eq!(assigned_slots::TemporarySlotCount::<Test>::get(), 0);
1421+
assert_eq!(assigned_slots::ActiveTemporarySlotCount::<Test>::get(), 0);
14241422
assert_eq!(AssignedSlots::has_temporary_slot(ParaId::from(1_u32)), false);
1425-
assert_eq!(AssignedSlots::temporary_slots(ParaId::from(1_u32)), None);
1423+
assert_eq!(assigned_slots::TemporarySlots::<Test>::get(ParaId::from(1_u32)), None);
14261424

14271425
assert_eq!(Slots::already_leased(ParaId::from(1_u32), 0, 1), false);
14281426
});

0 commit comments

Comments
 (0)