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

Adds election provider multi-block pallet (wip) #6213

Closed
wants to merge 14 commits into from

Conversation

gpestana
Copy link
Contributor

@gpestana gpestana commented Oct 24, 2024

This PR adds the election provider multi-block pallet. It doesn't necessarily need to be audited and completed in order to merge, assuming that the multi-block types and refactors have been merged and audited (#6034).

Remove from WIP/draft once #6034 is merged/locked.

Todo before merge:

@gpestana gpestana added the T2-pallets This PR/Issue is related to a particular pallet. label Oct 24, 2024
@gpestana gpestana self-assigned this Oct 24, 2024
@gpestana gpestana requested a review from a team as a code owner October 24, 2024 09:19
@gpestana gpestana marked this pull request as draft October 24, 2024 09:19
@gpestana gpestana changed the title Adds election provider multi-block pallet Adds election provider multi-block pallet (wip) Oct 24, 2024
//! ## Pallet organization and sub-pallets
//!
//! This pallet consists of a `core` pallet and multiple sub-pallets. Conceptually, the pallets have
//! a hierarquical relationship, where the `core` pallet sets and manages shared state between all
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//! a hierarquical relationship, where the `core` pallet sets and manages shared state between all
//! a hierarchical relationship, where the `core` pallet sets and manages shared state between all

//! Even though the [`frame_election_provider_support::ElectionDataProvider`] and
//! [`frame_election_provider_support::ElectionProvider`] traits support multi-paged election, this
//! pallet only supports a single page election flow. Thus, [`Config::Pages`] must be always set to
//! one, which is asserted by the [`frame_support::traits::Hooks::integrity_test`].
Copy link
Contributor

Choose a reason for hiding this comment

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

So in short this pallet does not support multi-page election and if one wants to the multi-page election on their runtime, they should use the multi-block pallet, correct?
If it's so it'd be good to add such a mention to the doc.

//! [`verifier::SolutionDataProvider`], which is used by the [`verifier`] pallet to fetch solution
//! data to perform the solution verification.
//! - The [`unsigned`] pallet implements the unsigned phase, where block authors can compute and
//! submit through inherent paged solutions. This pallet also implements the
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding, based on https://github.com/paritytech/polkadot-sdk/blob/gpestana/pallet-epm-mb/substrate/frame/election-provider-multi-phase/src/lib.rs#L98, is that this phase is essentially as the signed one but the origins of solutions are different, is it not the case?
This description is a little unclear as-well, thus my remark here.


ensure!(
crate::Pallet::<T>::current_phase().is_signed(),
Error::<T>::NotAcceptingSubmissions
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there be a different error? e.g. CannotBailAtThisPhase

// updates metadata release strategy so that all the deposit is burned when the
// leader's data is cleared.
metadata.release_strategy = ReleaseStrategy::BurnAll;
Submissions::<T>::set_metadata(round, &leader, metadata);
Copy link
Contributor

@Zebedeusz Zebedeusz Nov 4, 2024

Choose a reason for hiding this comment

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

This will fail because set_metadata checks for the leader to be present in SortedScores but he (that entry) was already removed in line 828 by Submissions::<T>::take_leader_score(round).

"error fetching the desired targets from the election data provider {}",
err
);
None
Copy link
Contributor

@Zebedeusz Zebedeusz Nov 5, 2024

Choose a reason for hiding this comment

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

Will "None" be ever returned? I wrote a test and it panics at "defensive" already

if Self::ensure_score_quality(claimed_score).is_err() {
Self::deposit_event(Event::<T>::VerificationFailed(
crate::Pallet::<T>::msp(),
FeasibilityError::ScoreTooLow,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be the exact error returned from ensure_score_quality instead?

/// better than the minimum score, of no queued solution exists.
/// 5. Submits the paged solution as an inherent through the [`Call::submit_page_unsigned`]
/// callable.
pub fn do_sync_offchain_worker(_now: BlockNumberFor<T>) -> Result<(), OffchainMinerError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

_now parameter is unused. Is it needed here?

type MaxWinnersPerPage: Get<u32>;
type MaxBackersPerWinner: Get<u32>;

type VoterSnapshotPerBlock: Get<u32>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be called ...PerPage rather?
Maybe stupid question but line 146 with argument all_voter_pages made me think this way: it's a vector with max length equal to T::Pages so each entry in this vector should be "per page" therefore each entry should have at most N MinerVoterOf entities, where N is a cap on these voters "per page".


if let Status::Ongoing(current_page) = <VerificationStatus<T>>::get() {
let maybe_page_solution =
<T::SolutionDataProvider as SolutionDataProvider>::get_paged_solution(current_page);
Copy link
Contributor

Choose a reason for hiding this comment

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

get_paged_solution returns the leader's solution so if it's none (no leader solution) T::SolutionDataProvider::report_result will panic because it does Submissions::<T>::take_leader_score which already is none.
So maybe report_result shouldn't check for the leader's score or there is some other change needed in the logic.

@kianenigma kianenigma changed the base branch from master to gpestana/epm-mb January 17, 2025 13:45
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/12830293178
Failed job name: fmt

@kianenigma
Copy link
Contributor

I will re-open this from another branch. Thank you @gpestana for your contributions here!

@kianenigma kianenigma closed this Jan 21, 2025
@seadanda
Copy link
Contributor

Superseded by #7282

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
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants