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

Commit

Permalink
Run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekvpandya committed Mar 8, 2023
1 parent 4bededa commit 3ea93d9
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 134 deletions.
25 changes: 5 additions & 20 deletions runtime/parachains/src/configuration/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
PendingConfigs::<Test>::get(),
vec![(2, intermediate_config.clone())]
);
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, intermediate_config.clone())]);

on_new_session(1);

Expand All @@ -148,10 +145,7 @@ fn pending_next_session_but_we_upgrade_once_more() {
on_new_session(2);

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

on_new_session(3);

Expand All @@ -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!(
PendingConfigs::<Test>::get(),
vec![(2, intermediate_config.clone())]
);
assert_eq!(PendingConfigs::<Test>::get(), vec![(2, intermediate_config.clone())]);

on_new_session(1);

Expand All @@ -197,10 +188,7 @@ fn scheduled_session_config_update_while_next_session_pending() {
on_new_session(2);

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

on_new_session(3);

Expand Down Expand Up @@ -514,10 +502,7 @@ fn setting_pending_config_members() {
Configuration::set_pvf_voting_ttl(RuntimeOrigin::root(), new_config.pvf_voting_ttl)
.unwrap();

assert_eq!(
PendingConfigs::<Test>::get(),
vec![(shared::SESSION_DELAY, new_config)],
);
assert_eq!(PendingConfigs::<Test>::get(), vec![(shared::SESSION_DELAY, new_config)],);
})
}

Expand Down
8 changes: 2 additions & 6 deletions runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

if DownwardMessageQueues::<T>::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)
}

Expand All @@ -178,9 +176,7 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

if DownwardMessageQueues::<T>::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)
}

Expand Down
48 changes: 16 additions & 32 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ pub mod pallet {
) -> DispatchResult {
let origin = ensure_parachain(<T as Config>::RuntimeOrigin::from(origin))?;
ensure!(
HrmpOpenChannelRequestsList::<T>::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())?;
Expand Down Expand Up @@ -684,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 = 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;
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,
Expand Down Expand Up @@ -1103,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 =
HrmpChannelDigests::<T>::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)
Expand Down Expand Up @@ -1161,8 +1160,7 @@ impl<T: Config> Pallet<T> {
Error::<T>::OpenHrmpChannelAlreadyExists,
);

let egress_cnt =
HrmpEgressChannelsIndex::<T>::decode_len(&origin).unwrap_or(0) as u32;
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
Expand Down Expand Up @@ -1239,8 +1237,7 @@ impl<T: Config> Pallet<T> {
} else {
config.hrmp_max_parachain_inbound_channels
};
let ingress_cnt =
HrmpIngressChannelsIndex::<T>::decode_len(&origin).unwrap_or(0) as u32;
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,
Expand Down Expand Up @@ -1367,8 +1364,7 @@ impl<T: Config> Pallet<T> {
// 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 =
HrmpChannels::<T>::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());
Expand Down Expand Up @@ -1437,12 +1433,8 @@ impl<T: Config> Pallet<T> {
};

assert_eq!(
HrmpOpenChannelRequests::<T>::iter()
.map(|(k, _)| k)
.collect::<BTreeSet<_>>(),
HrmpOpenChannelRequestsList::<T>::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
Expand All @@ -1457,9 +1449,7 @@ impl<T: Config> Pallet<T> {
.map(|(k, _)| k.sender)
.collect::<BTreeSet<_>>(),
);
for (open_channel_initiator, expected_num) in
HrmpOpenChannelRequestCount::<T>::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;
Expand All @@ -1477,22 +1467,16 @@ impl<T: Config> Pallet<T> {
.map(|(k, _)| k.recipient)
.collect::<BTreeSet<_>>(),
);
for (channel_recipient, expected_num) in
HrmpAcceptedChannelRequestCount::<T>::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!(
HrmpCloseChannelRequests::<T>::iter()
.map(|(k, _)| k)
.collect::<BTreeSet<_>>(),
HrmpCloseChannelRequestsList::<T>::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
Expand Down
25 changes: 10 additions & 15 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,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 = PastCodePruning::<T>::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 =
Expand Down Expand Up @@ -1356,8 +1356,7 @@ impl<T: Config> Pallet<T> {
}

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
Expand Down Expand Up @@ -1385,10 +1384,8 @@ impl<T: Config> Pallet<T> {

// account weight for `UpgradeCooldowns::get`.
weight += T::DbWeight::get().reads(1);
let cooldowns_expired = UpgradeCooldowns::<T>::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`.
Expand All @@ -1403,13 +1400,11 @@ impl<T: Config> Pallet<T> {
///
/// See `process_scheduled_upgrade_changes` for more details.
fn process_scheduled_upgrade_cooldowns(now: T::BlockNumber) {
UpgradeCooldowns::<T>::mutate(
|upgrade_cooldowns: &mut Vec<(ParaId, T::BlockNumber)>| {
for &(para, _) in upgrade_cooldowns.iter().take_while(|&(_, at)| at <= &now) {
UpgradeRestrictionSignal::<T>::remove(&para);
}
},
);
UpgradeCooldowns::<T>::mutate(|upgrade_cooldowns: &mut Vec<(ParaId, T::BlockNumber)>| {
for &(para, _) in upgrade_cooldowns.iter().take_while(|&(_, at)| at <= &now) {
UpgradeRestrictionSignal::<T>::remove(&para);
}
});
}

/// Goes over all PVF votes in progress, reinitializes ballots, increments ages and prunes the
Expand Down
50 changes: 10 additions & 40 deletions runtime/parachains/src/paras/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,11 @@ fn para_past_code_pruning_in_initialize() {
}

let pruned_at: BlockNumber = included_block + code_retention_period + 1;
assert_eq!(
PastCodeHash::<Test>::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!(
PastCodeHash::<Test>::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);

Expand Down Expand Up @@ -440,10 +434,7 @@ fn code_upgrade_applied_after_delay() {
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(expected_at));
assert_eq!(FutureCodeHash::<Test>::get(&para_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!(UpgradeCooldowns::<Test>::get(), vec![(para_id, next_possible_upgrade_at)]);
assert_eq!(Paras::current_code(&para_id), Some(original_code.clone()));
check_code_is_stored(&original_code);
check_code_is_stored(&new_code);
Expand All @@ -461,10 +452,7 @@ fn code_upgrade_applied_after_delay() {
assert!(Paras::past_code_meta(&para_id).most_recent_change().is_none());
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(expected_at));
assert_eq!(FutureCodeHash::<Test>::get(&para_id), Some(new_code.hash()));
assert_eq!(
UpgradeGoAheadSignal::<Test>::get(&para_id),
Some(UpgradeGoAhead::GoAhead)
);
assert_eq!(UpgradeGoAheadSignal::<Test>::get(&para_id), Some(UpgradeGoAhead::GoAhead));
assert_eq!(Paras::current_code(&para_id), Some(original_code.clone()));
check_code_is_stored(&original_code);
check_code_is_stored(&new_code);
Expand Down Expand Up @@ -541,10 +529,7 @@ fn code_upgrade_applied_after_delay_even_when_late() {
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(expected_at));
assert_eq!(FutureCodeHash::<Test>::get(&para_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!(UpgradeCooldowns::<Test>::get(), vec![(para_id, next_possible_upgrade_at)]);
assert!(UpgradeGoAheadSignal::<Test>::get(&para_id).is_none());
assert_eq!(Paras::current_code(&para_id), Some(original_code.clone()));

Expand All @@ -557,10 +542,7 @@ 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!(
UpgradeGoAheadSignal::<Test>::get(&para_id),
Some(UpgradeGoAhead::GoAhead),
);
assert_eq!(UpgradeGoAheadSignal::<Test>::get(&para_id), Some(UpgradeGoAhead::GoAhead),);

Paras::note_new_head(para_id, Default::default(), expected_at + 4);

Expand Down Expand Up @@ -615,10 +597,7 @@ 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!(
FutureCodeUpgrades::<Test>::get(&para_id),
Some(1 + validation_upgrade_delay)
);
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(1 + validation_upgrade_delay));
assert_eq!(FutureCodeHash::<Test>::get(&para_id), Some(new_code.hash()));
check_code_is_stored(&new_code);

Expand Down Expand Up @@ -688,10 +667,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() {
UpgradeRestrictionSignal::<Test>::get(&para_id),
Some(UpgradeRestriction::Present),
);
assert_eq!(
FutureCodeUpgrades::<Test>::get(&para_id),
Some(0 + validation_upgrade_delay)
);
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(0 + validation_upgrade_delay));
assert!(!Paras::can_upgrade_validation_code(para_id));

run_to_block(31, None);
Expand All @@ -702,10 +678,7 @@ fn upgrade_restriction_elapsed_doesnt_mean_can_upgrade() {

// 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!(
FutureCodeUpgrades::<Test>::get(&para_id),
Some(0 + validation_upgrade_delay)
);
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(0 + validation_upgrade_delay));
});
}

Expand Down Expand Up @@ -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!(
FutureCodeUpgrades::<Test>::get(&para_id),
Some(1 + validation_upgrade_delay)
);
assert_eq!(FutureCodeUpgrades::<Test>::get(&para_id), Some(1 + validation_upgrade_delay));

// Verify that the required events were emitted.
EventValidator::new()
Expand Down
Loading

0 comments on commit 3ea93d9

Please sign in to comment.