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

Commit 79eaf7c

Browse files
committed
Rustfmt changes
1 parent 5df6e9e commit 79eaf7c

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

Diff for: runtime/parachains/src/disputes.rs

+17-23
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
//! Runtime component for handling disputes of parachain candidates.
1818
1919
use crate::{
20-
shared,
2120
configuration::{self, HostConfiguration},
2221
initializer::SessionChangeNotification,
23-
session_info,
22+
session_info, shared,
2423
};
2524
use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0};
2625
use frame_support::{ensure, traits::Get, weights::Weight};
@@ -554,10 +553,8 @@ impl<T: Config> Pallet<T> {
554553
dispute.concluded_at = Some(now);
555554
<Disputes<T>>::insert(session_index, candidate_hash, &dispute);
556555

557-
let is_local = <shared::Pallet<T>>::is_included_candidate(
558-
&session_index,
559-
&candidate_hash,
560-
);
556+
let is_local =
557+
<shared::Pallet<T>>::is_included_candidate(&session_index, &candidate_hash);
561558
if is_local {
562559
// Local disputes don't count towards spam.
563560

@@ -780,7 +777,8 @@ impl<T: Config> Pallet<T> {
780777
};
781778

782779
// Apply spam slot changes. Bail early if too many occupied.
783-
let is_local = <shared::Pallet<T>>::is_included_candidate(&set.session, &set.candidate_hash);
780+
let is_local =
781+
<shared::Pallet<T>>::is_included_candidate(&set.session, &set.candidate_hash);
784782
if !is_local {
785783
let mut spam_slots: Vec<u32> =
786784
SpamSlots::<T>::get(&set.session).unwrap_or_else(|| vec![0; n_validators]);
@@ -912,10 +910,8 @@ impl<T: Config> Pallet<T> {
912910
};
913911

914912
// Apply spam slot changes. Bail early if too many occupied.
915-
let is_local = <shared::Pallet<T>>::is_included_candidate(
916-
&set.session,
917-
&set.candidate_hash,
918-
);
913+
let is_local =
914+
<shared::Pallet<T>>::is_included_candidate(&set.session, &set.candidate_hash);
919915
if !is_local {
920916
let mut spam_slots: Vec<u32> =
921917
SpamSlots::<T>::get(&set.session).unwrap_or_else(|| vec![0; n_validators]);
@@ -989,10 +985,9 @@ impl<T: Config> Pallet<T> {
989985

990986
// Freeze if just concluded against some local candidate
991987
if summary.new_flags.contains(DisputeStateFlags::AGAINST_SUPERMAJORITY) {
992-
if let Some((revert_to, _)) = <shared::Pallet<T>>::get_included_candidate(
993-
&set.session,
994-
&set.candidate_hash,
995-
) {
988+
if let Some((revert_to, _)) =
989+
<shared::Pallet<T>>::get_included_candidate(&set.session, &set.candidate_hash)
990+
{
996991
Self::revert_and_freeze(revert_to);
997992
}
998993
}
@@ -1111,7 +1106,6 @@ fn check_signature(
11111106
#[cfg(test)]
11121107
mod tests {
11131108
use super::*;
1114-
use primitives::v1::CoreIndex;
11151109
use crate::mock::{
11161110
new_test_ext, AccountId, AllPallets, Initializer, MockGenesisConfig, System, Test,
11171111
PUNISH_VALIDATORS_AGAINST, PUNISH_VALIDATORS_FOR, PUNISH_VALIDATORS_INCONCLUSIVE,
@@ -1122,7 +1116,7 @@ mod tests {
11221116
traits::{OnFinalize, OnInitialize},
11231117
};
11241118
use frame_system::InitKind;
1125-
use primitives::v1::BlockNumber;
1119+
use primitives::v1::{BlockNumber, CoreIndex};
11261120
use sp_core::{crypto::CryptoType, Pair};
11271121

11281122
// All arguments for `initializer::on_new_session`
@@ -1160,18 +1154,18 @@ mod tests {
11601154
}
11611155
}
11621156

1163-
fn include_candidate(session: SessionIndex, candidate_hash: &CandidateHash, block_number: BlockNumber) {
1157+
fn include_candidate(
1158+
session: SessionIndex,
1159+
candidate_hash: &CandidateHash,
1160+
block_number: BlockNumber,
1161+
) {
11641162
if let Some(revert_to) = shared::Pallet::<Test>::note_included_candidate(
11651163
session,
11661164
candidate_hash.clone(),
11671165
block_number,
11681166
CoreIndex(0),
11691167
) {
1170-
Pallet::<Test>::process_included(
1171-
session,
1172-
candidate_hash.clone(),
1173-
revert_to,
1174-
);
1168+
Pallet::<Test>::process_included(session, candidate_hash.clone(), revert_to);
11751169
}
11761170
}
11771171

Diff for: runtime/parachains/src/shared.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
2222
use frame_support::pallet_prelude::*;
2323
use primitives::v1::{CandidateHash, CoreIndex, SessionIndex, ValidatorId, ValidatorIndex};
24-
use sp_std::vec::Vec;
2524
use sp_runtime::traits::{One, Zero};
25+
use sp_std::vec::Vec;
2626

2727
use rand::{seq::SliceRandom, SeedableRng};
2828
use rand_chacha::ChaCha20Rng;
@@ -72,8 +72,10 @@ pub mod pallet {
7272
#[pallet::getter(fn included_candidates)]
7373
pub(super) type IncludedCandidates<T: Config> = StorageDoubleMap<
7474
_,
75-
Twox64Concat, SessionIndex,
76-
Blake2_128Concat, CandidateHash,
75+
Twox64Concat,
76+
SessionIndex,
77+
Blake2_128Concat,
78+
CandidateHash,
7779
(T::BlockNumber, CoreIndex),
7880
>;
7981

@@ -136,7 +138,9 @@ impl<T: Config> Pallet<T> {
136138
included_in: T::BlockNumber,
137139
core_index: CoreIndex,
138140
) -> Option<T::BlockNumber> {
139-
if included_in.is_zero() { return None }
141+
if included_in.is_zero() {
142+
return None
143+
}
140144

141145
let revert_to = included_in - One::one();
142146
<IncludedCandidates<T>>::insert(&session, &candidate_hash, (revert_to, core_index));
@@ -168,7 +172,7 @@ impl<T: Config> Pallet<T> {
168172
#[cfg(test)]
169173
pub(crate) fn included_candidates_iter_prefix(
170174
session: SessionIndex,
171-
) -> impl Iterator<Item=(CandidateHash, (T::BlockNumber, CoreIndex))> {
175+
) -> impl Iterator<Item = (CandidateHash, (T::BlockNumber, CoreIndex))> {
172176
<IncludedCandidates<T>>::iter_prefix(session)
173177
}
174178

@@ -291,7 +295,8 @@ mod tests {
291295
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
292296
let session = 1;
293297
let candidate_hash = CandidateHash(sp_core::H256::repeat_byte(1));
294-
assert!(ParasShared::note_included_candidate(session, candidate_hash, 0, CoreIndex(0)).is_none());
298+
assert!(ParasShared::note_included_candidate(session, candidate_hash, 0, CoreIndex(0))
299+
.is_none());
295300
assert!(!ParasShared::is_included_candidate(&session, &candidate_hash));
296301
assert!(ParasShared::get_included_candidate(&session, &candidate_hash).is_none());
297302
});
@@ -305,7 +310,12 @@ mod tests {
305310
let block_number = 1;
306311
let core_index = CoreIndex(2);
307312
assert_eq!(
308-
ParasShared::note_included_candidate(session, candidate_hash, block_number, core_index),
313+
ParasShared::note_included_candidate(
314+
session,
315+
candidate_hash,
316+
block_number,
317+
core_index
318+
),
309319
Some(block_number - 1),
310320
);
311321
assert!(ParasShared::is_included_candidate(&session, &candidate_hash));
@@ -323,9 +333,15 @@ mod tests {
323333
let candidate_hash2 = CandidateHash(sp_core::H256::repeat_byte(2));
324334
let candidate_hash3 = CandidateHash(sp_core::H256::repeat_byte(3));
325335

326-
assert!(ParasShared::note_included_candidate(1, candidate_hash1, 1, CoreIndex(0)).is_some());
327-
assert!(ParasShared::note_included_candidate(1, candidate_hash2, 1, CoreIndex(0)).is_some());
328-
assert!(ParasShared::note_included_candidate(2, candidate_hash3, 2, CoreIndex(0)).is_some());
336+
assert!(
337+
ParasShared::note_included_candidate(1, candidate_hash1, 1, CoreIndex(0)).is_some()
338+
);
339+
assert!(
340+
ParasShared::note_included_candidate(1, candidate_hash2, 1, CoreIndex(0)).is_some()
341+
);
342+
assert!(
343+
ParasShared::note_included_candidate(2, candidate_hash3, 2, CoreIndex(0)).is_some()
344+
);
329345

330346
assert_eq!(ParasShared::included_candidates_iter_prefix(1).count(), 2);
331347
assert_eq!(ParasShared::included_candidates_iter_prefix(2).count(), 1);

0 commit comments

Comments
 (0)