mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
Remove use of Store trait (#6835)
* Remove use of Store trait from runtime directory
* Remove Store trait usage from xcm directory
* Run cargo fmt
* update lockfile for {"substrate"}
---------
Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -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>(_);
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
@@ -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);
|
||||
@@ -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.
|
||||
@@ -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!(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
@@ -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![]);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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![]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -127,10 +127,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(),
|
||||
vec![(2, intermediate_config.clone())]
|
||||
);
|
||||
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, intermediate_config.clone())]);
|
||||
|
||||
on_new_session(1);
|
||||
|
||||
@@ -141,22 +138,19 @@ 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(),
|
||||
vec![(3, final_config.clone())]
|
||||
);
|
||||
assert_eq!(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![]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -175,10 +169,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(),
|
||||
vec![(2, intermediate_config.clone())]
|
||||
);
|
||||
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, intermediate_config.clone())]);
|
||||
|
||||
on_new_session(1);
|
||||
|
||||
@@ -190,22 +181,19 @@ 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(),
|
||||
vec![(3, final_config.clone())]
|
||||
);
|
||||
assert_eq!(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![]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -240,7 +228,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,
|
||||
@@ -514,10 +502,7 @@ fn setting_pending_config_members() {
|
||||
Configuration::set_pvf_voting_ttl(RuntimeOrigin::root(), new_config.pvf_voting_ttl)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
<Configuration as Store>::PendingConfigs::get(),
|
||||
vec![(shared::SESSION_DELAY, new_config)],
|
||||
);
|
||||
assert_eq!(PendingConfigs::<Test>::get(), vec![(shared::SESSION_DELAY, new_config)],);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -539,7 +524,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)
|
||||
|
||||
@@ -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>(_);
|
||||
|
||||
@@ -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
|
||||
@@ -152,9 +151,7 @@ impl<T: Config> Pallet<T> {
|
||||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
|
||||
}
|
||||
|
||||
if <Self as Store>::DownwardMessageQueues::decode_len(para).unwrap_or(0) >
|
||||
MAX_MESSAGE_QUEUE_SIZE
|
||||
{
|
||||
if DownwardMessageQueues::<T>::decode_len(para).unwrap_or(0) > MAX_MESSAGE_QUEUE_SIZE {
|
||||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
|
||||
}
|
||||
|
||||
@@ -179,9 +176,7 @@ impl<T: Config> Pallet<T> {
|
||||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
|
||||
}
|
||||
|
||||
if <Self as Store>::DownwardMessageQueues::decode_len(para).unwrap_or(0) >
|
||||
MAX_MESSAGE_QUEUE_SIZE
|
||||
{
|
||||
if DownwardMessageQueues::<T>::decode_len(para).unwrap_or(0) > MAX_MESSAGE_QUEUE_SIZE {
|
||||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
|
||||
}
|
||||
|
||||
@@ -189,13 +184,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);
|
||||
});
|
||||
|
||||
@@ -224,7 +219,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
|
||||
@@ -241,14 +236,14 @@ impl<T: Config> Pallet<T> {
|
||||
/// associated with it.
|
||||
#[cfg(test)]
|
||||
fn dmq_mqc_head(para: ParaId) -> Hash {
|
||||
<Self as Store>::DownwardMessageQueueHeads::get(¶)
|
||||
DownwardMessageQueueHeads::<T>::get(¶)
|
||||
}
|
||||
|
||||
/// 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(¶)
|
||||
DownwardMessageQueues::<T>::decode_len(¶)
|
||||
.unwrap_or(0)
|
||||
.saturated_into::<u32>()
|
||||
}
|
||||
@@ -257,6 +252,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -73,9 +73,9 @@ fn clean_dmp_works() {
|
||||
let outgoing_paras = vec![a, b];
|
||||
Dmp::initializer_on_new_session(¬ification, &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());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +235,6 @@ pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
@@ -584,8 +583,8 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_parachain(<T as Config>::RuntimeOrigin::from(origin))?;
|
||||
ensure!(
|
||||
<Self as Store>::HrmpOpenChannelRequestsList::decode_len().unwrap_or_default()
|
||||
as u32 <= open_requests,
|
||||
HrmpOpenChannelRequestsList::<T>::decode_len().unwrap_or_default() as u32 <=
|
||||
open_requests,
|
||||
Error::<T>::WrongWitness
|
||||
);
|
||||
Self::cancel_open_request(origin, channel_id.clone())?;
|
||||
@@ -685,10 +684,10 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// we need a few extra bits of data to weigh this -- all of this is read internally
|
||||
// anyways, so no overhead.
|
||||
let ingress_count = <Self as Store>::HrmpIngressChannelsIndex::decode_len(outgoing_para)
|
||||
.unwrap_or_default() as u32;
|
||||
let egress_count = <Self as Store>::HrmpEgressChannelsIndex::decode_len(outgoing_para)
|
||||
.unwrap_or_default() as u32;
|
||||
let ingress_count =
|
||||
HrmpIngressChannelsIndex::<T>::decode_len(outgoing_para).unwrap_or_default() as u32;
|
||||
let egress_count =
|
||||
HrmpEgressChannelsIndex::<T>::decode_len(outgoing_para).unwrap_or_default() as u32;
|
||||
w = w.saturating_add(<T as Config>::WeightInfo::force_clean_hrmp(
|
||||
ingress_count,
|
||||
egress_count,
|
||||
@@ -709,16 +708,16 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// Both the open channel request list and outgoing list are expected to be small enough.
|
||||
// In the most common case there will be only single outgoing para.
|
||||
let open_channel_reqs = <Self as Store>::HrmpOpenChannelRequestsList::get();
|
||||
let open_channel_reqs = HrmpOpenChannelRequestsList::<T>::get();
|
||||
let (go, stay): (Vec<HrmpChannelId>, Vec<HrmpChannelId>) = open_channel_reqs
|
||||
.into_iter()
|
||||
.partition(|req_id| outgoing.iter().any(|id| req_id.is_participant(*id)));
|
||||
<Self as Store>::HrmpOpenChannelRequestsList::put(stay);
|
||||
HrmpOpenChannelRequestsList::<T>::put(stay);
|
||||
|
||||
// Then iterate over all open requests to be removed, pull them out of the set and perform
|
||||
// the refunds if applicable.
|
||||
for req_id in go {
|
||||
let req_data = match <Self as Store>::HrmpOpenChannelRequests::take(&req_id) {
|
||||
let req_data = match HrmpOpenChannelRequests::<T>::take(&req_id) {
|
||||
Some(req_data) => req_data,
|
||||
None => {
|
||||
// Can't normally happen but no need to panic.
|
||||
@@ -755,13 +754,13 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Remove all storage entries associated with the given para.
|
||||
fn clean_hrmp_after_outgoing(outgoing_para: &ParaId) {
|
||||
<Self as Store>::HrmpOpenChannelRequestCount::remove(outgoing_para);
|
||||
<Self as Store>::HrmpAcceptedChannelRequestCount::remove(outgoing_para);
|
||||
HrmpOpenChannelRequestCount::<T>::remove(outgoing_para);
|
||||
HrmpAcceptedChannelRequestCount::<T>::remove(outgoing_para);
|
||||
|
||||
let ingress = <Self as Store>::HrmpIngressChannelsIndex::take(outgoing_para)
|
||||
let ingress = HrmpIngressChannelsIndex::<T>::take(outgoing_para)
|
||||
.into_iter()
|
||||
.map(|sender| HrmpChannelId { sender, recipient: *outgoing_para });
|
||||
let egress = <Self as Store>::HrmpEgressChannelsIndex::take(outgoing_para)
|
||||
let egress = HrmpEgressChannelsIndex::<T>::take(outgoing_para)
|
||||
.into_iter()
|
||||
.map(|recipient| HrmpChannelId { sender: *outgoing_para, recipient });
|
||||
let mut to_close = ingress.chain(egress).collect::<Vec<_>>();
|
||||
@@ -778,7 +777,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// - prune the stale requests
|
||||
/// - enact the confirmed requests
|
||||
fn process_hrmp_open_channel_requests(config: &HostConfiguration<T::BlockNumber>) {
|
||||
let mut open_req_channels = <Self as Store>::HrmpOpenChannelRequestsList::get();
|
||||
let mut open_req_channels = HrmpOpenChannelRequestsList::<T>::get();
|
||||
if open_req_channels.is_empty() {
|
||||
return
|
||||
}
|
||||
@@ -794,7 +793,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
idx -= 1;
|
||||
let channel_id = open_req_channels[idx].clone();
|
||||
let request = <Self as Store>::HrmpOpenChannelRequests::get(&channel_id).expect(
|
||||
let request = HrmpOpenChannelRequests::<T>::get(&channel_id).expect(
|
||||
"can't be `None` due to the invariant that the list contains the same items as the set; qed",
|
||||
);
|
||||
|
||||
@@ -802,7 +801,7 @@ impl<T: Config> Pallet<T> {
|
||||
if <paras::Pallet<T>>::is_valid_para(channel_id.sender) &&
|
||||
<paras::Pallet<T>>::is_valid_para(channel_id.recipient)
|
||||
{
|
||||
<Self as Store>::HrmpChannels::insert(
|
||||
HrmpChannels::<T>::insert(
|
||||
&channel_id,
|
||||
HrmpChannel {
|
||||
sender_deposit: request.sender_deposit,
|
||||
@@ -816,12 +815,12 @@ impl<T: Config> Pallet<T> {
|
||||
},
|
||||
);
|
||||
|
||||
<Self as Store>::HrmpIngressChannelsIndex::mutate(&channel_id.recipient, |v| {
|
||||
HrmpIngressChannelsIndex::<T>::mutate(&channel_id.recipient, |v| {
|
||||
if let Err(i) = v.binary_search(&channel_id.sender) {
|
||||
v.insert(i, channel_id.sender);
|
||||
}
|
||||
});
|
||||
<Self as Store>::HrmpEgressChannelsIndex::mutate(&channel_id.sender, |v| {
|
||||
HrmpEgressChannelsIndex::<T>::mutate(&channel_id.sender, |v| {
|
||||
if let Err(i) = v.binary_search(&channel_id.recipient) {
|
||||
v.insert(i, channel_id.recipient);
|
||||
}
|
||||
@@ -832,18 +831,18 @@ impl<T: Config> Pallet<T> {
|
||||
Self::decrease_accepted_channel_request_count(channel_id.recipient);
|
||||
|
||||
let _ = open_req_channels.swap_remove(idx);
|
||||
<Self as Store>::HrmpOpenChannelRequests::remove(&channel_id);
|
||||
HrmpOpenChannelRequests::<T>::remove(&channel_id);
|
||||
}
|
||||
}
|
||||
|
||||
<Self as Store>::HrmpOpenChannelRequestsList::put(open_req_channels);
|
||||
HrmpOpenChannelRequestsList::<T>::put(open_req_channels);
|
||||
}
|
||||
|
||||
/// Iterate over all close channel requests unconditionally closing the channels.
|
||||
fn process_hrmp_close_channel_requests() {
|
||||
let close_reqs = <Self as Store>::HrmpCloseChannelRequestsList::take();
|
||||
let close_reqs = HrmpCloseChannelRequestsList::<T>::take();
|
||||
for condemned_ch_id in close_reqs {
|
||||
<Self as Store>::HrmpCloseChannelRequests::remove(&condemned_ch_id);
|
||||
HrmpCloseChannelRequests::<T>::remove(&condemned_ch_id);
|
||||
Self::close_hrmp_channel(&condemned_ch_id);
|
||||
}
|
||||
}
|
||||
@@ -856,7 +855,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// effect (i.e. it won't return the deposits twice).
|
||||
fn close_hrmp_channel(channel_id: &HrmpChannelId) {
|
||||
if let Some(HrmpChannel { sender_deposit, recipient_deposit, .. }) =
|
||||
<Self as Store>::HrmpChannels::take(channel_id)
|
||||
HrmpChannels::<T>::take(channel_id)
|
||||
{
|
||||
T::Currency::unreserve(
|
||||
&channel_id.sender.into_account_truncating(),
|
||||
@@ -868,14 +867,14 @@ impl<T: Config> Pallet<T> {
|
||||
);
|
||||
}
|
||||
|
||||
<Self as Store>::HrmpChannelContents::remove(channel_id);
|
||||
HrmpChannelContents::<T>::remove(channel_id);
|
||||
|
||||
<Self as Store>::HrmpEgressChannelsIndex::mutate(&channel_id.sender, |v| {
|
||||
HrmpEgressChannelsIndex::<T>::mutate(&channel_id.sender, |v| {
|
||||
if let Ok(i) = v.binary_search(&channel_id.recipient) {
|
||||
v.remove(i);
|
||||
}
|
||||
});
|
||||
<Self as Store>::HrmpIngressChannelsIndex::mutate(&channel_id.recipient, |v| {
|
||||
HrmpIngressChannelsIndex::<T>::mutate(&channel_id.recipient, |v| {
|
||||
if let Ok(i) = v.binary_search(&channel_id.sender) {
|
||||
v.remove(i);
|
||||
}
|
||||
@@ -895,7 +894,7 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// (b) However, a parachain cannot read into "the future", therefore the watermark should
|
||||
// not be greater than the relay-chain context block which the parablock refers to.
|
||||
if let Some(last_watermark) = <Self as Store>::HrmpWatermarks::get(&recipient) {
|
||||
if let Some(last_watermark) = HrmpWatermarks::<T>::get(&recipient) {
|
||||
if new_hrmp_watermark <= last_watermark {
|
||||
return Err(HrmpWatermarkAcceptanceErr::AdvancementRule {
|
||||
new_watermark: new_hrmp_watermark,
|
||||
@@ -917,7 +916,7 @@ impl<T: Config> Pallet<T> {
|
||||
if new_hrmp_watermark == relay_chain_parent_number {
|
||||
Ok(())
|
||||
} else {
|
||||
let digest = <Self as Store>::HrmpChannelDigests::get(&recipient);
|
||||
let digest = HrmpChannelDigests::<T>::get(&recipient);
|
||||
if !digest
|
||||
.binary_search_by_key(&new_hrmp_watermark, |(block_no, _)| *block_no)
|
||||
.is_ok()
|
||||
@@ -958,7 +957,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
let channel_id = HrmpChannelId { sender, recipient: out_msg.recipient };
|
||||
|
||||
let channel = match <Self as Store>::HrmpChannels::get(&channel_id) {
|
||||
let channel = match HrmpChannels::<T>::get(&channel_id) {
|
||||
Some(channel) => channel,
|
||||
None => return Err(OutboundHrmpAcceptanceErr::NoSuchChannel { channel_id, idx }),
|
||||
};
|
||||
@@ -999,7 +998,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// sift through the incoming messages digest to collect the paras that sent at least one
|
||||
// message to this parachain between the old and new watermarks.
|
||||
let senders = <Self as Store>::HrmpChannelDigests::mutate(&recipient, |digest| {
|
||||
let senders = HrmpChannelDigests::<T>::mutate(&recipient, |digest| {
|
||||
let mut senders = BTreeSet::new();
|
||||
let mut leftover = Vec::with_capacity(digest.len());
|
||||
for (block_no, paras_sent_msg) in mem::replace(digest, Vec::new()) {
|
||||
@@ -1022,7 +1021,7 @@ impl<T: Config> Pallet<T> {
|
||||
// and what is the total byte size of them.
|
||||
let (mut pruned_cnt, mut pruned_size) = (0, 0);
|
||||
|
||||
let contents = <Self as Store>::HrmpChannelContents::get(&channel_id);
|
||||
let contents = HrmpChannelContents::<T>::get(&channel_id);
|
||||
let mut leftover = Vec::with_capacity(contents.len());
|
||||
for msg in contents {
|
||||
if msg.sent_at <= new_hrmp_watermark {
|
||||
@@ -1033,13 +1032,13 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
}
|
||||
if !leftover.is_empty() {
|
||||
<Self as Store>::HrmpChannelContents::insert(&channel_id, leftover);
|
||||
HrmpChannelContents::<T>::insert(&channel_id, leftover);
|
||||
} else {
|
||||
<Self as Store>::HrmpChannelContents::remove(&channel_id);
|
||||
HrmpChannelContents::<T>::remove(&channel_id);
|
||||
}
|
||||
|
||||
// update the channel metadata.
|
||||
<Self as Store>::HrmpChannels::mutate(&channel_id, |channel| {
|
||||
HrmpChannels::<T>::mutate(&channel_id, |channel| {
|
||||
if let Some(ref mut channel) = channel {
|
||||
channel.msg_count -= pruned_cnt as u32;
|
||||
channel.total_size -= pruned_size as u32;
|
||||
@@ -1049,7 +1048,7 @@ impl<T: Config> Pallet<T> {
|
||||
weight += T::DbWeight::get().reads_writes(2, 2);
|
||||
}
|
||||
|
||||
<Self as Store>::HrmpWatermarks::insert(&recipient, new_hrmp_watermark);
|
||||
HrmpWatermarks::<T>::insert(&recipient, new_hrmp_watermark);
|
||||
weight += T::DbWeight::get().reads_writes(0, 1);
|
||||
|
||||
weight
|
||||
@@ -1065,7 +1064,7 @@ impl<T: Config> Pallet<T> {
|
||||
for out_msg in out_hrmp_msgs {
|
||||
let channel_id = HrmpChannelId { sender, recipient: out_msg.recipient };
|
||||
|
||||
let mut channel = match <Self as Store>::HrmpChannels::get(&channel_id) {
|
||||
let mut channel = match HrmpChannels::<T>::get(&channel_id) {
|
||||
Some(channel) => channel,
|
||||
None => {
|
||||
// apparently, that since acceptance of this candidate the recipient was
|
||||
@@ -1089,8 +1088,8 @@ impl<T: Config> Pallet<T> {
|
||||
));
|
||||
channel.mqc_head = Some(new_head);
|
||||
|
||||
<Self as Store>::HrmpChannels::insert(&channel_id, channel);
|
||||
<Self as Store>::HrmpChannelContents::append(&channel_id, inbound);
|
||||
HrmpChannels::<T>::insert(&channel_id, channel);
|
||||
HrmpChannelContents::<T>::append(&channel_id, inbound);
|
||||
|
||||
// The digests are sorted in ascending by block number order. Assuming absence of
|
||||
// contextual execution, there are only two possible scenarios here:
|
||||
@@ -1104,8 +1103,7 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// Note that having the latest entry greater than the current block number is a logical
|
||||
// error.
|
||||
let mut recipient_digest =
|
||||
<Self as Store>::HrmpChannelDigests::get(&channel_id.recipient);
|
||||
let mut recipient_digest = HrmpChannelDigests::<T>::get(&channel_id.recipient);
|
||||
if let Some(cur_block_digest) = recipient_digest
|
||||
.last_mut()
|
||||
.filter(|(block_no, _)| *block_no == now)
|
||||
@@ -1115,7 +1113,7 @@ impl<T: Config> Pallet<T> {
|
||||
} else {
|
||||
recipient_digest.push((now, vec![sender]));
|
||||
}
|
||||
<Self as Store>::HrmpChannelDigests::insert(&channel_id.recipient, recipient_digest);
|
||||
HrmpChannelDigests::<T>::insert(&channel_id.recipient, recipient_digest);
|
||||
|
||||
weight += T::DbWeight::get().reads_writes(2, 2);
|
||||
}
|
||||
@@ -1154,17 +1152,16 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
let channel_id = HrmpChannelId { sender: origin, recipient };
|
||||
ensure!(
|
||||
<Self as Store>::HrmpOpenChannelRequests::get(&channel_id).is_none(),
|
||||
HrmpOpenChannelRequests::<T>::get(&channel_id).is_none(),
|
||||
Error::<T>::OpenHrmpChannelAlreadyRequested,
|
||||
);
|
||||
ensure!(
|
||||
<Self as Store>::HrmpChannels::get(&channel_id).is_none(),
|
||||
HrmpChannels::<T>::get(&channel_id).is_none(),
|
||||
Error::<T>::OpenHrmpChannelAlreadyExists,
|
||||
);
|
||||
|
||||
let egress_cnt =
|
||||
<Self as Store>::HrmpEgressChannelsIndex::decode_len(&origin).unwrap_or(0) as u32;
|
||||
let open_req_cnt = <Self as Store>::HrmpOpenChannelRequestCount::get(&origin);
|
||||
let egress_cnt = HrmpEgressChannelsIndex::<T>::decode_len(&origin).unwrap_or(0) as u32;
|
||||
let open_req_cnt = HrmpOpenChannelRequestCount::<T>::get(&origin);
|
||||
let channel_num_limit = if <paras::Pallet<T>>::is_parathread(origin) {
|
||||
config.hrmp_max_parathread_outbound_channels
|
||||
} else {
|
||||
@@ -1182,8 +1179,8 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// mutating storage directly now -- shall not bail henceforth.
|
||||
|
||||
<Self as Store>::HrmpOpenChannelRequestCount::insert(&origin, open_req_cnt + 1);
|
||||
<Self as Store>::HrmpOpenChannelRequests::insert(
|
||||
HrmpOpenChannelRequestCount::<T>::insert(&origin, open_req_cnt + 1);
|
||||
HrmpOpenChannelRequests::<T>::insert(
|
||||
&channel_id,
|
||||
HrmpOpenChannelRequest {
|
||||
confirmed: false,
|
||||
@@ -1194,7 +1191,7 @@ impl<T: Config> Pallet<T> {
|
||||
max_total_size: config.hrmp_channel_max_total_size,
|
||||
},
|
||||
);
|
||||
<Self as Store>::HrmpOpenChannelRequestsList::append(channel_id);
|
||||
HrmpOpenChannelRequestsList::<T>::append(channel_id);
|
||||
|
||||
let notification_bytes = {
|
||||
use parity_scale_codec::Encode as _;
|
||||
@@ -1228,7 +1225,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// intended for calling directly from other pallets rather than dispatched.
|
||||
pub fn accept_open_channel(origin: ParaId, sender: ParaId) -> DispatchResult {
|
||||
let channel_id = HrmpChannelId { sender, recipient: origin };
|
||||
let mut channel_req = <Self as Store>::HrmpOpenChannelRequests::get(&channel_id)
|
||||
let mut channel_req = HrmpOpenChannelRequests::<T>::get(&channel_id)
|
||||
.ok_or(Error::<T>::AcceptHrmpChannelDoesntExist)?;
|
||||
ensure!(!channel_req.confirmed, Error::<T>::AcceptHrmpChannelAlreadyConfirmed);
|
||||
|
||||
@@ -1240,9 +1237,8 @@ impl<T: Config> Pallet<T> {
|
||||
} else {
|
||||
config.hrmp_max_parachain_inbound_channels
|
||||
};
|
||||
let ingress_cnt =
|
||||
<Self as Store>::HrmpIngressChannelsIndex::decode_len(&origin).unwrap_or(0) as u32;
|
||||
let accepted_cnt = <Self as Store>::HrmpAcceptedChannelRequestCount::get(&origin);
|
||||
let ingress_cnt = HrmpIngressChannelsIndex::<T>::decode_len(&origin).unwrap_or(0) as u32;
|
||||
let accepted_cnt = HrmpAcceptedChannelRequestCount::<T>::get(&origin);
|
||||
ensure!(
|
||||
ingress_cnt + accepted_cnt < channel_num_limit,
|
||||
Error::<T>::AcceptHrmpChannelLimitExceeded,
|
||||
@@ -1256,8 +1252,8 @@ impl<T: Config> Pallet<T> {
|
||||
// persist the updated open channel request and then increment the number of accepted
|
||||
// channels.
|
||||
channel_req.confirmed = true;
|
||||
<Self as Store>::HrmpOpenChannelRequests::insert(&channel_id, channel_req);
|
||||
<Self as Store>::HrmpAcceptedChannelRequestCount::insert(&origin, accepted_cnt + 1);
|
||||
HrmpOpenChannelRequests::<T>::insert(&channel_id, channel_req);
|
||||
HrmpAcceptedChannelRequestCount::<T>::insert(&origin, accepted_cnt + 1);
|
||||
|
||||
let notification_bytes = {
|
||||
use parity_scale_codec::Encode as _;
|
||||
@@ -1284,13 +1280,13 @@ impl<T: Config> Pallet<T> {
|
||||
// check if the origin is allowed to close the channel.
|
||||
ensure!(channel_id.is_participant(origin), Error::<T>::CancelHrmpOpenChannelUnauthorized);
|
||||
|
||||
let open_channel_req = <Self as Store>::HrmpOpenChannelRequests::get(&channel_id)
|
||||
let open_channel_req = HrmpOpenChannelRequests::<T>::get(&channel_id)
|
||||
.ok_or(Error::<T>::OpenHrmpChannelDoesntExist)?;
|
||||
ensure!(!open_channel_req.confirmed, Error::<T>::OpenHrmpChannelAlreadyConfirmed);
|
||||
|
||||
// Remove the request by the channel id and sync the accompanying list with the set.
|
||||
<Self as Store>::HrmpOpenChannelRequests::remove(&channel_id);
|
||||
<Self as Store>::HrmpOpenChannelRequestsList::mutate(|open_req_channels| {
|
||||
HrmpOpenChannelRequests::<T>::remove(&channel_id);
|
||||
HrmpOpenChannelRequestsList::<T>::mutate(|open_req_channels| {
|
||||
if let Some(pos) = open_req_channels.iter().position(|x| x == &channel_id) {
|
||||
open_req_channels.swap_remove(pos);
|
||||
}
|
||||
@@ -1316,18 +1312,18 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// check if the channel requested to close does exist.
|
||||
ensure!(
|
||||
<Self as Store>::HrmpChannels::get(&channel_id).is_some(),
|
||||
HrmpChannels::<T>::get(&channel_id).is_some(),
|
||||
Error::<T>::CloseHrmpChannelDoesntExist,
|
||||
);
|
||||
|
||||
// check that there is no outstanding close request for this channel
|
||||
ensure!(
|
||||
<Self as Store>::HrmpCloseChannelRequests::get(&channel_id).is_none(),
|
||||
HrmpCloseChannelRequests::<T>::get(&channel_id).is_none(),
|
||||
Error::<T>::CloseHrmpChannelAlreadyUnderway,
|
||||
);
|
||||
|
||||
<Self as Store>::HrmpCloseChannelRequests::insert(&channel_id, ());
|
||||
<Self as Store>::HrmpCloseChannelRequestsList::append(channel_id.clone());
|
||||
HrmpCloseChannelRequests::<T>::insert(&channel_id, ());
|
||||
HrmpCloseChannelRequestsList::<T>::append(channel_id.clone());
|
||||
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
let notification_bytes = {
|
||||
@@ -1363,13 +1359,12 @@ impl<T: Config> Pallet<T> {
|
||||
/// multiple entries with the same sender.
|
||||
#[cfg(test)]
|
||||
fn hrmp_mqc_heads(recipient: ParaId) -> Vec<(ParaId, Hash)> {
|
||||
let sender_set = <Self as Store>::HrmpIngressChannelsIndex::get(&recipient);
|
||||
let sender_set = HrmpIngressChannelsIndex::<T>::get(&recipient);
|
||||
|
||||
// The ingress channels vector is sorted, thus `mqc_heads` is sorted as well.
|
||||
let mut mqc_heads = Vec::with_capacity(sender_set.len());
|
||||
for sender in sender_set {
|
||||
let channel_metadata =
|
||||
<Self as Store>::HrmpChannels::get(&HrmpChannelId { sender, recipient });
|
||||
let channel_metadata = HrmpChannels::<T>::get(&HrmpChannelId { sender, recipient });
|
||||
let mqc_head = channel_metadata
|
||||
.and_then(|metadata| metadata.mqc_head)
|
||||
.unwrap_or(Hash::default());
|
||||
@@ -1384,12 +1379,12 @@ impl<T: Config> Pallet<T> {
|
||||
pub(crate) fn inbound_hrmp_channels_contents(
|
||||
recipient: ParaId,
|
||||
) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<T::BlockNumber>>> {
|
||||
let sender_set = <Self as Store>::HrmpIngressChannelsIndex::get(&recipient);
|
||||
let sender_set = HrmpIngressChannelsIndex::<T>::get(&recipient);
|
||||
|
||||
let mut inbound_hrmp_channels_contents = BTreeMap::new();
|
||||
for sender in sender_set {
|
||||
let channel_contents =
|
||||
<Self as Store>::HrmpChannelContents::get(&HrmpChannelId { sender, recipient });
|
||||
HrmpChannelContents::<T>::get(&HrmpChannelId { sender, recipient });
|
||||
inbound_hrmp_channels_contents.insert(sender, channel_contents);
|
||||
}
|
||||
|
||||
@@ -1401,7 +1396,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// Decreases the open channel request count for the given sender. If the value reaches zero
|
||||
/// it is removed completely.
|
||||
fn decrease_open_channel_request_count(sender: ParaId) {
|
||||
<Self as Store>::HrmpOpenChannelRequestCount::mutate_exists(&sender, |opt_rc| {
|
||||
HrmpOpenChannelRequestCount::<T>::mutate_exists(&sender, |opt_rc| {
|
||||
*opt_rc = opt_rc.and_then(|rc| match rc.saturating_sub(1) {
|
||||
0 => None,
|
||||
n => Some(n),
|
||||
@@ -1412,7 +1407,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// Decreases the accepted channel request count for the given sender. If the value reaches
|
||||
/// zero it is removed completely.
|
||||
fn decrease_accepted_channel_request_count(recipient: ParaId) {
|
||||
<Self as Store>::HrmpAcceptedChannelRequestCount::mutate_exists(&recipient, |opt_rc| {
|
||||
HrmpAcceptedChannelRequestCount::<T>::mutate_exists(&recipient, |opt_rc| {
|
||||
*opt_rc = opt_rc.and_then(|rc| match rc.saturating_sub(1) {
|
||||
0 => None,
|
||||
n => Some(n),
|
||||
@@ -1438,12 +1433,8 @@ impl<T: Config> Pallet<T> {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
<Self as Store>::HrmpOpenChannelRequests::iter()
|
||||
.map(|(k, _)| k)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
<Self as Store>::HrmpOpenChannelRequestsList::get()
|
||||
.into_iter()
|
||||
.collect::<BTreeSet<_>>(),
|
||||
HrmpOpenChannelRequests::<T>::iter().map(|(k, _)| k).collect::<BTreeSet<_>>(),
|
||||
HrmpOpenChannelRequestsList::<T>::get().into_iter().collect::<BTreeSet<_>>(),
|
||||
);
|
||||
|
||||
// verify that the set of keys in `HrmpOpenChannelRequestCount` corresponds to the set
|
||||
@@ -1451,17 +1442,15 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// having ensured that, we can go ahead and go over all counts and verify that they match.
|
||||
assert_eq!(
|
||||
<Self as Store>::HrmpOpenChannelRequestCount::iter()
|
||||
HrmpOpenChannelRequestCount::<T>::iter()
|
||||
.map(|(k, _)| k)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
<Self as Store>::HrmpOpenChannelRequests::iter()
|
||||
HrmpOpenChannelRequests::<T>::iter()
|
||||
.map(|(k, _)| k.sender)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
);
|
||||
for (open_channel_initiator, expected_num) in
|
||||
<Self as Store>::HrmpOpenChannelRequestCount::iter()
|
||||
{
|
||||
let actual_num = <Self as Store>::HrmpOpenChannelRequests::iter()
|
||||
for (open_channel_initiator, expected_num) in HrmpOpenChannelRequestCount::<T>::iter() {
|
||||
let actual_num = HrmpOpenChannelRequests::<T>::iter()
|
||||
.filter(|(ch, _)| ch.sender == open_channel_initiator)
|
||||
.count() as u32;
|
||||
assert_eq!(expected_num, actual_num);
|
||||
@@ -1470,43 +1459,37 @@ impl<T: Config> Pallet<T> {
|
||||
// The same as above, but for accepted channel request count. Note that we are interested
|
||||
// only in confirmed open requests.
|
||||
assert_eq!(
|
||||
<Self as Store>::HrmpAcceptedChannelRequestCount::iter()
|
||||
HrmpAcceptedChannelRequestCount::<T>::iter()
|
||||
.map(|(k, _)| k)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
<Self as Store>::HrmpOpenChannelRequests::iter()
|
||||
HrmpOpenChannelRequests::<T>::iter()
|
||||
.filter(|(_, v)| v.confirmed)
|
||||
.map(|(k, _)| k.recipient)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
);
|
||||
for (channel_recipient, expected_num) in
|
||||
<Self as Store>::HrmpAcceptedChannelRequestCount::iter()
|
||||
{
|
||||
let actual_num = <Self as Store>::HrmpOpenChannelRequests::iter()
|
||||
for (channel_recipient, expected_num) in HrmpAcceptedChannelRequestCount::<T>::iter() {
|
||||
let actual_num = HrmpOpenChannelRequests::<T>::iter()
|
||||
.filter(|(ch, v)| ch.recipient == channel_recipient && v.confirmed)
|
||||
.count() as u32;
|
||||
assert_eq!(expected_num, actual_num);
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
<Self as Store>::HrmpCloseChannelRequests::iter()
|
||||
.map(|(k, _)| k)
|
||||
.collect::<BTreeSet<_>>(),
|
||||
<Self as Store>::HrmpCloseChannelRequestsList::get()
|
||||
.into_iter()
|
||||
.collect::<BTreeSet<_>>(),
|
||||
HrmpCloseChannelRequests::<T>::iter().map(|(k, _)| k).collect::<BTreeSet<_>>(),
|
||||
HrmpCloseChannelRequestsList::<T>::get().into_iter().collect::<BTreeSet<_>>(),
|
||||
);
|
||||
|
||||
// A HRMP watermark can be None for an onboarded parachain. However, an offboarded parachain
|
||||
// cannot have an HRMP watermark: it should've been cleanup.
|
||||
assert_contains_only_onboarded(
|
||||
<Self as Store>::HrmpWatermarks::iter().map(|(k, _)| k).collect::<Vec<_>>(),
|
||||
HrmpWatermarks::<T>::iter().map(|(k, _)| k).collect::<Vec<_>>(),
|
||||
"HRMP watermarks should contain only onboarded paras",
|
||||
);
|
||||
|
||||
// An entry in `HrmpChannels` indicates that the channel is open. Only open channels can
|
||||
// have contents.
|
||||
for (non_empty_channel, contents) in <Self as Store>::HrmpChannelContents::iter() {
|
||||
assert!(<Self as Store>::HrmpChannels::contains_key(&non_empty_channel));
|
||||
for (non_empty_channel, contents) in HrmpChannelContents::<T>::iter() {
|
||||
assert!(HrmpChannels::<T>::contains_key(&non_empty_channel));
|
||||
|
||||
// pedantic check: there should be no empty vectors in storage, those should be modeled
|
||||
// by a removed kv pair.
|
||||
@@ -1516,7 +1499,7 @@ impl<T: Config> Pallet<T> {
|
||||
// Senders and recipients must be onboarded. Otherwise, all channels associated with them
|
||||
// are removed.
|
||||
assert_contains_only_onboarded(
|
||||
<Self as Store>::HrmpChannels::iter()
|
||||
HrmpChannels::<T>::iter()
|
||||
.flat_map(|(k, _)| vec![k.sender, k.recipient])
|
||||
.collect::<Vec<_>>(),
|
||||
"senders and recipients in all channels should be onboarded",
|
||||
@@ -1541,30 +1524,30 @@ impl<T: Config> Pallet<T> {
|
||||
// (b, z) (b, z)
|
||||
//
|
||||
// and then that we compare that to the channel list in the `HrmpChannels`.
|
||||
let channel_set_derived_from_ingress = <Self as Store>::HrmpIngressChannelsIndex::iter()
|
||||
let channel_set_derived_from_ingress = HrmpIngressChannelsIndex::<T>::iter()
|
||||
.flat_map(|(p, v)| v.into_iter().map(|i| (i, p)).collect::<Vec<_>>())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let channel_set_derived_from_egress = <Self as Store>::HrmpEgressChannelsIndex::iter()
|
||||
let channel_set_derived_from_egress = HrmpEgressChannelsIndex::<T>::iter()
|
||||
.flat_map(|(p, v)| v.into_iter().map(|e| (p, e)).collect::<Vec<_>>())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let channel_set_ground_truth = <Self as Store>::HrmpChannels::iter()
|
||||
let channel_set_ground_truth = HrmpChannels::<T>::iter()
|
||||
.map(|(k, _)| (k.sender, k.recipient))
|
||||
.collect::<BTreeSet<_>>();
|
||||
assert_eq!(channel_set_derived_from_ingress, channel_set_derived_from_egress);
|
||||
assert_eq!(channel_set_derived_from_egress, channel_set_ground_truth);
|
||||
|
||||
<Self as Store>::HrmpIngressChannelsIndex::iter()
|
||||
HrmpIngressChannelsIndex::<T>::iter()
|
||||
.map(|(_, v)| v)
|
||||
.for_each(|v| assert_is_sorted(&v, "HrmpIngressChannelsIndex"));
|
||||
<Self as Store>::HrmpEgressChannelsIndex::iter()
|
||||
HrmpEgressChannelsIndex::<T>::iter()
|
||||
.map(|(_, v)| v)
|
||||
.for_each(|v| assert_is_sorted(&v, "HrmpIngressChannelsIndex"));
|
||||
|
||||
assert_contains_only_onboarded(
|
||||
<Self as Store>::HrmpChannelDigests::iter().map(|(k, _)| k).collect::<Vec<_>>(),
|
||||
HrmpChannelDigests::<T>::iter().map(|(k, _)| k).collect::<Vec<_>>(),
|
||||
"HRMP channel digests should contain only onboarded paras",
|
||||
);
|
||||
for (_digest_for_para, digest) in <Self as Store>::HrmpChannelDigests::iter() {
|
||||
for (_digest_for_para, digest) in HrmpChannelDigests::<T>::iter() {
|
||||
// Assert that items are in **strictly** ascending order. The strictness also implies
|
||||
// there are no duplicates.
|
||||
assert!(digest.windows(2).all(|xs| xs[0].0 < xs[1].0));
|
||||
|
||||
@@ -150,7 +150,7 @@ fn deregister_parachain(id: ParaId) {
|
||||
}
|
||||
|
||||
fn channel_exists(sender: ParaId, recipient: ParaId) -> bool {
|
||||
<Hrmp as Store>::HrmpChannels::get(&HrmpChannelId { sender, recipient }).is_some()
|
||||
HrmpChannels::<Test>::get(&HrmpChannelId { sender, recipient }).is_some()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -184,7 +184,6 @@ pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
|
||||
@@ -99,7 +99,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>(_);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use super::*;
|
||||
use crate::mock::{
|
||||
new_test_ext, Configuration, Dmp, Initializer, MockGenesisConfig, Paras, SessionInfo, System,
|
||||
Test,
|
||||
};
|
||||
use primitives::{HeadData, Id as ParaId};
|
||||
use test_helpers::dummy_validation_code;
|
||||
@@ -32,7 +33,7 @@ fn session_0_is_instantly_applied() {
|
||||
new_test_ext(Default::default()).execute_with(|| {
|
||||
Initializer::on_new_session(false, 0, Vec::new().into_iter(), Some(Vec::new().into_iter()));
|
||||
|
||||
let v = <Initializer as Store>::BufferedSessionChanges::get();
|
||||
let v = BufferedSessionChanges::<Test>::get();
|
||||
assert!(v.is_empty());
|
||||
|
||||
assert_eq!(SessionInfo::earliest_stored_session(), 0);
|
||||
@@ -48,7 +49,7 @@ fn session_change_before_initialize_is_still_buffered_after() {
|
||||
let now = System::block_number();
|
||||
Initializer::on_initialize(now);
|
||||
|
||||
let v = <Initializer as Store>::BufferedSessionChanges::get();
|
||||
let v = BufferedSessionChanges::<Test>::get();
|
||||
assert_eq!(v.len(), 1);
|
||||
});
|
||||
}
|
||||
@@ -61,7 +62,7 @@ fn session_change_applied_on_finalize() {
|
||||
|
||||
Initializer::on_finalize(1);
|
||||
|
||||
assert!(<Initializer as Store>::BufferedSessionChanges::get().is_empty());
|
||||
assert!(BufferedSessionChanges::<Test>::get().is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ fn sets_flag_on_initialize() {
|
||||
new_test_ext(Default::default()).execute_with(|| {
|
||||
Initializer::on_initialize(1);
|
||||
|
||||
assert!(<Initializer as Store>::HasInitialized::get().is_some());
|
||||
assert!(HasInitialized::<Test>::get().is_some());
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ fn clears_flag_on_finalize() {
|
||||
Initializer::on_initialize(1);
|
||||
Initializer::on_finalize(1);
|
||||
|
||||
assert!(<Initializer as Store>::HasInitialized::get().is_none());
|
||||
assert!(HasInitialized::<Test>::get().is_none());
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ pub mod pallet {
|
||||
use frame_support::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
|
||||
@@ -48,7 +48,7 @@ fn generate_disordered_pruning<T: Config>() {
|
||||
needs_pruning.push((id, block_number));
|
||||
}
|
||||
|
||||
<Pallet<T> as Store>::PastCodePruning::put(needs_pruning);
|
||||
PastCodePruning::<T>::put(needs_pruning);
|
||||
}
|
||||
|
||||
pub(crate) fn generate_disordered_upgrades<T: Config>() {
|
||||
@@ -62,8 +62,8 @@ pub(crate) fn generate_disordered_upgrades<T: Config>() {
|
||||
cooldowns.push((id, block_number));
|
||||
}
|
||||
|
||||
<Pallet<T> as Store>::UpcomingUpgrades::put(upgrades);
|
||||
<Pallet<T> as Store>::UpgradeCooldowns::put(cooldowns);
|
||||
UpcomingUpgrades::<T>::put(upgrades);
|
||||
UpgradeCooldowns::<T>::put(cooldowns);
|
||||
}
|
||||
|
||||
fn generate_disordered_actions_queue<T: Config>() {
|
||||
@@ -75,7 +75,7 @@ fn generate_disordered_actions_queue<T: Config>() {
|
||||
queue.push(id);
|
||||
}
|
||||
|
||||
<Pallet<T> as Store>::ActionsQueue::mutate(next_session, |v| {
|
||||
ActionsQueue::<T>::mutate(next_session, |v| {
|
||||
*v = queue;
|
||||
});
|
||||
}
|
||||
@@ -85,7 +85,7 @@ benchmarks! {
|
||||
let c in 1 .. MAX_CODE_SIZE;
|
||||
let new_code = ValidationCode(vec![0; c as usize]);
|
||||
let para_id = ParaId::from(c as u32);
|
||||
<Pallet<T> as Store>::CurrentCodeHash::insert(¶_id, new_code.hash());
|
||||
CurrentCodeHash::<T>::insert(¶_id, new_code.hash());
|
||||
generate_disordered_pruning::<T>();
|
||||
}: _(RawOrigin::Root, para_id, new_code)
|
||||
verify {
|
||||
@@ -114,7 +114,7 @@ benchmarks! {
|
||||
let para_id = ParaId::from(1000);
|
||||
let new_head = HeadData(vec![0; s as usize]);
|
||||
let old_code_hash = ValidationCode(vec![0]).hash();
|
||||
<Pallet<T> as Store>::CurrentCodeHash::insert(¶_id, old_code_hash);
|
||||
CurrentCodeHash::<T>::insert(¶_id, old_code_hash);
|
||||
// schedule an expired code upgrade for this `para_id` so that force_note_new_head would use
|
||||
// the worst possible code path
|
||||
let expired = frame_system::Pallet::<T>::block_number().saturating_sub(One::one());
|
||||
|
||||
@@ -533,7 +533,6 @@ pub mod pallet {
|
||||
};
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
@@ -799,10 +798,10 @@ pub mod pallet {
|
||||
new_code: ValidationCode,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
let maybe_prior_code_hash = <Self as Store>::CurrentCodeHash::get(¶);
|
||||
let maybe_prior_code_hash = CurrentCodeHash::<T>::get(¶);
|
||||
let new_code_hash = new_code.hash();
|
||||
Self::increase_code_ref(&new_code_hash, &new_code);
|
||||
<Self as Store>::CurrentCodeHash::insert(¶, new_code_hash);
|
||||
CurrentCodeHash::<T>::insert(¶, new_code_hash);
|
||||
|
||||
let now = frame_system::Pallet::<T>::block_number();
|
||||
if let Some(prior_code_hash) = maybe_prior_code_hash {
|
||||
@@ -901,7 +900,7 @@ pub mod pallet {
|
||||
ensure_root(origin)?;
|
||||
let code_hash = validation_code.hash();
|
||||
|
||||
if let Some(vote) = <Self as Store>::PvfActiveVoteMap::get(&code_hash) {
|
||||
if let Some(vote) = PvfActiveVoteMap::<T>::get(&code_hash) {
|
||||
// Remove the existing vote.
|
||||
PvfActiveVoteMap::<T>::remove(&code_hash);
|
||||
PvfActiveVoteList::<T>::mutate(|l| {
|
||||
@@ -921,7 +920,7 @@ pub mod pallet {
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
if <Self as Store>::CodeByHash::contains_key(&code_hash) {
|
||||
if CodeByHash::<T>::contains_key(&code_hash) {
|
||||
// There is no vote, but the code exists. Nothing to do here.
|
||||
return Ok(())
|
||||
}
|
||||
@@ -931,7 +930,7 @@ pub mod pallet {
|
||||
//
|
||||
// NOTE That we do not use `increase_code_ref` here, because the code is not yet used
|
||||
// by any parachain.
|
||||
<Self as Store>::CodeByHash::insert(code_hash, &validation_code);
|
||||
CodeByHash::<T>::insert(code_hash, &validation_code);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -948,8 +947,8 @@ pub mod pallet {
|
||||
validation_code_hash: ValidationCodeHash,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
if <Self as Store>::CodeByHashRefs::get(&validation_code_hash) == 0 {
|
||||
<Self as Store>::CodeByHash::remove(&validation_code_hash);
|
||||
if CodeByHashRefs::<T>::get(&validation_code_hash) == 0 {
|
||||
CodeByHash::<T>::remove(&validation_code_hash);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1151,7 +1150,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Set the current head of a parachain.
|
||||
pub(crate) fn set_current_head(para: ParaId, new_head: HeadData) {
|
||||
<Self as Store>::Heads::insert(¶, new_head);
|
||||
Heads::<T>::insert(¶, new_head);
|
||||
Self::deposit_event(Event::CurrentHeadUpdated(para));
|
||||
}
|
||||
|
||||
@@ -1212,7 +1211,7 @@ impl<T: Config> Pallet<T> {
|
||||
None | Some(ParaLifecycle::Parathread) | Some(ParaLifecycle::Parachain) => { /* Nothing to do... */
|
||||
},
|
||||
Some(ParaLifecycle::Onboarding) => {
|
||||
if let Some(genesis_data) = <Self as Store>::UpcomingParasGenesis::take(¶) {
|
||||
if let Some(genesis_data) = UpcomingParasGenesis::<T>::take(¶) {
|
||||
Self::initialize_para_now(&mut parachains, para, &genesis_data);
|
||||
}
|
||||
},
|
||||
@@ -1231,17 +1230,17 @@ impl<T: Config> Pallet<T> {
|
||||
Some(ParaLifecycle::OffboardingParathread) => {
|
||||
parachains.remove(para);
|
||||
|
||||
<Self as Store>::Heads::remove(¶);
|
||||
<Self as Store>::FutureCodeUpgrades::remove(¶);
|
||||
<Self as Store>::UpgradeGoAheadSignal::remove(¶);
|
||||
<Self as Store>::UpgradeRestrictionSignal::remove(¶);
|
||||
Heads::<T>::remove(¶);
|
||||
FutureCodeUpgrades::<T>::remove(¶);
|
||||
UpgradeGoAheadSignal::<T>::remove(¶);
|
||||
UpgradeRestrictionSignal::<T>::remove(¶);
|
||||
ParaLifecycles::<T>::remove(¶);
|
||||
let removed_future_code_hash = <Self as Store>::FutureCodeHash::take(¶);
|
||||
let removed_future_code_hash = FutureCodeHash::<T>::take(¶);
|
||||
if let Some(removed_future_code_hash) = removed_future_code_hash {
|
||||
Self::decrease_code_ref(&removed_future_code_hash);
|
||||
}
|
||||
|
||||
let removed_code_hash = <Self as Store>::CurrentCodeHash::take(¶);
|
||||
let removed_code_hash = CurrentCodeHash::<T>::take(¶);
|
||||
if let Some(removed_code_hash) = removed_code_hash {
|
||||
Self::note_past_code(para, now, now, removed_code_hash);
|
||||
}
|
||||
@@ -1258,13 +1257,13 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// NOTE both of those iterates over the list and the outgoing. We do not expect either
|
||||
// of these to be large. Thus should be fine.
|
||||
<Self as Store>::UpcomingUpgrades::mutate(|upcoming_upgrades| {
|
||||
UpcomingUpgrades::<T>::mutate(|upcoming_upgrades| {
|
||||
*upcoming_upgrades = mem::take(upcoming_upgrades)
|
||||
.into_iter()
|
||||
.filter(|&(ref para, _)| !outgoing.contains(para))
|
||||
.collect();
|
||||
});
|
||||
<Self as Store>::UpgradeCooldowns::mutate(|upgrade_cooldowns| {
|
||||
UpgradeCooldowns::<T>::mutate(|upgrade_cooldowns| {
|
||||
*upgrade_cooldowns = mem::take(upgrade_cooldowns)
|
||||
.into_iter()
|
||||
.filter(|&(ref para, _)| !outgoing.contains(para))
|
||||
@@ -1290,15 +1289,15 @@ impl<T: Config> Pallet<T> {
|
||||
now: T::BlockNumber,
|
||||
old_code_hash: ValidationCodeHash,
|
||||
) -> Weight {
|
||||
<Self as Store>::PastCodeMeta::mutate(&id, |past_meta| {
|
||||
PastCodeMeta::<T>::mutate(&id, |past_meta| {
|
||||
past_meta.note_replacement(at, now);
|
||||
});
|
||||
|
||||
<Self as Store>::PastCodeHash::insert(&(id, at), old_code_hash);
|
||||
PastCodeHash::<T>::insert(&(id, at), old_code_hash);
|
||||
|
||||
// Schedule pruning for this past-code to be removed as soon as it
|
||||
// exits the slashing window.
|
||||
<Self as Store>::PastCodePruning::mutate(|pruning| {
|
||||
PastCodePruning::<T>::mutate(|pruning| {
|
||||
let insert_idx =
|
||||
pruning.binary_search_by_key(&now, |&(_, b)| b).unwrap_or_else(|idx| idx);
|
||||
pruning.insert(insert_idx, (id, now));
|
||||
@@ -1320,8 +1319,8 @@ impl<T: Config> Pallet<T> {
|
||||
// The height of any changes we no longer should keep around.
|
||||
let pruning_height = now - (code_retention_period + One::one());
|
||||
|
||||
let pruning_tasks_done = <Self as Store>::PastCodePruning::mutate(
|
||||
|pruning_tasks: &mut Vec<(_, T::BlockNumber)>| {
|
||||
let pruning_tasks_done =
|
||||
PastCodePruning::<T>::mutate(|pruning_tasks: &mut Vec<(_, T::BlockNumber)>| {
|
||||
let (pruning_tasks_done, pruning_tasks_to_do) = {
|
||||
// find all past code that has just exited the pruning window.
|
||||
let up_to_idx =
|
||||
@@ -1330,10 +1329,10 @@ impl<T: Config> Pallet<T> {
|
||||
};
|
||||
|
||||
for (para_id, _) in pruning_tasks_to_do {
|
||||
let full_deactivate = <Self as Store>::PastCodeMeta::mutate(¶_id, |meta| {
|
||||
let full_deactivate = PastCodeMeta::<T>::mutate(¶_id, |meta| {
|
||||
for pruned_repl_at in meta.prune_up_to(pruning_height) {
|
||||
let removed_code_hash =
|
||||
<Self as Store>::PastCodeHash::take(&(para_id, pruned_repl_at));
|
||||
PastCodeHash::<T>::take(&(para_id, pruned_repl_at));
|
||||
|
||||
if let Some(removed_code_hash) = removed_code_hash {
|
||||
Self::decrease_code_ref(&removed_code_hash);
|
||||
@@ -1352,13 +1351,12 @@ impl<T: Config> Pallet<T> {
|
||||
// This parachain has been removed and now the vestigial code
|
||||
// has been removed from the state. clean up meta as well.
|
||||
if full_deactivate {
|
||||
<Self as Store>::PastCodeMeta::remove(¶_id);
|
||||
PastCodeMeta::<T>::remove(¶_id);
|
||||
}
|
||||
}
|
||||
|
||||
pruning_tasks_done as u64
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// 1 read for the meta for each pruning task, 1 read for the config
|
||||
// 2 writes: updating the meta and pruning the code
|
||||
@@ -1373,11 +1371,11 @@ impl<T: Config> Pallet<T> {
|
||||
fn process_scheduled_upgrade_changes(now: T::BlockNumber) -> Weight {
|
||||
// account weight for `UpcomingUpgrades::mutate`.
|
||||
let mut weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
let upgrades_signaled = <Self as Store>::UpcomingUpgrades::mutate(
|
||||
let upgrades_signaled = UpcomingUpgrades::<T>::mutate(
|
||||
|upcoming_upgrades: &mut Vec<(ParaId, T::BlockNumber)>| {
|
||||
let num = upcoming_upgrades.iter().take_while(|&(_, at)| at <= &now).count();
|
||||
for (para, _) in upcoming_upgrades.drain(..num) {
|
||||
<Self as Store>::UpgradeGoAheadSignal::insert(¶, UpgradeGoAhead::GoAhead);
|
||||
UpgradeGoAheadSignal::<T>::insert(¶, UpgradeGoAhead::GoAhead);
|
||||
}
|
||||
num
|
||||
},
|
||||
@@ -1386,10 +1384,8 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// account weight for `UpgradeCooldowns::get`.
|
||||
weight += T::DbWeight::get().reads(1);
|
||||
let cooldowns_expired = <Self as Store>::UpgradeCooldowns::get()
|
||||
.iter()
|
||||
.take_while(|&(_, at)| at <= &now)
|
||||
.count();
|
||||
let cooldowns_expired =
|
||||
UpgradeCooldowns::<T>::get().iter().take_while(|&(_, at)| at <= &now).count();
|
||||
|
||||
// reserve weight for `initializer_finalize`:
|
||||
// - 1 read and 1 write for `UpgradeCooldowns::mutate`.
|
||||
@@ -1404,13 +1400,11 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// See `process_scheduled_upgrade_changes` for more details.
|
||||
fn process_scheduled_upgrade_cooldowns(now: T::BlockNumber) {
|
||||
<Self as Store>::UpgradeCooldowns::mutate(
|
||||
|upgrade_cooldowns: &mut Vec<(ParaId, T::BlockNumber)>| {
|
||||
for &(para, _) in upgrade_cooldowns.iter().take_while(|&(_, at)| at <= &now) {
|
||||
<Self as Store>::UpgradeRestrictionSignal::remove(¶);
|
||||
}
|
||||
},
|
||||
);
|
||||
UpgradeCooldowns::<T>::mutate(|upgrade_cooldowns: &mut Vec<(ParaId, T::BlockNumber)>| {
|
||||
for &(para, _) in upgrade_cooldowns.iter().take_while(|&(_, at)| at <= &now) {
|
||||
UpgradeRestrictionSignal::<T>::remove(¶);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Goes over all PVF votes in progress, reinitializes ballots, increments ages and prunes the
|
||||
@@ -1539,7 +1533,7 @@ impl<T: Config> Pallet<T> {
|
||||
weight += T::DbWeight::get().reads_writes(1, 4);
|
||||
FutureCodeUpgrades::<T>::insert(&id, expected_at);
|
||||
|
||||
<Self as Store>::UpcomingUpgrades::mutate(|upcoming_upgrades| {
|
||||
UpcomingUpgrades::<T>::mutate(|upcoming_upgrades| {
|
||||
let insert_idx = upcoming_upgrades
|
||||
.binary_search_by_key(&expected_at, |&(_, b)| b)
|
||||
.unwrap_or_else(|idx| idx);
|
||||
@@ -1653,7 +1647,7 @@ impl<T: Config> Pallet<T> {
|
||||
mem::replace(&mut genesis_data.validation_code, ValidationCode(Vec::new()));
|
||||
UpcomingParasGenesis::<T>::insert(&id, genesis_data);
|
||||
let validation_code_hash = validation_code.hash();
|
||||
<Self as Store>::CurrentCodeHash::insert(&id, validation_code_hash);
|
||||
CurrentCodeHash::<T>::insert(&id, validation_code_hash);
|
||||
|
||||
let cfg = configuration::Pallet::<T>::config();
|
||||
Self::kick_off_pvf_check(
|
||||
@@ -1814,7 +1808,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
weight += T::DbWeight::get().reads_writes(1, 1);
|
||||
let next_possible_upgrade_at = relay_parent_number + cfg.validation_upgrade_cooldown;
|
||||
<Self as Store>::UpgradeCooldowns::mutate(|upgrade_cooldowns| {
|
||||
UpgradeCooldowns::<T>::mutate(|upgrade_cooldowns| {
|
||||
let insert_idx = upgrade_cooldowns
|
||||
.binary_search_by_key(&next_possible_upgrade_at, |&(_, b)| b)
|
||||
.unwrap_or_else(|idx| idx);
|
||||
@@ -1926,10 +1920,10 @@ impl<T: Config> Pallet<T> {
|
||||
) -> Weight {
|
||||
Heads::<T>::insert(&id, new_head);
|
||||
|
||||
if let Some(expected_at) = <Self as Store>::FutureCodeUpgrades::get(&id) {
|
||||
if let Some(expected_at) = FutureCodeUpgrades::<T>::get(&id) {
|
||||
if expected_at <= execution_context {
|
||||
<Self as Store>::FutureCodeUpgrades::remove(&id);
|
||||
<Self as Store>::UpgradeGoAheadSignal::remove(&id);
|
||||
FutureCodeUpgrades::<T>::remove(&id);
|
||||
UpgradeGoAheadSignal::<T>::remove(&id);
|
||||
|
||||
// Both should always be `Some` in this case, since a code upgrade is scheduled.
|
||||
let new_code_hash = if let Some(new_code_hash) = FutureCodeHash::<T>::take(&id) {
|
||||
@@ -2048,10 +2042,10 @@ impl<T: Config> Pallet<T> {
|
||||
/// Returns the weight consumed.
|
||||
fn increase_code_ref(code_hash: &ValidationCodeHash, code: &ValidationCode) -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
<Self as Store>::CodeByHashRefs::mutate(code_hash, |refs| {
|
||||
CodeByHashRefs::<T>::mutate(code_hash, |refs| {
|
||||
if *refs == 0 {
|
||||
weight += T::DbWeight::get().writes(1);
|
||||
<Self as Store>::CodeByHash::insert(code_hash, code);
|
||||
CodeByHash::<T>::insert(code_hash, code);
|
||||
}
|
||||
*refs += 1;
|
||||
});
|
||||
@@ -2064,18 +2058,18 @@ impl<T: Config> Pallet<T> {
|
||||
/// Returns the weight consumed.
|
||||
fn decrease_code_ref(code_hash: &ValidationCodeHash) -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
let refs = <Self as Store>::CodeByHashRefs::get(code_hash);
|
||||
let refs = CodeByHashRefs::<T>::get(code_hash);
|
||||
if refs == 0 {
|
||||
log::error!(target: LOG_TARGET, "Code refs is already zero for {:?}", code_hash);
|
||||
return weight
|
||||
}
|
||||
if refs <= 1 {
|
||||
weight += T::DbWeight::get().writes(2);
|
||||
<Self as Store>::CodeByHash::remove(code_hash);
|
||||
<Self as Store>::CodeByHashRefs::remove(code_hash);
|
||||
CodeByHash::<T>::remove(code_hash);
|
||||
CodeByHashRefs::<T>::remove(code_hash);
|
||||
} else {
|
||||
weight += T::DbWeight::get().writes(1);
|
||||
<Self as Store>::CodeByHashRefs::insert(code_hash, refs - 1);
|
||||
CodeByHashRefs::<T>::insert(code_hash, refs - 1);
|
||||
}
|
||||
weight
|
||||
}
|
||||
|
||||
@@ -102,13 +102,13 @@ fn upgrade_at(
|
||||
}
|
||||
|
||||
fn check_code_is_stored(validation_code: &ValidationCode) {
|
||||
assert!(<Paras as Store>::CodeByHashRefs::get(validation_code.hash()) != 0);
|
||||
assert!(<Paras as Store>::CodeByHash::contains_key(validation_code.hash()));
|
||||
assert!(CodeByHashRefs::<Test>::get(validation_code.hash()) != 0);
|
||||
assert!(CodeByHash::<Test>::contains_key(validation_code.hash()));
|
||||
}
|
||||
|
||||
fn check_code_is_not_stored(validation_code: &ValidationCode) {
|
||||
assert!(!<Paras as Store>::CodeByHashRefs::contains_key(validation_code.hash()));
|
||||
assert!(!<Paras as Store>::CodeByHash::contains_key(validation_code.hash()));
|
||||
assert!(!CodeByHashRefs::<Test>::contains_key(validation_code.hash()));
|
||||
assert!(!CodeByHash::<Test>::contains_key(validation_code.hash()));
|
||||
}
|
||||
|
||||
/// An utility for checking that certain events were deposited.
|
||||
@@ -276,32 +276,26 @@ fn para_past_code_pruning_in_initialize() {
|
||||
let validation_code = ValidationCode(vec![4, 5, 6]);
|
||||
|
||||
Paras::increase_code_ref(&validation_code.hash(), &validation_code);
|
||||
<Paras as Store>::PastCodeHash::insert(&(id, at_block), &validation_code.hash());
|
||||
<Paras as Store>::PastCodePruning::put(&vec![(id, included_block)]);
|
||||
PastCodeHash::<Test>::insert(&(id, at_block), &validation_code.hash());
|
||||
PastCodePruning::<Test>::put(&vec![(id, included_block)]);
|
||||
|
||||
{
|
||||
let mut code_meta = Paras::past_code_meta(&id);
|
||||
code_meta.note_replacement(at_block, included_block);
|
||||
<Paras as Store>::PastCodeMeta::insert(&id, &code_meta);
|
||||
PastCodeMeta::<Test>::insert(&id, &code_meta);
|
||||
}
|
||||
|
||||
let pruned_at: BlockNumber = included_block + code_retention_period + 1;
|
||||
assert_eq!(
|
||||
<Paras as Store>::PastCodeHash::get(&(id, at_block)),
|
||||
Some(validation_code.hash())
|
||||
);
|
||||
assert_eq!(PastCodeHash::<Test>::get(&(id, at_block)), Some(validation_code.hash()));
|
||||
check_code_is_stored(&validation_code);
|
||||
|
||||
run_to_block(pruned_at - 1, None);
|
||||
assert_eq!(
|
||||
<Paras as Store>::PastCodeHash::get(&(id, at_block)),
|
||||
Some(validation_code.hash())
|
||||
);
|
||||
assert_eq!(PastCodeHash::<Test>::get(&(id, at_block)), Some(validation_code.hash()));
|
||||
assert_eq!(Paras::past_code_meta(&id).most_recent_change(), Some(at_block));
|
||||
check_code_is_stored(&validation_code);
|
||||
|
||||
run_to_block(pruned_at, None);
|
||||
assert!(<Paras as Store>::PastCodeHash::get(&(id, at_block)).is_none());
|
||||
assert!(PastCodeHash::<Test>::get(&(id, at_block)).is_none());
|
||||
assert!(Paras::past_code_meta(&id).most_recent_change().is_none());
|
||||
check_code_is_not_stored(&validation_code);
|
||||
});
|
||||
@@ -377,7 +371,7 @@ fn note_past_code_sets_up_pruning_correctly() {
|
||||
Paras::note_past_code(id_a, 10, 12, ValidationCode(vec![1, 2, 3]).hash());
|
||||
Paras::note_past_code(id_b, 20, 23, ValidationCode(vec![4, 5, 6]).hash());
|
||||
|
||||
assert_eq!(<Paras as Store>::PastCodePruning::get(), vec![(id_a, 12), (id_b, 23)]);
|
||||
assert_eq!(PastCodePruning::<Test>::get(), vec![(id_a, 12), (id_b, 23)]);
|
||||
assert_eq!(
|
||||
Paras::past_code_meta(&id_a),
|
||||
ParaPastCodeMeta { upgrade_times: vec![upgrade_at(10, 12)], last_pruned: None }
|
||||
@@ -437,13 +431,10 @@ fn code_upgrade_applied_after_delay() {
|
||||
Paras::note_new_head(para_id, Default::default(), 1);
|
||||
|
||||
assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none());
|
||||
assert_eq!(<Paras as Store>::FutureCodeUpgrades::get(¶_id), Some(expected_at));
|
||||
assert_eq!(<Paras as Store>::FutureCodeHash::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(<Paras as Store>::UpcomingUpgrades::get(), vec![(para_id, expected_at)]);
|
||||
assert_eq!(
|
||||
<Paras as Store>::UpgradeCooldowns::get(),
|
||||
vec![(para_id, next_possible_upgrade_at)]
|
||||
);
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(expected_at));
|
||||
assert_eq!(FutureCodeHash::<Test>::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(UpcomingUpgrades::<Test>::get(), vec![(para_id, expected_at)]);
|
||||
assert_eq!(UpgradeCooldowns::<Test>::get(), vec![(para_id, next_possible_upgrade_at)]);
|
||||
assert_eq!(Paras::current_code(¶_id), Some(original_code.clone()));
|
||||
check_code_is_stored(&original_code);
|
||||
check_code_is_stored(&new_code);
|
||||
@@ -459,12 +450,9 @@ fn code_upgrade_applied_after_delay() {
|
||||
Paras::note_new_head(para_id, Default::default(), expected_at - 1);
|
||||
|
||||
assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none());
|
||||
assert_eq!(<Paras as Store>::FutureCodeUpgrades::get(¶_id), Some(expected_at));
|
||||
assert_eq!(<Paras as Store>::FutureCodeHash::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(
|
||||
<Paras as Store>::UpgradeGoAheadSignal::get(¶_id),
|
||||
Some(UpgradeGoAhead::GoAhead)
|
||||
);
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(expected_at));
|
||||
assert_eq!(FutureCodeHash::<Test>::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(UpgradeGoAheadSignal::<Test>::get(¶_id), Some(UpgradeGoAhead::GoAhead));
|
||||
assert_eq!(Paras::current_code(¶_id), Some(original_code.clone()));
|
||||
check_code_is_stored(&original_code);
|
||||
check_code_is_stored(&new_code);
|
||||
@@ -479,12 +467,12 @@ fn code_upgrade_applied_after_delay() {
|
||||
|
||||
assert_eq!(Paras::past_code_meta(¶_id).most_recent_change(), Some(expected_at));
|
||||
assert_eq!(
|
||||
<Paras as Store>::PastCodeHash::get(&(para_id, expected_at)),
|
||||
PastCodeHash::<Test>::get(&(para_id, expected_at)),
|
||||
Some(original_code.hash()),
|
||||
);
|
||||
assert!(<Paras as Store>::FutureCodeUpgrades::get(¶_id).is_none());
|
||||
assert!(<Paras as Store>::FutureCodeHash::get(¶_id).is_none());
|
||||
assert!(<Paras as Store>::UpgradeGoAheadSignal::get(¶_id).is_none());
|
||||
assert!(FutureCodeUpgrades::<Test>::get(¶_id).is_none());
|
||||
assert!(FutureCodeHash::<Test>::get(¶_id).is_none());
|
||||
assert!(UpgradeGoAheadSignal::<Test>::get(¶_id).is_none());
|
||||
assert_eq!(Paras::current_code(¶_id), Some(new_code.clone()));
|
||||
check_code_is_stored(&original_code);
|
||||
check_code_is_stored(&new_code);
|
||||
@@ -538,14 +526,11 @@ fn code_upgrade_applied_after_delay_even_when_late() {
|
||||
Paras::note_new_head(para_id, Default::default(), 1);
|
||||
|
||||
assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none());
|
||||
assert_eq!(<Paras as Store>::FutureCodeUpgrades::get(¶_id), Some(expected_at));
|
||||
assert_eq!(<Paras as Store>::FutureCodeHash::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(<Paras as Store>::UpcomingUpgrades::get(), vec![(para_id, expected_at)]);
|
||||
assert_eq!(
|
||||
<Paras as Store>::UpgradeCooldowns::get(),
|
||||
vec![(para_id, next_possible_upgrade_at)]
|
||||
);
|
||||
assert!(<Paras as Store>::UpgradeGoAheadSignal::get(¶_id).is_none());
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(expected_at));
|
||||
assert_eq!(FutureCodeHash::<Test>::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(UpcomingUpgrades::<Test>::get(), vec![(para_id, expected_at)]);
|
||||
assert_eq!(UpgradeCooldowns::<Test>::get(), vec![(para_id, next_possible_upgrade_at)]);
|
||||
assert!(UpgradeGoAheadSignal::<Test>::get(¶_id).is_none());
|
||||
assert_eq!(Paras::current_code(¶_id), Some(original_code.clone()));
|
||||
|
||||
expected_at
|
||||
@@ -557,22 +542,19 @@ fn code_upgrade_applied_after_delay_even_when_late() {
|
||||
// the upgrade.
|
||||
{
|
||||
// The signal should be set to go-ahead until the new head is actually processed.
|
||||
assert_eq!(
|
||||
<Paras as Store>::UpgradeGoAheadSignal::get(¶_id),
|
||||
Some(UpgradeGoAhead::GoAhead),
|
||||
);
|
||||
assert_eq!(UpgradeGoAheadSignal::<Test>::get(¶_id), Some(UpgradeGoAhead::GoAhead),);
|
||||
|
||||
Paras::note_new_head(para_id, Default::default(), expected_at + 4);
|
||||
|
||||
assert_eq!(Paras::past_code_meta(¶_id).most_recent_change(), Some(expected_at));
|
||||
|
||||
assert_eq!(
|
||||
<Paras as Store>::PastCodeHash::get(&(para_id, expected_at)),
|
||||
PastCodeHash::<Test>::get(&(para_id, expected_at)),
|
||||
Some(original_code.hash()),
|
||||
);
|
||||
assert!(<Paras as Store>::FutureCodeUpgrades::get(¶_id).is_none());
|
||||
assert!(<Paras as Store>::FutureCodeHash::get(¶_id).is_none());
|
||||
assert!(<Paras as Store>::UpgradeGoAheadSignal::get(¶_id).is_none());
|
||||
assert!(FutureCodeUpgrades::<Test>::get(¶_id).is_none());
|
||||
assert!(FutureCodeHash::<Test>::get(¶_id).is_none());
|
||||
assert!(UpgradeGoAheadSignal::<Test>::get(¶_id).is_none());
|
||||
assert_eq!(Paras::current_code(¶_id), Some(new_code.clone()));
|
||||
}
|
||||
});
|
||||
@@ -615,11 +597,8 @@ fn submit_code_change_when_not_allowed_is_err() {
|
||||
|
||||
run_to_block(1, None);
|
||||
Paras::schedule_code_upgrade(para_id, new_code.clone(), 1, &Configuration::config());
|
||||
assert_eq!(
|
||||
<Paras as Store>::FutureCodeUpgrades::get(¶_id),
|
||||
Some(1 + validation_upgrade_delay)
|
||||
);
|
||||
assert_eq!(<Paras as Store>::FutureCodeHash::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(1 + validation_upgrade_delay));
|
||||
assert_eq!(FutureCodeHash::<Test>::get(¶_id), Some(new_code.hash()));
|
||||
check_code_is_stored(&new_code);
|
||||
|
||||
// We expect that if an upgrade is signalled while there is already one pending we just
|
||||
@@ -628,10 +607,10 @@ fn submit_code_change_when_not_allowed_is_err() {
|
||||
assert!(!Paras::can_upgrade_validation_code(para_id));
|
||||
Paras::schedule_code_upgrade(para_id, newer_code.clone(), 2, &Configuration::config());
|
||||
assert_eq!(
|
||||
<Paras as Store>::FutureCodeUpgrades::get(¶_id),
|
||||
FutureCodeUpgrades::<Test>::get(¶_id),
|
||||
Some(1 + validation_upgrade_delay), // did not change since the same assertion from the last time.
|
||||
);
|
||||
assert_eq!(<Paras as Store>::FutureCodeHash::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(FutureCodeHash::<Test>::get(¶_id), Some(new_code.hash()));
|
||||
check_code_is_not_stored(&newer_code);
|
||||
});
|
||||
}
|
||||
@@ -685,27 +664,21 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() {
|
||||
Paras::schedule_code_upgrade(para_id, new_code.clone(), 0, &Configuration::config());
|
||||
Paras::note_new_head(para_id, dummy_head_data(), 0);
|
||||
assert_eq!(
|
||||
<Paras as Store>::UpgradeRestrictionSignal::get(¶_id),
|
||||
UpgradeRestrictionSignal::<Test>::get(¶_id),
|
||||
Some(UpgradeRestriction::Present),
|
||||
);
|
||||
assert_eq!(
|
||||
<Paras as Store>::FutureCodeUpgrades::get(¶_id),
|
||||
Some(0 + validation_upgrade_delay)
|
||||
);
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(0 + validation_upgrade_delay));
|
||||
assert!(!Paras::can_upgrade_validation_code(para_id));
|
||||
|
||||
run_to_block(31, None);
|
||||
assert!(<Paras as Store>::UpgradeRestrictionSignal::get(¶_id).is_none());
|
||||
assert!(UpgradeRestrictionSignal::<Test>::get(¶_id).is_none());
|
||||
|
||||
// Note the para still cannot upgrade the validation code.
|
||||
assert!(!Paras::can_upgrade_validation_code(para_id));
|
||||
|
||||
// And scheduling another upgrade does not do anything. `expected_at` is still the same.
|
||||
Paras::schedule_code_upgrade(para_id, newer_code.clone(), 30, &Configuration::config());
|
||||
assert_eq!(
|
||||
<Paras as Store>::FutureCodeUpgrades::get(¶_id),
|
||||
Some(0 + validation_upgrade_delay)
|
||||
);
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(0 + validation_upgrade_delay));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -760,8 +733,8 @@ fn full_parachain_cleanup_storage() {
|
||||
Paras::note_new_head(para_id, Default::default(), 1);
|
||||
|
||||
assert!(Paras::past_code_meta(¶_id).most_recent_change().is_none());
|
||||
assert_eq!(<Paras as Store>::FutureCodeUpgrades::get(¶_id), Some(expected_at));
|
||||
assert_eq!(<Paras as Store>::FutureCodeHash::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(expected_at));
|
||||
assert_eq!(FutureCodeHash::<Test>::get(¶_id), Some(new_code.hash()));
|
||||
assert_eq!(Paras::current_code(¶_id), Some(original_code.clone()));
|
||||
check_code_is_stored(&original_code);
|
||||
check_code_is_stored(&new_code);
|
||||
@@ -789,15 +762,15 @@ fn full_parachain_cleanup_storage() {
|
||||
// Why 7 and 8? See above, the clean up scheduled above was processed at the block 8.
|
||||
// The initial upgrade was enacted at the block 7.
|
||||
assert_eq!(Paras::past_code_meta(¶_id).most_recent_change(), Some(8));
|
||||
assert_eq!(<Paras as Store>::PastCodeHash::get(&(para_id, 8)), Some(new_code.hash()));
|
||||
assert_eq!(<Paras as Store>::PastCodePruning::get(), vec![(para_id, 7), (para_id, 8)]);
|
||||
assert_eq!(PastCodeHash::<Test>::get(&(para_id, 8)), Some(new_code.hash()));
|
||||
assert_eq!(PastCodePruning::<Test>::get(), vec![(para_id, 7), (para_id, 8)]);
|
||||
check_code_is_stored(&original_code);
|
||||
check_code_is_stored(&new_code);
|
||||
|
||||
// any future upgrades haven't been used to validate yet, so those
|
||||
// are cleaned up immediately.
|
||||
assert!(<Paras as Store>::FutureCodeUpgrades::get(¶_id).is_none());
|
||||
assert!(<Paras as Store>::FutureCodeHash::get(¶_id).is_none());
|
||||
assert!(FutureCodeUpgrades::<Test>::get(¶_id).is_none());
|
||||
assert!(FutureCodeHash::<Test>::get(¶_id).is_none());
|
||||
assert!(Paras::current_code(¶_id).is_none());
|
||||
|
||||
// run to do the final cleanup
|
||||
@@ -806,9 +779,9 @@ fn full_parachain_cleanup_storage() {
|
||||
|
||||
// now the final cleanup: last past code cleaned up, and this triggers meta cleanup.
|
||||
assert_eq!(Paras::past_code_meta(¶_id), Default::default());
|
||||
assert!(<Paras as Store>::PastCodeHash::get(&(para_id, 7)).is_none());
|
||||
assert!(<Paras as Store>::PastCodeHash::get(&(para_id, 8)).is_none());
|
||||
assert!(<Paras as Store>::PastCodePruning::get().is_empty());
|
||||
assert!(PastCodeHash::<Test>::get(&(para_id, 7)).is_none());
|
||||
assert!(PastCodeHash::<Test>::get(&(para_id, 8)).is_none());
|
||||
assert!(PastCodePruning::<Test>::get().is_empty());
|
||||
check_code_is_not_stored(&original_code);
|
||||
check_code_is_not_stored(&new_code);
|
||||
});
|
||||
@@ -948,34 +921,34 @@ fn para_incoming_at_session() {
|
||||
})
|
||||
.for_each(sign_and_include_pvf_check_statement);
|
||||
|
||||
assert_eq!(<Paras as Store>::ActionsQueue::get(Paras::scheduled_session()), vec![c, b, a],);
|
||||
assert_eq!(ActionsQueue::<Test>::get(Paras::scheduled_session()), vec![c, b, a],);
|
||||
|
||||
// Lifecycle is tracked correctly
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&a), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&b), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&c), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&a), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&b), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&c), Some(ParaLifecycle::Onboarding));
|
||||
|
||||
// run to block without session change.
|
||||
run_to_block(2, None);
|
||||
|
||||
assert_eq!(Paras::parachains(), Vec::new());
|
||||
assert_eq!(<Paras as Store>::ActionsQueue::get(Paras::scheduled_session()), vec![c, b, a],);
|
||||
assert_eq!(ActionsQueue::<Test>::get(Paras::scheduled_session()), vec![c, b, a],);
|
||||
|
||||
// Lifecycle is tracked correctly
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&a), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&b), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&c), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&a), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&b), Some(ParaLifecycle::Onboarding));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&c), Some(ParaLifecycle::Onboarding));
|
||||
|
||||
// Two sessions pass, so action queue is triggered
|
||||
run_to_block(4, Some(vec![3, 4]));
|
||||
|
||||
assert_eq!(Paras::parachains(), vec![c, b]);
|
||||
assert_eq!(<Paras as Store>::ActionsQueue::get(Paras::scheduled_session()), Vec::new());
|
||||
assert_eq!(ActionsQueue::<Test>::get(Paras::scheduled_session()), Vec::new());
|
||||
|
||||
// Lifecycle is tracked correctly
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&a), Some(ParaLifecycle::Parathread));
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&b), Some(ParaLifecycle::Parachain));
|
||||
assert_eq!(<Paras as Store>::ParaLifecycles::get(&c), Some(ParaLifecycle::Parachain));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&a), Some(ParaLifecycle::Parathread));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&b), Some(ParaLifecycle::Parachain));
|
||||
assert_eq!(ParaLifecycles::<Test>::get(&c), Some(ParaLifecycle::Parachain));
|
||||
|
||||
assert_eq!(Paras::current_code(&a), Some(vec![2].into()));
|
||||
assert_eq!(Paras::current_code(&b), Some(vec![1].into()));
|
||||
@@ -1054,18 +1027,18 @@ fn code_ref_is_cleaned_correctly() {
|
||||
Paras::increase_code_ref(&code.hash(), &code);
|
||||
Paras::increase_code_ref(&code.hash(), &code);
|
||||
|
||||
assert!(<Paras as Store>::CodeByHash::contains_key(code.hash()));
|
||||
assert_eq!(<Paras as Store>::CodeByHashRefs::get(code.hash()), 2);
|
||||
assert!(CodeByHash::<Test>::contains_key(code.hash()));
|
||||
assert_eq!(CodeByHashRefs::<Test>::get(code.hash()), 2);
|
||||
|
||||
Paras::decrease_code_ref(&code.hash());
|
||||
|
||||
assert!(<Paras as Store>::CodeByHash::contains_key(code.hash()));
|
||||
assert_eq!(<Paras as Store>::CodeByHashRefs::get(code.hash()), 1);
|
||||
assert!(CodeByHash::<Test>::contains_key(code.hash()));
|
||||
assert_eq!(CodeByHashRefs::<Test>::get(code.hash()), 1);
|
||||
|
||||
Paras::decrease_code_ref(&code.hash());
|
||||
|
||||
assert!(!<Paras as Store>::CodeByHash::contains_key(code.hash()));
|
||||
assert!(!<Paras as Store>::CodeByHashRefs::contains_key(code.hash()));
|
||||
assert!(!CodeByHash::<Test>::contains_key(code.hash()));
|
||||
assert!(!CodeByHashRefs::<Test>::contains_key(code.hash()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1140,11 +1113,11 @@ fn pvf_check_coalescing_onboarding_and_upgrade() {
|
||||
.for_each(sign_and_include_pvf_check_statement);
|
||||
|
||||
// Check that `b` actually onboards.
|
||||
assert_eq!(<Paras as Store>::ActionsQueue::get(EXPECTED_SESSION + 2), vec![b]);
|
||||
assert_eq!(ActionsQueue::<Test>::get(EXPECTED_SESSION + 2), vec![b]);
|
||||
|
||||
// Check that the upgrade got scheduled.
|
||||
assert_eq!(
|
||||
<Paras as Store>::FutureCodeUpgrades::get(&a),
|
||||
FutureCodeUpgrades::<Test>::get(&a),
|
||||
Some(RELAY_PARENT + validation_upgrade_delay),
|
||||
);
|
||||
|
||||
@@ -1190,7 +1163,7 @@ fn pvf_check_onboarding_reject_on_expiry() {
|
||||
|
||||
// Make sure that we kicked off the PVF vote for this validation code and that the
|
||||
// validation code is stored.
|
||||
assert!(<Paras as Store>::PvfActiveVoteMap::get(&validation_code.hash()).is_some());
|
||||
assert!(PvfActiveVoteMap::<Test>::get(&validation_code.hash()).is_some());
|
||||
check_code_is_stored(&validation_code);
|
||||
|
||||
// Skip 2 sessions (i.e. `pvf_voting_ttl`) verifying that the code is still stored in
|
||||
@@ -1204,7 +1177,7 @@ fn pvf_check_onboarding_reject_on_expiry() {
|
||||
|
||||
// Verify that the PVF is no longer stored and there is no active PVF vote.
|
||||
check_code_is_not_stored(&validation_code);
|
||||
assert!(<Paras as Store>::PvfActiveVoteMap::get(&validation_code.hash()).is_none());
|
||||
assert!(PvfActiveVoteMap::<Test>::get(&validation_code.hash()).is_none());
|
||||
assert!(Paras::pvfs_require_precheck().is_empty());
|
||||
|
||||
// Verify that at this point we can again try to initialize the same para.
|
||||
@@ -1271,9 +1244,9 @@ fn pvf_check_upgrade_reject() {
|
||||
// Verify that the new code is discarded.
|
||||
check_code_is_not_stored(&new_code);
|
||||
|
||||
assert!(<Paras as Store>::PvfActiveVoteMap::get(&new_code.hash()).is_none());
|
||||
assert!(PvfActiveVoteMap::<Test>::get(&new_code.hash()).is_none());
|
||||
assert!(Paras::pvfs_require_precheck().is_empty());
|
||||
assert!(<Paras as Store>::FutureCodeHash::get(&a).is_none());
|
||||
assert!(FutureCodeHash::<Test>::get(&a).is_none());
|
||||
|
||||
// Verify that the required events were emitted.
|
||||
EventValidator::new().started(&new_code, a).rejected(&new_code, a).check();
|
||||
@@ -1516,7 +1489,7 @@ fn add_trusted_validation_code_inserts_with_no_users() {
|
||||
RuntimeOrigin::root(),
|
||||
validation_code.clone()
|
||||
));
|
||||
assert_eq!(<Paras as Store>::CodeByHashRefs::get(&validation_code.hash()), 0,);
|
||||
assert_eq!(CodeByHashRefs::<Test>::get(&validation_code.hash()), 0,);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1554,8 +1527,8 @@ fn poke_unused_validation_code_removes_code_cleanly() {
|
||||
validation_code.hash()
|
||||
));
|
||||
|
||||
assert_eq!(<Paras as Store>::CodeByHashRefs::get(&validation_code.hash()), 0);
|
||||
assert!(!<Paras as Store>::CodeByHash::contains_key(&validation_code.hash()));
|
||||
assert_eq!(CodeByHashRefs::<Test>::get(&validation_code.hash()), 0);
|
||||
assert!(!CodeByHash::<Test>::contains_key(&validation_code.hash()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1598,15 +1571,15 @@ fn increase_code_ref_doesnt_have_allergy_on_add_trusted_validation_code() {
|
||||
assert_ok!(Paras::add_trusted_validation_code(RuntimeOrigin::root(), code.clone()));
|
||||
Paras::increase_code_ref(&code.hash(), &code);
|
||||
Paras::increase_code_ref(&code.hash(), &code);
|
||||
assert!(<Paras as Store>::CodeByHash::contains_key(code.hash()));
|
||||
assert_eq!(<Paras as Store>::CodeByHashRefs::get(code.hash()), 2);
|
||||
assert!(CodeByHash::<Test>::contains_key(code.hash()));
|
||||
assert_eq!(CodeByHashRefs::<Test>::get(code.hash()), 2);
|
||||
});
|
||||
|
||||
new_test_ext(Default::default()).execute_with(|| {
|
||||
assert_ok!(Paras::add_trusted_validation_code(RuntimeOrigin::root(), code.clone()));
|
||||
Paras::decrease_code_ref(&code.hash());
|
||||
assert!(<Paras as Store>::CodeByHash::contains_key(code.hash()));
|
||||
assert_eq!(<Paras as Store>::CodeByHashRefs::get(code.hash()), 0);
|
||||
assert!(CodeByHash::<Test>::contains_key(code.hash()));
|
||||
assert_eq!(CodeByHashRefs::<Test>::get(code.hash()), 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1643,10 +1616,7 @@ fn add_trusted_validation_code_insta_approval() {
|
||||
|
||||
// Verify that the code upgrade has `expected_at` set to `26`. This is the behavior
|
||||
// equal to that of `pvf_checking_enabled: false`.
|
||||
assert_eq!(
|
||||
<Paras as Store>::FutureCodeUpgrades::get(¶_id),
|
||||
Some(1 + validation_upgrade_delay)
|
||||
);
|
||||
assert_eq!(FutureCodeUpgrades::<Test>::get(¶_id), Some(1 + validation_upgrade_delay));
|
||||
|
||||
// Verify that the required events were emitted.
|
||||
EventValidator::new()
|
||||
@@ -1685,16 +1655,16 @@ fn add_trusted_validation_code_enacts_existing_pvf_vote() {
|
||||
|
||||
// No upgrade should be scheduled at this point. PVF pre-checking vote should run for
|
||||
// that PVF.
|
||||
assert!(<Paras as Store>::FutureCodeUpgrades::get(¶_id).is_none());
|
||||
assert!(<Paras as Store>::PvfActiveVoteMap::contains_key(&validation_code.hash()));
|
||||
assert!(FutureCodeUpgrades::<Test>::get(¶_id).is_none());
|
||||
assert!(PvfActiveVoteMap::<Test>::contains_key(&validation_code.hash()));
|
||||
|
||||
// Then we add a trusted validation code. That should conclude the vote.
|
||||
assert_ok!(Paras::add_trusted_validation_code(
|
||||
RuntimeOrigin::root(),
|
||||
validation_code.clone()
|
||||
));
|
||||
assert!(<Paras as Store>::FutureCodeUpgrades::get(¶_id).is_some());
|
||||
assert!(!<Paras as Store>::PvfActiveVoteMap::contains_key(&validation_code.hash()));
|
||||
assert!(FutureCodeUpgrades::<Test>::get(¶_id).is_some());
|
||||
assert!(!PvfActiveVoteMap::<Test>::contains_key(&validation_code.hash()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1706,7 +1676,7 @@ fn verify_upgrade_go_ahead_signal_is_externally_accessible() {
|
||||
|
||||
new_test_ext(Default::default()).execute_with(|| {
|
||||
assert!(sp_io::storage::get(&well_known_keys::upgrade_go_ahead_signal(a)).is_none());
|
||||
<Paras as Store>::UpgradeGoAheadSignal::insert(&a, UpgradeGoAhead::GoAhead);
|
||||
UpgradeGoAheadSignal::<Test>::insert(&a, UpgradeGoAhead::GoAhead);
|
||||
assert_eq!(
|
||||
sp_io::storage::get(&well_known_keys::upgrade_go_ahead_signal(a)).unwrap(),
|
||||
vec![1u8],
|
||||
@@ -1722,7 +1692,7 @@ fn verify_upgrade_restriction_signal_is_externally_accessible() {
|
||||
|
||||
new_test_ext(Default::default()).execute_with(|| {
|
||||
assert!(sp_io::storage::get(&well_known_keys::upgrade_restriction_signal(a)).is_none());
|
||||
<Paras as Store>::UpgradeRestrictionSignal::insert(&a, UpgradeRestriction::Present);
|
||||
UpgradeRestrictionSignal::<Test>::insert(&a, UpgradeRestriction::Present);
|
||||
assert_eq!(
|
||||
sp_io::storage::get(&well_known_keys::upgrade_restriction_signal(a)).unwrap(),
|
||||
vec![0],
|
||||
@@ -1783,7 +1753,7 @@ fn parachains_cache_is_set() {
|
||||
drop(parachains_cache);
|
||||
|
||||
// In order after addition
|
||||
assert_eq!(<Paras as Store>::Parachains::get(), vec![a]);
|
||||
assert_eq!(Parachains::<Test>::get(), vec![a]);
|
||||
|
||||
let mut parachains_cache: ParachainsCache<Test> = ParachainsCache::new();
|
||||
|
||||
@@ -1795,14 +1765,14 @@ fn parachains_cache_is_set() {
|
||||
drop(parachains_cache);
|
||||
|
||||
// In order after removal
|
||||
assert_eq!(<Paras as Store>::Parachains::get(), vec![]);
|
||||
assert_eq!(Parachains::<Test>::get(), vec![]);
|
||||
|
||||
let mut parachains_cache: ParachainsCache<Test> = ParachainsCache::new();
|
||||
|
||||
// Remove nonexisting element
|
||||
parachains_cache.remove(a);
|
||||
assert_storage_noop!(drop(parachains_cache));
|
||||
assert_eq!(<Paras as Store>::Parachains::get(), vec![]);
|
||||
assert_eq!(Parachains::<Test>::get(), vec![]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1826,7 +1796,7 @@ fn parachains_cache_preserves_order() {
|
||||
drop(parachains_cache);
|
||||
|
||||
// In order after addition
|
||||
assert_eq!(<Paras as Store>::Parachains::get(), vec![a, b, c, d]);
|
||||
assert_eq!(Parachains::<Test>::get(), vec![a, b, c, d]);
|
||||
|
||||
let mut parachains_cache: ParachainsCache<Test> = ParachainsCache::new();
|
||||
|
||||
@@ -1838,6 +1808,6 @@ fn parachains_cache_preserves_order() {
|
||||
drop(parachains_cache);
|
||||
|
||||
// In order after removal
|
||||
assert_eq!(<Paras as Store>::Parachains::get(), vec![a, c]);
|
||||
assert_eq!(Parachains::<Test>::get(), vec![a, c]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
|
||||
@@ -158,7 +158,6 @@ pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
|
||||
@@ -865,7 +865,7 @@ fn schedule_rotates_groups() {
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let session_start_block = <Scheduler as Store>::SessionStartBlock::get();
|
||||
let session_start_block = SessionStartBlock::<Test>::get();
|
||||
assert_eq!(session_start_block, 1);
|
||||
|
||||
Scheduler::add_parathread_claim(ParathreadClaim(thread_a, collator.clone()));
|
||||
|
||||
@@ -63,7 +63,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>(_);
|
||||
|
||||
@@ -43,7 +43,6 @@ pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
|
||||
@@ -215,7 +215,6 @@ pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
#[pallet::storage_version(migration::STORAGE_VERSION)]
|
||||
pub struct Pallet<T>(_);
|
||||
@@ -402,22 +401,20 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Remove all relevant storage items for an outgoing parachain.
|
||||
pub(crate) fn clean_ump_after_outgoing(outgoing_para: &ParaId) -> Weight {
|
||||
<Self as Store>::RelayDispatchQueueSize::remove(outgoing_para);
|
||||
<Self as Store>::RelayDispatchQueues::remove(outgoing_para);
|
||||
RelayDispatchQueueSize::<T>::remove(outgoing_para);
|
||||
RelayDispatchQueues::<T>::remove(outgoing_para);
|
||||
|
||||
// Remove the outgoing para from the `NeedsDispatch` list and from
|
||||
// `NextDispatchRoundStartWith`.
|
||||
//
|
||||
// That's needed for maintaining invariant that `NextDispatchRoundStartWith` points to an
|
||||
// existing item in `NeedsDispatch`.
|
||||
<Self as Store>::NeedsDispatch::mutate(|v| {
|
||||
NeedsDispatch::<T>::mutate(|v| {
|
||||
if let Ok(i) = v.binary_search(outgoing_para) {
|
||||
v.remove(i);
|
||||
}
|
||||
});
|
||||
<Self as Store>::NextDispatchRoundStartWith::mutate(|v| {
|
||||
*v = v.filter(|p| p == outgoing_para)
|
||||
});
|
||||
NextDispatchRoundStartWith::<T>::mutate(|v| *v = v.filter(|p| p == outgoing_para));
|
||||
|
||||
<T as Config>::WeightInfo::clean_ump_after_outgoing()
|
||||
}
|
||||
@@ -436,8 +433,7 @@ impl<T: Config> Pallet<T> {
|
||||
})
|
||||
}
|
||||
|
||||
let (mut para_queue_count, mut para_queue_size) =
|
||||
<Self as Store>::RelayDispatchQueueSize::get(¶);
|
||||
let (mut para_queue_count, mut para_queue_size) = RelayDispatchQueueSize::<T>::get(¶);
|
||||
|
||||
for (idx, msg) in upward_messages.into_iter().enumerate() {
|
||||
let msg_size = msg.len() as u32;
|
||||
@@ -479,19 +475,14 @@ impl<T: Config> Pallet<T> {
|
||||
.iter()
|
||||
.fold((0, 0), |(cnt, size), d| (cnt + 1, size + d.len() as u32));
|
||||
|
||||
<Self as Store>::RelayDispatchQueues::mutate(¶, |v| {
|
||||
v.extend(upward_messages.into_iter())
|
||||
RelayDispatchQueues::<T>::mutate(¶, |v| v.extend(upward_messages.into_iter()));
|
||||
|
||||
RelayDispatchQueueSize::<T>::mutate(¶, |(ref mut cnt, ref mut size)| {
|
||||
*cnt += extra_count;
|
||||
*size += extra_size;
|
||||
});
|
||||
|
||||
<Self as Store>::RelayDispatchQueueSize::mutate(
|
||||
¶,
|
||||
|(ref mut cnt, ref mut size)| {
|
||||
*cnt += extra_count;
|
||||
*size += extra_size;
|
||||
},
|
||||
);
|
||||
|
||||
<Self as Store>::NeedsDispatch::mutate(|v| {
|
||||
NeedsDispatch::<T>::mutate(|v| {
|
||||
if let Err(i) = v.binary_search(¶) {
|
||||
v.insert(i, para);
|
||||
}
|
||||
@@ -592,13 +583,13 @@ impl<T: Config> Pallet<T> {
|
||||
/// Puts a given upward message into the list of overweight messages allowing it to be executed
|
||||
/// later.
|
||||
fn stash_overweight(sender: ParaId, upward_message: Vec<u8>) -> OverweightIndex {
|
||||
let index = <Self as Store>::OverweightCount::mutate(|count| {
|
||||
let index = OverweightCount::<T>::mutate(|count| {
|
||||
let index = *count;
|
||||
*count += 1;
|
||||
index
|
||||
});
|
||||
|
||||
<Self as Store>::Overweight::insert(index, (sender, upward_message));
|
||||
Overweight::<T>::insert(index, (sender, upward_message));
|
||||
index
|
||||
}
|
||||
}
|
||||
@@ -714,8 +705,8 @@ struct NeedsDispatchCursor {
|
||||
|
||||
impl NeedsDispatchCursor {
|
||||
fn new<T: Config>() -> Self {
|
||||
let needs_dispatch: Vec<ParaId> = <Pallet<T> as Store>::NeedsDispatch::get();
|
||||
let start_with = <Pallet<T> as Store>::NextDispatchRoundStartWith::get();
|
||||
let needs_dispatch: Vec<ParaId> = NeedsDispatch::<T>::get();
|
||||
let start_with = NextDispatchRoundStartWith::<T>::get();
|
||||
|
||||
let initial_index = match start_with {
|
||||
Some(para) => match needs_dispatch.binary_search(¶) {
|
||||
@@ -766,7 +757,7 @@ impl NeedsDispatchCursor {
|
||||
/// Flushes the dispatcher state into the persistent storage.
|
||||
fn flush<T: Config>(self) {
|
||||
let next_one = self.peek();
|
||||
<Pallet<T> as Store>::NextDispatchRoundStartWith::set(next_one);
|
||||
<Pallet<T> as Store>::NeedsDispatch::put(self.needs_dispatch);
|
||||
NextDispatchRoundStartWith::<T>::set(next_one);
|
||||
NeedsDispatch::<T>::put(self.needs_dispatch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,13 +79,13 @@ fn queue_upward_msg(para: ParaId, msg: UpwardMessage) {
|
||||
|
||||
fn assert_storage_consistency_exhaustive() {
|
||||
// check that empty queues don't clutter the storage.
|
||||
for (_para, queue) in <Ump as Store>::RelayDispatchQueues::iter() {
|
||||
for (_para, queue) in RelayDispatchQueues::<Test>::iter() {
|
||||
assert!(!queue.is_empty());
|
||||
}
|
||||
|
||||
// actually count the counts and sizes in queues and compare them to the bookkept version.
|
||||
for (para, queue) in <Ump as Store>::RelayDispatchQueues::iter() {
|
||||
let (expected_count, expected_size) = <Ump as Store>::RelayDispatchQueueSize::get(para);
|
||||
for (para, queue) in RelayDispatchQueues::<Test>::iter() {
|
||||
let (expected_count, expected_size) = RelayDispatchQueueSize::<Test>::get(para);
|
||||
let (actual_count, actual_size) = queue
|
||||
.into_iter()
|
||||
.fold((0, 0), |(acc_count, acc_size), x| (acc_count + 1, acc_size + x.len() as u32));
|
||||
@@ -96,24 +96,22 @@ fn assert_storage_consistency_exhaustive() {
|
||||
|
||||
// since we wipe the empty queues the sets of paras in queue contents, queue sizes and
|
||||
// need dispatch set should all be equal.
|
||||
let queue_contents_set = <Ump as Store>::RelayDispatchQueues::iter()
|
||||
let queue_contents_set =
|
||||
RelayDispatchQueues::<Test>::iter().map(|(k, _)| k).collect::<HashSet<ParaId>>();
|
||||
let queue_sizes_set = RelayDispatchQueueSize::<Test>::iter()
|
||||
.map(|(k, _)| k)
|
||||
.collect::<HashSet<ParaId>>();
|
||||
let queue_sizes_set = <Ump as Store>::RelayDispatchQueueSize::iter()
|
||||
.map(|(k, _)| k)
|
||||
.collect::<HashSet<ParaId>>();
|
||||
let needs_dispatch_set =
|
||||
<Ump as Store>::NeedsDispatch::get().into_iter().collect::<HashSet<ParaId>>();
|
||||
let needs_dispatch_set = NeedsDispatch::<Test>::get().into_iter().collect::<HashSet<ParaId>>();
|
||||
assert_eq!(queue_contents_set, queue_sizes_set);
|
||||
assert_eq!(queue_contents_set, needs_dispatch_set);
|
||||
|
||||
// `NextDispatchRoundStartWith` should point into a para that is tracked.
|
||||
if let Some(para) = <Ump as Store>::NextDispatchRoundStartWith::get() {
|
||||
if let Some(para) = NextDispatchRoundStartWith::<Test>::get() {
|
||||
assert!(queue_contents_set.contains(¶));
|
||||
}
|
||||
|
||||
// `NeedsDispatch` is always sorted.
|
||||
assert!(<Ump as Store>::NeedsDispatch::get().windows(2).all(|xs| xs[0] <= xs[1]));
|
||||
assert!(NeedsDispatch::<Test>::get().windows(2).all(|xs| xs[0] <= xs[1]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user