Skip to content

Commit 6217936

Browse files
paritytech-release-backport-bot[bot]kianenigmagithub-actions[bot]Ank4nEgorPopelyaev
authored
[stable2509] Backport #10248 (#10289)
Backport #10248 into `stable2509` from kianenigma. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Ankan <[email protected]> Co-authored-by: EgorPopelyaev <[email protected]>
1 parent abe0541 commit 6217936

File tree

11 files changed

+486
-113
lines changed

11 files changed

+486
-113
lines changed

cumulus/parachains/runtimes/assets/asset-hub-westend/src/staking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ impl multi_block::Config for Runtime {
122122
type TargetSnapshotPerBlock = TargetSnapshotPerBlock;
123123
type AdminOrigin =
124124
EitherOfDiverse<EnsureRoot<AccountId>, EnsureSignedBy<WestendStakingMiner, AccountId>>;
125+
type ManagerOrigin =
126+
EitherOfDiverse<EnsureRoot<AccountId>, EnsureSignedBy<WestendStakingMiner, AccountId>>;
125127
type DataProvider = Staking;
126128
type MinerConfig = Self;
127129
type Verifier = MultiBlockElectionVerifier;

prdoc/pr_10248.prdoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
title: Fix origin check in EPMB's manage extrinsic
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
Fix origin check in EPMB's manage extrinsic and:
6+
7+
- Break down `Admin` and `Manager` origins/extrinsics for easier configuration
8+
- update the corresponding weights
9+
crates:
10+
- name: asset-hub-westend-runtime
11+
bump: minor
12+
- name: pallet-election-provider-multi-block
13+
bump: minor

substrate/frame/election-provider-multi-block/src/benchmarking.rs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
};
2222
use frame_benchmarking::v2::*;
2323
use frame_election_provider_support::{ElectionDataProvider, ElectionProvider};
24-
use frame_support::pallet_prelude::*;
24+
use frame_support::{assert_ok, pallet_prelude::*};
2525

2626
const SNAPSHOT_NOT_BIG_ENOUGH: &'static str = "Snapshot page is not full, you should run this \
2727
benchmark with enough genesis stakers in staking (DataProvider) to fill a page of voters/targets \
@@ -253,10 +253,81 @@ mod benchmarks {
253253
}
254254

255255
#[benchmark(pov_mode = Measured)]
256-
fn manage() -> Result<(), BenchmarkError> {
257-
// TODO
256+
fn manage_fallback() -> Result<(), BenchmarkError> {
257+
// heaviest case is emergency set.
258+
#[cfg(test)]
259+
crate::mock::ElectionStart::set(sp_runtime::traits::Bounded::max_value());
260+
crate::Pallet::<T>::start().unwrap();
261+
262+
// roll to signed so the snapshot exists
263+
Pallet::<T>::roll_until_before_matches(|| {
264+
matches!(CurrentPhase::<T>::get(), Phase::Signed(_))
265+
});
266+
267+
// set phase to emergency
268+
CurrentPhase::<T>::set(Phase::Emergency);
269+
let origin = T::ManagerOrigin::try_successful_origin()
270+
.map_err(|_| -> BenchmarkError { "cannot create manager origin".into() })?;
271+
#[block]
272+
{
273+
// fallback might decide to fail, that's okay..
274+
let maybe_err = Pallet::<T>::manage(origin, crate::ManagerOperation::EmergencyFallback);
275+
//.. but it cannot be bad origin.
276+
assert!(maybe_err.is_ok() || maybe_err.unwrap_err() != DispatchError::BadOrigin.into());
277+
}
278+
279+
Ok(())
280+
}
281+
282+
#[benchmark(pov_mode = Measured)]
283+
fn admin_set() -> Result<(), BenchmarkError> {
284+
// heaviest case is emergency set.
285+
#[cfg(test)]
286+
crate::mock::ElectionStart::set(sp_runtime::traits::Bounded::max_value());
287+
crate::Pallet::<T>::start().unwrap();
288+
289+
// mine a single page solution.
290+
let solution = crate::Pallet::<T>::roll_to_signed_and_mine_solution(1);
291+
292+
// verify to get the support.
293+
let (voter_pages, all_targets, desired_targets) =
294+
crate::unsigned::miner::OffchainWorkerMiner::<T>::fetch_snapshot(T::Pages::get())
295+
.map_err(|_| -> BenchmarkError { "fetch_snapshot".into() })?;
296+
let supports = crate::unsigned::miner::BaseMiner::<T::MinerConfig>::check_feasibility(
297+
&solution,
298+
&voter_pages,
299+
&all_targets,
300+
desired_targets,
301+
)
302+
.map_err(|_| -> BenchmarkError { "check_feasibility".into() })?;
303+
304+
let single_support = supports
305+
.first()
306+
.cloned()
307+
.ok_or_else(|| -> BenchmarkError { "no support".into() })?;
308+
309+
// set phase to emergency
310+
CurrentPhase::<T>::set(Phase::Emergency);
311+
312+
// nothing is queued in verified just yet.
313+
assert!(<T::Verifier as Verifier>::queued_score().is_none());
314+
315+
let origin = T::AdminOrigin::try_successful_origin()
316+
.map_err(|_| -> BenchmarkError { "cannot create admin origin".into() })?;
258317
#[block]
259-
{}
318+
{
319+
assert_ok!(Pallet::<T>::admin(
320+
origin,
321+
crate::AdminOperation::EmergencySetSolution(
322+
sp_std::boxed::Box::new(single_support),
323+
solution.score,
324+
),
325+
));
326+
}
327+
328+
// something is queued now.
329+
assert!(<T::Verifier as Verifier>::queued_score().is_some());
330+
260331
Ok(())
261332
}
262333

0 commit comments

Comments
 (0)