Chilled filtering adjustments (no-auto, recent Substrate) (#8551)
This commit is contained in:
parent
08fa9b3f5c
commit
2bef228fd0
@ -24,21 +24,25 @@ function extractState (api: ApiPromise, stashId: string, slashes: Option<Slashin
|
||||
const max = api.consts.staking?.maxNominatorRewardedPerValidator;
|
||||
|
||||
// chilled
|
||||
const nomsChilled = nominees.filter((_, index): boolean => {
|
||||
if (slashes[index].isNone) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { lastNonzeroSlash } = slashes[index].unwrap();
|
||||
|
||||
// to be chilled, we have a slash era and it is later than the submission era
|
||||
// (if submitted in the same, the nomination will only take effect after the era)
|
||||
return !lastNonzeroSlash.isZero() && lastNonzeroSlash.gt(submittedIn);
|
||||
});
|
||||
// NOTE With the introduction of the SlashReported event,
|
||||
// nominators are not auto-chilled on validator slash
|
||||
const nomsChilled = !api.events.staking.SlashReported
|
||||
? nominees.filter((_, index) =>
|
||||
slashes[index].isNone
|
||||
? false
|
||||
// to be chilled, we have a slash era and it is later than the submission era
|
||||
// (if submitted in the same, the nomination will only take effect after the era)
|
||||
: slashes[index].unwrap().lastNonzeroSlash.gt(submittedIn)
|
||||
)
|
||||
: [];
|
||||
|
||||
// all nominations that are oversubscribed
|
||||
const nomsOver = exposures
|
||||
.map(({ others }) => others.sort((a, b) => (b.value?.unwrap() || BN_ZERO).cmp(a.value?.unwrap() || BN_ZERO)))
|
||||
.map(({ others }) =>
|
||||
others.sort((a, b) =>
|
||||
(b.value?.unwrap() || BN_ZERO).cmp(a.value?.unwrap() || BN_ZERO)
|
||||
)
|
||||
)
|
||||
.map((others, index) =>
|
||||
!max || max.gtn(others.map(({ who }) => who.toString()).indexOf(stashId))
|
||||
? null
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
// Copyright 2017-2022 @polkadot/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { SlashingSpans } from '@polkadot/types/interfaces';
|
||||
import type { NominatedBy as NominatedByType } from '../../types';
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { AddressMini, ExpanderScroll } from '@polkadot/react-components';
|
||||
import { useApi } from '@polkadot/react-hooks';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../../translate';
|
||||
@ -35,12 +37,13 @@ function extractFunction (all: string[]): null | [number, () => React.ReactNode[
|
||||
: null;
|
||||
}
|
||||
|
||||
function extractChilled (nominators: NominatedByType[] = [], slashingSpans?: SlashingSpans | null): Chilled {
|
||||
const chilled = slashingSpans
|
||||
function extractChilled (api: ApiPromise, nominators: NominatedByType[] = [], slashingSpans?: SlashingSpans | null): Chilled {
|
||||
// NOTE With the introduction of the SlashReported event,
|
||||
// nominators are not auto-chilled on validator slash
|
||||
const chilled = slashingSpans && !api.events.staking.SlashReported
|
||||
? nominators
|
||||
.filter(({ submittedIn }) =>
|
||||
!slashingSpans.lastNonzeroSlash.isZero() &&
|
||||
slashingSpans.lastNonzeroSlash.gte(submittedIn)
|
||||
slashingSpans.lastNonzeroSlash.gt(submittedIn)
|
||||
)
|
||||
.map(({ nominatorId }) => nominatorId)
|
||||
: [];
|
||||
@ -57,10 +60,11 @@ function extractChilled (nominators: NominatedByType[] = [], slashingSpans?: Sla
|
||||
|
||||
function NominatedBy ({ nominators, slashingSpans }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
|
||||
const { active, chilled } = useMemo(
|
||||
() => extractChilled(nominators, slashingSpans),
|
||||
[nominators, slashingSpans]
|
||||
() => extractChilled(api, nominators, slashingSpans),
|
||||
[api, nominators, slashingSpans]
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user