Skip to content

Commit

Permalink
feat: remove use 'storage::getter', following polkadot-sdk paritytech…
Browse files Browse the repository at this point in the history
  • Loading branch information
LGLO committed Aug 13, 2024
1 parent 1d06167 commit 1967ee5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This changelog is based on [Keep A Changelog](https://keepachangelog.com/en/1.1.
* polkadot-sdk dependency updated to partnerchains-stable2407 (stable2407 is v1.15.0 in the previous scheme)
* remove Relay docker build files
* changed the inner type of `McBlockHash` from Vec to an array
* removed usage of 'storage::getter' macros, following polkadot-sdk changes

## Removed

Expand Down
13 changes: 11 additions & 2 deletions pallets/session-validator-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,13 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::getter(fn current_committee_storage)]
pub type CurrentCommittee<T: Config> = StorageValue<
_,
CommitteeInfo<T::ScEpochNumber, T::AuthorityId, T::AuthorityKeys, T::MaxValidators>,
ValueQuery,
>;

#[pallet::storage]
#[pallet::getter(fn next_committee_storage)]
pub type NextCommittee<T: Config> = StorageValue<
_,
CommitteeInfo<T::ScEpochNumber, T::AuthorityId, T::AuthorityKeys, T::MaxValidators>,
Expand Down Expand Up @@ -280,6 +278,17 @@ pub mod pallet {
.clone()
}

pub fn current_committee_storage(
) -> CommitteeInfo<T::ScEpochNumber, T::AuthorityId, T::AuthorityKeys, T::MaxValidators> {
CurrentCommittee::<T>::get()
}

pub fn next_committee_storage() -> Option<
CommitteeInfo<T::ScEpochNumber, T::AuthorityId, T::AuthorityKeys, T::MaxValidators>,
> {
NextCommittee::<T>::get()
}

/// This function's result should be always defined after inherent call of 1st block of each epoch
pub fn next_committee() -> Option<BoundedVec<T::AuthorityId, T::MaxValidators>> {
Some(BoundedVec::truncate_from(
Expand Down
3 changes: 1 addition & 2 deletions pallets/session-validator-management/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub mod mock_pallet {
pub trait Config: frame_system::Config {}

#[pallet::storage]
#[pallet::getter(fn current_epoch)]
pub type CurrentEpoch<T: Config> = StorageValue<_, u64, ValueQuery>;
}

Expand Down Expand Up @@ -202,5 +201,5 @@ pub fn create_inherent_set_validators_call(
}

pub(crate) fn current_epoch_number() -> u64 {
Mock::current_epoch()
mock_pallet::CurrentEpoch::<Test>::get()
}
6 changes: 4 additions & 2 deletions pallets/sidechain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ pub mod pallet {
}

#[pallet::storage]
#[pallet::getter(fn epoch_number)]
pub(super) type EpochNumber<T: Config> = StorageValue<_, ScEpochNumber, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn slots_per_epoch)]
pub(super) type SlotsPerEpoch<T: Config> =
StorageValue<_, sidechain_slots::SlotsPerEpoch, ValueQuery>;

Expand All @@ -53,6 +51,10 @@ pub mod pallet {
let slots_per_epoch = Self::slots_per_epoch();
slots_per_epoch.epoch_number_from_sc_slot(current_slot)
}

pub fn slots_per_epoch() -> sidechain_slots::SlotsPerEpoch {
SlotsPerEpoch::<T>::get()
}
}

#[pallet::genesis_config]
Expand Down
5 changes: 1 addition & 4 deletions pallets/sidechain/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ pub(crate) mod mock_pallet {
pub trait Config: frame_system::Config {}

#[pallet::storage]
#[pallet::getter(fn current_epoch)]
pub type CurrentEpoch<T: Config> = StorageValue<_, ScEpochNumber, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn current_slot)]
pub type CurrentSlot<T: Config> = StorageValue<_, ScSlotNumber, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn on_new_epoch_call_count)]
pub type OnNewEpochCallCount<T: Config> = StorageValue<_, u32, ValueQuery>;

impl<T: Config> OnNewEpoch for Pallet<T> {
Expand Down Expand Up @@ -97,7 +94,7 @@ impl frame_system::Config for Test {

impl pallet::Config for Test {
fn current_slot_number() -> ScSlotNumber {
Mock::current_slot()
mock_pallet::CurrentSlot::<Test>::get()
}
type OnNewEpoch = Mock;
type SidechainParams = u64;
Expand Down
6 changes: 3 additions & 3 deletions pallets/sidechain/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ fn on_new_epoch_is_triggered_by_epoch_change() {
new_test_ext().execute_with(|| {
Mock::set_slot(4);
Sidechain::on_initialize(1);
assert_eq!(Mock::on_new_epoch_call_count(), 0);
assert_eq!(mock_pallet::OnNewEpochCallCount::<Test>::get(), 0);

Mock::set_slot(MOCK_SLOTS_PER_EPOCH.0.into());
Sidechain::on_initialize(3);
assert_eq!(Mock::on_new_epoch_call_count(), 1);
assert_eq!(mock_pallet::OnNewEpochCallCount::<Test>::get(), 1);
})
}

Expand All @@ -23,7 +23,7 @@ fn on_new_epoch_is_not_triggered_without_epoch_change() {
Sidechain::on_initialize(2);
Mock::set_slot(u64::from(MOCK_SLOTS_PER_EPOCH.0) - 1);
Sidechain::on_initialize(3);
assert_eq!(Mock::on_new_epoch_call_count(), 0);
assert_eq!(mock_pallet::OnNewEpochCallCount::<Test>::get(), 0);
})
}

Expand Down

0 comments on commit 1967ee5

Please sign in to comment.