Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove use of Store trait #6835

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Remove use of Store trait from runtime directory
  • Loading branch information
vivekvpandya committed Mar 8, 2023
commit 708784c2b059e36c13099468fed7decfe2f382c5
4 changes: 2 additions & 2 deletions primitives/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ pub mod well_known_keys {
//
// The `StorageValue`, such as `ACTIVE_CONFIG` was obtained by calling:
//
// <Self as Store>::ActiveConfig::hashed_key()
// ActiveConfig::<T>::hashed_key()
//
// The `StorageMap` values require `prefix`, and for example for `hrmp_egress_channel_index`,
// it could be obtained like:
//
// <Hrmp as Store>::HrmpEgressChannelsIndex::prefix_hash();
// HrmpEgressChannelsIndex::<T>::prefix_hash();
//

/// The current epoch index.
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/assigned_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub mod pallet {
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ pub mod pallet {
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

/// The module's configuration trait.
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ pub mod pallet {
use frame_system::pallet_prelude::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ pub mod pallet {
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ pub mod pallet {
use frame_system::pallet_prelude::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/paras_sudo_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod pallet {
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub mod pallet {
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down
1 change: 0 additions & 1 deletion runtime/common/src/slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pub mod pallet {
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down
11 changes: 5 additions & 6 deletions runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ pub mod pallet {
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(migration::STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
Expand Down Expand Up @@ -1155,7 +1154,7 @@ pub mod pallet {
))]
pub fn set_bypass_consistency_check(origin: OriginFor<T>, new: bool) -> DispatchResult {
ensure_root(origin)?;
<Self as Store>::BypassConsistencyCheck::put(new);
BypassConsistencyCheck::<T>::put(new);
Ok(())
}
}
Expand Down Expand Up @@ -1200,7 +1199,7 @@ impl<T: Config> Pallet<T> {
session_index: &SessionIndex,
) -> SessionChangeOutcome<T::BlockNumber> {
let pending_configs = <PendingConfigs<T>>::get();
let prev_config = <Self as Store>::ActiveConfig::get();
let prev_config = ActiveConfig::<T>::get();

// No pending configuration changes, so we're done.
if pending_configs.is_empty() {
Expand All @@ -1223,7 +1222,7 @@ impl<T: Config> Pallet<T> {
let new_config = past_and_present.pop().map(|(_, config)| config);
if let Some(ref new_config) = new_config {
// Apply the new configuration.
<Self as Store>::ActiveConfig::put(new_config);
ActiveConfig::<T>::put(new_config);
}

<PendingConfigs<T>>::put(future);
Expand All @@ -1240,7 +1239,7 @@ impl<T: Config> Pallet<T> {
/// only when enabling parachains runtime pallets for the first time on a chain which has
/// been running without them.
pub fn force_set_active_config(config: HostConfiguration<T::BlockNumber>) {
<Self as Store>::ActiveConfig::set(config);
ActiveConfig::<T>::set(config);
}

/// This function should be used to update members of the configuration.
Expand Down Expand Up @@ -1302,7 +1301,7 @@ impl<T: Config> Pallet<T> {
updater(&mut base_config);
let new_config = base_config;

if <Self as Store>::BypassConsistencyCheck::get() {
if BypassConsistencyCheck::<T>::get() {
// This will emit a warning each configuration update if the consistency check is
// bypassed. This is an attempt to make sure the bypass is not accidentally left on.
log::warn!(
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/configuration/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! A module that is responsible for migration of storage.

use crate::configuration::{self, Config, Pallet, Store, MAX_POV_SIZE};
use crate::configuration::{self, ActiveConfig, Config, Pallet, MAX_POV_SIZE};
use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight};
use frame_system::pallet_prelude::BlockNumberFor;

Expand Down Expand Up @@ -230,7 +230,7 @@ minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay,
}
};

if let Err(_) = <Pallet<T> as Store>::ActiveConfig::translate(|pre| pre.map(translate)) {
if let Err(_) = ActiveConfig::<T>::translate(|pre| pre.map(translate)) {
// `Err` is returned when the pre-migration type cannot be deserialized. This
// cannot happen if the migration runs correctly, i.e. against the expected version.
//
Expand Down
34 changes: 17 additions & 17 deletions runtime/parachains/src/configuration/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ fn config_changes_after_2_session_boundary() {
// Verify that the current configuration has not changed and that there is a scheduled
// change for the SESSION_DELAY sessions in advance.
assert_eq!(Configuration::config(), old_config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![(2, config.clone())]);
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, config.clone())]);

on_new_session(1);

// One session has passed, we should be still waiting for the pending configuration.
assert_eq!(Configuration::config(), old_config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![(2, config.clone())]);
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, config.clone())]);

on_new_session(2);

assert_eq!(Configuration::config(), config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![]);
assert_eq!(PendingConfigs::<Test>::get(), vec![]);
})
}

Expand All @@ -99,17 +99,17 @@ fn consecutive_changes_within_one_session() {
assert_ok!(Configuration::set_validation_upgrade_delay(RuntimeOrigin::root(), 100));
assert_ok!(Configuration::set_validation_upgrade_cooldown(RuntimeOrigin::root(), 100));
assert_eq!(Configuration::config(), old_config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![(2, config.clone())]);
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, config.clone())]);

on_new_session(1);

assert_eq!(Configuration::config(), old_config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![(2, config.clone())]);
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, config.clone())]);

on_new_session(2);

assert_eq!(Configuration::config(), config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![]);
assert_eq!(PendingConfigs::<Test>::get(), vec![]);
});
}

Expand All @@ -128,7 +128,7 @@ fn pending_next_session_but_we_upgrade_once_more() {
assert_ok!(Configuration::set_validation_upgrade_delay(RuntimeOrigin::root(), 100));
assert_eq!(Configuration::config(), initial_config);
assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(2, intermediate_config.clone())]
);

Expand All @@ -141,22 +141,22 @@ fn pending_next_session_but_we_upgrade_once_more() {
// This should result in yet another configiguration change scheduled.
assert_eq!(Configuration::config(), initial_config);
assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(2, intermediate_config.clone()), (3, final_config.clone())]
);

on_new_session(2);

assert_eq!(Configuration::config(), intermediate_config);
assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(3, final_config.clone())]
);

on_new_session(3);

assert_eq!(Configuration::config(), final_config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![]);
assert_eq!(PendingConfigs::<Test>::get(), vec![]);
});
}

Expand All @@ -176,7 +176,7 @@ fn scheduled_session_config_update_while_next_session_pending() {
assert_ok!(Configuration::set_validation_upgrade_delay(RuntimeOrigin::root(), 100));
assert_eq!(Configuration::config(), initial_config);
assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(2, intermediate_config.clone())]
);

Expand All @@ -190,22 +190,22 @@ fn scheduled_session_config_update_while_next_session_pending() {
// This should result in yet another configiguration change scheduled.
assert_eq!(Configuration::config(), initial_config);
assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(2, intermediate_config.clone()), (3, final_config.clone())]
);

on_new_session(2);

assert_eq!(Configuration::config(), intermediate_config);
assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(3, final_config.clone())]
);

on_new_session(3);

assert_eq!(Configuration::config(), final_config);
assert_eq!(<Configuration as Store>::PendingConfigs::get(), vec![]);
assert_eq!(PendingConfigs::<Test>::get(), vec![]);
});
}

Expand Down Expand Up @@ -240,7 +240,7 @@ fn invariants() {
Error::<Test>::InvalidNewValue
);

<Configuration as Store>::ActiveConfig::put(HostConfiguration {
ActiveConfig::<Test>::put(HostConfiguration {
chain_availability_period: 10,
thread_availability_period: 8,
minimum_validation_upgrade_delay: 11,
Expand Down Expand Up @@ -515,7 +515,7 @@ fn setting_pending_config_members() {
.unwrap();

assert_eq!(
<Configuration as Store>::PendingConfigs::get(),
PendingConfigs::<Test>::get(),
vec![(shared::SESSION_DELAY, new_config)],
);
})
Expand All @@ -539,7 +539,7 @@ fn verify_externally_accessible() {
let ground_truth = HostConfiguration::default();

// Make sure that the configuration is stored in the storage.
<Configuration as Store>::ActiveConfig::put(ground_truth.clone());
ActiveConfig::<Test>::put(ground_truth.clone());

// Extract the active config via the well known key.
let raw_active_config = sp_io::storage::get(well_known_keys::ACTIVE_CONFIG)
Expand Down
21 changes: 10 additions & 11 deletions runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub mod pallet {
use super::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down Expand Up @@ -135,8 +134,8 @@ impl<T: Config> Pallet<T> {

/// Remove all relevant storage items for an outgoing parachain.
fn clean_dmp_after_outgoing(outgoing_para: &ParaId) {
<Self as Store>::DownwardMessageQueues::remove(outgoing_para);
<Self as Store>::DownwardMessageQueueHeads::remove(outgoing_para);
DownwardMessageQueues::<T>::remove(outgoing_para);
DownwardMessageQueueHeads::<T>::remove(outgoing_para);
}

/// Determine whether enqueuing a downward message to a specific recipient para would result
Expand All @@ -152,7 +151,7 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

if <Self as Store>::DownwardMessageQueues::decode_len(para).unwrap_or(0) >
if DownwardMessageQueues::<T>::decode_len(para).unwrap_or(0) >
MAX_MESSAGE_QUEUE_SIZE
{
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
Expand All @@ -179,7 +178,7 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

if <Self as Store>::DownwardMessageQueues::decode_len(para).unwrap_or(0) >
if DownwardMessageQueues::<T>::decode_len(para).unwrap_or(0) >
MAX_MESSAGE_QUEUE_SIZE
{
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
Expand All @@ -189,13 +188,13 @@ impl<T: Config> Pallet<T> {
InboundDownwardMessage { msg, sent_at: <frame_system::Pallet<T>>::block_number() };

// obtain the new link in the MQC and update the head.
<Self as Store>::DownwardMessageQueueHeads::mutate(para, |head| {
DownwardMessageQueueHeads::<T>::mutate(para, |head| {
let new_head =
BlakeTwo256::hash_of(&(*head, inbound.sent_at, T::Hashing::hash_of(&inbound.msg)));
*head = new_head;
});

<Self as Store>::DownwardMessageQueues::mutate(para, |v| {
DownwardMessageQueues::<T>::mutate(para, |v| {
v.push(inbound);
});

Expand Down Expand Up @@ -224,7 +223,7 @@ impl<T: Config> Pallet<T> {

/// Prunes the specified number of messages from the downward message queue of the given para.
pub(crate) fn prune_dmq(para: ParaId, processed_downward_messages: u32) -> Weight {
<Self as Store>::DownwardMessageQueues::mutate(para, |q| {
DownwardMessageQueues::<T>::mutate(para, |q| {
let processed_downward_messages = processed_downward_messages as usize;
if processed_downward_messages > q.len() {
// reaching this branch is unexpected due to the constraint established by
Expand All @@ -241,14 +240,14 @@ impl<T: Config> Pallet<T> {
/// associated with it.
#[cfg(test)]
fn dmq_mqc_head(para: ParaId) -> Hash {
<Self as Store>::DownwardMessageQueueHeads::get(&para)
DownwardMessageQueueHeads::<T>::get(&para)
}

/// Returns the number of pending downward messages addressed to the given para.
///
/// Returns 0 if the para doesn't have an associated downward message queue.
pub(crate) fn dmq_length(para: ParaId) -> u32 {
<Self as Store>::DownwardMessageQueues::decode_len(&para)
DownwardMessageQueues::<T>::decode_len(&para)
.unwrap_or(0)
.saturated_into::<u32>()
}
Expand All @@ -257,6 +256,6 @@ impl<T: Config> Pallet<T> {
///
/// The most recent messages are the latest in the vector.
pub(crate) fn dmq_contents(recipient: ParaId) -> Vec<InboundDownwardMessage<T::BlockNumber>> {
<Self as Store>::DownwardMessageQueues::get(&recipient)
DownwardMessageQueues::<T>::get(&recipient)
}
}
8 changes: 4 additions & 4 deletions runtime/parachains/src/dmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use crate::mock::{new_test_ext, Configuration, Dmp, MockGenesisConfig, Paras, System};
use crate::mock::{new_test_ext, Configuration, Dmp, MockGenesisConfig, Paras, System, Test};
use hex_literal::hex;
use parity_scale_codec::Encode;
use primitives::BlockNumber;
Expand Down Expand Up @@ -73,9 +73,9 @@ fn clean_dmp_works() {
let outgoing_paras = vec![a, b];
Dmp::initializer_on_new_session(&notification, &outgoing_paras);

assert!(<Dmp as Store>::DownwardMessageQueues::get(&a).is_empty());
assert!(<Dmp as Store>::DownwardMessageQueues::get(&b).is_empty());
assert!(!<Dmp as Store>::DownwardMessageQueues::get(&c).is_empty());
assert!(DownwardMessageQueues::<Test>::get(&a).is_empty());
assert!(DownwardMessageQueues::<Test>::get(&b).is_empty());
assert!(!DownwardMessageQueues::<Test>::get(&c).is_empty());
});
}

Expand Down
Loading