Skip to content

Commit

Permalink
NoOp Impl Polling Trait (#5311)
Browse files Browse the repository at this point in the history
Adds NoOp implementation for the `Polling` trait and updates benchmarks
in `pallet-ranked-collective`.

---------

Co-authored-by: Oliver Tale-Yazdi <[email protected]>
(cherry picked from commit 9f603b1)
  • Loading branch information
Doordashcon authored and github-actions[bot] committed Dec 9, 2024
1 parent ed1932e commit c3fdb59
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 156 deletions.
16 changes: 16 additions & 0 deletions prdoc/pr_5311.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: No-op Impl Polling Trait

doc:
- audience: Runtime Dev
description: |
Provide a NoOp implementation of the Polling trait for unit where the trait is defined and skiping benchmarks that necessitate it's definition.

crates:
- name: pallet-core-fellowship
bump: minor
- name: pallet-ranked-collective
bump: minor
- name: pallet-salary
bump: minor
- name: frame-support
bump: minor
47 changes: 4 additions & 43 deletions substrate/frame/core-fellowship/src/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use frame_support::{
assert_noop, assert_ok, derive_impl, hypothetically, ord_parameter_types,
pallet_prelude::Weight,
parameter_types,
traits::{ConstU16, EitherOf, IsInVec, MapSuccess, PollStatus, Polling, TryMapSuccess},
traits::{ConstU16, EitherOf, IsInVec, MapSuccess, NoOpPoll, TryMapSuccess},
};
use frame_system::EnsureSignedBy;
use pallet_ranked_collective::{EnsureRanked, Geometric, Rank, TallyOf, Votes};
use pallet_ranked_collective::{EnsureRanked, Geometric, Rank};
use sp_core::{ConstU32, Get};
use sp_runtime::{
bounded_vec,
traits::{Convert, ReduceBy, ReplaceWithDefault, TryMorphInto},
BuildStorage, DispatchError,
BuildStorage,
};
type Class = Rank;

Expand Down Expand Up @@ -83,45 +83,6 @@ impl Config for Test {
type MaxRank = ConstU32<9>;
}

pub struct TestPolls;
impl Polling<TallyOf<Test>> for TestPolls {
type Index = u8;
type Votes = Votes;
type Moment = u64;
type Class = Class;

fn classes() -> Vec<Self::Class> {
unimplemented!()
}
fn as_ongoing(_: u8) -> Option<(TallyOf<Test>, Self::Class)> {
unimplemented!()
}
fn access_poll<R>(
_: Self::Index,
_: impl FnOnce(PollStatus<&mut TallyOf<Test>, Self::Moment, Self::Class>) -> R,
) -> R {
unimplemented!()
}
fn try_access_poll<R>(
_: Self::Index,
_: impl FnOnce(
PollStatus<&mut TallyOf<Test>, Self::Moment, Self::Class>,
) -> Result<R, DispatchError>,
) -> Result<R, DispatchError> {
unimplemented!()
}

#[cfg(feature = "runtime-benchmarks")]
fn create_ongoing(_: Self::Class) -> Result<Self::Index, ()> {
unimplemented!()
}

#[cfg(feature = "runtime-benchmarks")]
fn end_ongoing(_: Self::Index, _: bool) -> Result<(), ()> {
unimplemented!()
}
}

/// Convert the tally class into the minimum rank required to vote on the poll.
/// MinRank(Class) = Class - Delta
pub struct MinRankOfClass<Delta>(PhantomData<Delta>);
Expand Down Expand Up @@ -154,7 +115,7 @@ impl pallet_ranked_collective::Config for Test {
// Members can exchange up to the rank of 2 below them.
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
>;
type Polls = TestPolls;
type Polls = NoOpPoll;
type MinRankOfClass = MinRankOfClass<MinRankOfClassDelta>;
type MemberSwappedHandler = CoreFellowship;
type VoteWeight = Geometric;
Expand Down
Loading

0 comments on commit c3fdb59

Please sign in to comment.