Struct Internals

Source
pub(crate) struct Internals<T: Config>(PhantomData<T>);
Expand description

Internal helper struct for implementing not-exposable blockchain trait operations.

Internals implements the blockchain low-level helper traits:

Tuple Fields§

§0: PhantomData<T>

Trait Implementations§

Source§

impl<T: Config> ElectAuthors<<T as Config>::AccountId, <<T as Config>::ElectionAdapter as ElectionManager<<T as Config>::AccountId>>::ElectionWeightOf> for Internals<T>

Implementation of the ElectAuthors trait for the pallet internal type (not exposable).

This implementation bridges the generic ElectAuthors abstraction with the pallet’s internal affidavit and role-management infrastructure, coordinating candidate selection, time-gated election execution, and result revelation for upcoming sessions.

§Design Notes
  • Elections are session-scoped and always target the upcoming session.
  • Only authors who have successfully submitted affidavits are eligible.
  • All election logic is time-gated and derived from session timing, affidavit windows, and election offsets.
  • This layer is deterministic; it does not perform probabilistic or stateful election logic.
§Implementation Notes
  • This implementation does not execute the election algorithm itself.

  • All ranking, scoring, and selection logic is delegated to the configured ElectionManager via the pallet’s Config::ElectionAdapter.

  • This layer is responsible only for:

    • Validating election timing
    • Preparing candidate inputs
    • Revealing results from the election manager
Source§

type Candidates = <<T as Config>::ElectionAdapter as ElectionManager<<T as Config>::AccountId>>::Params

Type representing the prepared election candidates.

Typically a vector of author’s ID and their corresponding election weights.

Source§

type Elected = <<T as Config>::ElectionAdapter as ElectionManager<<T as Config>::AccountId>>::Elected

Type representing the final elected author set.

Typically a vector of author IDs.

Source§

fn prepare_authors(candidates: Self::Candidates) -> DispatchResult

Prepares election candidates via the configured election manager.

  • Acts as a thin delegation layer to ElectionManager::prepare.
  • Any failure here prevents election execution.
  • Typically runs the election algorithm and stores the election result.
  • Inconsistencies return explicit errors.
Source§

fn can_process_election(_runner: &Option<AuthorOf<T>>) -> DispatchResult

Checks whether the election can be processed at the current block.

§Parameters
  • runner: Optional executor of the election (runtime or author-driven). This is not validated here, but is assumed to be the entity responsible for executing the election, as permitted by the caller.
§Validation
  • Ensures the affidavit window is valid (start < end).
  • Ensures the current block is within the affidavit window.
  • Ensures the election window has started.
  • Ensures the election has not yet ended (bounded by affidavit end).

Violations return explicit, user-facing errors.

Source§

fn prepare_candidates() -> Result<Self::Candidates, DispatchError>

Prepares the final list of candidates for election.

§Overview
  • Iterates all affidavits submitted for the upcoming session.
  • Extracts and normalizes each author’s election weights.
  • Produces a deterministic candidate list for the election manager.
§Notes
  • Only affidavit-submitting authors are included.
  • This function performs no ranking or filtering.
  • Ordering guarantees are provided by downstream election logic.
Source§

fn reveal() -> Option<Self::Elected>

Reveals the elected authors from the underlying election manager.

Acts as a thin delegation layer to ElectionManager::reveal.

§Failure Semantics

This may return None if:

  • The election was never executed
  • Preparation failed
  • Minimum candidate constraints were not met
§Caller Responsibility

Callers must handle the None case gracefully, typically by retaining the previously elected author set.

Source§

fn on_elect_success(runner: &Option<AuthorOf<T>>)

Hook invoked after a successful election preparation.

Emits a Event::ElectedInstance event if Config::EmitEvents is true.

Source§

fn on_elect_fail(runner: &Option<AuthorOf<T>>, error: DispatchError)

Hook invoked when an election attempt fails.

Emits a Event::ElectionAttemptFailed event if Config::EmitEvents is true.

Source§

fn prepare_election(runner: &Option<Author>) -> Result<(), DispatchError>

High-level orchestration function for running the entire election flow. Read more
Source§

impl<T: Config> PenalizeAuthors<<T as Config>::AccountId, <<T as Config>::RoleAdapter as CompensateRoles<<T as Config>::AccountId>>::Ratio> for Internals<T>

Implementation of the PenalizeAuthors trait for the pallet internal type (not-exposable).

This implementation bridges author offence signals with the protocol’s penalty and slashing mechanisms, enabling penalties to be scheduled and processed according to runtime-defined rules.

Penalties, like rewards, follow a deferred enforcement model. They are recorded and transformed first, then enforced later by downstream role and penalty management logic.

§Design Notes
  • Penalties are author-scoped and apply to active roles.
  • Enforcement is scheduled, not immediate.
  • Multiple penalties may be:
    • Aggregated
    • Scaled
    • Capped
    • Reverted prior to final enforcement.
  • Penalty values are interpreted as inputs, not final amounts.
  • Transformation and enforcement are governed by runtime-configured penalty models for flexibility and governance control.
§Implementation Notes
  • This layer does not detect offences or compute severity.
  • It does not finalize or immediately apply penalties.
  • All penalty logic is delegated to:
  • This implementation guarantees deterministic, auditable scheduling of penalties without side effects.
Source§

type PenaltyFor = Vec<(<T as Config>::AccountId, <<T as Config>::RoleAdapter as CompensateRoles<<T as Config>::AccountId>>::Ratio)>

Mapping of authors to their applied penalties (percentage typically).

Source§

type PenaltyContext = <T as Config>::PenaltyContext

Context provided to the penalty plugin model for transformation.

Source§

type PenaltyModel = <T as Config>::PenaltyModel

Plugin Model responsible for transforming raw penalties according to runtime-defined rules (e.g. caps, scaling, thresholds).

Source§

fn penalize(who: &AuthorOf<T>, penalty: PenaltyOf<T>) -> DispatchResult

Applies a penalty to the given author.

Acts as a thin delegation layer to CompensateRoles::penalize.

§Semantics
  • Penalties are scheduled, not applied immediately.
  • Downstream logic may:
    • Aggregate multiple penalties
    • Scale or cap penalties
    • Delay or revert enforcement prior to finalization
§Notes
  • This function does not persist offence metadata.
  • Offence detection and validation are the responsibility of the caller.
§Errors

Returns a DispatchError if penalty scheduling fails.

Source§

fn on_penalty_success(who: &AuthorOf<T>, penalty: PenaltyOf<T>)

Hook invoked after a penalty is successfully applied to an author.

This hook emits the Penalized event, reflecting the penalty enforced against the author.

Source§

fn on_penalty_fail(who: &AuthorOf<T>, error: DispatchError)

Hook invoked when applying a penalty to an author fails.

This hook emits the PenaltyFailed event, reflecting the error that prevented the penalty from being applied.

Source§

fn penalize_authors(towards: Self::PenaltyFor)

Apply penalties to a list of authors. Read more
Source§

fn transform_penalty(input: Self::PenaltyFor) -> Self::PenaltyFor

Transforms raw penalties using the Self::PenaltyModel plugin. Read more
Source§

impl<T: Config> RewardAuthors<<T as Config>::AccountId, <<T as Config>::RoleAdapter as RoleManager<<T as Config>::AccountId>>::Asset, <T as Config>::Points> for Internals<T>

Implementation of the RewardAuthors trait for the pallet internal type (not exposable).

This implementation bridges abstract author points with the protocol’s reward and inflation mechanisms, translating session-scoped behavioural signals into scheduled economic rewards.

This layer does not mint, transfer, or finalize rewards directly. Instead, it provides deterministic inputs to downstream reward logic owned by the configured RoleManager adapters.

§Design Notes
  • Rewards are derived from session-scoped point accumulation.
  • Points are interpreted as relative behavioural weights, not absolute reward amounts.
  • The payout context is configurable and may be based on:
    • Total token issuance (inflation-based) or,
    • Total backing + collateral stake (stake-weighted)
  • All reward operations must remain deterministic, auditable, and reversible until finalization.
§Implementation Notes
Source§

type AuthorPointsAdapter = <T as Config>::PointsAdapter

Adapter used to query accumulated author points.

Source§

type PayoutFor = Vec<(<T as Config>::AccountId, <T as Config>::Points)>

Type representing authors eligible for payout and their points.

Typically a vector of author’s ID and their correspoinding points.

Source§

type PayoutContext = <T as Config>::InflationContext

Context used by the inflation plugin model.

Source§

type PayoutModel = <T as Config>::InflationModel

Inflation plugin model used to derive reward budgets.

Source§

type PayeeList = Vec<(<T as Config>::AccountId, <<T as Config>::RoleAdapter as RoleManager<<T as Config>::AccountId>>::Asset)>

Type representing the set of reward payees.

Typically a vector of author’s ID and their correspoinding reward asset amount.

Source§

type PayeeContext = <T as Config>::RewardContext

Context supplied to the reward plugin model.

Source§

type PayeeModel = <T as Config>::RewardModel

Reward plugin model used to translate points into payouts.

Source§

fn payout_via() -> AssetOf<T>

Returns the total asset context used to compute rewards.

§Semantics

Depending on configuration, this returns:

  • Total token issuance (supply-based inflation), or
  • Total backing + collateral stake (stake-weighted inflation)
§Notes
  • This value represents the upper bound for reward calculation.
  • It does not imply immediate minting or transfer.
Source§

fn reward(who: &AuthorOf<T>, value: AssetOf<T>) -> DispatchResult

Schedules a reward for the given author.

Acts as a thin delegation layer to CompensateRoles::reward.

§Semantics
  • This function does not finalize the reward.
  • Rewards are scheduled with best-effort precision.
  • Downstream logic may:
    • Aggregate
    • Adjust
    • Revert the scheduled reward before finalization.
§Errors

Returns a DispatchError if reward scheduling fails.

Source§

fn payout_for() -> Self::PayoutFor

Returns the set of authors eligible for payout and their accumulated points for the current session.

§Notes
  • This function is expected to be called at session end.
  • Calling it earlier may yield partial or unstable results.
  • The returned data is treated as immutable for reward computation.
Source§

fn on_reward_success(who: &AuthorOf<T>, value: AssetOf<T>)

Hook invoked after a reward is successfully applied to an author.

This hook emits the Rewarded event, reflecting the distributed reward amount for the given author.

Source§

fn on_reward_fail(who: &AuthorOf<T>, error: DispatchError)

Hook invoked when applying a reward to an author fails.

This hook emits the RewardFailed event, reflecting the error that prevented the reward from being applied.

Source§

fn payout() -> Asset

Computes the final total payout for the current reward cycle. Read more
Source§

fn payout_process(input: Asset) -> Asset

Self::PayoutModel plugin output function. Utilizes the plugin model’s context Self::PayoutContext
Source§

fn payee_process(input: (Asset, Self::PayoutFor)) -> Self::PayeeList

Self::PayeeModel plugin output function. Utilizes the plugin model’s context Self::PayeeContext
Source§

fn reward_authors()

Distributes rewards to authors based on their points and available payout. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Internals<T>

§

impl<T> RefUnwindSafe for Internals<T>
where T: RefUnwindSafe,

§

impl<T> Send for Internals<T>
where T: Send,

§

impl<T> Sync for Internals<T>
where T: Sync,

§

impl<T> Unpin for Internals<T>
where T: Unpin,

§

impl<T> UnwindSafe for Internals<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CheckedConversion for T

§

fn checked_from<T>(t: T) -> Option<Self>
where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
§

fn checked_into<T>(self) -> Option<T>
where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> IntoKey<U> for T
where U: FromKey<T>,

§

fn into_key(self) -> U

Source§

impl<T, U, Tag> IntoTag<U, Tag> for T
where U: FromTag<T, Tag>, Tag: DiscriminantTag,

Source§

fn into_tag(self) -> U

§

impl<Src, Dest> IntoTuple<Dest> for Src
where Dest: FromTuple<Src>,

§

fn into_tuple(self) -> Dest

§

impl<T> IsType<T> for T

§

fn from_ref(t: &T) -> &T

Cast reference.
§

fn into_ref(&self) -> &T

Cast reference.
§

fn from_mut(t: &mut T) -> &mut T

Cast mutable reference.
§

fn into_mut(&mut self) -> &mut T

Cast mutable reference.
§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

Source§

impl<T, Time> Logging<Time> for T
where Time: Time,

Source§

const FALLBACK_TARGET: &'static str = "routine"

Default logging target if none is provided.

Most routines, especially offchain workers or background tasks, use this target for simplicity.

It allows a consistent place to look for routine logs without requiring every call to specify a target.

Note: This target is only a conveninence and may be somewhat vague. To ensure errors can still be traced accurately, the logged messages should include additional metadata (e.g., module name, error index, or contextual info) so that the source of the error can be identified even if the target is generic.

Source§

type Logger = DispatchError

The type taken and returned for logging.

We simply return the same [DispatchError] that was logged, so logging does not change control flow or error propagation.

DispatchError is used because in Substrate it encompasses all runtime errors - including module errors, token errors, arithmetic issues, and transactional boundaries - making it the universal substrate-side error representation.

Source§

type Level = LogLevel

The log level type.

We use the LogLevel enum to standardize severity levels (Info, Warn, Error, Debug) across all routine logs.

Source§

fn log( level: <T as Logging<Time>>::Level, err: &<T as Logging<Time>>::Logger, timestamp: Time, target: Option<&str>, fmt: Option<fn(Time, &<T as Logging<Time>>::Level, &str, &str) -> String>, ) -> <T as Logging<Time>>::Logger

Core logging function that all helpers delegate to. Read more
Source§

fn info( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs an info-level message. Read more
Source§

fn warn( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs a warning-level message. Read more
Source§

fn error( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs an error-level message. Read more
Source§

fn debug( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>, ) -> Self::Logger
where Self: Sized,

Logs a debug-level message. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SaturatedConversion for T

§

fn saturated_from<T>(t: T) -> Self
where Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
§

fn saturated_into<T>(self) -> T
where Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T, U> TryIntoKey<U> for T
where U: TryFromKey<T>,

§

type Error = <U as TryFromKey<T>>::Error

§

fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>

§

impl<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
§

impl<T, S> UniqueSaturatedInto<T> for S
where T: Bounded, S: TryInto<T>,

§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<Provider, Discriminant, T> DelegateVirtualDynBound<Provider, Discriminant> for T
where Provider: VirtualDynBound<Discriminant>, Discriminant: DiscriminantTag,

Source§

impl<Provider, Discriminant, T> DelegateVirtualStaticBound<Provider, Discriminant> for T
where Provider: VirtualStaticBound<Discriminant>, Discriminant: DiscriminantTag,

§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeRefUnwindSafe for T
where T: RefUnwindSafe,