-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Rewards pallet benchmarking. | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use sp_std::prelude::*; | ||
use frame_system::RawOrigin; | ||
use frame_support::{traits::OnFinalize}; | ||
use frame_benchmarking::benchmarks; | ||
use crate::Module as Rewards; | ||
use sp_runtime::generic::DigestItem; | ||
use codec::{Encode}; | ||
|
||
const MAX_TIME: u32 = 100; | ||
|
||
benchmarks! { | ||
_ { } | ||
|
||
claim { | ||
let validators = pallet_session::Module::<T>::validators(); | ||
// let validators_size: usize = validators.len(); | ||
// let i in 0..validators_size; | ||
let validator = validators[0].clone(); | ||
let miner = T::AccountIdOf::convert(validator).unwrap(); | ||
// let rewards = Rewards::<T>::current_reward_per_block(); | ||
let rewards = T::RewardThreshold::get(); | ||
Rewards::<T>::set_rewards(miner.clone(), rewards, Zero::zero()); | ||
Rewards::<T>::set_rewards(miner.clone(), rewards, Zero::zero()); | ||
}: claim(RawOrigin::Signed(miner.clone())) | ||
verify { | ||
// assert_eq!(Rewards::<T>::immature_rewards(&miner).0, rewards); | ||
assert_eq!(Rewards::<T>::mature_rewards(&miner), Zero::zero()); | ||
} | ||
|
||
on_finalize { | ||
let _ = Rewards::<T>::set_start_block(RawOrigin::Root.into(), Zero::zero()); | ||
let t in 1 .. MAX_TIME; | ||
|
||
let slot = 1u64; | ||
let log: DigestItem<T::Hash> = DigestItem::PreRuntime( | ||
sp_consensus_aura::AURA_ENGINE_ID, | ||
slot.encode() | ||
); | ||
<frame_system::Module<T>>::deposit_log(log.into()); | ||
|
||
let prev_mined_rewards = Rewards::<T>::mined_rewards(); | ||
}: { Rewards::<T>::on_finalize(t.into()); } | ||
verify { | ||
let rewards_per_block = Rewards::<T>::current_reward_per_block(); | ||
assert_eq!(Rewards::<T>::mined_rewards(), prev_mined_rewards + rewards_per_block); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; | ||
use sp_std::marker::PhantomData; | ||
|
||
pub struct WeightInfo<T>(PhantomData<T>); | ||
impl<T: frame_system::Trait> pallet_rewards::WeightInfo for WeightInfo<T> { | ||
fn claim() -> Weight { | ||
(50_000_000 as Weight) | ||
.saturating_add(DbWeight::get().reads(3 as Weight)) | ||
.saturating_add(DbWeight::get().writes(2 as Weight)) | ||
} | ||
// WARNING! Some components were not used: ["t"] | ||
fn on_finalize() -> Weight { | ||
(29_157_000 as Weight) | ||
.saturating_add(DbWeight::get().reads(7 as Weight)) | ||
.saturating_add(DbWeight::get().writes(2 as Weight)) | ||
} | ||
} |