Add ump/dmp/hrmp queue sizes (#4412)
This commit is contained in:
parent
62d1fea4f2
commit
5f3bd186c7
@ -4,7 +4,7 @@
|
||||
import type { LinkOption } from '@polkadot/apps-config/settings/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { Balance, BlockNumber, HeadData, Header, ParaId, RelayChainBlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { Codec, ITuple } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useMemo } from 'react';
|
||||
@ -22,6 +22,10 @@ interface Props {
|
||||
lastInclusion?: [string, string];
|
||||
}
|
||||
|
||||
const transformDmpUmp = {
|
||||
transform: (list: Codec[][]) => list.length
|
||||
};
|
||||
|
||||
const transformHead = {
|
||||
transform: (headData: Option<HeadData>): string | null =>
|
||||
headData.isSome
|
||||
@ -58,10 +62,14 @@ function getChainLink (endpoints: LinkOption[]): React.ReactNode {
|
||||
function Parachain ({ bestNumber, className = '', id, lastInclusion }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const { api: paraApi, endpoints } = useParaApi(id);
|
||||
const headHex = useCall<string | null>(api.query.paras.heads, [id], transformHead);
|
||||
const paraBest = useCall<BlockNumber>(paraApi?.derive.chain.bestNumber);
|
||||
const paraIssu = useCall<Balance>(paraApi?.query.balances?.totalIssuance);
|
||||
const headHex = useCall<string | null>(api.query.paras.heads, [id], transformHead);
|
||||
const updateAt = useCall<BlockNumber | null>(api.query.paras.futureCodeUpgrades, [id], transformUpgrade);
|
||||
const qDmp = useCall<number>(api.query.dmp.downwardMessageQueues, [id], transformDmpUmp);
|
||||
const qUmp = useCall<number>(api.query.dmp.relayDispatchQueues, [id], transformDmpUmp);
|
||||
const qHrmpE = useCall<number>(api.query.hrmp.hrmpEgressChannelsIndex, [id], transformDmpUmp);
|
||||
const qHrmpI = useCall<number>(api.query.hrmp.hrmpIngressChannelsIndex, [id], transformDmpUmp);
|
||||
const lastRelayNumber = useCall<BN>(lastInclusion && api.rpc.chain.getHeader, [lastInclusion && lastInclusion[1]], transformLast);
|
||||
|
||||
const blockDelay = useMemo(
|
||||
@ -88,7 +96,7 @@ function Parachain ({ bestNumber, className = '', id, lastInclusion }: Props): R
|
||||
</td>
|
||||
<td className='number media--900'>{paraBest && <>{formatNumber(paraBest)}</>}</td>
|
||||
<td className='number media--1100'>{paraIssu && <FormatBalance valueFormatted={paraIssu.toHuman()} />}</td>
|
||||
<td className='number media--1200'>
|
||||
<td className='number media--1300'>
|
||||
{updateAt && bestNumber && (
|
||||
<>
|
||||
<BlockToTime blocks={bestNumber.sub(updateAt)} />
|
||||
@ -96,6 +104,9 @@ function Parachain ({ bestNumber, className = '', id, lastInclusion }: Props): R
|
||||
</>
|
||||
)}
|
||||
</td>
|
||||
<td className='number media--1200'>
|
||||
{formatNumber(qUmp)} / {formatNumber(qDmp)} / {formatNumber(qHrmpE)} / {formatNumber(qHrmpI)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
@ -60,7 +60,8 @@ function ParachainList ({ ids }: Props): React.ReactElement<Props> {
|
||||
[t('relay parent'), undefined, 2],
|
||||
[t('chain best'), 'media--900'],
|
||||
[t('issuance'), 'media--1100'],
|
||||
[t('upgrade'), ' media--1200']
|
||||
[t('upgrade'), 'media--1300'],
|
||||
[t('ump/dmp/hrmp'), 'media--1200']
|
||||
]);
|
||||
|
||||
return (
|
||||
|
||||
@ -165,7 +165,6 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise<InjectedEx
|
||||
const defaultMethod = Object.keys(api.tx[defaultSection])[0];
|
||||
const apiDefaultTx = api.tx[defaultSection][defaultMethod];
|
||||
const apiDefaultTxSudo = (api.tx.system && api.tx.system.setCode) || apiDefaultTx;
|
||||
const isSubstrateV2 = !!Object.keys(api.consts).length;
|
||||
|
||||
setDeriveCache(api.genesisHash.toHex(), deriveMapCache);
|
||||
|
||||
@ -176,7 +175,6 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise<InjectedEx
|
||||
isApiReady: true,
|
||||
isDevelopment: isEthereum ? false : isDevelopment,
|
||||
isEthereum,
|
||||
isSubstrateV2,
|
||||
systemChain,
|
||||
systemName,
|
||||
systemVersion
|
||||
|
||||
@ -21,7 +21,6 @@ export interface ApiState {
|
||||
isApiReady: boolean;
|
||||
isDevelopment: boolean;
|
||||
isEthereum: boolean;
|
||||
isSubstrateV2: boolean;
|
||||
systemChain: string;
|
||||
systemName: string;
|
||||
systemVersion: string;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/app-democracy authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { Time } from '@polkadot/util/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -15,16 +16,17 @@ type Result = [number, string, Time];
|
||||
|
||||
const DEFAULT_TIME = new BN(6000);
|
||||
|
||||
export function useBlockTime (blocks = BN_ONE): Result {
|
||||
export function useBlockTime (blocks = BN_ONE, apiOverride?: ApiPromise): Result {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
|
||||
return useMemo(
|
||||
(): Result => {
|
||||
const a = apiOverride || api;
|
||||
const blockTime = (
|
||||
api.consts.babe?.expectedBlockTime ||
|
||||
api.consts.difficulty?.targetBlockTime ||
|
||||
api.consts.timestamp?.minimumPeriod.muln(2) ||
|
||||
a.consts.babe?.expectedBlockTime ||
|
||||
a.consts.difficulty?.targetBlockTime ||
|
||||
a.consts.timestamp?.minimumPeriod.muln(2) ||
|
||||
DEFAULT_TIME
|
||||
);
|
||||
const time = extractTime(blockTime.mul(blocks).toNumber());
|
||||
@ -45,6 +47,6 @@ export function useBlockTime (blocks = BN_ONE): Result {
|
||||
time
|
||||
];
|
||||
},
|
||||
[api, blocks, t]
|
||||
[api, apiOverride, blocks, t]
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/react-query authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
@ -8,6 +10,7 @@ import styled from 'styled-components';
|
||||
import { useBlockTime } from '@polkadot/react-hooks';
|
||||
|
||||
interface Props {
|
||||
api?: ApiPromise;
|
||||
blocks?: BN;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
@ -15,8 +18,8 @@ interface Props {
|
||||
label?: React.ReactNode;
|
||||
}
|
||||
|
||||
function BlockToTime ({ blocks, children, className = '', isInline, label }: Props): React.ReactElement<Props> | null {
|
||||
const [, text] = useBlockTime(blocks);
|
||||
function BlockToTime ({ api, blocks, children, className = '', isInline, label }: Props): React.ReactElement<Props> | null {
|
||||
const [, text] = useBlockTime(blocks, api);
|
||||
|
||||
if (blocks?.ltn(0)) {
|
||||
return null;
|
||||
|
||||
@ -14,20 +14,17 @@ interface Props {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
label?: React.ReactNode;
|
||||
value?: Moment;
|
||||
}
|
||||
|
||||
function TimeNow ({ children, className = '', label }: Props): React.ReactElement<Props> {
|
||||
const { api, isSubstrateV2 } = useApi();
|
||||
const timestamp = useCall<Moment>(api.query.timestamp.now);
|
||||
function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const timestamp = useCall<Moment>(!value && api.query.timestamp.now);
|
||||
const [now, setNow] = useState<BN | undefined>();
|
||||
|
||||
useEffect((): void => {
|
||||
setNow(
|
||||
isSubstrateV2 || !timestamp
|
||||
? timestamp
|
||||
: timestamp.muln(1000)
|
||||
);
|
||||
}, [timestamp, isSubstrateV2]);
|
||||
setNow(value || timestamp);
|
||||
}, [timestamp, value]);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user