mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 01:27:56 +00:00
Weight v1.5: Opaque Struct (#12138)
* initial idea * update frame_support * update a bunch more * add ord * adjust RuntimeDbWeight * frame_system builds * re-export * frame_support tests pass * frame_executive compile * frame_executive builds * frame_system tests passing * pallet-utility tests pass * fix a bunch of pallets * more * phragmen * state-trie-migration * scheduler and referenda * pallet-election-provider-multi-phase * aura * staking * more * babe * balances * bunch more * sudo * transaction-payment * asset-tx-payment * last pallets * fix alliance merge * fix node template runtime * fix pallet-contracts cc @athei * fix node runtime * fix compile on runtime-benchmarks feature * comment * fix frame-support-test * fix more tests * weight regex * frame system works * fix a bunch * more * more * more * more * more * more fixes * update templates * fix contracts benchmarks * Update lib.rs * Update lib.rs * fix ui * make scalar saturating mul const * more const functions * scalar div * refactor using constant functions * move impl * fix overhead template * use compactas * Update lib.rs
This commit is contained in:
@@ -3759,7 +3759,7 @@ fn payout_stakers_handles_weight_refund() {
|
||||
let half_max_nom_rewarded_weight =
|
||||
<Test as Config>::WeightInfo::payout_stakers_alive_staked(half_max_nom_rewarded);
|
||||
let zero_nom_payouts_weight = <Test as Config>::WeightInfo::payout_stakers_alive_staked(0);
|
||||
assert!(zero_nom_payouts_weight > 0);
|
||||
assert!(zero_nom_payouts_weight > Weight::zero());
|
||||
assert!(half_max_nom_rewarded_weight > zero_nom_payouts_weight);
|
||||
assert!(max_nom_rewarded_weight > half_max_nom_rewarded_weight);
|
||||
|
||||
@@ -3898,42 +3898,68 @@ fn bond_during_era_correctly_populates_claimed_rewards() {
|
||||
fn offences_weight_calculated_correctly() {
|
||||
ExtBuilder::default().nominate(true).build_and_execute(|| {
|
||||
// On offence with zero offenders: 4 Reads, 1 Write
|
||||
let zero_offence_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1);
|
||||
assert_eq!(Staking::on_offence(&[], &[Perbill::from_percent(50)], 0, DisableStrategy::WhenSlashed), zero_offence_weight);
|
||||
let zero_offence_weight =
|
||||
<Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1);
|
||||
assert_eq!(
|
||||
Staking::on_offence(&[], &[Perbill::from_percent(50)], 0, DisableStrategy::WhenSlashed),
|
||||
zero_offence_weight
|
||||
);
|
||||
|
||||
// On Offence with N offenders, Unapplied: 4 Reads, 1 Write + 4 Reads, 5 Writes
|
||||
let n_offence_unapplied_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1)
|
||||
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 5);
|
||||
let n_offence_unapplied_weight = <Test as frame_system::Config>::DbWeight::get()
|
||||
.reads_writes(4, 1) +
|
||||
<Test as frame_system::Config>::DbWeight::get().reads_writes(4, 5);
|
||||
|
||||
let offenders: Vec<OffenceDetails<<Test as frame_system::Config>::AccountId, pallet_session::historical::IdentificationTuple<Test>>>
|
||||
= (1..10).map(|i|
|
||||
OffenceDetails {
|
||||
offender: (i, Staking::eras_stakers(active_era(), i)),
|
||||
reporters: vec![],
|
||||
}
|
||||
).collect();
|
||||
assert_eq!(Staking::on_offence(&offenders, &[Perbill::from_percent(50)], 0, DisableStrategy::WhenSlashed), n_offence_unapplied_weight);
|
||||
let offenders: Vec<
|
||||
OffenceDetails<
|
||||
<Test as frame_system::Config>::AccountId,
|
||||
pallet_session::historical::IdentificationTuple<Test>,
|
||||
>,
|
||||
> = (1..10)
|
||||
.map(|i| OffenceDetails {
|
||||
offender: (i, Staking::eras_stakers(active_era(), i)),
|
||||
reporters: vec![],
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
Staking::on_offence(
|
||||
&offenders,
|
||||
&[Perbill::from_percent(50)],
|
||||
0,
|
||||
DisableStrategy::WhenSlashed
|
||||
),
|
||||
n_offence_unapplied_weight
|
||||
);
|
||||
|
||||
// On Offence with one offenders, Applied
|
||||
let one_offender = [
|
||||
OffenceDetails {
|
||||
offender: (11, Staking::eras_stakers(active_era(), 11)),
|
||||
reporters: vec![1],
|
||||
},
|
||||
];
|
||||
let one_offender = [OffenceDetails {
|
||||
offender: (11, Staking::eras_stakers(active_era(), 11)),
|
||||
reporters: vec![1],
|
||||
}];
|
||||
|
||||
let n = 1; // Number of offenders
|
||||
let rw = 3 + 3 * n; // rw reads and writes
|
||||
let one_offence_unapplied_weight = <Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1)
|
||||
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(rw, rw)
|
||||
let one_offence_unapplied_weight =
|
||||
<Test as frame_system::Config>::DbWeight::get().reads_writes(4, 1)
|
||||
+
|
||||
<Test as frame_system::Config>::DbWeight::get().reads_writes(rw, rw)
|
||||
// One `slash_cost`
|
||||
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(6, 5)
|
||||
// `slash_cost` * nominators (1)
|
||||
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(6, 5)
|
||||
// `reward_cost` * reporters (1)
|
||||
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(2, 2);
|
||||
+ <Test as frame_system::Config>::DbWeight::get().reads_writes(2, 2)
|
||||
;
|
||||
|
||||
assert_eq!(Staking::on_offence(&one_offender, &[Perbill::from_percent(50)], 0, DisableStrategy::WhenSlashed), one_offence_unapplied_weight);
|
||||
assert_eq!(
|
||||
Staking::on_offence(
|
||||
&one_offender,
|
||||
&[Perbill::from_percent(50)],
|
||||
0,
|
||||
DisableStrategy::WhenSlashed
|
||||
),
|
||||
one_offence_unapplied_weight
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user