Benchmark Offences Pallet (#5411)

* Add initial report_ofence bench.

* Remove unused imports

* Style nit

* Add nominators

* Remove logs.

* Nits.

* Add nominators param.

* Reorg, comment.

* Remove whitespaces.

* Apply review suggestion: move benchmark to own crate.

* Remove import.

* Remove line.

* Add feature flag.

* Pass can_report.

* Cleaning up.

* More cleaning
This commit is contained in:
Marcio Diaz
2020-04-07 11:36:57 +02:00
committed by GitHub
parent d3cc051419
commit fb9bbf306d
10 changed files with 463 additions and 205 deletions
+15 -5
View File
@@ -583,10 +583,10 @@ pub struct Nominations<AccountId> {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, RuntimeDebug)]
pub struct IndividualExposure<AccountId, Balance: HasCompact> {
/// The stash account of the nominator in question.
who: AccountId,
pub who: AccountId,
/// Amount of funds exposed.
#[codec(compact)]
value: Balance,
pub value: Balance,
}
/// A snapshot of the stake backing a single validator in the system.
@@ -1252,7 +1252,7 @@ decl_module! {
/// unless the `origin` falls below _existential deposit_ and gets removed as dust.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(500_000)]
fn bond(origin,
pub fn bond(origin,
controller: <T::Lookup as StaticLookup>::Source,
#[compact] value: BalanceOf<T>,
payee: RewardDestination,
@@ -1446,7 +1446,7 @@ decl_module! {
/// - Writes are limited to the `origin` account key.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(750_000)]
fn validate(origin, prefs: ValidatorPrefs) {
pub fn validate(origin, prefs: ValidatorPrefs) {
let controller = ensure_signed(origin)?;
let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
let stash = &ledger.stash;
@@ -1466,7 +1466,7 @@ decl_module! {
/// - Both the reads and writes follow a similar pattern.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(750_000)]
fn nominate(origin, targets: Vec<<T::Lookup as StaticLookup>::Source>) {
pub fn nominate(origin, targets: Vec<<T::Lookup as StaticLookup>::Source>) {
let controller = ensure_signed(origin)?;
let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
let stash = &ledger.stash;
@@ -2878,6 +2878,16 @@ impl<T: Trait> Module<T> {
_ => ForceEra::put(Forcing::ForceNew),
}
}
#[cfg(feature = "runtime-benchmarks")]
pub fn add_era_stakers(current_era: EraIndex, controller: T::AccountId, exposure: Exposure<T::AccountId, BalanceOf<T>>) {
<ErasStakers<T>>::insert(&current_era, &controller, &exposure);
}
#[cfg(feature = "runtime-benchmarks")]
pub fn put_election_status(status: ElectionStatus::<T::BlockNumber>) {
<EraElectionStatus<T>>::put(status);
}
}
/// In this implementation `new_session(session)` must be called before `end_session(session-1)`