Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoOp Impl Polling Trait #5311

Merged
merged 27 commits into from
Nov 12, 2024
Merged

NoOp Impl Polling Trait #5311

merged 27 commits into from
Nov 12, 2024

Conversation

Doordashcon
Copy link
Contributor

@Doordashcon Doordashcon commented Aug 10, 2024

Adds NoOp implementation for the Polling trait and updates benchmarks in pallet-ranked-collective.

@Doordashcon Doordashcon marked this pull request as ready for review September 3, 2024 09:30
@Doordashcon Doordashcon requested a review from a team as a code owner September 3, 2024 09:30
@bkchr
Copy link
Member

bkchr commented Sep 3, 2024

@Doordashcon do you have any reasoning for this?

@Doordashcon
Copy link
Contributor Author

Doordashcon commented Sep 3, 2024

@bkchr just a follow up on this?
polkadot-fellows/runtimes#347 (comment)

@bkchr
Copy link
Member

bkchr commented Sep 10, 2024

@bkchr just a follow up on this?
polkadot-fellows/runtimes#347 (comment)

The comment is saying that this no-op should be implemented on () or some special NoOp struct.

@Doordashcon Doordashcon changed the title No-op Impl Polling Trait NoOp Impl Polling Trait Sep 10, 2024
@Doordashcon
Copy link
Contributor Author

Doordashcon commented Sep 10, 2024

Implemented Polling for () and updated the tests where we have methods unimplemented!().

@bkchr bkchr requested a review from muharem September 10, 2024 20:40
@bkchr bkchr added the T2-pallets This PR/Issue is related to a particular pallet. label Sep 10, 2024
@paritytech-review-bot paritytech-review-bot bot requested a review from a team September 13, 2024 17:56
@Doordashcon
Copy link
Contributor Author

Added Default bound.

please review @muharem @bkchr

@bkchr
Copy link
Member

bkchr commented Sep 14, 2024

@Doordashcon can you please fix it as done in this pr #3049?

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looking good, just some nitpicks

@@ -139,7 +139,7 @@ pub struct TrackInfo<Balance, Moment> {
/// Information on the voting tracks.
pub trait TracksInfo<Balance, Moment> {
/// The identifier for a track.
type Id: Copy + Parameter + Ord + PartialOrd + Send + Sync + 'static + MaxEncodedLen;
type Id: Copy + Parameter + Ord + PartialOrd + Send + Sync + 'static + MaxEncodedLen + Default;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need Default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id -----> tracks, tracks -----> classes in pallet_referenda's implementation of the Polling trait.

fn classes() -> Vec<Self::Class> {
T::Tracks::tracks().iter().map(|x| x.0).collect()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change (major bump in the prdoc), since it can break existing code.
If it is something that is only needed for benchmarking, then the benchmark can use a where clause to only work if the Id is Default, but not requiring it on the trait itself. (the trait does not care about benchmarks).

For example like here:

<T as Config>::MaxMessagePayloadSize: Get<u32>,

substrate/frame/support/src/traits/voting.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
@paritytech-review-bot paritytech-review-bot bot requested a review from a team September 24, 2024 19:47
@Doordashcon
Copy link
Contributor Author

@bkchr @muharem please review

@Doordashcon
Copy link
Contributor Author

Doordashcon commented Oct 5, 2024

It is known that both extrinsics each involve a single read operation. This can be manually accounted for, rather than relying on the default value for a non existent class. Would you agree with this approach @bkchr?

let class_exists = T::Polls::classes().into_iter().next().is_some();
        let class = if class_exists {
            T::Polls::classes().into_iter().next().unwrap() // Assuming there's at least one class here
        } else {
            return Err(BenchmarkError::Override(BenchmarkResult::from_weight(
                T::DbWeight::get().reads(1),
            )));
      };

@bkchr
Copy link
Member

bkchr commented Oct 7, 2024

See this.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team October 12, 2024 20:29
@Doordashcon
Copy link
Contributor Author

please review @bkchr

I saw no other way to create an invalid poll for a NoOp Poll than adding From<u8> bound to the Index type

@muharem muharem self-requested a review October 28, 2024 10:54
@Doordashcon
Copy link
Contributor Author

Doordashcon commented Nov 7, 2024

Hopefully we get to backport the Secretary Collective after this is merged @bkchr @muharem

substrate/frame/support/src/traits/voting.rs Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
substrate/frame/ranked-collective/src/benchmarking.rs Outdated Show resolved Hide resolved
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to approve since am async, but could still be worth to try and remove the additional added requirements in the traits.

@Doordashcon
Copy link
Contributor Author

Thanks for the benchmarking tip @ggwpez should be ready to merge now!

@ggwpez ggwpez added this pull request to the merge queue Nov 12, 2024
Merged via the queue into paritytech:master with commit 9f603b1 Nov 12, 2024
166 of 197 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants