mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 06:21:11 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -22,18 +22,18 @@
|
||||
// Ensure we're `no_std` when compiling for Wasm.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
mod migration;
|
||||
mod mock;
|
||||
mod tests;
|
||||
mod migration;
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::weights::Weight;
|
||||
use sp_runtime::{traits::Hash, Perbill};
|
||||
use sp_staking::{
|
||||
offence::{Kind, Offence, OffenceDetails, OffenceError, OnOffenceHandler, ReportOffence},
|
||||
SessionIndex
|
||||
SessionIndex,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
@@ -44,17 +44,25 @@ type OpaqueTimeSlot = Vec<u8>;
|
||||
type ReportIdOf<T> = <T as frame_system::Config>::Hash;
|
||||
|
||||
pub trait WeightInfo {
|
||||
fn report_offence_im_online(r: u32, o: u32, n: u32, ) -> Weight;
|
||||
fn report_offence_grandpa(r: u32, n: u32, ) -> Weight;
|
||||
fn report_offence_babe(r: u32, n: u32, ) -> Weight;
|
||||
fn on_initialize(d: u32, ) -> Weight;
|
||||
fn report_offence_im_online(r: u32, o: u32, n: u32) -> Weight;
|
||||
fn report_offence_grandpa(r: u32, n: u32) -> Weight;
|
||||
fn report_offence_babe(r: u32, n: u32) -> Weight;
|
||||
fn on_initialize(d: u32) -> Weight;
|
||||
}
|
||||
|
||||
impl WeightInfo for () {
|
||||
fn report_offence_im_online(_r: u32, _o: u32, _n: u32, ) -> Weight { 1_000_000_000 }
|
||||
fn report_offence_grandpa(_r: u32, _n: u32, ) -> Weight { 1_000_000_000 }
|
||||
fn report_offence_babe(_r: u32, _n: u32, ) -> Weight { 1_000_000_000 }
|
||||
fn on_initialize(_d: u32, ) -> Weight { 1_000_000_000 }
|
||||
fn report_offence_im_online(_r: u32, _o: u32, _n: u32) -> Weight {
|
||||
1_000_000_000
|
||||
}
|
||||
fn report_offence_grandpa(_r: u32, _n: u32) -> Weight {
|
||||
1_000_000_000
|
||||
}
|
||||
fn report_offence_babe(_r: u32, _n: u32) -> Weight {
|
||||
1_000_000_000
|
||||
}
|
||||
fn on_initialize(_d: u32) -> Weight {
|
||||
1_000_000_000
|
||||
}
|
||||
}
|
||||
|
||||
#[frame_support::pallet]
|
||||
@@ -145,22 +153,20 @@ where
|
||||
|
||||
// Go through all offenders in the offence report and find all offenders that were spotted
|
||||
// in unique reports.
|
||||
let TriageOutcome {
|
||||
concurrent_offenders,
|
||||
} = match Self::triage_offence_report::<O>(reporters, &time_slot, offenders) {
|
||||
Some(triage) => triage,
|
||||
// The report contained only duplicates, so there is no need to slash again.
|
||||
None => return Err(OffenceError::DuplicateReport),
|
||||
};
|
||||
let TriageOutcome { concurrent_offenders } =
|
||||
match Self::triage_offence_report::<O>(reporters, &time_slot, offenders) {
|
||||
Some(triage) => triage,
|
||||
// The report contained only duplicates, so there is no need to slash again.
|
||||
None => return Err(OffenceError::DuplicateReport),
|
||||
};
|
||||
|
||||
let offenders_count = concurrent_offenders.len() as u32;
|
||||
|
||||
// The amount new offenders are slashed
|
||||
let new_fraction = O::slash_fraction(offenders_count, validator_set_count);
|
||||
|
||||
let slash_perbill: Vec<_> = (0..concurrent_offenders.len())
|
||||
.map(|_| new_fraction.clone())
|
||||
.collect();
|
||||
let slash_perbill: Vec<_> =
|
||||
(0..concurrent_offenders.len()).map(|_| new_fraction.clone()).collect();
|
||||
|
||||
T::OnOffenceHandler::on_offence(
|
||||
&concurrent_offenders,
|
||||
@@ -212,10 +218,7 @@ impl<T: Config> Pallet<T> {
|
||||
any_new = true;
|
||||
<Reports<T>>::insert(
|
||||
&report_id,
|
||||
OffenceDetails {
|
||||
offender,
|
||||
reporters: reporters.clone(),
|
||||
},
|
||||
OffenceDetails { offender, reporters: reporters.clone() },
|
||||
);
|
||||
|
||||
storage.insert(time_slot, report_id);
|
||||
@@ -232,9 +235,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
storage.save();
|
||||
|
||||
Some(TriageOutcome {
|
||||
concurrent_offenders,
|
||||
})
|
||||
Some(TriageOutcome { concurrent_offenders })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -270,20 +271,14 @@ impl<T: Config, O: Offence<T::IdentificationTuple>> ReportIndexStorage<T, O> {
|
||||
|
||||
let concurrent_reports = <ConcurrentReportsIndex<T>>::get(&O::ID, &opaque_time_slot);
|
||||
|
||||
Self {
|
||||
opaque_time_slot,
|
||||
concurrent_reports,
|
||||
same_kind_reports,
|
||||
}
|
||||
Self { opaque_time_slot, concurrent_reports, same_kind_reports }
|
||||
}
|
||||
|
||||
/// Insert a new report to the index.
|
||||
fn insert(&mut self, time_slot: &O::TimeSlot, report_id: ReportIdOf<T>) {
|
||||
// Insert the report id into the list while maintaining the ordering by the time
|
||||
// slot.
|
||||
let pos = self
|
||||
.same_kind_reports
|
||||
.partition_point(|&(ref when, _)| when <= time_slot);
|
||||
let pos = self.same_kind_reports.partition_point(|&(ref when, _)| when <= time_slot);
|
||||
self.same_kind_reports.insert(pos, (time_slot.clone(), report_id));
|
||||
|
||||
// Update the list of concurrent reports.
|
||||
|
||||
Reference in New Issue
Block a user