From 79eaf7c6efa7e346971f74bb1dbdb87f28d1f770 Mon Sep 17 00:00:00 2001 From: Lldenaurois Date: Tue, 3 Aug 2021 13:58:41 -0400 Subject: [PATCH] Rustfmt changes --- runtime/parachains/src/disputes.rs | 40 +++++++++++++----------------- runtime/parachains/src/shared.rs | 36 +++++++++++++++++++-------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index 46aa4fb0d660..f4b99a172faa 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -17,10 +17,9 @@ //! Runtime component for handling disputes of parachain candidates. use crate::{ - shared, configuration::{self, HostConfiguration}, initializer::SessionChangeNotification, - session_info, + session_info, shared, }; use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0}; use frame_support::{ensure, traits::Get, weights::Weight}; @@ -554,10 +553,8 @@ impl Pallet { dispute.concluded_at = Some(now); >::insert(session_index, candidate_hash, &dispute); - let is_local = >::is_included_candidate( - &session_index, - &candidate_hash, - ); + let is_local = + >::is_included_candidate(&session_index, &candidate_hash); if is_local { // Local disputes don't count towards spam. @@ -780,7 +777,8 @@ impl Pallet { }; // Apply spam slot changes. Bail early if too many occupied. - let is_local = >::is_included_candidate(&set.session, &set.candidate_hash); + let is_local = + >::is_included_candidate(&set.session, &set.candidate_hash); if !is_local { let mut spam_slots: Vec = SpamSlots::::get(&set.session).unwrap_or_else(|| vec![0; n_validators]); @@ -912,10 +910,8 @@ impl Pallet { }; // Apply spam slot changes. Bail early if too many occupied. - let is_local = >::is_included_candidate( - &set.session, - &set.candidate_hash, - ); + let is_local = + >::is_included_candidate(&set.session, &set.candidate_hash); if !is_local { let mut spam_slots: Vec = SpamSlots::::get(&set.session).unwrap_or_else(|| vec![0; n_validators]); @@ -989,10 +985,9 @@ impl Pallet { // Freeze if just concluded against some local candidate if summary.new_flags.contains(DisputeStateFlags::AGAINST_SUPERMAJORITY) { - if let Some((revert_to, _)) = >::get_included_candidate( - &set.session, - &set.candidate_hash, - ) { + if let Some((revert_to, _)) = + >::get_included_candidate(&set.session, &set.candidate_hash) + { Self::revert_and_freeze(revert_to); } } @@ -1111,7 +1106,6 @@ fn check_signature( #[cfg(test)] mod tests { use super::*; - use primitives::v1::CoreIndex; use crate::mock::{ new_test_ext, AccountId, AllPallets, Initializer, MockGenesisConfig, System, Test, PUNISH_VALIDATORS_AGAINST, PUNISH_VALIDATORS_FOR, PUNISH_VALIDATORS_INCONCLUSIVE, @@ -1122,7 +1116,7 @@ mod tests { traits::{OnFinalize, OnInitialize}, }; use frame_system::InitKind; - use primitives::v1::BlockNumber; + use primitives::v1::{BlockNumber, CoreIndex}; use sp_core::{crypto::CryptoType, Pair}; // All arguments for `initializer::on_new_session` @@ -1160,18 +1154,18 @@ mod tests { } } - fn include_candidate(session: SessionIndex, candidate_hash: &CandidateHash, block_number: BlockNumber) { + fn include_candidate( + session: SessionIndex, + candidate_hash: &CandidateHash, + block_number: BlockNumber, + ) { if let Some(revert_to) = shared::Pallet::::note_included_candidate( session, candidate_hash.clone(), block_number, CoreIndex(0), ) { - Pallet::::process_included( - session, - candidate_hash.clone(), - revert_to, - ); + Pallet::::process_included(session, candidate_hash.clone(), revert_to); } } diff --git a/runtime/parachains/src/shared.rs b/runtime/parachains/src/shared.rs index 5862a6f2b3ad..40f597a669c5 100644 --- a/runtime/parachains/src/shared.rs +++ b/runtime/parachains/src/shared.rs @@ -21,8 +21,8 @@ use frame_support::pallet_prelude::*; use primitives::v1::{CandidateHash, CoreIndex, SessionIndex, ValidatorId, ValidatorIndex}; -use sp_std::vec::Vec; use sp_runtime::traits::{One, Zero}; +use sp_std::vec::Vec; use rand::{seq::SliceRandom, SeedableRng}; use rand_chacha::ChaCha20Rng; @@ -72,8 +72,10 @@ pub mod pallet { #[pallet::getter(fn included_candidates)] pub(super) type IncludedCandidates = StorageDoubleMap< _, - Twox64Concat, SessionIndex, - Blake2_128Concat, CandidateHash, + Twox64Concat, + SessionIndex, + Blake2_128Concat, + CandidateHash, (T::BlockNumber, CoreIndex), >; @@ -136,7 +138,9 @@ impl Pallet { included_in: T::BlockNumber, core_index: CoreIndex, ) -> Option { - if included_in.is_zero() { return None } + if included_in.is_zero() { + return None + } let revert_to = included_in - One::one(); >::insert(&session, &candidate_hash, (revert_to, core_index)); @@ -168,7 +172,7 @@ impl Pallet { #[cfg(test)] pub(crate) fn included_candidates_iter_prefix( session: SessionIndex, - ) -> impl Iterator { + ) -> impl Iterator { >::iter_prefix(session) } @@ -291,7 +295,8 @@ mod tests { new_test_ext(MockGenesisConfig::default()).execute_with(|| { let session = 1; let candidate_hash = CandidateHash(sp_core::H256::repeat_byte(1)); - assert!(ParasShared::note_included_candidate(session, candidate_hash, 0, CoreIndex(0)).is_none()); + assert!(ParasShared::note_included_candidate(session, candidate_hash, 0, CoreIndex(0)) + .is_none()); assert!(!ParasShared::is_included_candidate(&session, &candidate_hash)); assert!(ParasShared::get_included_candidate(&session, &candidate_hash).is_none()); }); @@ -305,7 +310,12 @@ mod tests { let block_number = 1; let core_index = CoreIndex(2); assert_eq!( - ParasShared::note_included_candidate(session, candidate_hash, block_number, core_index), + ParasShared::note_included_candidate( + session, + candidate_hash, + block_number, + core_index + ), Some(block_number - 1), ); assert!(ParasShared::is_included_candidate(&session, &candidate_hash)); @@ -323,9 +333,15 @@ mod tests { let candidate_hash2 = CandidateHash(sp_core::H256::repeat_byte(2)); let candidate_hash3 = CandidateHash(sp_core::H256::repeat_byte(3)); - assert!(ParasShared::note_included_candidate(1, candidate_hash1, 1, CoreIndex(0)).is_some()); - assert!(ParasShared::note_included_candidate(1, candidate_hash2, 1, CoreIndex(0)).is_some()); - assert!(ParasShared::note_included_candidate(2, candidate_hash3, 2, CoreIndex(0)).is_some()); + assert!( + ParasShared::note_included_candidate(1, candidate_hash1, 1, CoreIndex(0)).is_some() + ); + assert!( + ParasShared::note_included_candidate(1, candidate_hash2, 1, CoreIndex(0)).is_some() + ); + assert!( + ParasShared::note_included_candidate(2, candidate_hash3, 2, CoreIndex(0)).is_some() + ); assert_eq!(ParasShared::included_candidates_iter_prefix(1).count(), 2); assert_eq!(ParasShared::included_candidates_iter_prefix(2).count(), 1);