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).
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
ElectionManagervia the pallet’sConfig::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 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 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.
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
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>
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>
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>>)
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)
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§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).
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)>
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
type PenaltyContext = <T as Config>::PenaltyContext
Context provided to the penalty plugin model for transformation.
Source§type PenaltyModel = <T as Config>::PenaltyModel
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
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>)
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)
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 transform_penalty(input: Self::PenaltyFor) -> Self::PenaltyFor
fn transform_penalty(input: Self::PenaltyFor) -> Self::PenaltyFor
Self::PenaltyModel plugin. Read moreSource§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).
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
- This implementation does not compute reward shares.
- Reward distribution logic is delegated to:
- This layer only exposes:
- The payout context
- The eligible payee set
- A scheduling hook for rewards
Source§type AuthorPointsAdapter = <T as Config>::PointsAdapter
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 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
type PayoutContext = <T as Config>::InflationContext
Context used by the inflation plugin model.
Source§type PayoutModel = <T as Config>::InflationModel
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 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
type PayeeContext = <T as Config>::RewardContext
Context supplied to the reward plugin model.
Source§type PayeeModel = <T as Config>::RewardModel
type PayeeModel = <T as Config>::RewardModel
Reward plugin model used to translate points into payouts.
Source§fn payout_via() -> AssetOf<T>
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
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
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>)
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)
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_process(input: Asset) -> Asset
fn payout_process(input: Asset) -> Asset
Self::PayoutModel plugin output function.
Utilizes the plugin model’s context Self::PayoutContextSource§fn payee_process(input: (Asset, Self::PayoutFor)) -> Self::PayeeList
fn payee_process(input: (Asset, Self::PayoutFor)) -> Self::PayeeList
Self::PayeeModel plugin output function.
Utilizes the plugin model’s context Self::PayeeContextAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T, U, Tag> IntoTag<U, Tag> for Twhere
U: FromTag<T, Tag>,
Tag: DiscriminantTag,
impl<T, U, Tag> IntoTag<U, Tag> for Twhere
U: FromTag<T, Tag>,
Tag: DiscriminantTag,
§impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T> IsType<T> for T
impl<T> IsType<T> for T
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T, Time> Logging<Time> for Twhere
Time: Time,
impl<T, Time> Logging<Time> for Twhere
Time: Time,
Source§const FALLBACK_TARGET: &'static str = "routine"
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
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
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
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
Source§fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
Source§fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<fn(Timestamp, &Self::Level, &str, &str) -> String>,
) -> Self::Loggerwhere
Self: Sized,
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
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 Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.