Adjust validator lookups (#4975)
This commit is contained in:
parent
467dfd9820
commit
f644d8c3be
@ -98,7 +98,7 @@ function Fund ({ bestNumber, className, isOngoing, leasePeriod, value: { childKe
|
||||
: leasePeriod.currentPeriod.gt(firstSlot)
|
||||
);
|
||||
const canContribute = isOngoing && blocksLeft && !isCapped && !isWinner && retiring.isFalse;
|
||||
const canDissolve = raised.isZero() || (isRetired && isLeaseOver);
|
||||
const canDissolve = raised.isZero() || (retiring.isTrue && isLeaseOver);
|
||||
const canWithdraw = canDissolve || (!!(bestNumber && bestNumber.gt(end)) && isLeaseOver);
|
||||
|
||||
return (
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
import type { Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, BlockNumber, CandidatePendingAvailability, HeadData, Header, ParaId, ParaInfo, ParaLifecycle } from '@polkadot/types/interfaces';
|
||||
import type { Codec } from '@polkadot/types/types';
|
||||
import type { EventMapInfo, QueuedAction } from './types';
|
||||
import type { EventMapInfo, QueuedAction, ValidatorInfo } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
@ -28,7 +28,7 @@ interface Props {
|
||||
lastTimeout?: EventMapInfo;
|
||||
nextAction?: QueuedAction;
|
||||
sessionValidators?: AccountId[] | null;
|
||||
validators?: AccountId[];
|
||||
validators?: ValidatorInfo[];
|
||||
}
|
||||
|
||||
type QueryResult = [Option<HeadData>, Option<BlockNumber>, Option<ParaLifecycle>, Vec<Codec>, Vec<Codec>, Vec<Codec>, Vec<Codec>, Option<BlockNumber>, Option<CandidatePendingAvailability>, Option<ParaInfo>];
|
||||
@ -119,7 +119,7 @@ function Parachain ({ bestNumber, className = '', id, lastBacked, lastInclusion,
|
||||
);
|
||||
|
||||
const valRender = useCallback(
|
||||
() => renderAddresses(validators),
|
||||
() => renderAddresses(validators?.map(({ validatorId }) => validatorId)),
|
||||
[validators]
|
||||
);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import type { SignedBlockExtended } from '@polkadot/api-derive/types';
|
||||
import type { AccountId, CandidateReceipt, Event, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
|
||||
import type { IEvent } from '@polkadot/types/types';
|
||||
import type { ScheduledProposals } from '../types';
|
||||
import type { EventMapInfo, QueuedAction } from './types';
|
||||
import type { EventMapInfo, QueuedAction, ValidatorInfo } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
@ -31,10 +31,12 @@ interface LastEvents {
|
||||
lastTimeout: EventMap;
|
||||
}
|
||||
|
||||
type MultiResult = [AccountId[] | null, ParaValidatorIndex[][] | null, ParaValidatorIndex[] | null];
|
||||
|
||||
const EMPTY_EVENTS: LastEvents = { lastBacked: {}, lastIncluded: {}, lastTimeout: {} };
|
||||
|
||||
const optionsMulti = {
|
||||
defaultValue: [null, null] as [AccountId[] | null, ParaValidatorIndex[][] | null]
|
||||
defaultValue: [null, null, null] as MultiResult
|
||||
};
|
||||
|
||||
function includeEntry (map: EventMap, event: Event, blockHash: string, blockNumber: BN): void {
|
||||
@ -57,12 +59,17 @@ function extractScheduledIds (scheduled: ScheduledProposals[] = []): Record<stri
|
||||
}), all), {});
|
||||
}
|
||||
|
||||
function mapValidators (ids?: ParaId[], validators?: AccountId[] | null, validatorGroups?: ParaValidatorIndex[][] | null): AccountId[][] {
|
||||
return validators && validatorGroups && ids && ids.length === validatorGroups.length
|
||||
? validatorGroups.map((ids) =>
|
||||
ids
|
||||
.map((id) => validators[id.toNumber()])
|
||||
.filter((a) => a)
|
||||
function mapValidators (ids: ParaId[] | undefined, validators: AccountId[] | null, validatorGroups: ParaValidatorIndex[][] | null, activeIndices: ParaValidatorIndex[] | null): ValidatorInfo[][] {
|
||||
return activeIndices && validators && validatorGroups && ids && ids.length === validatorGroups.length
|
||||
? validatorGroups.map((indices) =>
|
||||
indices
|
||||
.map((indexActive) => [indexActive, activeIndices[indexActive.toNumber()]])
|
||||
.filter(([, a]) => a)
|
||||
.map(([indexActive, indexValidator]) => ({
|
||||
indexActive,
|
||||
indexValidator,
|
||||
validatorId: validators[indexValidator.toNumber()]
|
||||
}))
|
||||
)
|
||||
: [];
|
||||
}
|
||||
@ -122,9 +129,10 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
const bestNumber = useBestNumber();
|
||||
const lastBlock = useCall<SignedBlockExtended>(api.derive.chain.subscribeNewBlocks);
|
||||
const [{ lastBacked, lastIncluded, lastTimeout }, setLastEvents] = useState<LastEvents>(EMPTY_EVENTS);
|
||||
const [validators, validatorGroups] = useCallMulti<[AccountId[] | null, ParaValidatorIndex[][] | null]>([
|
||||
const [validators, validatorGroups, activeIndices] = useCallMulti<MultiResult>([
|
||||
api.query.session?.validators,
|
||||
api.query.paraScheduler?.validatorGroups || api.query.scheduler?.validatorGroups
|
||||
api.query.paraScheduler?.validatorGroups || api.query.scheduler?.validatorGroups,
|
||||
api.query.shared?.activeValidatorIndices
|
||||
], optionsMulti);
|
||||
|
||||
const headerRef = useRef([
|
||||
@ -147,8 +155,8 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
);
|
||||
|
||||
const validatorMap = useMemo(
|
||||
() => mapValidators(ids, validators, validatorGroups),
|
||||
[ids, validators, validatorGroups]
|
||||
() => mapValidators(ids, validators, validatorGroups, activeIndices),
|
||||
[activeIndices, ids, validators, validatorGroups]
|
||||
);
|
||||
|
||||
const knownIds = useMemo(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AccountId, BalanceOf, ParaId } from '@polkadot/types/interfaces';
|
||||
import type { AccountId, BalanceOf, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
export interface LeaseInfo {
|
||||
accountId: AccountId;
|
||||
@ -20,3 +20,9 @@ export interface EventMapInfo {
|
||||
blockNumber: BN;
|
||||
relayParent: string;
|
||||
}
|
||||
|
||||
export interface ValidatorInfo {
|
||||
indexActive: ParaValidatorIndex;
|
||||
indexValidator: ParaValidatorIndex;
|
||||
validatorId: AccountId;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user