54 releases (major breaking)

38.0.0 Sep 26, 2024
37.0.0 Jul 18, 2024
36.0.0 Jul 12, 2024
35.0.0 Jun 21, 2024
2.0.0-alpha.5 Mar 24, 2020

#7 in #candidate

Download history 36/week @ 2024-09-16 230/week @ 2024-09-23 57/week @ 2024-09-30 45/week @ 2024-10-07 113/week @ 2024-10-14 177/week @ 2024-10-21 212/week @ 2024-10-28 249/week @ 2024-11-04 20196/week @ 2024-11-11 24311/week @ 2024-11-18 27418/week @ 2024-11-25 22156/week @ 2024-12-02 26881/week @ 2024-12-09

101,957 downloads per month
Used in 9 crates (via polkadot-sdk)

Apache-2.0

2MB
36K SLoC

Scored Pool Module

The module maintains a scored membership pool. Each entity in the pool can be attributed a Score. From this pool a set Members is constructed. This set contains the MemberCount highest scoring entities. Unscored entities are never part of Members.

If an entity wants to be part of the pool a deposit is required. The deposit is returned when the entity withdraws or when it is removed by an entity with the appropriate authority.

Every Period blocks the set of Members is refreshed from the highest scoring members in the pool and, no matter if changes occurred, T::MembershipChanged::set_members_sorted is invoked. On first load T::MembershipInitialized::initialize_members is invoked with the initial Members set.

It is possible to withdraw candidacy/resign your membership at any time. If an entity is currently a member, this results in removal from the Pool and Members; the entity is immediately replaced by the next highest scoring candidate in the pool, if available.

Interface

Public Functions

  • submit_candidacy - Submit candidacy to become a member. Requires a deposit.
  • withdraw_candidacy - Withdraw candidacy. Deposit is returned.
  • score - Attribute a quantitative score to an entity.
  • kick - Remove an entity from the pool and members. Deposit is returned.
  • change_member_count - Changes the amount of candidates taken into Members.

Usage

use pallet_scored_pool::{self as scored_pool};

#[frame_support::pallet]
pub mod pallet {
    use super::*;
    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;

    #[pallet::pallet]
    pub struct Pallet<T>(_);

    #[pallet::config]
    pub trait Config: frame_system::Config + scored_pool::Config {}

    #[pallet::call]
    impl<T: Config> Pallet<T> {
        #[pallet::weight(0)]
        pub fn candidate(origin: OriginFor<T>) -> DispatchResult {
            let who = ensure_signed(origin)?;

            let _ = <scored_pool::Pallet<T>>::submit_candidacy(
                T::RuntimeOrigin::from(Some(who.clone()).into())
            );
            Ok(())
        }
    }
}

Dependencies

This module depends on the System module.

License: Apache-2.0

Release

Polkadot SDK stable2409

Dependencies

~17–31MB
~519K SLoC