-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Co reducing fast-unstake bench time and more #6552
Changes from all commits
1052ffd
e0e7b98
467c282
69f01c5
c7cc367
292221b
aee9758
6e93949
0c9d768
4891dbf
6496a57
133e26c
9a4972c
b5945ef
1e64eb8
6427465
b1b19c0
d8e099e
f7afb5d
b513136
8861212
4d0abd7
729f7bd
a1fef94
4c3eb7d
6825d0a
119d604
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2023 Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Common try-runtime only tests for runtimes. | ||
use frame_support::{ | ||
dispatch::RawOrigin, | ||
traits::{Get, Hooks}, | ||
}; | ||
use pallet_fast_unstake::{Pallet as FastUnstake, *}; | ||
use pallet_staking::*; | ||
use sp_std::{collections::btree_set::BTreeSet, prelude::*}; | ||
|
||
/// register all inactive nominators for fast-unstake, and progress until they have all been | ||
/// processed. | ||
pub fn migrate_all_inactive_nominators<T: pallet_fast_unstake::Config + pallet_staking::Config>() | ||
where | ||
<T as frame_system::Config>::RuntimeEvent: TryInto<pallet_fast_unstake::Event<T>>, | ||
{ | ||
let mut unstaked_ok = 0; | ||
let mut unstaked_err = 0; | ||
let mut unstaked_slashed = 0; | ||
|
||
let all_stakers = Ledger::<T>::iter().map(|(ctrl, l)| (ctrl, l.stash)).collect::<BTreeSet<_>>(); | ||
let mut all_exposed = BTreeSet::new(); | ||
ErasStakers::<T>::iter().for_each(|(_, val, expo)| { | ||
all_exposed.insert(val); | ||
all_exposed.extend(expo.others.iter().map(|ie| ie.who.clone())) | ||
}); | ||
|
||
let eligible = all_stakers | ||
.iter() | ||
.filter_map(|(ctrl, stash)| all_exposed.contains(stash).then_some(ctrl)) | ||
.collect::<Vec<_>>(); | ||
|
||
log::info!( | ||
target: "runtime::test", | ||
"registering {} out of {} stakers for fast-unstake", | ||
eligible.len(), | ||
all_stakers.len() | ||
); | ||
for ctrl in eligible { | ||
if let Err(why) = | ||
FastUnstake::<T>::register_fast_unstake(RawOrigin::Signed(ctrl.clone()).into()) | ||
{ | ||
log::warn!(target: "runtime::test", "failed to register {:?} due to {:?}", ctrl, why); | ||
} | ||
} | ||
|
||
log::info!( | ||
target: "runtime::test", | ||
"registered {} successfully, starting at {:?}.", | ||
Queue::<T>::count(), | ||
frame_system::Pallet::<T>::block_number(), | ||
); | ||
while Queue::<T>::count() != 0 || Head::<T>::get().is_some() { | ||
let now = frame_system::Pallet::<T>::block_number(); | ||
let weight = <T as frame_system::Config>::BlockWeights::get().max_block; | ||
let consumed = FastUnstake::<T>::on_idle(now, weight); | ||
log::debug!(target: "runtime::test", "consumed {:?} ({})", consumed, consumed.ref_time() as f32 / weight.ref_time() as f32); | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
frame_system::Pallet::<T>::read_events_no_consensus() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only in consensus code since its a migration, or? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is purely test code, not migration. |
||
.into_iter() | ||
.map(|r| r.event) | ||
.filter_map(|e| { | ||
let maybe_fast_unstake_event: Option<pallet_fast_unstake::Event<T>> = | ||
e.try_into().ok(); | ||
maybe_fast_unstake_event | ||
}) | ||
.for_each(|e: pallet_fast_unstake::Event<T>| match e { | ||
pallet_fast_unstake::Event::<T>::Unstaked { result, .. } => | ||
if result.is_ok() { | ||
unstaked_ok += 1; | ||
} else { | ||
unstaked_err += 1 | ||
}, | ||
pallet_fast_unstake::Event::<T>::Slashed { .. } => unstaked_slashed += 1, | ||
pallet_fast_unstake::Event::<T>::InternalError => unreachable!(), | ||
_ => {}, | ||
}); | ||
|
||
if now % 100u32.into() == sp_runtime::traits::Zero::zero() { | ||
log::info!( | ||
target: "runtime::test", | ||
"status: ok {}, err {}, slash {}", | ||
unstaked_ok, | ||
unstaked_err, | ||
unstaked_slashed, | ||
); | ||
} | ||
|
||
frame_system::Pallet::<T>::reset_events(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you do the event checking here and not in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, this is test, not migration. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add a success log?
The queue count below could also contain non-migration unstakers, or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pallet is already logging that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queue is always the un-migrated ones.