Skip to content

Commit 45cc86a

Browse files
Doordashconbkchrbkonturgithub-actions[bot]
authored
Make NoOpPoll generic over Moment (#8938)
# Description This PR enhances the flexibility of the `NoOpPoll` implementation by introducing a generic `Moment` parameter. This change enables support for diverse clock configurations across different runtimes, allowing `NoOpPoll` to work seamlessly with various block number implementations (e.g., `u32`, `u64`, or custom block number types). ### Integration Downstream projects using `NoOpPoll` must make these adjustments: - Add generic parameter: Specify the Moment type when using `NoOpPoll` - Update type annotations: Modify existing references to include the generic parameter ### Example Migration: ```diff // Before use frame_support::traits::NoOpPoll; let _ = NoOpPoll; // After use frame_support::traits::NoOpPoll; use frame_system::pallet_prelude::BlockNumberFor; ``` ### Generic struct update: ```diff - pub struct NoOpPoll; + pub struct NoOpPoll<Moment>(core::marker::PhantomData<Moment>); ``` ### Polling trait implementation: ```diff - impl<Tally> Polling<Tally> for NoOpPoll { + impl<Tally, Moment> Polling<Tally> for NoOpPoll<Moment> { type Index = u8; type Votes = u32; type Class = u16; - type Moment = u64; + type Moment = Moment; ``` --------- Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fe26e9e commit 45cc86a

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

prdoc/pr_8938.prdoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
title: Make `NoOpPoll` generic over `Moment`
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
This PR enhances the flexibility of the `NoOpPoll` implementation by introducing a generic `Moment` parameter. This change enables support for diverse clock configurations across different runtimes, allowing `NoOpPoll` to work seamlessly with various block number implementations (e.g., `u32`, `u64`, or custom block number types).
6+
crates:
7+
- name: pallet-ranked-collective
8+
bump: patch
9+
- name: frame-support
10+
bump: minor
11+
- name: pallet-core-fellowship
12+
bump: patch
13+
- name: pallet-salary
14+
bump: patch

substrate/frame/core-fellowship/src/tests/integration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use frame_support::{
2525
parameter_types,
2626
traits::{ConstU16, EitherOf, IsInVec, MapSuccess, NoOpPoll, TryMapSuccess},
2727
};
28-
use frame_system::EnsureSignedBy;
28+
use frame_system::{pallet_prelude::BlockNumberFor, EnsureSignedBy};
2929
use pallet_ranked_collective::{EnsureRanked, Geometric, Rank};
3030
use sp_core::Get;
3131
use sp_runtime::{
@@ -117,7 +117,7 @@ impl pallet_ranked_collective::Config for Test {
117117
// Members can exchange up to the rank of 2 below them.
118118
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
119119
>;
120-
type Polls = NoOpPoll;
120+
type Polls = NoOpPoll<BlockNumberFor<Test>>;
121121
type MinRankOfClass = MinRankOfClass<MinRankOfClassDelta>;
122122
type MemberSwappedHandler = CoreFellowship;
123123
type VoteWeight = Geometric;

substrate/frame/ranked-collective/src/benchmarking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use frame_benchmarking::{
2727
};
2828

2929
use frame_support::{assert_err, assert_ok, traits::NoOpPoll};
30-
use frame_system::RawOrigin as SystemOrigin;
30+
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin};
3131

3232
const SEED: u32 = 0;
3333

@@ -197,7 +197,7 @@ mod benchmarks {
197197
T::Polls::create_ongoing(class.clone())
198198
.expect("Poll creation should succeed for rank 0")
199199
} else {
200-
<NoOpPoll as Polling<T>>::Index::MAX.into()
200+
<NoOpPoll<BlockNumberFor<T>> as Polling<T>>::Index::MAX.into()
201201
};
202202

203203
// Benchmark the vote logic for a positive vote (true).
@@ -255,7 +255,7 @@ mod benchmarks {
255255
T::Polls::create_ongoing(class.clone())
256256
.expect("Poll creation should succeed for rank 0")
257257
} else {
258-
<NoOpPoll as Polling<T>>::Index::MAX.into()
258+
<NoOpPoll<BlockNumberFor<T>> as Polling<T>>::Index::MAX.into()
259259
};
260260

261261
// Simulate voting by `n` members.

substrate/frame/salary/src/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl pallet_ranked_collective::Config for Test {
125125
// Members can exchange up to the rank of 2 below them.
126126
MapSuccess<EnsureRanked<Test, (), 2>, ReduceBy<ConstU16<2>>>,
127127
>;
128-
type Polls = NoOpPoll;
128+
type Polls = NoOpPoll<BlockNumberFor<Test>>;
129129
type MinRankOfClass = MinRankOfClass<MinRankOfClassDelta>;
130130
type MemberSwappedHandler = Salary;
131131
type VoteWeight = Geometric;

substrate/frame/support/src/traits/voting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ pub trait Polling<Tally> {
128128
}
129129

130130
/// NoOp polling is required if pallet-referenda functionality not needed.
131-
pub struct NoOpPoll;
132-
impl<Tally> Polling<Tally> for NoOpPoll {
131+
pub struct NoOpPoll<Moment>(core::marker::PhantomData<Moment>);
132+
impl<Tally, Moment> Polling<Tally> for NoOpPoll<Moment> {
133133
type Index = u8;
134134
type Votes = u32;
135135
type Class = u16;
136-
type Moment = u64;
136+
type Moment = Moment;
137137

138138
fn classes() -> Vec<Self::Class> {
139139
vec![]

0 commit comments

Comments
 (0)